Dinitz's Blocking-Flow Maximum-Flow Algorithm #
Formalizes an executable version of Dinitz's algorithm ([Din70]; [Sch03],
Section 10.6) over Network (Fin n): repeatedly compute the breadth-first levels of the residual
network, find a blocking flow of the level network, and augment by it, until N.t is no longer
residually reachable from N.s.
Mathematical and algorithmic overview #
- Greedy blocking flows (
greedyBlockingFlow): inside a level networkL, while a path of unsaturated arcs joins the terminals (found bybfson the slack networkFlow.slackNet), push its bottleneck. Since a level network has no antiparallel arcs, each push only increases arc flows and saturates a new arc (Flow.card_unsatArcs_augmentByBottleneck_lt), so the loop stops with a blocking flow after at most|Flow.unsatArcs|pushes (greedyBlockingFlow_spec), which is at most|N.posArcs|at the zero flow of a level network (Flow.card_unsatArcs_zero_levelNet_le). - Phases (
dinitzLoop,dinitz): each phase computesFlow.bfsDist(equal toFlow.resDist), stops ifN.tis unreachable, and otherwise augments by a greedy blocking flow of the level network. The phases form a run of Dinitz phases (dinitz_isDinitzRun), hence there are at mostn - 1of them (Network.IsDinitzRun.length_le). - Correctness (
dinitz_correct): the final flow has no augmenting path, so it is a maximum flow and its residual-reachability cut is a minimum cut of equal capacity, by the max-flow min-cut API ofCslibFrontier.Algorithms.Lean.MaxFlow.Basic.
Cost model and limitations #
- Proved quantities: at most
n - 1phases and at most(n - 1) * |N.posArcs|bottleneck pushes in total (dinitz_correct). No machine running time is proved here: the functions are pure. - The blocking flow is found by a fresh breadth-first search per push, not by the depth-first
search with dead-end deletion that gives Dinitz's
O(|V| |E|)time per phase andO(|V|^2 |E|)overall; this module does not claim those time bounds. Flow.bfsDistrecomputes breadth-first balls and is meant for specification and small evaluations;FlowMatrix.ofFlowtabulates flows between phases.
Main definitions #
Cslib.Algorithms.Lean.MaxFlow.greedyBlockingFlow: greedy blocking flows in a network without antiparallel arcs.Cslib.Algorithms.Lean.MaxFlow.DinitzOutput,dinitzLoop,dinitz,dinitzDense: the algorithm.
Main results #
Cslib.Algorithms.Lean.MaxFlow.greedyBlockingFlow_spec: the greedy search returns a blocking flow after at most|unsaturated arcs|pushes.Cslib.Algorithms.Lean.MaxFlow.dinitz_isDinitzRun: the phases ofdinitzform a run of Dinitz phases from the zero flow.Cslib.Algorithms.Lean.MaxFlow.dinitz_correct,dinitzDense_correct: maximum flow, minimum cut of equal value, and the phase and push bounds.
References #
Greedy blocking flows #
Pushing the bottleneck along a path of unsaturated arcs of a network without antiparallel arcs only increases arc flows.
The bottleneck push saturates an arc that was unsaturated.
Each bottleneck push along unsaturated arcs saturates a new arc and keeps saturated arcs saturated.
A level network has at most |N.posArcs| arcs: it has no antiparallel arcs and its arcs lie
in N.symArcs.
Tabulate a flow as a FlowMatrix, so that later lookups are O(1).
Result of the greedy blocking-flow search.
- flow : FlowMatrix L
The flow found.
- pushes : ℕ
Number of bottleneck pushes performed.
Greedy blocking flows: on a network L without antiparallel arcs and with L.s ≠ L.t,
with valid neighbor lists and enough fuel, greedyBlockingFlow returns a blocking flow after at
most |G.toFlow.unsatArcs| further bottleneck pushes.
Output of Dinitz's algorithm on N : Network (Fin n).
Phases of Dinitz's algorithm with fuel remaining phases: compute the breadth-first levels;
stop if N.t is unreachable, and otherwise find a blocking flow of the level network greedily and
augment by it.
Dense specialization of dinitz using defaultAdj n.
Correctness of Dinitz's algorithm ([Din70]; [Sch03], Section 10.6): on
N : Network (Fin n) with N.s ≠ N.t and valid neighbor lists, dinitz N adj returns a maximum
flow and a minimum cut of equal value, after at most n - 1 phases of at most |N.posArcs|
bottleneck pushes each.
Correctness of dinitzDense without external adjacency obligations.