Documentation

CslibFrontier.Algorithms.WordRAM.HopcroftKarp.Layout

Hopcroft–Karp instances, register layout, and CSR frame #

Problem instances (SparseInstance, DenseInstance), their word encodings and maximum-matching outputs, the public register layout (Reg), and the in-memory CSR and workspace-pointer invariants (CSRMem, BaseRegs) for the word-RAM Hopcroft–Karp implementation.

Main definitions #

Main results #

Problem instances and encodings #

A bipartite graph instance on Fin m × Fin r represented by left-vertex adjacency lists adj, encoded in compressed sparse row (CSR) format.

  • m : ℕ

    Number of left vertices.

  • r : ℕ

    Number of right vertices.

  • adj : Fin self.m → List (Fin self.r)

    Candidate right-neighbour list of each left vertex u : Fin m.

Bipartite edge indicator induced by inst.adj.

Starting CSR offset of left vertex u (0 ≤ u ≤ m).

Total number of CSR edge entries ∑ u, (adj u).length.

CSR word encoding m :: r :: offsets ++ flatEdges (m + numEdges + 3 words).

Matched pairs (u, v) of (hopcroftKarp inst.graph inst.adj).matching, ordered by ascending right vertex v : Fin inst.r.

Flat output word list [u₀, v₀, u₁, v₁, …] of length 2 * maxMatchingCard.

Sufficient word-value envelope for all input words, CSR pointers, workspace addresses, and output words on inst.

theorem Cslib.Algorithms.WordRAM.HopcroftKarp.SparseInstance.offset_succ (inst : SparseInstance) {u : ℕ} (hu : u < inst.m) :
inst.offset (u + 1) = inst.offset u + (inst.adj ⟨u, hu⟩).length
theorem Cslib.Algorithms.WordRAM.HopcroftKarp.SparseInstance.flatEdges_getElem (inst : SparseInstance) (u : Fin inst.m) {i : ℕ} (hi : i < (inst.adj u).length) :
inst.flatEdges[inst.offset ↑u + i] = ↑(inst.adj u)[i]

Entry offset u + i of inst.flatEdges is the i-th neighbour of u.

inst.matchingPairs agrees with filtering the final hkLoop right-vertex mate vector.

inst.matchingPairs.toFinset equals (hopcroftKarp inst.graph inst.adj).matching, hence is a maximum matching of inst.graph.

Entry 2 * i of inst.matchingWords is the left endpoint of the i-th matched edge.

Entry 2 * i + 1 of inst.matchingWords is the right endpoint of the i-th matched edge.

inst is balanced (m = r) and inst.graph admits a perfect matching.

Instances For

    A dense bipartite graph instance on Fin m × Fin r represented by an m × r 0/1 adjacency matrix.

    Underlying exact CSR instance ⟨m, r, exactBipAdj graph⟩.

    Row-major word encoding m :: r :: matrixWords (2 + m * r words).

    Ordered edge list of the maximum matching computed by dense Hopcroft–Karp on inst.graph.

    Flat output word list [u₀, v₀, u₁, v₁, …] of a maximum matching of inst.graph.

    Sufficient word-value envelope for dense Hopcroft–Karp on inst.

    Entry 2 * i of inst.matchingWords is the left endpoint of the i-th matched edge.

    Entry 2 * i + 1 of inst.matchingWords is the right endpoint of the i-th matched edge.

    Registers and memory layout #

    @[reducible, inline]

    Constant 0.

    @[reducible, inline]

    Constant 1.

    @[reducible, inline]

    Constant 2.

    @[reducible, inline]

    Left side size m.

    @[reducible, inline]

    Right side size r.

    @[reducible, inline]

    Total CSR edge entries numEdges.

    @[reducible, inline]

    Base address of CSR offset[0..m].

    @[reducible, inline]

    Base address of CSR edges[0..numEdges).

    @[reducible, inline]

    Base address of colMate[0..r).

    @[reducible, inline]

    Base address of matched-left flags ml[0..m).

    @[reducible, inline]

    Base address of layer distances dist[0..m).

    @[reducible, inline]

    Base address of BFS queue queue[0..m).

    @[reducible, inline]

    Base address of DFS visited flags vis[0..r).

    @[reducible, inline]

    Base address of DFS left-vertex stack stackU[0..m + 2).

    @[reducible, inline]

    Base address of DFS right-vertex stack stackV[0..m + 2).

    @[reducible, inline]

    Base address of DFS current-arc cursor stack stackPos[0..m + 2).

    @[reducible, inline]

    Base address of phase rematch left endpoints augU[0..r).

    @[reducible, inline]

    Base address of phase rematch right endpoints augV[0..r).

    @[reducible, inline]

    Output header address register (for ExecutesList programs).

    @[reducible, inline]

    Scalar output / loop-active register (for Executes programs).

    In-memory CSR representation of inst : SparseInstance starting at bOff.

    • hoff {u : ℕ} : u ≤ inst.m → mem (bOff + u) = inst.offset u

      offset[u] for 0 ≤ u ≤ m.

    • hedge (u : Fin inst.m) {i : ℕ} (hi : i < (inst.adj u).length) : mem (bOff + inst.m + 1 + (inst.offset ↑u + i)) = ↑(inst.adj u)[i]

      edges[offset u + i] for u : Fin m, i < (adj u).length.

    theorem Cslib.Algorithms.WordRAM.HopcroftKarp.CSRMem.of_outside {inst : SparseInstance} {bOff : ℕ} {mem mem' : ℕ → ℕ} (h : CSRMem inst bOff mem) (hf : ∀ (a : ℕ), bOff ≤ a ∧ a < bOff + inst.m + 1 + inst.numEdges → mem' a = mem a) :
    CSRMem inst bOff mem'

    Read-only constant and workspace base-pointer registers (0 .. 18) for coreCode.

    theorem Cslib.Algorithms.WordRAM.HopcroftKarp.BaseRegs.of_eq {inst : SparseInstance} {bOff : ℕ} {x y : WordRAM.Data 34} (hb : BaseRegs inst bOff x) (heq : ∀ (i : Fin 34), ↑i < 19 → y.regs i = x.regs i) :
    BaseRegs inst bOff y

    Transport BaseRegs across states that agree on registers 0 .. 18.