Gomory–Hu trees with n - 1 maximum flow computations #
An executable TimeM construction of a Gomory–Hu tree of a weighted multigraph
W : Fin n → Fin n → ℕ, following Gusfield's contraction-free algorithm ([Gus90]): one
Edmonds–Karp maximum flow computation ([EK72]) per non-root vertex, so n - 1 in total,
all on the original graph, plus O(n) bookkeeping per vertex on a parent array and edge-weight
array fl. Correctness is transferred from the abstract algorithm
Cslib.Algorithms.Lean.GomoryHu.gusfieldWithWeights of
CslibFrontier.Algorithms.Lean.GomoryHu.Gusfield, with the Edmonds–Karp minimum cut and maximum
flow value as the oracle.
Main definitions #
Cslib.Algorithms.Lean.GomoryHu.Output: parent arrayparentand edge-weight arrayweightreturned by Gusfield's algorithm.Cslib.Algorithms.Lean.GomoryHu.gomoryHuM: Gusfield's algorithm overFin ninTimeM ℕ, returning the parent array and edge weights of the tree.Cslib.Algorithms.Lean.GomoryHu.ekCut,Cslib.Algorithms.Lean.GomoryHu.ekValue: the minimum cut and maximum flow value returned byedmondsKarpM.
Main results #
Cslib.Algorithms.Lean.GomoryHu.isGomoryHuTree_gomoryHuM: the parent graph of the output is a Gomory–Hu tree ofcutWeight W(cut-equivalent: the side of each tree edgeuvcontaininguis a minimumu–vcut ofW).Cslib.Algorithms.Lean.GomoryHu.vget_gomoryHuM_weight_eq_minCutBetween: for every vertexu : Fin n, the recorded weightvget (gomoryHuM W adj r).ret.weight uequalsminCutBetween W u (vget (gomoryHuM W adj r).ret.parent u)(0at the rootr,vget_gomoryHuM_weight_root).Cslib.Algorithms.Lean.GomoryHu.vget_gomoryHuM,Cslib.Algorithms.Lean.GomoryHu.vget_gomoryHuM_parent,Cslib.Algorithms.Lean.GomoryHu.vget_gomoryHuM_weight: the output agrees with the abstractgusfieldParentandgusfieldWithWeightsrun withekCutandekValue.Cslib.Algorithms.Lean.GomoryHu.gomoryHuM_time_le_of_forall: the charged time is at most3 nplusn - 1times (any bound on one Edmonds–Karp computation, plusn + 3).Cslib.Algorithms.Lean.GomoryHu.gomoryHuM_time_le: the same with the Edmonds–Karp boundedmondsKarpM_time_le,O(n m²)per computation formedges, soO(n² m²)in total.Cslib.Algorithms.Lean.GomoryHu.gomoryHuM_time_le_dense:O(n ^ 6)with dense adjacency lists.
Cost model #
The unit-cost model of Cslib.Algorithms.Lean.MaxFlow.edmondsKarpM, extended with Finset
membership on the returned cut and reading out.flow.value (netOut N.s, an O(n) sum over
Fin n) as free primitives: Vector reads and writes, those membership tests, that Flow.value
sum, equality tests on Fin n, and evaluating W u v count as O(1) primitives inside charged
steps. (Computing out.flow.value once per step would add O(n²) in total, subsumed by the
re-hanging scan; O(n) Finset membership tests inside each n-vertex scan would add O(n³) in
total.) Charged: n ticks to allocate the parent array p, n ticks to allocate the edge-weight
array fl, 1 tick per vertex for the loop test s = r, and for each non-root vertex s: 1
tick to read its parent, the full Edmonds–Karp cost, n ticks for the re-hanging scan over all
vertices, 1 tick for the final swap test and its parent writes, and 1 tick to record the edge
weight in fl.
Limitations #
The weights of W are natural numbers, and only Edmonds–Karp is instantiated as the maximum flow
oracle (gomoryHuM_time_le_of_forall accepts any per-call bound).
References #
Output of Gusfield's Gomory–Hu tree construction on Fin n: the parent array parent rooted
at r and the edge-weight array weight storing λ(u, parent[u]) for every non-root u (0 at
the root r).
Parent array of the tree (
vget parent r = r).Edge weight
λ(u, vget parent u)for every non-root vertexu(0atr).
Instances For
The Edmonds–Karp cut is a minimum s–t cut of the cut function of W, for adjacency lists
covering the edges of W.
The Edmonds–Karp maximum flow value equals the weight of ekCut W adj s t, for adjacency lists
covering the edges of W.
One step of Gusfield's algorithm on the parent array p and weight array fl for vertex s:
one Edmonds–Karp computation between s and its parent t, a scan re-hanging the vertices on the
s-side below s, the swap of s and t when the parent of t is on the s-side, and the
weight update from the maximum flow value (fl[s] := val, or on a swap fl[s] := fl[t] and
fl[t] := val).
Instances For
The weight array computed by gusfieldStepM agrees pointwise with gusfieldStepWeight.
Gusfield's Gomory–Hu tree algorithm ([Gus90]) over Fin n in TimeM ℕ: start
from the star centred at the root r with 0 initial weights, and process the other vertices in
order with one Edmonds–Karp computation each. Returns both the parent array parent and the tree
edge weights weight.
Instances For
The parent array returned by gomoryHuM agrees pointwise with the first component of
gusfieldWithWeights.
The weight array returned by gomoryHuM agrees pointwise with the second component of
gusfieldWithWeights.
Correctness of Gusfield's algorithm with Edmonds–Karp ([Gus90]): for a weighted
multigraph W on Fin n and adjacency lists adj covering its edges, the parent array computed
by gomoryHuM is a Gomory–Hu tree of W: for every tree edge uv, the side of T - uv
containing u is a minimum u–v cut of W.
Correctness of the edge weights returned by gomoryHuM ([Gus90]): for every vertex
u : Fin n, the weight vget (gomoryHuM W adj r).ret.weight u equals the minimum cut weight
minCutBetween W u (vget (gomoryHuM W adj r).ret.parent u) between u and its parent (0 at the
root r).
Running time of Gusfield's algorithm. If every Edmonds–Karp computation on the
capacities W takes at most B charged steps, gomoryHuM W adj r takes at most
3 n + (n - 1) (B + n + 3): 2 n to allocate the parent and weight arrays, 1 per vertex for
the loop, and for each of the n - 1 non-root vertices one maximum flow computation, the n-step
re-hanging scan and 3 steps of pointer and weight updates.
Running time with sparse adjacency lists. With adjacency lists adj covering the edges
of W, Gusfield's algorithm makes n - 1 Edmonds–Karp computations, each within
(adjSteps adj * (n / 2) + 2) * (adjSteps adj + 5 n) steps (O(n m²) for m edges), plus
O(n) bookkeeping per computation.