Documentation

CslibFrontier.Algorithms.Lean.TSP.PerfectMatching

Minimum-weight perfect matchings and the matching bound for metric TSP #

A perfect matching on a duplicate-free list O of vertices is a list of edges M whose endpoints (Cslib.Algorithms.Lean.VertexCover.endpoints) are a permutation of O: every vertex of O is an endpoint of exactly one edge, and no other vertex is. Its weight under a cost δ is (M.map fun e => δ e.1 e.2).sum.

A key combinatorial step after [WS11], proof of Theorem 2.13, is two_mul_sum_le_cycleCost: under the triangle inequality, a minimum-weight perfect matching on O costs at most half of any tour visiting every vertex of O. The tour, shortcut to O, has an even number of edges, which alternate between two perfect matchings on O.

minPerfectMatching computes a minimum-weight perfect matching by exhaustive search.

Model #

Vertices form any type with decidable equality, and costs are natural numbers. Perfect matchings are lists of ordered pairs; for a symmetric cost the orientation of an edge does not matter.

Limitations #

minPerfectMatching tries every way to match the first vertex and recurses, so on 2k vertices it examines (2k - 1)!! = (2k - 1) (2k - 3) ⋯ 1 matchings. A polynomial-time algorithm (Edmonds' weighted blossom algorithm, [Edm65]) is not formalized (tracked in #2869 and #3337); the results here certify optimality of exhaustive search, not polynomial running time.

Main definitions #

Main results #

References #

The degree of a vertex in a multigraph is its number of occurrences among the endpoints.

The matching bound #

theorem Cslib.Algorithms.Lean.TSP.two_mul_sum_le_cycleCost {α : Type u_1} {δ : α → α → ℕ} (htri : ∀ (x y z : α), δ x z ≤ δ x y + δ y z) {O : List α} (hO : O.Nodup) {M : List (α × α)} (hM : (VertexCover.endpoints M).Perm O) (hmin : ∀ (M' : List (α × α)), (VertexCover.endpoints M').Perm O → (List.map (fun (e : α × α) => δ e.1 e.2) M).sum ≤ (List.map (fun (e : α × α) => δ e.1 e.2) M').sum) {q : List α} (hq : q.Nodup) (hOq : ∀ x ∈ O, x ∈ q) :
2 * (List.map (fun (e : α × α) => δ e.1 e.2) M).sum ≤ cycleCost δ q

Combinatorial matching bound (a step after [WS11], proof of Theorem 2.13): under the triangle inequality, a minimum-weight perfect matching on the vertices of O, all visited by a closed walk q without repetitions, costs at most half of q. Shortcut q to the vertices of O; the resulting closed walk has an even number of edges, which split into two perfect matchings on O. No symmetry of δ is needed.

def Cslib.Algorithms.Lean.TSP.minPerfectMatching {α : Type u_1} [DecidableEq α] (δ : α → α → ℕ) (fuel : ℕ) :
List α → List (α × α)

Minimum-weight perfect matching by exhaustive search: match the first vertex with each other vertex in turn, match the rest recursively, and keep a lightest result (the first one among ties). The recursion makes at most fuel rounds; fuel k suffices for lists of length at most 2 * k. On 2k vertices this examines (2k - 1)!! matchings and is not Edmonds' polynomial-time weighted blossom algorithm ([Edm65], tracked in #2869 and #3337).

theorem Cslib.Algorithms.Lean.TSP.endpoints_minPerfectMatching_perm {α : Type u_1} [DecidableEq α] (δ : α → α → ℕ) {k : ℕ} {O : List α} (hk : O.length ≤ 2 * k) (heven : Even O.length) :

With fuel for half its length, exhaustive search returns a perfect matching on a list of even length.

theorem Cslib.Algorithms.Lean.TSP.sum_minPerfectMatching_le {α : Type u_1} [DecidableEq α] {δ : α → α → ℕ} (hsymm : ∀ (x y : α), δ x y = δ y x) {k : ℕ} {O : List α} (hk : O.length ≤ 2 * k) {M : List (α × α)} (hM : (VertexCover.endpoints M).Perm O) :
(List.map (fun (e : α × α) => δ e.1 e.2) (minPerfectMatching δ k O)).sum ≤ (List.map (fun (e : α × α) => δ e.1 e.2) M).sum

Optimality of exhaustive search: for symmetric δ and fuel for half the length of O, minPerfectMatching weighs at most any perfect matching on O.