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>
impl<S: Clone + Ord, C: Cost, const N: usize> IdealPoint<S, C, N>
Sourcepub fn new<G>(graph: &G, goals: impl IntoIterator<Item = S>) -> Selfwhere
G: ReverseGraph<State = S, Weight = [C; N]>,
pub fn new<G>(graph: &G, goals: impl IntoIterator<Item = S>) -> Selfwhere
G: ReverseGraph<State = S, Weight = [C; N]>,
Computes the heuristic toward goals on graph.
Trait Implementations§
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>
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>
impl<S, C, const N: usize> Sync for IdealPoint<S, C, N>
impl<S, C, const N: usize> Unpin for IdealPoint<S, C, N>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more