Documentation

CslibFrontier.Algorithms.Lean.MaxFlow.WeightedMatching

Weighted Bipartite Matching: Potentials and Linear-Programming Duality #

Costs, perfect matchings and vertex potentials on the edge-indicator representation G : L × R → Bool of CslibFrontier.Algorithms.Lean.MaxFlow.BipartiteMatching, with weak duality and complementary slackness for the minimum-cost (perfect) matching problem ([Sch03], Ch. 17; [Kuh55]). The executable Hungarian method and Egerváry's strong duality theorem for the assignment problem are in CslibFrontier.Algorithms.Lean.MaxFlow.Hungarian.

Conventions #

Costs take values in an ordered additive commutative monoid or group α and are minimized. Potentials y : L → α and z : R → α are feasible when every reduced cost c (u, v) - y u - z v of an edge is nonnegative, i.e. y u + z v ≤ c (u, v); an edge is tight when equality holds. This is the reduced-cost convention of primal-dual algorithms for minimum-cost flow, so the lemmas below are stated for arbitrary matchings and graphs, not only for the complete bipartite graph of the assignment problem. Maximum-weight problems are obtained by negating costs.

Main definitions #

Main results #

References #

def Cslib.Algorithms.Lean.MaxFlow.IsPerfectMatching {L : Type u_1} {R : Type u_2} [DecidableEq L] [DecidableEq R] [Fintype L] [Fintype R] (G : L × R → Bool) (M : Finset (L × R)) :

M is a perfect matching of G: a matching covering every left and every right vertex.

def Cslib.Algorithms.Lean.MaxFlow.matchingCost {L : Type u_1} {R : Type u_2} {α : Type u_3} [AddCommMonoid α] (c : L × R → α) (M : Finset (L × R)) :
α

Total cost of the edges of M.

def Cslib.Algorithms.Lean.MaxFlow.IsFeasiblePotential {L : Type u_1} {R : Type u_2} {α : Type u_3} [Add α] [LE α] (G : L × R → Bool) (c : L × R → α) (y : L → α) (z : R → α) :

Potentials y, z are feasible for the cost c on G if every edge has nonnegative reduced cost: y u + z v ≤ c (u, v).

def Cslib.Algorithms.Lean.MaxFlow.IsMinCostPerfectMatching {L : Type u_1} {R : Type u_2} {α : Type u_3} [DecidableEq L] [DecidableEq R] [Fintype L] [Fintype R] [AddCommMonoid α] [LE α] (G : L × R → Bool) (c : L × R → α) (M : Finset (L × R)) :

M is a minimum-cost perfect matching of G for the cost c.

theorem Cslib.Algorithms.Lean.MaxFlow.IsMatching.sum_fst_eq {L : Type u_1} {R : Type u_2} {α : Type u_3} [DecidableEq L] [AddCommMonoid α] {G : L × R → Bool} {M : Finset (L × R)} (hM : IsMatching G M) (f : L → α) :
∑ e ∈ M, f e.1 = ∑ u ∈ matchedLeft M, f u
theorem Cslib.Algorithms.Lean.MaxFlow.IsMatching.sum_snd_eq {L : Type u_1} {R : Type u_2} {α : Type u_3} [DecidableEq R] [AddCommMonoid α] {G : L × R → Bool} {M : Finset (L × R)} (hM : IsMatching G M) (f : R → α) :
∑ e ∈ M, f e.2 = ∑ v ∈ matchedRight M, f v
theorem Cslib.Algorithms.Lean.MaxFlow.IsMatching.sum_potential_eq {L : Type u_1} {R : Type u_2} {α : Type u_3} [DecidableEq L] [DecidableEq R] [AddCommMonoid α] {G : L × R → Bool} {M : Finset (L × R)} (hM : IsMatching G M) (y : L → α) (z : R → α) :
∑ e ∈ M, (y e.1 + z e.2) = ∑ u ∈ matchedLeft M, y u + ∑ v ∈ matchedRight M, z v

The potential of a matching splits over its matched left and right vertices.

theorem Cslib.Algorithms.Lean.MaxFlow.IsPerfectMatching.sum_potential_eq {L : Type u_1} {R : Type u_2} {α : Type u_3} [DecidableEq L] [DecidableEq R] [AddCommMonoid α] {G : L × R → Bool} {M : Finset (L × R)} [Fintype L] [Fintype R] (hM : IsPerfectMatching G M) (y : L → α) (z : R → α) :
∑ e ∈ M, (y e.1 + z e.2) = ∑ u : L, y u + ∑ v : R, z v
theorem Cslib.Algorithms.Lean.MaxFlow.IsMatching.sum_matched_potential_le_cost {L : Type u_1} {R : Type u_2} {α : Type u_3} [DecidableEq L] [DecidableEq R] {G : L × R → Bool} {M : Finset (L × R)} {c : L × R → α} {y : L → α} {z : R → α} [AddCommMonoid α] [PartialOrder α] [IsOrderedAddMonoid α] (hM : IsMatching G M) (hf : IsFeasiblePotential G c y z) :
∑ u ∈ matchedLeft M, y u + ∑ v ∈ matchedRight M, z v ≤ matchingCost c M

