pub struct LabelCount<'a, G, F> { /* private fields */ }Expand description
A graph whose objective slot counts the distinct labels a path uses:
the minimum-label path objective (Pascoal et al. 2013), made additive by
carrying the set of labels seen in the state.
label names each edge (from, to, weight); the edge’s cost in slot
is replaced by one if its label is new on the path, else zero. The
other objectives are kept. States are (state, labels), so the search
space grows with the label combinations reached; use it for few labels.
Goals are the pairs whose state is a goal.
§Examples
use multiobjective_search::{Graph, LabelCount, ZeroHeuristic, namoa_star};
/// Two routes from 0 to 2: one short with two operators, one long
/// with one. The second objective is a placeholder for the count.
struct Lines;
impl Graph for Lines {
type State = u8;
type Weight = [u32; 2];
fn successors(&self, state: &u8, out: &mut Vec<(u8, [u32; 2])>) {
match state {
0 => out.extend([(1, [1, 0]), (2, [9, 0])]),
1 => out.push((2, [1, 0])),
_ => {}
}
}
}
// Operator: "a" from 0, "b" from 1.
let counted = LabelCount::new(&Lines, 1, |from: &u8, _: &u8, _: &[u32; 2]| *from);
let out = namoa_star(&counted, ZeroHeuristic, counted.start(0), |s: &(u8, _)| s.0 == 2);
let costs: Vec<_> = out.solutions.iter().map(|s| s.cost).collect();
assert_eq!(costs, [[2, 2], [9, 1]]);Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<'a, G, F> Forget for LabelCount<'a, G, F>
impl<'a, G, F> Freeze for LabelCount<'a, G, F>
impl<'a, G, F> Move for LabelCount<'a, G, F>
impl<'a, G, F> RefUnwindSafe for LabelCount<'a, G, F>
impl<'a, G, F> Send for LabelCount<'a, G, F>
impl<'a, G, F> Sync for LabelCount<'a, G, F>
impl<'a, G, F> Unpin for LabelCount<'a, G, F>
impl<'a, G, F> UnsafeUnpin for LabelCount<'a, G, F>
impl<'a, G, F> UnwindSafe for LabelCount<'a, G, F>
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