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)andc_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_informedwith foci start and goal center and boundc_best + tolerance, falling back to rejection, and then filtered to valid states withf_hat < c_best; a batch can come out smaller thanbatch_sizewhenINFORMED_ATTEMPTSdraws 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>
impl<Sp, Sa, C> BitStar<Sp, Sa, C>
Sourcepub fn new(
space: Sp,
sampler: Sa,
checker: C,
start: Sp::State,
goal: GoalRegion<Sp::State>,
config: BitStarConfig,
) -> Result<Self, Error>
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,
impl<Sp, Sa, C, N> BitStar<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,
start: Sp::State,
goal: GoalRegion<Sp::State>,
config: BitStarConfig,
nn: N,
) -> Result<Self, Error>
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
Error::InvalidStartifstartis not valid.Error::EmptyBatchif the batch size is zero.Error::InvalidRadiusifgamma, the k-nearest constant ormax_radiusis out of range.
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: 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.
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 found so far, or None if no vertex reached the goal yet. Its cost
never increases as iterations run.
Sourcepub fn vertex_count(&self) -> usize
pub fn vertex_count(&self) -> usize
The number of tree vertices, including the start.
Sourcepub fn sample_count(&self) -> usize
pub fn sample_count(&self) -> usize
The number of samples not connected to the tree.
Sourcepub const fn batch_count(&self) -> usize
pub const fn batch_count(&self) -> usize
The number of batches started so far.