Augmenting Paths, Berge's Theorem, and the Hopcroft–Karp Phase Bound #
Combinatorial core of the Hopcroft–Karp maximum bipartite matching algorithm
([HK73]; [CLRS09], Problem 26-6), on the edge-indicator representation
G : L × R → Bool and Finset (L × R) matchings of
CslibFrontier.Algorithms.Lean.MaxFlow.BipartiteMatching.
Main definitions #
altLeft,altRight,IsLayer:altLeft G M jis the set of left vertices reachable from a free left vertex by anM-alternating path with at mostjmatching edges,altRight G M jitsG-neighbourhood, andIsLayer G M u jsaysufirst appears in layerj. This is the breadth-first layering of one Hopcroft–Karp phase.NoShortAug G M ksays no layerj < kreaches a free right vertex, i.e. every augmenting path has at leastk + 1non-matching edges.IsAugmentingPath,augment: an augmenting pathu₀ v₀ u₁ v₁ … u_ℓ v_ℓis recorded by its non-matching edges(uᵢ, vᵢ), with(uᵢ₊₁, vᵢ) ∈ M, distinct vertices and free ends.augment M Nreplaces theM-edges at left vertices covered byNwithN; for a path this is the symmetric differenceM ⊕ p.IsMaximalLayeredAugmentation,IsLayeredFamily: the edge setNfound by one phase follows the layers ofMto a free right vertex in layerk, replacesM-edges at both ends, and admits no further layered path avoiding it.IsLayeredFamilyis the list-level description produced by depth-first search (concatenated vertex-disjoint shortest augmenting paths), andIsLayeredFamily.isMaximalLayeredAugmentationpackages it.IsPhaseRun G M n:nHopcroft–Karp phases fromM, each using the exact shortest augmenting path parameter and a maximal layered augmentation.layerCover G M j: unreached left vertices together with reached right vertices.
Main results #
card_mul_le_of_noShortAug(layered counting lemma):k * |M'| ≤ (k + 1) * |M|for every matchingM'whenNoShortAug G M k, obtained from weak duality against the vertex coverslayerCover G M j.isMaxMatching_iff_forall_not_isAugmentingPath(Berge's theorem): the bipartite case of [Ber57], Theorem 1. The proof is not the textbook decomposition ofM ⊕ M*into alternating paths and cycles: it uses the layered counting lemma.IsMaximalLayeredAugmentation.noShortAug_augment(phase lemma): after augmenting along a maximal set of vertex-disjoint shortest augmenting paths, the shortest augmenting path is strictly longer ([HK73], consequence of Theorem 2; [CLRS09], Problem 26-6).IsPhaseRun.add_card_le_and_add_le_two_mul_sqrt,IsPhaseRun.le_two_mul_sqrt(phase count): the counting lemma gives the deficit boundt * (ν - |M|) ≤ |M|aftertphases, hence at most2 ⌊√ν⌋augmenting phases from the empty matching,νthe maximum matching size. This is slightly sharper than the2 ⌊√s⌋ + 2bound on distinct shortest-path lengths of [HK73], Theorem 3, because only phases that augment are counted.isMaxMatching_isMinVertexCover_of_stable(König certificate): when the layers stop growing without reaching a free right vertex, the layer cover is a minimum vertex cover of size|M|.
Limitations #
- The decomposition of
M ⊕ M*into at least|M*| - |M|vertex-disjoint augmenting paths is not formalized; the counting lemma replaces it in both Berge's theorem and the phase bound. - Only bipartite graphs are treated (no blossoms).
References #
Left endpoints of the edges of M.
Right endpoints of the edges of M.
A matching has at most as many edges as there are left vertices.
A matching has at most as many edges as there are right vertices.
Left vertices reachable from free left vertices by an M-alternating path with at most j
matched edges.
Right vertices adjacent to altLeft G M j.
u first appears in alternating layer j.
No alternating path with at most k - 1 matched edges from a free left vertex ends at a free
right vertex: every vertex of altRight G M j, j < k, is matched.
Vertex cover built from alternating layer j: unreached left vertices and reached right
vertices.
Layered counting lemma. If no alternating path with fewer than k matched edges leads from
a free left vertex to a free right vertex, then every matching M' satisfies
k * |M'| ≤ (k + 1) * |M|.
Replace the edges of M at left vertices covered by N with the edges of N.
Augmenting a matching M by a matching N gives a matching provided every edge of M whose
right end is covered by N also has its left end covered by N.
Exact size of an augmentation: each newly covered left vertex adds one edge.
The left vertices covered by an augmentation are those covered by N or by M.
An M-augmenting path u₀ v₀ u₁ v₁ … uₗ vₗ, recorded by its non-matching edges
(uᵢ, vᵢ): consecutive ones are joined by matching edges (uᵢ₊₁, vᵢ) ∈ M, all vertices are
distinct, and both ends u₀, vₗ are free.
Every left vertex of an augmenting path other than its first is already matched.
An augmenting path covers a matched left vertex iff it covers its mate.
Augmenting along an augmenting path gives a matching.
Augmenting along an augmenting path increases the matching size by one.
A maximum matching has no augmenting path (the easy direction of Berge's theorem).
IsLayeredPath G M U k u i p: p lists the non-matching edges of an alternating path that
starts at u in exact layer i, visits exact layers i, i + 1, …, k, avoids the right vertices
in U, and ends at a free right vertex.
- last {L : Type u_1} {R : Type u_2} [Fintype L] [Fintype R] [DecidableEq L] [DecidableEq R] {G : L × R → Bool} {M : Finset (L × R)} {U : Finset R} {k : ℕ} {u : L} {v : R} : IsLayer G M u k → G (u, v) = true → v ∉ matchedRight M → v ∉ U → IsLayeredPath G M U k u k [(u, v)]
- cons {L : Type u_1} {R : Type u_2} [Fintype L] [Fintype R] [DecidableEq L] [DecidableEq R] {G : L × R → Bool} {M : Finset (L × R)} {U : Finset R} {k : ℕ} {u u' : L} {v : R} {i : ℕ} {p : List (L × R)} : IsLayer G M u i → G (u, v) = true → (u', v) ∈ M → v ∉ U → IsLayeredPath G M U k u' (i + 1) p → IsLayeredPath G M U k u i ((u, v) :: p)
IsLayeredPrefix G M U r u j q: q lists the non-matching edges of an alternating path from
the free vertex r to u in exact layer j, avoiding U.
- root {L : Type u_1} {R : Type u_2} [Fintype L] [Fintype R] [DecidableEq L] [DecidableEq R] {G : L × R → Bool} {M : Finset (L × R)} {U : Finset R} {r : L} : IsLayer G M r 0 → IsLayeredPrefix G M U r r 0 []
- snoc {L : Type u_1} {R : Type u_2} [Fintype L] [Fintype R] [DecidableEq L] [DecidableEq R] {G : L × R → Bool} {M : Finset (L × R)} {U : Finset R} {r w u : L} {v : R} {j : ℕ} {q : List (L × R)} : IsLayeredPrefix G M U r w j q → G (w, v) = true → (u, v) ∈ M → v ∉ U → IsLayer G M u (j + 1) → IsLayeredPrefix G M U r u (j + 1) (q ++ [(w, v)])
A layered path starting in layer 0 is an augmenting path.
If M has no augmenting path, then no alternating layer reaches a free right vertex.
Berge's theorem (bipartite case): a matching is maximum iff it has no augmenting path.
IsLayeredFamily G M k l: l is the concatenation of layered paths of length k starting
at distinct free left vertices, each avoiding the right vertices used by the later ones. This is
what one depth-first phase of Hopcroft–Karp produces.
- nil {L : Type u_1} {R : Type u_2} [Fintype L] [Fintype R] [DecidableEq L] [DecidableEq R] {G : L × R → Bool} {M : Finset (L × R)} {k : ℕ} : IsLayeredFamily G M k []
- cons {L : Type u_1} {R : Type u_2} [Fintype L] [Fintype R] [DecidableEq L] [DecidableEq R] {G : L × R → Bool} {M : Finset (L × R)} {k : ℕ} {r : L} {p l : List (L × R)} : IsLayeredFamily G M k l → r ∉ List.map Prod.fst l → IsLayeredPath G M (matchedRight l.toFinset) k r 0 p → IsLayeredFamily G M k (p ++ l)
A nonempty layered family starts at a free left vertex.
N is the edge set found by one Hopcroft–Karp phase for M with shortest augmenting path
parameter k: a matching whose edges follow the alternating layers of M, ending in layer k at
free right vertices, such that each M-edge is either kept or replaced at both ends, and no
layered path with k + 1 non-matching edges from a free left vertex avoids the vertices of N.
- isMatching : IsMatching G N
- maximal (r : L) : r ∉ matchedLeft N → ∀ (p : List (L × R)), ¬IsLayeredPath G M (matchedRight N) k r 0 p
A layered family that cannot be extended by a further layered path is a maximal layered augmentation.
Alternating layers do not grow after a phase: altLeft (augment M N) j ⊆ altLeft M j for
j ≤ k.
Phase lemma (Hopcroft–Karp). Augmenting M along a maximal layered augmentation for the
shortest augmenting path parameter k leaves no alternating path with at most k matched edges
between free vertices: the shortest augmenting path length strictly increases.
A phase covering some free left vertex strictly enlarges the matching.
Progress. A nonempty maximal layered augmentation covers a left vertex that was free.
If a free right vertex is adjacent to layer k, a maximal layered augmentation for k is
nonempty.
A phase run after a BFS that found a free right vertex in layer k strictly enlarges the
matching.
Deficit bound: if no augmenting path has fewer than t matched edges, then M is within
|M| / t of every matching.
IsPhaseRun G M n: starting from M, n Hopcroft–Karp phases are performed. Each phase
follows a breadth-first search that found the shortest augmenting path parameter k (no free
right vertex in layers < k, one in layer k) and augments along a maximal layered
augmentation.
- done {L : Type u_1} {R : Type u_2} [Fintype L] [Fintype R] [DecidableEq L] [DecidableEq R] {G : L × R → Bool} {M : Finset (L × R)} : IsPhaseRun G M 0
- step {L : Type u_1} {R : Type u_2} [Fintype L] [Fintype R] [DecidableEq L] [DecidableEq R] {G : L × R → Bool} {M N : Finset (L × R)} {k n : ℕ} {t : R} : NoShortAug G M k → t ∈ altRight G M k → t ∉ matchedRight M → IsMaximalLayeredAugmentation G M N k → IsPhaseRun G (augment M N) n → IsPhaseRun G M (n + 1)
Hopcroft–Karp phase bound. A run of n phases from a matching M with no augmenting path
shorter than t satisfies n + |M| ≤ ν and, when t ≤ ⌊√ν⌋, t + n ≤ 2⌊√ν⌋, where ν is the
maximum matching size. In particular, from the empty matching at most 2⌊√ν⌋ phases occur.
From the empty matching, Hopcroft–Karp performs at most 2⌊√ν⌋ augmenting phases.
If the alternating layers of M stop growing at j and reach no free right vertex, then the
layer cover at j has size |M|.
König certificate from a closed BFS. When the alternating layers stop growing without
reaching a free right vertex, M is a maximum matching and the layer cover is a minimum vertex
cover of the same size.
Under stability, the right vertices reached by the layers are exactly the mates of reached left vertices.