Skip to main content

BfmtStar

Struct BfmtStar 

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

Source

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,

Source

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.

Source

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

Trait Implementations§

Source§

impl<Sp: Clone + StateSpace, Sa: Clone, C: Clone, N: Clone> Clone for BfmtStar<Sp, Sa, C, N>

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 BfmtStar<Sp, Sa, C, N>

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 BfmtStar<Sp, Sa, C, N>

§

impl<Sp, Sa, C, N> Freeze for BfmtStar<Sp, Sa, C, N>
where Sp: Freeze, Sa: Freeze, C: Freeze, N: Freeze,

§

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

§

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

§

impl<Sp, Sa, C, N> Send for BfmtStar<Sp, Sa, C, N>
where Sp: Send, N: Send, C: Send, Sa: Send,

§

impl<Sp, Sa, C, N> Sync for BfmtStar<Sp, Sa, C, N>
where Sp: Sync, N: Sync, C: Sync, Sa: Sync,

§

impl<Sp, Sa, C, N> Unpin for BfmtStar<Sp, Sa, C, N>
where Sp: Unpin, N: Unpin, C: Unpin, Sa: Unpin,

§

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

§

impl<Sp, Sa, C, N> UnwindSafe for BfmtStar<Sp, Sa, C, N>
where Sp: UnwindSafe, Sa: UnwindSafe, C: UnwindSafe, N: 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.