Skip to main content

Sst

Struct Sst 

Source
pub struct Sst<Sp, Sa, C, P, N = LinearScan<<Sp as StateSpace>::State>>
where Sp: StateSpace, P: Propagator<Sp>,
{ /* private fields */ }
Expand description

SST: an RRT-like tree grown by random forward propagation, kept sparse by witnesses.

Each iteration picks the cheapest active node near a goal-biased sample, applies a random control for a random number of integration steps, and keeps the new node only if it is the cheapest node near its witness; the previous representative then becomes inactive and is never expanded again (Li, Littlefield and Bekris 2016). SST is asymptotically near-optimal; with an SstStarSchedule it becomes SST*, which is asymptotically optimal.

The cost is the total control duration. Sst::best_trajectory keeps the best solution found so far, so its cost never increases.

Inactive nodes stay only as long as they are ancestors of other nodes: an inactive leaf is freed at once, and so is every ancestor that becomes an inactive leaf in turn (Li et al. 2016, Algorithm 6). Memory therefore tracks the active nodes and their branches, not the iteration count. Freed node ids are reused. The cheapest goal node is never freed while it is the best solution, so Sst::best_trajectory stays available.

§Examples

use rand_core::{Rng, SeedableRng};
use sampling_planning::{
    Euclidean, GoalRegion, UniformBox, Validity, ValidityChecker, unit_f64,
    kinodynamic::{KinodynamicProblem, Propagator, Sst, SstConfig},
};

/// Free space everywhere.
struct Free;

impl ValidityChecker<Euclidean<2>> for Free {
    fn check_state(&self, _: &[f64; 2]) -> Validity {
        Validity::Valid
    }

    fn check_motion(&self, _: &Euclidean<2>, _: &[f64; 2], _: &[f64; 2]) -> Validity {
        Validity::Valid
    }
}

/// A point that moves with a velocity of at most 1 per axis.
struct Velocity;

impl Propagator<Euclidean<2>> for Velocity {
    type Control = [f64; 2];

    fn control_dimension(&self) -> usize {
        2
    }

    fn sample_control<R: Rng + ?Sized>(&mut self, rng: &mut R) -> [f64; 2] {
        [2.0 * unit_f64(rng) - 1.0, 2.0 * unit_f64(rng) - 1.0]
    }

    fn propagate(&self, _: &Euclidean<2>, from: &[f64; 2], u: &[f64; 2], dt: f64) -> [f64; 2] {
        [from[0] + u[0] * dt, from[1] + u[1] * dt]
    }
}

let problem = KinodynamicProblem {
    space: Euclidean::<2>,
    sampler: UniformBox::new([0.0, 0.0], [10.0, 10.0]),
    checker: Free,
    propagator: Velocity,
    start: [1.0, 1.0],
    goal: GoalRegion::new([9.0, 9.0], 0.5),
};

let mut sst = Sst::new(problem, SstConfig::new(1.0, 0.3, 0.1, 10)).expect("valid");
sst.run(5000, &mut rand_pcg::Pcg64Mcg::seed_from_u64(1));

let trajectory = sst.best_trajectory().expect("free space");
assert_eq!(trajectory.controls.len() + 1, trajectory.states.len());

Implementations§

Source§

impl<Sp, Sa, C, P> Sst<Sp, Sa, C, P>
where Sp: StateSpace, Sa: Sampler<Sp::State>, C: ValidityChecker<Sp>, P: Propagator<Sp>,

Source

pub fn new( problem: KinodynamicProblem<Sp, Sa, C, P>, config: SstConfig, ) -> Result<Self, Error>

Creates a planner with LinearScan indices.

§Errors
Source§

impl<Sp, Sa, C, P, N> Sst<Sp, Sa, C, P, N>
where Sp: StateSpace, Sa: Sampler<Sp::State>, C: ValidityChecker<Sp>, P: Propagator<Sp>, N: RemovableNeighbors<Sp> + Clone,

Source

pub fn with_nearest_neighbors( problem: KinodynamicProblem<Sp, Sa, C, P>, config: SstConfig, nn: N, ) -> Result<Self, Error>

Creates a planner; the active-node and witness indices are clones of the given empty index.

