Skip to main content

parallel_moa_star

Function parallel_moa_star 

Source
pub fn parallel_moa_star<G, H, C, P, const N: usize>(
    graph: &G,
    heuristic: H,
    start: G::State,
    is_goal: P,
) -> Output<G::State, [C; N]>
where G: Graph<Weight = [C; N]> + Sync, G::State: Send + Sync, H: Heuristic<G::State, [C; N]> + Clone + Send, C: Cost + Send + Sync, P: Fn(&G::State) -> bool + Sync,
Expand description

Parallel MOA*: finds one path for every Pareto-optimal cost vector from start to a state that satisfies is_goal, with N threads.

Thread i runs a lexicographic MOA* (lazy dominance checks, one truncated closed set per state, Algorithm 3) with objective i first and the others in cyclic order (Algorithm 2). Its solutions feed a multi-level upper bound (Algorithms 4 and 5): a solution’s truncated cost moves one level down, dropping one more objective j, once thread j has found a solution at least as expensive in j, since every cheaper one in j is then known. A cost truncated N - 1 times is a scalar bound on the last objective that every thread prunes against, and the thread led by that objective stops once its primary cost reaches it. The search ends when the first thread ends; the union of all threads’ solutions, filtered to its non-dominated vectors, is the front, whatever the thread timing.

Requirements, not checked at run time:

  • edge costs are non-negative;
  • heuristic is consistent in every objective and zero on every goal (each thread uses its own clone).

Solutions are sorted lexicographically, one per Pareto-optimal cost.

§Examples

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

/// A small diamond with three objectives.
struct Diamond;

impl Graph for Diamond {
    type State = u8;
    type Weight = [u32; 3];

    fn successors(&self, state: &u8, out: &mut Vec<(u8, [u32; 3])>) {
        match state {
            0 => out.extend([(1, [1, 2, 3]), (2, [3, 2, 1]), (3, [5, 5, 5])]),
            1 | 2 => out.push((3, [1, 1, 1])),
            _ => {}
        }
    }
}

let out = parallel_moa_star(&Diamond, ZeroHeuristic, 0, |s| *s == 3);
let exact = namoa_star(&Diamond, ZeroHeuristic, 0, |s| *s == 3);
let costs = |o: &multiobjective_search::Output<u8, [u32; 3]>| {
    o.solutions.iter().map(|s| s.cost).collect::<Vec<_>>()
};
assert_eq!(costs(&out), costs(&exact));

§Panics

Panics if a thread panics.