pub struct Spars2<Sp: StateSpace, Sa, C, N = LinearScan<<Sp as StateSpace>::State>> { /* private fields */ }Expand description
SPARS2: an incremental sparse roadmap spanner that needs no dense graph (Dobson and Bekris
2013, “Improving sparse roadmap spanners”), ported from OMPL’s SPARStwo.
Every valid sample q is tested against four criteria, in order, using the guards it can
see within sparse_delta:
- Coverage: it sees no guard, so it becomes a guard.
- Connectivity: it sees guards of different components, so it becomes a guard joining them.
- Interface: its two closest guards are both visible but not adjacent, so they are
connected directly, or through
q. - Quality:
near_samplesstates nearqreveal neighboring guards’ regions; the pair points next to each interface are recorded per guard, and when the graph distance between two neighbors of a guard exceedsstretchtimes the distance between their interface points, a shortcut is added: the direct edge if valid, else the path through the points.
Construction ends after max_failures consecutive samples change nothing. The roadmap is
then, with high probability, a spanner: paths through it cost at most about stretch times
the optimum plus a term in sparse_delta (asymptotic near-optimality), with far fewer nodes
than a PRM.
Differences to OMPL’s SPARStwo, documented here so that results can be compared: the
quality criterion uses OMPL’s midpoint estimate (d(r, v) + d(v, r'')) / 2 for the path
through v, as OMPL does (the paper takes a graph shortest path), but adds the path of
interface points without OMPL’s smoothing step; the stretch test around a guard stops at the
first violation, even when no shortcut could be added (OMPL finishes the neighbor’s inner
loop); any change to the graph resets the failure
counter (OMPL resets it only for new guards and direct interface edges); and sampling near
a state follows the geodesic toward a uniform sample, NEAR_ATTEMPTS tries at most, instead
of OMPL’s unbounded retry.
§Examples
use rand_core::SeedableRng;
use sampling_planning::{
Euclidean, GoalRegion, UniformBox, Validity, ValidityChecker,
roadmaps::{Spars2, Spars2Config},
};
/// 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
}
}
let sampler = UniformBox::new([0.0, 0.0], [10.0, 10.0]);
let mut config = Spars2Config::new(2.5, 0.05);
config.max_failures = 500;
let mut spars = Spars2::new(Euclidean::<2>, sampler, Free, config).expect("valid");
spars.construct(100_000, &mut rand_pcg::Pcg64Mcg::seed_from_u64(1));
assert!(spars.is_complete());
let path = spars.query(&[1.0, 1.0], &GoalRegion::new([9.0, 9.0], 0.5)).expect("valid start");
assert!(path.expect("free space").cost < 3.0 * 11.4);Implementations§
Source§impl<Sp, Sa, C> Spars2<Sp, Sa, C>
impl<Sp, Sa, C> Spars2<Sp, Sa, C>
Sourcepub fn new(
space: Sp,
sampler: Sa,
checker: C,
config: Spars2Config,
) -> Result<Self, Error>
pub fn new( space: Sp, sampler: Sa, checker: C, config: Spars2Config, ) -> Result<Self, Error>
Creates an empty roadmap with a LinearScan index over its guards.
§Errors
Error::InvalidRadius if a range is not positive and finite, dense_delta is not
below sparse_delta, or the stretch is not above one.
Source§impl<Sp, Sa, C, N> Spars2<Sp, Sa, C, N>
impl<Sp, Sa, C, N> Spars2<Sp, Sa, C, N>
Sourcepub fn with_nearest_neighbors(
space: Sp,
sampler: Sa,
checker: C,
config: Spars2Config,
nn: N,
) -> Result<Self, Error>
pub fn with_nearest_neighbors( space: Sp, sampler: Sa, checker: C, config: Spars2Config, nn: N, ) -> Result<Self, Error>
Creates an empty roadmap with the given empty index over its guards.
§Errors
The same as Spars2::new.
Sourcepub fn construct<R: Rng + ?Sized>(
&mut self,
max_samples: usize,
rng: &mut R,
) -> usize
pub fn construct<R: Rng + ?Sized>( &mut self, max_samples: usize, rng: &mut R, ) -> usize
Processes samples until construction is complete or max_samples were drawn. Returns
the number of samples drawn.
Sourcepub fn step<R: Rng + ?Sized>(&mut self, rng: &mut R) -> bool
pub fn step<R: Rng + ?Sized>(&mut self, rng: &mut R) -> bool
Draws one sample and applies the four criteria. Returns whether the roadmap changed.
Sourcepub fn query(
&self,
start: &Sp::State,
goal: &GoalRegion<Sp::State>,
) -> Result<Option<Path<Sp::State>>, Error>
pub fn query( &self, start: &Sp::State, goal: &GoalRegion<Sp::State>, ) -> Result<Option<Path<Sp::State>>, Error>
The cheapest path from start to goal through the roadmap, or None if the roadmap
does not connect them. Both endpoints connect to every visible guard within
sparse_delta.
§Errors
Error::InvalidStart if start does not check as valid.
Sourcepub const fn is_complete(&self) -> bool
pub const fn is_complete(&self) -> bool
Whether max_failures consecutive samples changed nothing.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
The number of guards.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
The number of roadmap edges.
Sourcepub fn guard_counts(&self) -> [usize; 4]
pub fn guard_counts(&self) -> [usize; 4]
The number of guards added for each criterion: coverage, connectivity, interface, quality.