Skip to main content

fptas_constrained

Function fptas_constrained 

Source
pub fn fptas_constrained<G, C, P>(
    graph: &G,
    start: G::State,
    is_goal: P,
    budget: C,
    eps: Epsilon,
    stats: &mut Stats,
) -> Option<Solution<G::State, [C; 2]>>
where G: Graph<Weight = [C; 2]>, C: Cost + Into<u64>, P: Fn(&G::State) -> bool,
Expand description

An FPTAS for the constrained shortest path: a path from start to a goal with second cost at most budget and first cost at most 1 + ε times the optimum constrained_shortest_path finds; None if no path fits the budget.

The reachable graph (n states, which must be finite) is relaxed in n - 1 Bellman-Ford rounds. Each state keeps at most one label per box of first costs, the boxes growing geometrically by 1 + δ with δ = ε / (2 (n - 1)), and in each box the label with the smallest second cost. So every state holds O(n log(C) / ε) labels, polynomial in the input and 1 / ε, unlike the exact and ε-searches, whose label counts can grow exponentially. Trimming loses at most a factor 1 + δ per edge of the optimal path, and (1 + δ)^(n-1) <= e^(ε/2) <= 1 + ε for ε <= 2; larger tolerances are capped at 2. ε = 0 is exact.

Requirements, not checked at run time: non-negative costs and a finite reachable graph. Costs must convert into u64 for the box arithmetic. Goal states are not expanded. Counters go to stats.

§Examples

use multiobjective_search::{Epsilon, Graph, Stats, fptas_constrained};

/// Three routes from 0 to 1: (time, fuel).
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, [10, 9]), (1, [30, 5]), (1, [31, 4])]);
        }
    }
}

let mut stats = Stats::default();
let tenth = Epsilon::new(1, 10);
let best = fptas_constrained(&Routes, 0, |s| *s == 1, 5, tenth, &mut stats).unwrap();
assert!(best.cost[1] <= 5 && best.cost[0] <= 33); // optimum 30, within 10 %