pub fn brute_force<G, C, P, const N: usize>(
graph: &G,
start: G::State,
is_goal: P,
) -> Output<G::State, [C; N]>Expand description
Finds one path for every Pareto-optimal cost vector by enumerating
every simple path from start, for any number of objectives.
Meant for tests on small graphs: it takes time exponential in the
graph size, and recursion depth up to the longest simple path. With
non-negative costs every Pareto-optimal cost vector is the cost of
some simple path, so the result is exact. It shares no dominance code
with the searches beyond Dominates, so a disagreement points at the
search. For a polynomial-per-label reference, use
namoa_star with
ZeroHeuristic, the classic multi-objective
label-setting algorithm.
Paths do not continue through a goal: with non-negative costs, a
longer path to another goal is never cheaper. Solutions are sorted
lexicographically ascending, one per cost vector; among equal-cost
paths the first one found is kept. Output::stats counts the states
visited by the enumeration as expanded, and the paths reaching a goal
as generated.
ยงExamples
use multiobjective_search::{Graph, ZeroHeuristic, brute_force, namoa_star};
/// Two parallel routes from 0 to 1, plus a dominated one.
struct Routes;
impl Graph for Routes {
type State = u8;
type Weight = [u32; 3];
fn successors(&self, state: &u8, out: &mut Vec<(u8, [u32; 3])>) {
if *state == 0 {
out.extend([(1, [1, 2, 3]), (1, [3, 2, 1]), (1, [3, 3, 3])]);
}
}
}
let reference = brute_force(&Routes, 0, |s| *s == 1);
let search = namoa_star(&Routes, ZeroHeuristic, 0, |s| *s == 1);
assert_eq!(reference.solutions, search.solutions);