Maximum Bipartite Matching and König's Theorem via Network Flows #
Formalizes the reduction of maximum bipartite matching and minimum bipartite vertex cover
to integral s-t network flow ([FF62], Chapter II, Sections 4–5, Theorem 4.1;
[CLRS09], Section 26.3, Lemma 26.9, Theorem 26.10 & Corollary 26.11, pp. 732–735), derives
König's Theorem ([Kon31], pp. 116–119), bridges to
Cslib.Circuits.BipartiteMatching.HasPerfectMatching, and provides a pure executable solver via
edmondsKarpDense. For the checked Word-RAM running-time bound (O((m + r)^5) instructions), see
CslibFrontier.Algorithms.WordRAM.EdmondsKarp.
Model and source mapping #
- Bipartite graph (
G : L × R → Bool): edge indicator on finite left/right vertex typesLandR, matching the convention ofCslib.Circuits.BipartiteMatchingonV × V → Bool. - Unit-capacity flow network (
bipartiteNetwork G): addsBipartiteVertex.sourceandBipartiteVertex.sinkwith unit-capacity arcs.source → .left u,.left u → .right vwheneverG (u, v) = true, and.right v → .sink([CLRS09], Section 26.3, pp. 732–733). - Flows ↔ matchings (
matchingToFlow,flowToMatching): every matchingMyields an integral flow of valueM.card, and every feasible integral flowfonbipartiteNetwork Ginduces a matching of cardinalityf.value.toNat((M.card : ℤ) = f.value; [CLRS09], Lemma 26.9, pp. 733–734). - Cuts ↔ vertex covers & König's Theorem (
vertexCoverToCut,cutToVertexCover,exists_maxMatching_eq_minVertexCover): every vertex coverCyields ans-tcut of capacityC.size, and everys-tcutSyields a cover of size at mostcutCapacity S. Combining withNetwork.exists_maxFlow_eq_minCutproves that maximum matching size equals minimum vertex cover size ([Kon31], pp. 116–119; [FF62], Chapter II, Section 4, Theorem 4.1). - Pure executable solver (
bipartiteMatching,decidePerfectMatching): transportsbipartiteNetwork GontoFin (2 + (m + r)), runsedmondsKarpDense, and extracts the resulting matching and König cover.
Main definitions #
Cslib.Algorithms.Lean.MaxFlow.IsMatching,IsMaxMatching: bipartite matchings and maximum matchings.Cslib.Algorithms.Lean.MaxFlow.VertexCover,IsVertexCover,IsMinVertexCover: bipartite vertex covers and minimum vertex covers.Cslib.Algorithms.Lean.MaxFlow.BipartiteVertex,bipartiteNetwork,matchingToFlow,flowToMatching,vertexCoverToCut,cutToVertexCover: unit-capacity flow reduction.Cslib.Algorithms.Lean.MaxFlow.BipartiteOutput,bipartiteMatching,decidePerfectMatching: pure executable solver for maximum bipartite matching, minimum vertex cover, and perfect matching decision.
Main results #
Cslib.Algorithms.Lean.MaxFlow.card_le_size_of_matching_vertexCover: weak duality (M.card ≤ C.size).Cslib.Algorithms.Lean.MaxFlow.exists_maxMatching_eq_minVertexCover: König's Theorem.Cslib.Algorithms.Lean.MaxFlow.hasPerfectMatching_iff_exists_matching_cardandhasPerfectMatching_iff_exists_flow_value_card: characterizations ofCslib.Circuits.BipartiteMatching.HasPerfectMatching.Cslib.Algorithms.Lean.MaxFlow.bipartiteMatching_correctanddecidePerfectMatching_eq_true_iff: correctness of the pure executable solver.
References #
Bipartite matchings and vertex covers #
Total cardinality |C.left| + |C.right| of a bipartite vertex cover C.
C is a vertex cover of G if every edge (u, v) with G (u, v) = true has u ∈ C.left or
v ∈ C.right.
Instances For
C is a minimum-cardinality vertex cover of G.
Unit-capacity flow network for a bipartite graph #
Vertices of the unit-capacity s-t flow network for a bipartite graph on (L, R):
designated source and sink together with left u (u : L) and right v (v : R).
- source {L : Type u_3} {R : Type u_4} : BipartiteVertex L R
- sink {L : Type u_3} {R : Type u_4} : BipartiteVertex L R
- left {L : Type u_3} {R : Type u_4} (u : L) : BipartiteVertex L R
- right {L : Type u_3} {R : Type u_4} (v : R) : BipartiteVertex L R
Instances For
Canonical equivalence between BipartiteVertex L R and Bool ⊕ (L ⊕ R).
Unit-capacity s-t network associated with G : L × R → Bool ([CLRS09], Section 26.3,
pp. 732–733): unit arcs .source → .left u, .left u → .right v when G (u, v) = true, and
.right v → .sink.
Extract a bipartite matching from any feasible integral flow f on bipartiteNetwork G by
selecting pairs (u, v) carrying positive flow ([CLRS09], Lemma 26.9, p. 733).
Construct a feasible unit integral flow on bipartiteNetwork G of value M.card from any
bipartite matching M ([CLRS09], Lemma 26.9, p. 733).
Cuts, vertex covers, and König's Theorem #
Turn a bipartite vertex cover C into an s-t cut of bipartiteNetwork G of capacity
C.size ([FF62], Chapter II, Section 4, Theorem 4.1).
Extract a bipartite vertex cover of size at most cutCapacity S from any s-t cut S of
bipartiteNetwork G.
Weak duality for bipartite matchings and vertex covers: every matching M in G has
cardinality at most the size of every vertex cover C of G.
Any maximum flow f and minimum cut S of equal value on bipartiteNetwork G yield a
maximum matching flowToMatching f and minimum König vertex cover cutToVertexCover G S of
equal size.
König's Theorem ([Kon31], pp. 116–119; [FF62], Chapter II, Section 4,
Theorem 4.1): every finite bipartite graph G : L × R → Bool admits a maximum matching M and a
minimum vertex cover C of equal size (M.card = C.size).
HasPerfectMatching G holds if and only if G admits a matching of cardinality
Fintype.card V.
Flow characterization of HasPerfectMatching G: G : V × V → Bool has a perfect matching if
and only if bipartiteNetwork G admits an integral flow of value Fintype.card V.
Pure executable bipartite matching and König cover solver #
Computable vertex equivalence BipartiteVertex (Fin m) (Fin r) ≃ Fin (2 + (m + r)).
Output of bipartiteMatching on G : Fin m × Fin r → Bool.
Maximum-cardinality matching in
G.Minimum-cardinality König vertex cover of
G.- augmentations : ℕ
Number of shortest-path augmentations performed by Edmonds–Karp.
Correctness of bipartiteMatching: returns a maximum matching res.matching and minimum
vertex cover res.cover satisfying König strong duality res.matching.card = res.cover.size.
decidePerfectMatching G returns true if and only if
Cslib.Circuits.BipartiteMatching.HasPerfectMatching G holds.