pub struct BfmtStar<Sp: StateSpace, Sa, C, N = LinearScan<<Sp as StateSpace>::State>> { /* private fields */ }Expand description
BFMT*: marches one tree outward from the start and one inward from the goal center over the same batch, alternating expansions, and joins them where they meet (Starek, Gomez, Schmerling, Janson, Moreno and Pavone 2015).
Each expansion is an FMT* step on the current tree: connect the unvisited neighbors of its
cheapest open node z to their locally cheapest open neighbor. A newly connected node that
the other tree already holds is a connection with cost cost_start(x) + cost_goal(x); the
cheapest one is kept. After each expansion the trees swap (“swap every time”), unless the
other tree’s wavefront is empty. Termination decides when to stop.
Goal-tree edges are traveled toward the goal, so they are checked from child to parent, which keeps directional checkers sound. The goal center must be valid. A start-tree node inside the goal region is also a solution, ending there.
Like FmtStar it is asymptotically optimal and checks each motion at most
once; growing two trees from both ends typically settles fewer nodes.
§Examples
use rand_core::SeedableRng;
use sampling_planning::{
Euclidean, GoalRegion, UniformBox, Validity, ValidityChecker,
roadmaps::{BfmtStar, BfmtStarConfig},
};
/// 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 config = BfmtStarConfig::new(BfmtStarConfig::gamma_lower_bound(2, 100.0));
let mut bfmt = BfmtStar::new(Euclidean::<2>, sampler, Free, config).expect("valid");
let goal = GoalRegion::new([9.0, 9.0], 0.5);
let mut rng = rand_pcg::Pcg64Mcg::seed_from_u64(1);
let path = bfmt.plan(&[1.0, 1.0], &goal, 1000, &mut rng).expect("valid endpoints");
assert!(path.expect("free space").cost < 11.5);Implementations§
Source§impl<Sp, Sa, C> BfmtStar<Sp, Sa, C>
impl<Sp, Sa, C> BfmtStar<Sp, Sa, C>
Sourcepub fn new(
space: Sp,
sampler: Sa,
checker: C,
config: BfmtStarConfig,
) -> Result<Self, Error>
pub fn new( space: Sp, sampler: Sa, checker: C, config: BfmtStarConfig, ) -> Result<Self, Error>
Creates a planner with a LinearScan nearest-neighbor index.
§Errors
Error::InvalidRadius if gamma is not positive and finite.
Source§impl<Sp, Sa, C, N> BfmtStar<Sp, Sa, C, N>where
Sp: StateSpace,
Sa: Sampler<Sp::State>,
C: ValidityChecker<Sp>,
N: NearestNeighbors<Sp> + Clone,
impl<Sp, Sa, C, N> BfmtStar<Sp, Sa, C, N>where
Sp: StateSpace,
Sa: Sampler<Sp::State>,
C: ValidityChecker<Sp>,
N: NearestNeighbors<Sp> + Clone,
Sourcepub fn with_nearest_neighbors(
space: Sp,
sampler: Sa,
checker: C,
config: BfmtStarConfig,
nn: N,
) -> Result<Self, Error>
pub fn with_nearest_neighbors( space: Sp, sampler: Sa, checker: C, config: BfmtStarConfig, nn: N, ) -> Result<Self, Error>
Creates a planner; every batch gets a clone of the given empty nearest-neighbor index.
§Errors
Error::InvalidRadius if gamma is not positive and finite.
Sourcepub fn plan<R: Rng + ?Sized>(
&mut self,
start: &Sp::State,
goal: &GoalRegion<Sp::State>,
samples: usize,
rng: &mut R,
) -> Result<Option<Path<Sp::State>>, Error>
pub fn plan<R: Rng + ?Sized>( &mut self, start: &Sp::State, goal: &GoalRegion<Sp::State>, samples: usize, rng: &mut R, ) -> Result<Option<Path<Sp::State>>, Error>
Draws samples states, keeps the valid ones, and marches from both start and the
center of goal until Termination says to stop.
Returns None if both wavefronts die out without a connection.
§Errors
Error::InvalidStartifstartdoes not check as valid.Error::InvalidGoalif the goal center does not check as valid.