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
- scans the matrix for its maximum entry
M, the capacity bound given toekProg; - starts from the star centred at
r, with weight0everywhere; - for
s = 0, …, n - 1other thanr, withtthe current parent ofs: runsekProgon(s, t), whose final breadth-first search marks thes-sideXof a minimums–tcut; re-hangs belowsevery other vertex with parenttinX; and if the parent oftlies inX, letsstake the place oft. The tree-edge weights are updated from the flow value as inCslib.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 #
Cslib.Algorithms.WordRAM.GomoryHu.encodeInput: the input word listn :: r :: flattenMatrix W.Cslib.Algorithms.WordRAM.GomoryHu.parAddr,Cslib.Algorithms.WordRAM.GomoryHu.wtAddr,Cslib.Algorithms.WordRAM.GomoryHu.ghWorkspace: the output addresses and the memory frontier.
Main results #
Cslib.Algorithms.WordRAM.GomoryHu.exists_gomoryHu_program: one program overBasis.exacthalts withinC * (n + 1) ^ 6instructions on every weighted multigraphWonFin nwith entries at mostBand every rootr, at every word width fittingghWorkspace nandekBound n B, leaving in memory a parent function rooted atrwhose parent graph is a Gomory–Hu tree ofW, together with the minimum cut weightminCutBetween W u (p u)of every tree edge.
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 #
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 #
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).