Skip to main content

Prm

Struct Prm 

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

A probabilistic roadmap: a graph of valid sampled states connected by valid motions, built once and queried for many start and goal pairs.

Prm::grow adds samples, Prm::query connects a start and a goal region to the roadmap and runs Dijkstra. Queries do not change the roadmap, except that a lazy roadmap remembers which edges it has checked. With Connection::Star the roadmap is PRM*, whose query cost converges to the optimum as it grows.

PRM needs no Steering: edges are direct motions along StateSpace::interpolate.

§Examples

use rand_core::SeedableRng;
use sampling_planning::{
    Euclidean, GoalRegion, UniformBox, Validity, ValidityChecker,
    roadmaps::{Prm, PrmConfig},
};

/// 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 gamma = 1.5 * PrmConfig::gamma_lower_bound(2, 100.0);
let mut prm = Prm::new(Euclidean::<2>, sampler, Free, PrmConfig::star(gamma)).expect("valid");
prm.grow(500, &mut rand_pcg::Pcg64Mcg::seed_from_u64(1));

// The same roadmap answers several queries.
for goal in [[9.0, 9.0], [9.0, 1.0]] {
    let path = prm.query(&[1.0, 1.0], &GoalRegion::new(goal, 0.5)).expect("valid start");
    assert!(path.is_some());
}

Implementations§

Source§

impl<Sp, Sa, C> Prm<Sp, Sa, C>
where Sp: StateSpace, Sa: Sampler<Sp::State>, C: ValidityChecker<Sp>,

Source

pub fn new( space: Sp, sampler: Sa, checker: C, config: PrmConfig, ) -> Result<Self, Error>

Creates an empty roadmap with a LinearScan nearest-neighbor index.

§Errors

Error::InvalidRadius if the radius, gamma or k_constant is not positive and finite, or k is zero.

Source§

impl<Sp, Sa, C, N> Prm<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: PrmConfig, nn: N, ) -> Result<Self, Error>

Creates an empty roadmap with the given empty nearest-neighbor index.

§Errors

Error::InvalidRadius if the radius, gamma or k_constant is not positive and finite, or k is zero.

Source

pub fn grow<R: Rng + ?Sized>(&mut self, samples: usize, rng: &mut R) -> usize

Draws samples states and adds the valid ones to the roadmap, each connected to its neighbors. Returns the number of nodes added.

Source

pub fn query( &mut 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 yet.

The start connects to every node within the current connection radius by a valid motion. The path ends at a roadmap node inside goal or at goal’s center, which connects like the start when it is valid. A lazy roadmap checks the edges of each candidate path, drops invalid ones and searches again, so its result equals the eager one for the same samples.

§Errors

Error::InvalidStart if start does not check as valid.

Source

pub fn node_count(&self) -> usize

The number of roadmap nodes.

Source

pub fn edge_count(&self) -> usize

The number of roadmap edges that are valid or not checked yet.

Trait Implementations§

Source§

impl<Sp: Clone + StateSpace, Sa: Clone, C: Clone, N: Clone> Clone for Prm<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 Prm<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 Prm<Sp, Sa, C, N>

§

impl<Sp, Sa, C, N> Freeze for Prm<Sp, Sa, C, N>
where Sp: Freeze, Sa: Freeze, C: Freeze, Vec<<Sp as StateSpace>::State>: Freeze, N: Freeze,

§

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

§

impl<Sp, Sa, C, N> RefUnwindSafe for Prm<Sp, Sa, C, N>

§

impl<Sp, Sa, C, N> Send for Prm<Sp, Sa, C, N>
where Sp: Send, N: Send, C: Send, Sa: Send, Vec<<Sp as StateSpace>::State>: Send,

§

impl<Sp, Sa, C, N> Sync for Prm<Sp, Sa, C, N>
where Sp: Sync, N: Sync, C: Sync, Sa: Sync, Vec<<Sp as StateSpace>::State>: Sync,

§

impl<Sp, Sa, C, N> Unpin for Prm<Sp, Sa, C, N>
where Sp: Unpin, N: Unpin, C: Unpin, Sa: Unpin, Vec<<Sp as StateSpace>::State>: Unpin,

§

impl<Sp, Sa, C, N> UnsafeUnpin for Prm<Sp, Sa, C, N>

§

impl<Sp, Sa, C, N> UnwindSafe for Prm<Sp, Sa, C, N>

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.