Skip to main content

BitStar

Struct BitStar 

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

BIT*: batch informed trees (Gammell, Srinivasa and Barfoot 2015; Gammell, Barfoot and Srinivasa 2020).

BIT* treats each batch of samples as an implicit random geometric graph and builds a tree over it in order of the estimated solution cost through each edge, g_T(v) + c_hat(v, x) + h_hat(x), with an edge queue fed by expanding vertices. Edges are motion-checked only when they come out on top and could still improve the tree and the solution. When the best edge cannot improve the current solution, the batch is over: the planner prunes every state that cannot improve it (Algorithm 3), samples a new batch from the informed set and starts again. With one batch of infinitely many samples it would be Lifelong-Planning A* on the RGG; with batches of one sample it behaves like RRT*.

This follows Algorithms 1 to 3 of the 2020 paper, with these choices:

  • The heuristics are g_hat(x) = d(start, x), h_hat(x) = max(0, d(x, goal center) - tolerance) and c_hat = d. The goal center is the first sample when it is valid; any vertex inside the goal region is a solution.
  • Batches are drawn through Sampler::sample_informed with foci start and goal center and bound c_best + tolerance, falling back to rejection, and then filtered to valid states with f_hat < c_best; a batch can come out smaller than batch_size when INFORMED_ATTEMPTS draws per sample do not find one.
  • Queue keys go stale when a rewiring lowers the costs of a subtree; both queues are then re-sorted before the next pop, as OMPL does.
  • Edges are checked in travel direction, from tree parent to child.

The cost of BitStar::best_path never increases. Pruned states stay in memory until the planner is dropped.

§Examples

use rand_core::SeedableRng;
use sampling_planning::{
    Euclidean, GoalRegion, UniformBox, Validity, ValidityChecker,
    informed::{BitStar, BitStarConfig},
};

/// 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 = BitStarConfig::new(1.5 * BitStarConfig::gamma_lower_bound(2, 100.0));
let goal = GoalRegion::new([9.0, 9.0], 0.5);
let mut bit = BitStar::new(Euclidean::<2>, sampler, Free, [1.0, 1.0], goal, config)
    .expect("valid");
bit.run(2000, &mut rand_pcg::Pcg64Mcg::seed_from_u64(1));

assert!(bit.best_path().expect("free space").cost < 11.0);

Implementations§

Source§

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

Source

pub fn new( space: Sp, sampler: Sa, checker: C, start: Sp::State, goal: GoalRegion<Sp::State>, config: BitStarConfig, ) -> Result<Self, Error>

Creates a planner with a LinearScan nearest-neighbor index.

§Errors

The same as BitStar::with_nearest_neighbors.

Source§

impl<Sp, Sa, C, N> BitStar<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, start: Sp::State, goal: GoalRegion<Sp::State>, config: BitStarConfig, nn: N, ) -> Result<Self, Error>

Creates a planner; every batch indexes its states in a clone of the given empty index.

§Errors
Source

pub fn step<R: Rng + ?Sized>(&mut self, rng: &mut R) -> bool

Runs one iteration: starts a new batch if both queues are empty, expands vertices while the vertex queue is ahead, then processes the best edge. Returns whether the tree changed.

Source

pub fn run<R: Rng + ?Sized>(&mut self, iterations: usize, rng: &mut R)

Runs iterations iterations.

Source

pub fn best_path(&self) -> Option<Path<Sp::State>>

The cheapest path found so far, or None if no vertex reached the goal yet. Its cost never increases as iterations run.

Source

pub fn vertex_count(&self) -> usize

The number of tree vertices, including the start.

Source

pub fn sample_count(&self) -> usize

The number of samples not connected to the tree.

Source

pub const fn batch_count(&self) -> usize

The number of batches started so far.

Trait Implementations§

Source§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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