Skip to main content

widest_path_widths

Function widest_path_widths 

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

Single-source widest-path widths on graph from source, following out-edges on directed graphs.

Returns widths[v]:

  • Some(f64::INFINITY) for v == source (no path constraint yet)
  • Some(w) if v is reachable, with w the maximum bottleneck width of any source → v path
  • None if v is unreachable

A path’s bottleneck width is the minimum edge weight along it; the widest path maximises this bottleneck across all source→target paths. Useful in network-capacity problems.

weights[e] is the width of edge e; length must equal graph.ecount(). NaN widths are rejected. Edges with weight -f64::INFINITY are treated as “edge absent” (matches upstream).

Counterpart of igraph_widest_path_widths_dijkstra(_, _, vss(source), vss_all(), weights, IGRAPH_OUT).

§Examples

use rust_igraph::{Graph, widest_path_widths};

// Triangle 0-1-2 with edge weights 1, 4, 2.
// Widest 0→2 path: direct edge (width 4) beats 0-1-2 (min(1,2) = 1).
let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();  // edge 0, width 1
g.add_edge(0, 2).unwrap();  // edge 1, width 4
g.add_edge(1, 2).unwrap();  // edge 2, width 2
let w = widest_path_widths(&g, 0, &[1.0, 4.0, 2.0]).unwrap();
assert_eq!(w[0], Some(f64::INFINITY));
assert_eq!(w[1], Some(2.0));  // via 0-2-1: min(4, 2) = 2
assert_eq!(w[2], Some(4.0));  // direct