pub fn boa_star<G, H, C, P>(
graph: &G,
heuristic: H,
start: G::State,
is_goal: P,
) -> Output<G::State, [C; 2]>Expand description
Finds one path for every Pareto-optimal cost vector from start to a
state that satisfies is_goal.
Requirements, not checked at run time:
- edge costs are non-negative;
heuristicis consistent in both objectives and zero on every goal.
With ZeroHeuristic the search is a
bi-objective Dijkstra. Solutions are sorted by the first objective
ascending and so by the second strictly descending.
ยงExamples
use multiobjective_search::{Graph, ZeroHeuristic, boa_star};
/// Two routes from 0 to 2: fast but costly, or slow but cheap.
struct Routes;
impl Graph for Routes {
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, 5]), (2, [4, 1])]),
1 => out.push((2, [1, 5])),
_ => {}
}
}
}
let out = boa_star(&Routes, ZeroHeuristic, 0, |s| *s == 2);
let costs: Vec<_> = out.solutions.iter().map(|s| s.cost).collect();
assert_eq!(costs, [[2, 10], [4, 1]]);
assert_eq!(out.solutions[0].path, [0, 1, 2]);