§Errors
Source

pub fn step<R: Rng + ?Sized>(&mut self, rng: &mut R) -> bool

Runs one iteration. Returns whether a node was added.

Source

pub fn run<R: Rng + ?Sized>(&mut self, iterations: usize, rng: &mut R)

Runs iterations iterations.

Source

pub fn best_trajectory(&self) -> Option<Trajectory<Sp::State, P::Control>>

The cheapest trajectory into the goal region found so far, or None if the goal was not reached yet. Its cost never increases as iterations run.

Source

pub fn node_count(&self) -> usize

The number of stored nodes: active nodes, the inactive ancestors they still need, the root and the best goal node. Freed inactive leaves are not counted.

Source

pub fn active_count(&self) -> usize

The number of active nodes, which equals the number of witnesses.

Source

pub const fn radii(&self) -> (f64, f64)

The current selection and pruning radii; they shrink over time under SST*.

Trait Implementations§

Source§

impl<Sp, Sa: Clone, C: Clone, P, N: Clone> Clone for Sst<Sp, Sa, C, P, N>
where Sp: StateSpace + Clone, P: Propagator<Sp> + Clone, Sp::State: Clone, P::Control: Clone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<Sp, Sa, C, P, N> Forget for Sst<Sp, Sa, C, P, N>

§

impl<Sp, Sa, C, P, N> Freeze for Sst<Sp, Sa, C, P, N>
where KinodynamicProblem<Sp, Sa, C, P>: Freeze, Nodes<<Sp as StateSpace>::State, <P as Propagator<Sp>>::Control>: Freeze, N: Freeze, Vec<Witness<<Sp as StateSpace>::State>>: Freeze,

§

impl<Sp, Sa, C, P, N> Move for Sst<Sp, Sa, C, P, N>

§

impl<Sp, Sa, C, P, N> RefUnwindSafe for Sst<Sp, Sa, C, P, N>
where KinodynamicProblem<Sp, Sa, C, P>: RefUnwindSafe, Nodes<<Sp as StateSpace>::State, <P as Propagator<Sp>>::Control>: RefUnwindSafe, N: RefUnwindSafe, Vec<Witness<<Sp as StateSpace>::State>>: RefUnwindSafe,

§

impl<Sp, Sa, C, P, N> Send for Sst<Sp, Sa, C, P, N>
where N: Send, KinodynamicProblem<Sp, Sa, C, P>: Send, Nodes<<Sp as StateSpace>::State, <P as Propagator<Sp>>::Control>: Send, Vec<Witness<<Sp as StateSpace>::State>>: Send,

§

impl<Sp, Sa, C, P, N> Sync for Sst<Sp, Sa, C, P, N>
where N: Sync, KinodynamicProblem<Sp, Sa, C, P>: Sync, Nodes<<Sp as StateSpace>::State, <P as Propagator<Sp>>::Control>: Sync, Vec<Witness<<Sp as StateSpace>::State>>: Sync,

§

impl<Sp, Sa, C, P, N> Unpin for Sst<Sp, Sa, C, P, N>
where N: Unpin, KinodynamicProblem<Sp, Sa, C, P>: Unpin, Nodes<<Sp as StateSpace>::State, <P as Propagator<Sp>>::Control>: Unpin, Vec<Witness<<Sp as StateSpace>::State>>: Unpin,

§

impl<Sp, Sa, C, P, N> UnsafeUnpin for Sst<Sp, Sa, C, P, N>
where KinodynamicProblem<Sp, Sa, C, P>: UnsafeUnpin, Nodes<<Sp as StateSpace>::State, <P as Propagator<Sp>>::Control>: UnsafeUnpin, N: UnsafeUnpin, Vec<Witness<<Sp as StateSpace>::State>>: UnsafeUnpin,

§

impl<Sp, Sa, C, P, N> UnwindSafe for Sst<Sp, Sa, C, P, N>
where KinodynamicProblem<Sp, Sa, C, P>: UnwindSafe, Nodes<<Sp as StateSpace>::State, <P as Propagator<Sp>>::Control>: UnwindSafe, N: UnwindSafe, Vec<Witness<<Sp as StateSpace>::State>>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.