Skip to main content

ranking

Function ranking 

Source
pub fn ranking<G, H, C, P>(
    graph: &G,
    heuristic: H,
    start: G::State,
    is_goal: P,
) -> Output<G::State, [C; 2]>
where G: Graph<Weight = [C; 2]>, H: Heuristic<G::State, [C; 2]>, C: Cost, P: Fn(&G::State) -> bool,
Expand description

Finds one path for every Pareto-optimal cost vector by ranking: loopless paths from start to a goal are generated in lexicographic (c1, c2) order (a best-first k-shortest-path enumeration), and a path is kept when its second cost is below every kept one. The enumeration stops after the first cost of the lexicographically (c2, c1)-optimal path, beyond which nothing is efficient.

This is the classic ranking approach, exponential in the worst case and much slower than boa_star; it is here as the reference the survey describes and for comparison. Goal states end a path.

Requirements, not checked at run time: non-negative costs and a heuristic consistent in both objectives and zero on every goal.

ยงExamples

use multiobjective_search::{Graph, ZeroHeuristic, boa_star, ranking};

/// 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 ranked = ranking(&Diamond, ZeroHeuristic, 0, |s| *s == 3);
let exact = boa_star(&Diamond, ZeroHeuristic, 0, |s| *s == 3);
assert_eq!(ranked.solutions, exact.solutions);