mod kpiece;
mod sst;
use alloc::vec::Vec;
use core::fmt;
use rand_core::Rng;
pub use kpiece::{Kpiece, KpieceConfig, Projection};
pub use sst::{Sst, SstConfig, SstStarSchedule};
use crate::{GoalRegion, StateSpace, Validity};
pub trait Propagator<Sp: StateSpace> {
type Control: Clone;
fn control_dimension(&self) -> usize;
fn sample_control<R: Rng + ?Sized>(&mut self, rng: &mut R) -> Self::Control;
fn propagate(
&self,
space: &Sp,
from: &Sp::State,
control: &Self::Control,
duration: f64,
) -> Sp::State;
}
#[derive(Debug, Clone)]
pub struct KinodynamicProblem<Sp: StateSpace, Sa, C, P> {
pub space: Sp,
pub sampler: Sa,
pub checker: C,
pub propagator: P,
pub start: Sp::State,
pub goal: GoalRegion<Sp::State>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Trajectory<S, U> {
pub states: Vec<S>,
pub controls: Vec<(U, f64)>,
pub cost: f64,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Error {
InvalidStart(Validity),
GoalBiasOutOfRange,
InvalidRadius,
InvalidPropagation,
InvalidSchedule,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidStart(validity) => write!(f, "start state is not valid ({validity:?})"),
Self::GoalBiasOutOfRange => f.write_str("goal bias must be in [0, 1]"),
Self::InvalidRadius => f.write_str("radii and cell sizes must be positive and finite"),
Self::InvalidPropagation => {
f.write_str("step size must be positive and finite, step count at least one")
}
Self::InvalidSchedule => f.write_str(
"shrink factor must be in (0, 1) and first epoch at least one iteration, \
or score factors in (0, 1] and exterior bias in [0, 1]",
),
}
}
}
impl core::error::Error for Error {}