Hopcroft–Karp maximum bipartite matching on the word RAM #
This file implements and proves machine-level running-time bounds on the standard-basis word RAM
(Basis.standard) for:
- Sparse Hopcroft–Karp (
O((m + r + |E|) √ν)): given a bipartite graph onFin m × Fin rrepresented in compressed sparse row (CSR) format (SparseInstance),coreCodealternates queue-based breadth-first layering (O(m + r + |E|)instructions per round,CslibFrontier.Algorithms.WordRAM.HopcroftKarp.BFS) and iterative explicit-stack depth-first augmentation (O(m + r + |E|)instructions per phase,CslibFrontier.Algorithms.WordRAM.HopcroftKarp.DFS), matching the pure specificationCslib.Algorithms.Lean.MaxFlow.hopcroftKarp(IsMaxMatching, at most2⌊√ν⌋augmenting phases byIsPhaseRun.le_two_mul_sqrt). This yields end-to-endState.initprograms for maximum matching (sparseMatchingProgram), matching cardinality (sparseCardProgram), and balanced perfect-matching decision (sparsePerfectProgram). - Dense Hopcroft–Karp (
O((m + r)² √ν)): given anm × r0/1adjacency matrix (DenseInstance), converts the input matrix into exact CSR neighbour lists (exactBipAdj) inO(m + m r)instructions (buildCSRCode/matrixSetupCode,CslibFrontier.Algorithms.WordRAM.HopcroftKarp.MatrixCSR) and invokescoreCode, agreeing withhopcroftKarpDense.
The O(n^{5/2}) Dilworth minimum chain cover and maximum antichain endpoints built on top of
matrixSetupCode and coreCode live in CslibFrontier.Algorithms.WordRAM.ChainCover.
Main definitions #
Cslib.Algorithms.WordRAM.HopcroftKarp.SparseInstance,Cslib.Algorithms.WordRAM.HopcroftKarp.DenseInstance: sparse CSR and dense matrix problem instances with their word encodings, word-width envelopes, and outputs (SparseInstance.matchingPairs,DenseInstance.matchingPairs,matchingWords).Cslib.Algorithms.WordRAM.HopcroftKarp.CSRMem,Cslib.Algorithms.WordRAM.HopcroftKarp.BaseRegs: in-memory CSR layout and base-register frame forcoreCode.Cslib.Algorithms.WordRAM.HopcroftKarp.coreCode,Cslib.Algorithms.WordRAM.HopcroftKarp.buildCSRCode,Cslib.Algorithms.WordRAM.HopcroftKarp.matrixSetupCode,Cslib.Algorithms.WordRAM.HopcroftKarp.sparseMatchingProgram,Cslib.Algorithms.WordRAM.HopcroftKarp.sparseCardProgram,Cslib.Algorithms.WordRAM.HopcroftKarp.sparsePerfectProgram,Cslib.Algorithms.WordRAM.HopcroftKarp.denseMatchingProgram,Cslib.Algorithms.WordRAM.HopcroftKarp.denseCardProgram: word-RAM subroutines and programs.Cslib.Algorithms.WordRAM.HopcroftKarp.coreTime,Cslib.Algorithms.WordRAM.HopcroftKarp.sparseTime,Cslib.Algorithms.WordRAM.HopcroftKarp.sparseTimeSqrtMin,Cslib.Algorithms.WordRAM.HopcroftKarp.denseTime: instruction bounds.
Main results #
Cslib.Algorithms.WordRAM.HopcroftKarp.core_exec: in-memory CSR execution of Hopcroft–Karp inO((m + r + |E|) (√ν + 1))instructions.Cslib.Algorithms.WordRAM.HopcroftKarp.exec_buildCSRCode,Cslib.Algorithms.WordRAM.HopcroftKarp.exec_matrixSetupCode: dense/square0/1-matrix to CSR conversion inO(m + m r)instructions.Cslib.Algorithms.WordRAM.HopcroftKarp.SparseInstance.getElem_matchingWords_even,Cslib.Algorithms.WordRAM.HopcroftKarp.SparseInstance.getElem_matchingWords_odd,Cslib.Algorithms.WordRAM.HopcroftKarp.DenseInstance.isMaxMatching_matchingPairs: flat-word pair indexing and dense maximum-matching optimality.Cslib.Algorithms.WordRAM.HopcroftKarp.executesList_sparseMatching,Cslib.Algorithms.WordRAM.HopcroftKarp.computesListInTime_sparseMatching,Cslib.Algorithms.WordRAM.HopcroftKarp.executes_sparseCard,Cslib.Algorithms.WordRAM.HopcroftKarp.decidesInTime_sparsePerfect: sparseO((m + r + |E|) √ν)endpoints.Cslib.Algorithms.WordRAM.HopcroftKarp.executesList_denseMatching,Cslib.Algorithms.WordRAM.HopcroftKarp.computesListInTime_denseMatching,Cslib.Algorithms.WordRAM.HopcroftKarp.executes_denseCard: denseO((m + r)² √ν)endpoints.
References #
In-memory Hopcroft–Karp solver on a CSR bipartite graph inst stored at bOff.
Initializes colMate[0..r) to m (none), then alternates bfsCode and dfsPhaseCode until
no augmenting path remains, leaving the maximum matching in colMate[0..r) and the closed
alternating-layer distances in dist[0..m).
Instruction bound O((m + r + E) (√ν + 1)) for coreCode on a CSR graph with sides m, r,
E edge entries, and maximum matching cardinality ν.
In-memory O((m + r + |E|) (√ν + 1)) execution of Hopcroft–Karp (coreCode).
Starting from any state x with BaseRegs inst bOff x and CSRMem inst bOff x.mem, coreCode
terminates within coreTime inst.m inst.r inst.numEdges inst.maxMatchingCard instructions, leaving
the maximum matching res.mate in colMate[0..r) and the closed alternating-layer distances
res.dist in dist[0..m), while preserving BaseRegs, CSRMem, and all memory outside the
workspace [bOff + m + 1 + numEdges, outBase).
Matching output extraction (emitMatchingCode) #
End-to-end State.init sparse CSR endpoints #
Standard-basis word-RAM program returning inst.matchingWords (ExecutesList) on a CSR
bipartite graph inst : SparseInstance.
Standard-basis word-RAM program returning the maximum matching cardinality
inst.maxMatchingCard (Executes) on inst : SparseInstance.
Standard-basis word-RAM program deciding SparseInstance.HasPerfectMatching (1 iff balanced
and admitting a perfect matching, 0 otherwise).
Instruction bound O((m + r + E) (√ν + 1)) for sparseMatchingProgram, sparseCardProgram,
and sparsePerfectProgram.
Instance-only O((m + r + E) √(min m r)) upper bound on sparseTime.
O((m + r + |E|) √ν) Word-RAM maximum bipartite matching (ExecutesList).
Instance-only O((m + r + |E|) √(min m r)) corollary of executesList_sparseMatching.
Program.ComputesListInTime form of executesList_sparseMatching.
O((m + r + |E|) √ν) Word-RAM maximum matching cardinality (Executes).
Program.ComputesInTime form of executes_sparseCard.
O((m + r + |E|) √ν) Word-RAM perfect-matching decision (Executes).
Program.DecidesInTime form of executes_sparsePerfect.
End-to-end State.init dense endpoints #
Standard-basis word-RAM program returning inst.matchingWords (ExecutesList) on a dense
m × r 0/1 adjacency matrix inst : DenseInstance.
Standard-basis word-RAM program returning inst.maxMatchingCard (Executes) on
inst : DenseInstance.
Instruction bound O((m + r)² √ν) for denseMatchingProgram and denseCardProgram.
O((m + r)² √ν) Word-RAM dense maximum bipartite matching (ExecutesList).
Program.ComputesListInTime form of executesList_denseMatching.
O((m + r)² √ν) Word-RAM dense maximum matching cardinality (Executes).
Program.ComputesInTime form of executes_denseCard.