Skip to main content

DifferentialHeuristic

Struct DifferentialHeuristic 

Source
pub struct DifferentialHeuristic<S, C, const N: usize> { /* private fields */ }
Expand description

Differential heuristics (Goldberg and Harrelson 2005) per objective: exact distances from and to a few landmark states, giving for any goal g the consistent lower bound h_i(v) = max_L max(d_i(L, g) - d_i(L, v), d_i(v, L) - d_i(g, L), 0) by the triangle inequality. It is consistent along every edge whose head can reach the goal (a term undefined for lack of a path is left out).

The memory-based heuristics the survey discusses for multi-objective search; Zhang et al. 2023 extend them to multi-valued bi-objective forms. Build once per graph with DifferentialHeuristic::new, then aim at a goal with DifferentialHeuristic::towards.

§Examples

use multiobjective_search::{DifferentialHeuristic, Graph, Heuristic, ReverseGraph};

/// A path 0 - 1 - 2 - 3 in both directions, unit costs.
struct Path;

impl Graph for Path {
    type State = u8;
    type Weight = [u32; 1];

    fn successors(&self, s: &u8, out: &mut Vec<(u8, [u32; 1])>) {
        if *s > 0 { out.push((s - 1, [1])); }
        if *s < 3 { out.push((s + 1, [1])); }
    }
}

impl ReverseGraph for Path {
    fn predecessors(&self, s: &u8, out: &mut Vec<(u8, [u32; 1])>) {
        self.successors(s, out);
    }
}

let dh = DifferentialHeuristic::new(&Path, [0]);
let mut h = dh.towards(&3);
assert_eq!(h.estimate(&1), Some([2])); // exact here: the landmark is an end

Implementations§

Source§

impl<S: Clone + Ord, C: Cost + WideMul, const N: usize> DifferentialHeuristic<S, C, N>

Source

pub fn new<G>(graph: &G, landmarks: impl IntoIterator<Item = S>) -> Self
where G: ReverseGraph<State = S, Weight = [C; N]>,

Computes the landmark distances: two Dijkstras per landmark and objective, over the finite reachable graph.

Source

pub fn towards(&self, goal: &S) -> Towards<'_, S, C, N>

The heuristic toward goal.

Trait Implementations§

Source§

impl<S: Clone, C: Clone, const N: usize> Clone for DifferentialHeuristic<S, 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<S: Debug, C: Debug, const N: usize> Debug for DifferentialHeuristic<S, C, N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S, C, const N: usize> Forget for DifferentialHeuristic<S, C, N>

§

impl<S, C, const N: usize> Freeze for DifferentialHeuristic<S, C, N>
where Vec<Vec<BTreeMap<S, C>>>: Freeze,

§

impl<S, C, const N: usize> Move for DifferentialHeuristic<S, C, N>

§

impl<S, C, const N: usize> RefUnwindSafe for DifferentialHeuristic<S, C, N>
where Vec<Vec<BTreeMap<S, C>>>: RefUnwindSafe,

§

impl<S, C, const N: usize> Send for DifferentialHeuristic<S, C, N>
where Vec<Vec<BTreeMap<S, C>>>: Send,

§

impl<S, C, const N: usize> Sync for DifferentialHeuristic<S, C, N>
where Vec<Vec<BTreeMap<S, C>>>: Sync,

§

impl<S, C, const N: usize> Unpin for DifferentialHeuristic<S, C, N>
where Vec<Vec<BTreeMap<S, C>>>: Unpin,

§

impl<S, C, const N: usize> UnsafeUnpin for DifferentialHeuristic<S, C, N>
where Vec<Vec<BTreeMap<S, C>>>: UnsafeUnpin,

§

impl<S, C, const N: usize> UnwindSafe for DifferentialHeuristic<S, C, N>
where Vec<Vec<BTreeMap<S, C>>>: 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.