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>
impl<Sp, Sa, C> Prm<Sp, Sa, C>
Sourcepub fn new(
space: Sp,
sampler: Sa,
checker: C,
config: PrmConfig,
) -> Result<Self, Error>
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>
impl<Sp, Sa, C, N> Prm<Sp, Sa, C, N>
Sourcepub fn with_nearest_neighbors(
space: Sp,
sampler: Sa,
checker: C,
config: PrmConfig,
nn: N,
) -> Result<Self, Error>
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.
Sourcepub fn grow<R: Rng + ?Sized>(&mut self, samples: usize, rng: &mut R) -> usize
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.
Sourcepub fn query(
&mut self,
start: &Sp::State,
goal: &GoalRegion<Sp::State>,
) -> Result<Option<Path<Sp::State>>, Error>
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.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
The number of roadmap nodes.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
The number of roadmap edges that are valid or not checked yet.