Weak duality for an arbitrary matching: the potentials of the matched vertices sum to at most the cost.

theorem Cslib.Algorithms.Lean.MaxFlow.IsMatching.sum_matched_potential_eq_cost_iff {L : Type u_1} {R : Type u_2} {α : Type u_3} [DecidableEq L] [DecidableEq R] {G : L × R → Bool} {M : Finset (L × R)} {c : L × R → α} {y : L → α} {z : R → α} [AddCommMonoid α] [PartialOrder α] [IsOrderedCancelAddMonoid α] (hM : IsMatching G M) (hf : IsFeasiblePotential G c y z) :
∑ u ∈ matchedLeft M, y u + ∑ v ∈ matchedRight M, z v = matchingCost c M ↔ ∀ e ∈ M, y e.1 + z e.2 = c e

Complementary slackness for an arbitrary matching: weak duality is an equality iff every edge of the matching is tight.

theorem Cslib.Algorithms.Lean.MaxFlow.IsPerfectMatching.potential_le_cost {L : Type u_1} {R : Type u_2} {α : Type u_3} [DecidableEq L] [DecidableEq R] {G : L × R → Bool} {M : Finset (L × R)} {c : L × R → α} {y : L → α} {z : R → α} [Fintype L] [Fintype R] [AddCommMonoid α] [PartialOrder α] [IsOrderedAddMonoid α] (hM : IsPerfectMatching G M) (hf : IsFeasiblePotential G c y z) :
∑ u : L, y u + ∑ v : R, z v ≤ matchingCost c M

Weak duality for perfect matchings: ∑ y + ∑ z ≤ cost M.

theorem Cslib.Algorithms.Lean.MaxFlow.IsPerfectMatching.potential_eq_cost_iff {L : Type u_1} {R : Type u_2} {α : Type u_3} [DecidableEq L] [DecidableEq R] {G : L × R → Bool} {M : Finset (L × R)} {c : L × R → α} {y : L → α} {z : R → α} [Fintype L] [Fintype R] [AddCommMonoid α] [PartialOrder α] [IsOrderedCancelAddMonoid α] (hM : IsPerfectMatching G M) (hf : IsFeasiblePotential G c y z) :
∑ u : L, y u + ∑ v : R, z v = matchingCost c M ↔ ∀ e ∈ M, y e.1 + z e.2 = c e

Complementary slackness for perfect matchings.

theorem Cslib.Algorithms.Lean.MaxFlow.IsPerfectMatching.isMinCostPerfectMatching_of_tight {L : Type u_1} {R : Type u_2} {α : Type u_3} [DecidableEq L] [DecidableEq R] {G : L × R → Bool} {M : Finset (L × R)} {c : L × R → α} {y : L → α} {z : R → α} [Fintype L] [Fintype R] [AddCommMonoid α] [PartialOrder α] [IsOrderedCancelAddMonoid α] (hM : IsPerfectMatching G M) (hf : IsFeasiblePotential G c y z) (ht : ∀ e ∈ M, y e.1 + z e.2 = c e) :

A perfect matching all of whose edges are tight for feasible potentials has minimum cost, and its cost equals the total potential.

The perfect matching {(u, σ u)} of a permutation σ.

theorem Cslib.Algorithms.Lean.MaxFlow.mem_permMatching {V : Type u_1} [DecidableEq V] [Fintype V] {σ : Equiv.Perm V} {e : V × V} :
e ∈ permMatching σ ↔ σ e.1 = e.2
theorem Cslib.Algorithms.Lean.MaxFlow.matchingCost_permMatching {V : Type u_1} {α : Type u_2} [DecidableEq V] [Fintype V] [AddCommMonoid α] (c : V × V → α) (σ : Equiv.Perm V) :
matchingCost c (permMatching σ) = ∑ u : V, c (u, σ u)
theorem Cslib.Algorithms.Lean.MaxFlow.exists_eq_permMatching {V : Type u_1} [DecidableEq V] [Fintype V] {G : V × V → Bool} {M : Finset (V × V)} (hM : IsPerfectMatching G M) :
∃ (σ : Equiv.Perm V), M = permMatching σ

Every perfect matching of V × V is the matching of a permutation.