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>
impl<Sp, Sa, C, P> Sst<Sp, Sa, C, P>
Sourcepub fn new(
problem: KinodynamicProblem<Sp, Sa, C, P>,
config: SstConfig,
) -> Result<Self, Error>
pub fn new( problem: KinodynamicProblem<Sp, Sa, C, P>, config: SstConfig, ) -> Result<Self, Error>
Creates a planner with LinearScan indices.
§Errors
Error::InvalidStartif the start state is not valid.Error::GoalBiasOutOfRange,Error::InvalidRadius,Error::InvalidPropagationorError::InvalidScheduleif a config field is out of its documented range.
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,
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,
Sourcepub fn with_nearest_neighbors(
problem: KinodynamicProblem<Sp, Sa, C, P>,
config: SstConfig,
nn: N,
) -> Result<Self, Error>
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
Error::InvalidStartif the start state is not valid.Error::GoalBiasOutOfRange,Error::InvalidRadius,Error::InvalidPropagationorError::InvalidScheduleif a config field is out of its documented range.
Sourcepub fn step<R: Rng + ?Sized>(&mut self, rng: &mut R) -> bool
pub fn step<R: Rng + ?Sized>(&mut self, rng: &mut R) -> bool
Runs one iteration. Returns whether a node was added.
Sourcepub fn run<R: Rng + ?Sized>(&mut self, iterations: usize, rng: &mut R)
pub fn run<R: Rng + ?Sized>(&mut self, iterations: usize, rng: &mut R)
Runs iterations iterations.
Sourcepub fn best_trajectory(&self) -> Option<Trajectory<Sp::State, P::Control>>
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.
Sourcepub fn node_count(&self) -> usize
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.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
The number of active nodes, which equals the number of witnesses.