Skip to main content

two_phase

Function two_phase 

Source
pub fn two_phase<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 + WideMul, P: Fn(&G::State) -> bool,
Expand description

The two-phase method: every Pareto-optimal cost, one path each, sorted by cost.

Phase 1 is supported_solutions. Phase 2 searches each triangle between two neighbouring supported solutions a and b: every other Pareto-optimal cost lies strictly inside the box a1 < c1 < b1, b2 < c2 < a2, found by BOA*’s label setting restricted to that box, with a’s second cost as the initial bound.

Same requirements as supported_solutions; the result equals boa_star’s.

§Examples

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

/// Four routes from 0 to 1; (5, 5) is non-supported.
struct Routes;

impl Graph for Routes {
    type State = u8;
    type Weight = [u32; 2];

    fn successors(&self, state: &u8, out: &mut Vec<(u8, [u32; 2])>) {
        if *state == 0 {
            out.extend([(1, [1, 9]), (1, [2, 8]), (1, [5, 5]), (1, [9, 1])]);
        }
    }
}

let both = two_phase(&Routes, ZeroHeuristic, 0, |s| *s == 1);
let exact = boa_star(&Routes, ZeroHeuristic, 0, |s| *s == 1);
assert_eq!(both.solutions, exact.solutions);