Hopcroft–Karp queue-based breadth-first layering on the word RAM #
Implements the O(m + r + |E|) word-RAM breadth-first layering subroutine Internal.bfsCode
used by CslibFrontier.Algorithms.WordRAM.HopcroftKarp, matching the pure specification
Cslib.Algorithms.Lean.MaxFlow.hkBfs ([HK73]; [CLRS09], Problem 26-6).
Main definitions #
Cslib.Algorithms.WordRAM.HopcroftKarp.Internal.bfsCode: marks matched left vertices, seeds layer0into the FIFO queue, and expands alternating layers until a free right vertex is reached or the queue empties.
Main results #
Cslib.Algorithms.WordRAM.HopcroftKarp.Internal.exec_bfsCode:O(m + r + |E|)instruction bound and exact agreement withhkBfs.
References #
Queue-based breadth-first layering (O(m + r + |E|) instructions per round).
theorem Cslib.Algorithms.WordRAM.HopcroftKarp.Internal.exec_bfsCode {w bOff : ℕ} {inst : SparseInstance} {mate : Vector (Option (Fin inst.m)) inst.r} (x : WordRAM.Data 34) (hb : BaseRegs inst bOff x) (hcsr : CSRMem inst bOff x.mem) (hmate : MateMem inst bOff mate x.mem) (hfit : WordRAM.Fits w (bOff + 7 * inst.m + 5 * inst.r + inst.numEdges + 8)) :
have b := Lean.MaxFlow.hkBfs inst.graph inst.adj mate;
∃ (y : WordRAM.Data 34),
WordRAM.ExecWithin w bfsCode x y (51 * inst.m + 8 * inst.r + 36 * inst.numEdges + 33) ∧ (∀ (i : Fin 34), ↑i < 20 → y.regs i = x.regs i) ∧ DistMem inst bOff b.dist y.mem ∧ y.regs rk = b.k ∧ (y.regs rfound = if b.found = true then 1 else 0) ∧ ∀ (a : ℕ),
¬(bOff + inst.m + 1 + inst.numEdges + inst.r ≤ a ∧ a < bOff + inst.m + 1 + inst.numEdges + inst.r + 3 * inst.m) →
y.mem a = x.mem a
O(m + r + |E|) execution of bfsCode, agreeing with hkBfs.