pub fn max_flow_value(
graph: &Graph,
source: VertexId,
target: VertexId,
capacity: Option<&[f64]>,
) -> IgraphResult<f64>Expand description
Scalar maximum-flow value from source to target.
Counterpart of igraph_maxflow_value in
references/igraph/src/flow/flow.c (igraph C uses Goldberg-Tarjan
push-relabel; this implementation uses Dinic’s algorithm — the
scalar value matches by the max-flow / min-cut uniqueness theorem).
§Arguments
graph— input graph (directed or undirected).source— source vertex id (0 ≤ source < vcount()).target— sink vertex id (0 ≤ target < vcount(),target != source).capacity— optional per-edge capacity in the graph’s edge-id order. WhenNone, each edge contributes unit capacity. WhenSome(c),c.len()must equalgraph.ecount(), and every entry must be finite and≥ 0.
§Returns
The maximum total flow value as f64, summing to 0.0 when source
and target are in disjoint connected components or when every
source → target path is blocked by zero-capacity edges.
§Errors
IgraphError::VertexOutOfRangeifsourceortargetis outside[0, vcount()).IgraphError::InvalidArgumentifsource == target, the capacity slice length differs fromecount(), or any capacity is negative / non-finite.
§Examples
use rust_igraph::{Graph, max_flow_value};
// Two parallel paths of capacity 1 each → max flow = 2.
let mut g = Graph::new(4, true).unwrap();
g.add_edge(0, 1).unwrap();
g.add_edge(1, 3).unwrap();
g.add_edge(0, 2).unwrap();
g.add_edge(2, 3).unwrap();
let cap = vec![1.0, 1.0, 1.0, 1.0];
let f = max_flow_value(&g, 0, 3, Some(&cap)).unwrap();
assert!((f - 2.0).abs() < 1e-12);