aryagraph.algorithms.flow.maximum_flow#

aryagraph.algorithms.flow.maximum_flow(g: Graph, s: Hashable, t: Hashable, capacity: str | Callable[[Hashable, Hashable, dict], Any] = 'capacity') → FlowResult[source]#

Maximum s``→``t flow by Dinic’s algorithm (blocking flows on BFS level graphs).

Parameters:

capacity – Edge-attribute name (edges without it have unlimited capacity) or f(u, v, attrs) (None = unlimited).

Returns:

FlowResult – The flow value and flow[u][v] for every edge.

Raises:
  • NodeNotFound – If s or t is not in the graph.

  • ValueError – If s == t or a capacity is negative/NaN.

  • UnboundedFlowError – If an all-infinite path makes the flow unbounded (a subclass of ValueError).

Notes

O(n²·m) in general, O(m·√n) on unit-capacity networks.