Skip to main content

quickest_path

Function quickest_path 

Source
pub fn quickest_path<G, H, C, P>(
    graph: &G,
    heuristic: H,
    start: G::State,
    is_goal: P,
    sigma: C,
) -> Option<WidePath<G::State, C>>
where G: Graph<Weight = (C, C)>, H: Heuristic<G::State, C>, C: Cost + ExactArith, P: Fn(&G::State) -> bool,
Expand description

The quickest path for sending sigma units from start to a goal: the smallest transmission time delay + sigma / capacity, with the delay the sum of the edges’ first components and the capacity the smallest second component; None if no goal is reachable.

The quickest path problem (Moore 1976; Chen and Chin 1990; surveyed by Craveirinha et al., Section 2.2.3(d)). Its optimum lies on the minsum_maxmin front (Pelegrín and Fernández 1998), which is scanned comparing (d1 · c1 + σ) · c2 with (d2 · c2 + σ) · c1 exactly through ExactArith. A zero capacity makes the time infinite unless sigma is zero; ties go to the smaller delay.

Requirements as for minsum_maxmin.

§Examples

use multiobjective_search::{Graph, heuristic_fn, quickest_path};

/// A short thin link and a long fat one from 0 to 1: (delay, capacity).
struct Links;

impl Graph for Links {
    type State = u8;
    type Weight = (u32, u32);

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

let zero = heuristic_fn(|_: &u8| Some(0));
// 5 units: 1 + 5/1 = 6 beats 10 + 5/100.
assert_eq!(quickest_path(&Links, zero, 0, |s| *s == 1, 5).map(|s| s.cost.0), Some(1));
// 1000 units: 10 + 10 = 20 beats 1 + 1000.
assert_eq!(quickest_path(&Links, zero, 0, |s| *s == 1, 1000).map(|s| s.cost.0), Some(10));