Documentation

CslibFrontier.Algorithms.WordRAM.GomoryHu

Gomory–Hu trees on the Word-RAM #

Gusfield's algorithm ([Gus90]) as one uniform flat program over Cslib.WordRAM.Basis.exact, with the dense Edmonds–Karp solver Cslib.Algorithms.WordRAM.EdmondsKarp.ekProg ([EK72]) as its maximum flow subroutine. Basis.exact supplies the unit-cost multiplication used for the row-major addresses 3 + u * n + v of the n × n weight matrix and of the flow matrix of the subroutine.

Overview #

The input encodeInput W r = n :: r :: flattenMatrix W places n at address 1, the root r at address 2 and W u v at 3 + u * n + v. The program allocates the workspace up to ghWorkspace n = 3 + 2 * n ^ 2 + 4 * n: the parent array at parAddr n u = 3 + n * n + u, the weight array at wtAddr n u = 3 + n * n + n + u, and the scratch area of ekProg after them. It then

  1. scans the matrix for its maximum entry M, the capacity bound given to ekProg;
  2. starts from the star centred at r, with weight 0 everywhere;
  3. for s = 0, …, n - 1 other than r, with t the current parent of s: runs ekProg on (s, t), whose final breadth-first search marks the s-side X of a minimum s–t cut; re-hangs below s every other vertex with parent t in X; and if the parent of t lies in X, lets s take the place of t. The tree-edge weights are updated from the flow value as in Cslib.Algorithms.Lean.GomoryHu.gusfieldStepWeight.

Each step costs ekCost n + O(n) memory operations, O(n ^ 5), so the program halts within C * (n + 1) ^ 6 instructions. This is the O(n ^ 6) bound of Gusfield's algorithm with dense Edmonds–Karp, formerly stated with TimeM annotations, now proved for a machine.

Correctness is transferred from Cslib.Algorithms.Lean.GomoryHu.gusfieldWithWeights_spec, which accepts any oracle returning minimum cuts: after k steps the arrays hold gusfieldWeightLoop C val r run on the first k vertices, for oracles C and val that agree with the machine at every pair it queried. The machine and Cslib.Algorithms.Lean.GomoryHu.gomoryHu may return different minimum cuts, and hence different trees.

Main definitions #

Main results #

Limitations #

The weights are natural numbers, and the word width must hold ekBound n B, a bound on the cut sums and flow updates of the subroutine.

References #

Input encoding and layout #

Word-RAM input n :: r :: flattenMatrix W: the number of vertices, the root, and the weight matrix in row-major order, so that W u v is the input word at memory address 3 + u * n + v.

Address of the parent of u in the output tree (3 + n * n + u).

Address of the weight of the tree edge from u to its parent (3 + n * n + n + u).

Memory frontier 3 + 2 * (n * n) + 4 * n of the program: the input, the parent and weight arrays, and the scratch area of the Edmonds–Karp subroutine.

Programs #

Realization #

State-level effect of the loop steps #

Gusfield's algorithm on prefixes of the vertex order #

The input #

Admissibility #

Memory-operation counts #

Correctness #

The uniform program #

theorem Cslib.Algorithms.WordRAM.GomoryHu.exists_gomoryHu_program :
∃ (R : ℕ) (C : ℕ) (pc : ℕ), 0 < C ∧ ∃ (prog : WordRAM.Program WordRAM.Basis.exact R), ∀ {n : ℕ} (W : Fin n → Fin n → ℕ) (r : Fin n) (B w : ℕ), WeightedCut.IsMultigraph W → (∀ (u v : Fin n), W u v ≤ B) → WordRAM.Fits w (ghWorkspace n) → WordRAM.Fits w (EdmondsKarp.ekBound n B) → ∃ (y : WordRAM.Data R) (steps : ℕ) (res : ℕ) (p : Fin n → Fin n), WordRAM.Runs w prog (WordRAM.State.init (encodeInput W r)) { pc := pc, data := y } steps ∧ WordRAM.step w prog { pc := pc, data := y } = WordRAM.Outcome.halt res ∧ steps + 1 ≤ C * (n + 1) ^ 6 ∧ (∀ (u : Fin n), y.mem (parAddr n ↑u) = ↑(p u)) ∧ p r = r ∧ Lean.GomoryHu.IsGomoryHuTree (WeightedCut.cutWeight W) (SimpleGraph.parentGraph p) ∧ ∀ (u : Fin n), y.mem (wtAddr n ↑u) = WeightedCut.minCutBetween W u (p u)

Gusfield's Gomory–Hu tree algorithm on the Word-RAM ([Gus90], with [EK72] as the maximum flow subroutine): one flat program over Basis.exact that, on the input encodeInput W r of a weighted multigraph W on Fin n with entries at most B and a root r, halts within C * (n + 1) ^ 6 instructions at every word width w that fits the workspace ghWorkspace n and the subroutine's word bound ekBound n B. The final memory holds a parent function p rooted at r whose parent graph is a Gomory–Hu tree of W (at parAddr n u) and the minimum cut weight minCutBetween W u (p u) of every tree edge (at wtAddr n u, 0 at the root).