Skip to main content

widest_path_widths_floyd_warshall

Function widest_path_widths_floyd_warshall 

Source
pub fn widest_path_widths_floyd_warshall(
    graph: &Graph,
    weights: &[f64],
) -> IgraphResult<Vec<Vec<Option<f64>>>>
Expand description

All-pairs widest-path widths via the Floyd-Warshall recurrence.

Returns a vcount × vcount matrix where result[u][v] is the maximum bottleneck width of any u → v path:

  • Some(f64::INFINITY) on the diagonal (u == v)
  • Some(w) for reachable pairs with w the bottleneck width
  • None for unreachable pairs

weights[e] is the width of edge e; length must equal graph.ecount(). NaN is rejected; edges with weight -f64::INFINITY are ignored (matches upstream). Parallel edges are merged by the wider-wins rule when seeding the matrix.

Use this on dense graphs (|E| ~ V²); for sparse graphs the Dijkstra-based widest_path_widths called from every source is asymptotically faster.

Counterpart of igraph_widest_path_widths_floyd_warshall(_, _, vss_all(), vss_all(), weights, IGRAPH_OUT).

§Examples

use rust_igraph::{Graph, widest_path_widths_floyd_warshall};

// Undirected triangle (1, 4, 2) — same all-pairs result the
// Dijkstra variant produces when run from every source.
let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(0, 2).unwrap();
g.add_edge(1, 2).unwrap();
let m = widest_path_widths_floyd_warshall(&g, &[1.0, 4.0, 2.0]).unwrap();
assert_eq!(m[0][2], Some(4.0));   // direct
assert_eq!(m[0][1], Some(2.0));   // via vertex 2: min(4, 2)
assert_eq!(m[0][0], Some(f64::INFINITY));