Skip to main content

yen_k_shortest

Function yen_k_shortest 

Source
pub fn yen_k_shortest<N, FN, I>(
    src: N,
    dest: N,
    k: usize,
    neighbors: FN,
) -> Vec<YenPath<N>>
where N: Clone + Eq + Hash, FN: FnMut(&N) -> I, I: IntoIterator<Item = (N, f64)>,
Expand description

Find up to k shortest loopless paths from src to dest.

Uses Yen’s algorithm with Dijkstra as the inner shortest-path routine.

§Arguments

  • src - source node
  • dest - destination node
  • k - maximum number of paths to find
  • neighbors - closure returning (neighbor, edge_cost) pairs for a node

Returns paths sorted by ascending cost. May return fewer than k paths if fewer distinct loopless paths exist.