pub struct RrtSharp<Sp: StateSpace, Sa, C, St, N = LinearScan<<Sp as StateSpace>::State>> { /* private fields */ }Expand description
RRT#: grows a graph like RRG and keeps the cost-to-come of every promising vertex optimal on that graph by replanning after each extension (Arslan and Tsiotras 2013).
Each iteration extends the nearest vertex toward a goal-biased sample, like
RrtStar, and links the new vertex both ways to its neighbors (the same
radius or k-nearest rule, from RrtStarConfig). Instead of RRT*’s one-step rewiring, a
replanning step then runs an LPA*-like relaxation: vertices whose lookahead cost lmc
improved are processed cheapest key (lmc + h) first, until no queued vertex can beat the
best goal vertex. Vertices that cannot (lmc + h >= c_best) stay unprocessed. Because the
graph only grows and edge costs are fixed, costs only decrease and the underconsistent case
of LPA* never occurs.
After every step the cost of RrtSharp::best_path is the shortest-path cost to the goal
region on the current graph, so it never increases and improves faster per sample than
RRT*.
Edges are motion-checked lazily, in travel direction, and at most once: only when they would
lower a vertex’s lmc. This is sound for directional checkers and costs fewer checks than
checking every graph edge eagerly. Informed sampling works as in RRT*.
The secondary key of the paper, min(g, lmc), is replaced by the vertex id as the tie
break, which keeps runs deterministic.
§Examples
use rand_core::SeedableRng;
use sampling_planning::{
Euclidean, GoalRegion, Problem, StraightLine, UniformBox, Validity, ValidityChecker,
trees::{RrtSharp, RrtStarConfig},
};
/// 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 problem = Problem {
space: Euclidean::<2>,
sampler: UniformBox::new([0.0, 0.0], [10.0, 10.0]),
checker: Free,
steering: StraightLine::new(1.0),
start: [1.0, 1.0],
goal: GoalRegion::new([9.0, 9.0], 0.5),
};
let gamma = 1.5 * RrtStarConfig::gamma_lower_bound(2, 100.0);
let mut planner = RrtSharp::new(problem, RrtStarConfig::new(gamma, 1.0)).expect("valid");
planner.run(1000, &mut rand_pcg::Pcg64Mcg::seed_from_u64(1));
assert!(planner.best_path().expect("free space").cost < 11.5);Implementations§
Source§impl<Sp, Sa, C, St> RrtSharp<Sp, Sa, C, St>
impl<Sp, Sa, C, St> RrtSharp<Sp, Sa, C, St>
Sourcepub fn new(
problem: Problem<Sp, Sa, C, St>,
config: RrtStarConfig,
) -> Result<Self, Error>
pub fn new( problem: Problem<Sp, Sa, C, St>, config: RrtStarConfig, ) -> Result<Self, Error>
Creates a planner with a LinearScan nearest-neighbor index.
§Errors
The same as RrtSharp::with_nearest_neighbors.
Source§impl<Sp, Sa, C, St, N> RrtSharp<Sp, Sa, C, St, N>where
Sp: StateSpace,
Sa: Sampler<Sp::State>,
C: ValidityChecker<Sp>,
St: Steering<Sp>,
N: NearestNeighbors<Sp>,
impl<Sp, Sa, C, St, N> RrtSharp<Sp, Sa, C, St, N>where
Sp: StateSpace,
Sa: Sampler<Sp::State>,
C: ValidityChecker<Sp>,
St: Steering<Sp>,
N: NearestNeighbors<Sp>,
Sourcepub fn with_nearest_neighbors(
problem: Problem<Sp, Sa, C, St>,
config: RrtStarConfig,
nn: N,
) -> Result<Self, Error>
pub fn with_nearest_neighbors( problem: Problem<Sp, Sa, C, St>, config: RrtStarConfig, nn: N, ) -> Result<Self, Error>
Creates a planner with the given empty nearest-neighbor index.
§Errors
Error::InvalidStartif the start state is not valid.Error::GoalBiasOutOfRangeif the goal bias is not in[0, 1].Error::InvalidGammaifgamma(or the k-nearest constant) is not positive and finite.Error::InvalidMaxRadiusifmax_radiusis not positive.
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: extend, then replan. Returns whether a vertex 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_path(&self) -> Option<Path<Sp::State>>
pub fn best_path(&self) -> Option<Path<Sp::State>>
The cheapest path to the goal region on the current graph, 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 graph vertices, including the start.