Skip to main content

IdealPoint

Struct IdealPoint 

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

The ideal-point heuristic h_ideal(v) = (h_1(v), ..., h_N(v)), with h_i the exact shortest distance from v to a goal in objective i alone. Consistent and zero on goals; a state that reaches no goal has no estimate (a dead end).

Built by one backward Dijkstra per objective from the goal set, so the graph’s reachable part must be finite.

§Examples

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

/// 0 → 1 → 2 and 0 → 2 directly.
struct Line;

const EDGES: [(u8, u8, [u32; 2]); 3] = [(0, 1, [1, 5]), (1, 2, [1, 5]), (0, 2, [9, 1])];

impl Graph for Line {
    type State = u8;
    type Weight = [u32; 2];

    fn successors(&self, s: &u8, out: &mut Vec<(u8, [u32; 2])>) {
        out.extend(EDGES.iter().filter(|e| e.0 == *s).map(|e| (e.1, e.2)));
    }
}

impl ReverseGraph for Line {
    fn predecessors(&self, s: &u8, out: &mut Vec<(u8, [u32; 2])>) {
        out.extend(EDGES.iter().filter(|e| e.1 == *s).map(|e| (e.0, e.2)));
    }
}

let mut h = IdealPoint::new(&Line, [2]);
assert_eq!(h.estimate(&0), Some([2, 1])); // the best of each objective
assert_eq!(h.estimate(&2), Some([0, 0]));

Implementations§

Source§

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

Source

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

Computes the heuristic toward goals on graph.

Trait Implementations§

Source§

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

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<S: Ord, C: Cost, const N: usize> Heuristic<S, [C; N]> for IdealPoint<S, C, N>

Source§

fn estimate(&mut self, state: &S) -> Option<[C; N]>

Estimates the remaining cost from state to a goal. Read more
Source§

impl<S: Ord, C: Cost, const N: usize> Heuristic<S, [C; N]> for &IdealPoint<S, C, N>

Source§

fn estimate(&mut self, state: &S) -> Option<[C; N]>

Estimates the remaining cost from state to a goal. Read more

Auto Trait Implementations§

§

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

§

impl<S, C, const N: usize> Freeze for IdealPoint<S, C, N>
where BTreeMap<S, [C; N]>: Freeze,

§

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

§

impl<S, C, const N: usize> RefUnwindSafe for IdealPoint<S, C, N>

§

impl<S, C, const N: usize> Send for IdealPoint<S, C, N>
where BTreeMap<S, [C; N]>: Send,

§

impl<S, C, const N: usize> Sync for IdealPoint<S, C, N>
where BTreeMap<S, [C; N]>: Sync,

§

impl<S, C, const N: usize> Unpin for IdealPoint<S, C, N>
where BTreeMap<S, [C; N]>: Unpin,

§

impl<S, C, const N: usize> UnsafeUnpin for IdealPoint<S, C, N>

§

impl<S, C, const N: usize> UnwindSafe for IdealPoint<S, 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.