Skip to main content

label_correcting

Function label_correcting 

Source
pub fn label_correcting<G, C, P, const N: usize>(
    graph: &G,
    start: G::State,
    is_goal: P,
) -> Output<G::State, [C; N]>
where G: Graph<Weight = [C; N]>, C: Cost, P: Fn(&G::State) -> bool,
Expand description

Finds one path for every Pareto-optimal cost vector from start to a state that satisfies is_goal, by label correcting.

Every state keeps its set of non-dominated labels. A FIFO queue holds the states whose set changed; taking one, the labels added since its last visit are extended along every edge and merged into the successors’ sets, which drops the labels they dominate and enqueues the successors that changed. Unlike label setting, a label can be replaced after it was extended. Search at a goal are kept but not extended, and a label weakly dominated by a goal label is not extended either. The result is the non-dominated goal labels.

Requirements: non-negative edge costs (no heuristic is used).

§Panics

Never: every queued state has a label set.

§Examples

use multiobjective_search::{Graph, ZeroHeuristic, label_correcting, namoa_star};

/// A diamond: two routes from 0 to 3.
struct Diamond;

impl Graph for Diamond {
    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, 3]), (2, [3, 1])]),
            1 | 2 => out.push((3, [1, 1])),
            _ => {}
        }
    }
}

let a = label_correcting(&Diamond, 0, |s| *s == 3);
let b = namoa_star(&Diamond, ZeroHeuristic, 0, |s| *s == 3);
assert_eq!(a.solutions, b.solutions);