Skip to main content

Spars2

Struct Spars2 

Source
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:

  1. Coverage: it sees no guard, so it becomes a guard.
  2. Connectivity: it sees guards of different components, so it becomes a guard joining them.
  3. Interface: its two closest guards are both visible but not adjacent, so they are connected directly, or through q.
  4. Quality: near_samples states near q reveal 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 exceeds stretch times 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>
where Sp: StateSpace, Sa: Sampler<Sp::State>, C: ValidityChecker<Sp>,

Source

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>
where Sp: StateSpace, Sa: Sampler<Sp::State>, C: ValidityChecker<Sp>, N: NearestNeighbors<Sp>,

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn is_complete(&self) -> bool

Whether max_failures consecutive samples changed nothing.

Source

pub fn node_count(&self) -> usize

The number of guards.

Source

pub fn edge_count(&self) -> usize

The number of roadmap edges.

Source

pub fn guard_counts(&self) -> [usize; 4]

The number of guards added for each criterion: coverage, connectivity, interface, quality.

Trait Implementations§

Source§

impl<Sp: Clone + StateSpace, Sa: Clone, C: Clone, N: Clone> Clone for Spars2<Sp, Sa, C, N>
where Sp::State: 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
Source§

impl<Sp: Debug + StateSpace, Sa: Debug, C: Debug, N: Debug> Debug for Spars2<Sp, Sa, C, N>
where Sp::State: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Sp, Sa, C, N> Forget for Spars2<Sp, Sa, C, N>

§

impl<Sp, Sa, C, N> Freeze for Spars2<Sp, Sa, C, N>
where Sp: Freeze, Sa: Freeze, C: Freeze, SparseGraph<<Sp as StateSpace>::State, N>: Freeze, Vec<BTreeMap<(usize, usize), InterfaceData<<Sp as StateSpace>::State>>>: Freeze,

§

impl<Sp, Sa, C, N> Move for Spars2<Sp, Sa, C, N>

§

impl<Sp, Sa, C, N> RefUnwindSafe for Spars2<Sp, Sa, C, N>
where Sp: RefUnwindSafe, Sa: RefUnwindSafe, C: RefUnwindSafe, SparseGraph<<Sp as StateSpace>::State, N>: RefUnwindSafe, Vec<BTreeMap<(usize, usize), InterfaceData<<Sp as StateSpace>::State>>>: RefUnwindSafe,

§

impl<Sp, Sa, C, N> Send for Spars2<Sp, Sa, C, N>
where Sp: Send, C: Send, Sa: Send, SparseGraph<<Sp as StateSpace>::State, N>: Send, Vec<BTreeMap<(usize, usize), InterfaceData<<Sp as StateSpace>::State>>>: Send,

§

impl<Sp, Sa, C, N> Sync for Spars2<Sp, Sa, C, N>
where Sp: Sync, C: Sync, Sa: Sync, SparseGraph<<Sp as StateSpace>::State, N>: Sync, Vec<BTreeMap<(usize, usize), InterfaceData<<Sp as StateSpace>::State>>>: Sync,

§

impl<Sp, Sa, C, N> Unpin for Spars2<Sp, Sa, C, N>
where Sp: Unpin, C: Unpin, Sa: Unpin, SparseGraph<<Sp as StateSpace>::State, N>: Unpin, Vec<BTreeMap<(usize, usize), InterfaceData<<Sp as StateSpace>::State>>>: Unpin,

§

impl<Sp, Sa, C, N> UnsafeUnpin for Spars2<Sp, Sa, C, N>
where Sp: UnsafeUnpin, Sa: UnsafeUnpin, C: UnsafeUnpin, SparseGraph<<Sp as StateSpace>::State, N>: UnsafeUnpin, Vec<BTreeMap<(usize, usize), InterfaceData<<Sp as StateSpace>::State>>>: UnsafeUnpin,

§

impl<Sp, Sa, C, N> UnwindSafe for Spars2<Sp, Sa, C, N>
where Sp: UnwindSafe, Sa: UnwindSafe, C: UnwindSafe, SparseGraph<<Sp as StateSpace>::State, N>: UnwindSafe, Vec<BTreeMap<(usize, usize), InterfaceData<<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.