The traveling salesman problem #
TSP is the decision version of the traveling salesman problem
Papadimitriou, Section 9.3: an instance x : TSPInstance is a distance matrix
x.dist, given as a list of rows (row i lists the distances from city i), together with a
budget x.bound, and it belongs to TSP when some closed tour visiting every city exactly once
has length at most x.bound. The conventions are the following.
- The cities are the row indices
0, …, D.length - 1. Rows may have any length: an entry missing from a ragged or short matrix reads0(TSP.dist). - Distances need not be symmetric, and the diagonal entries are only used by the tour of a single
city, which costs
TSP.dist D 0 0. The matrix without rows is a yes-instance, through the empty tour of length0. - A tour is a permutation
pof the cities, and its lengthTSP.tourLength D pis the sum of the distances from each city ofpto the next one, the last city returning to the first. - Distances and the budget are binary (
encTSP).
TSP is in NP. As for the Hamiltonian problems, a certificate names an ordering of the cities,
decoded by Graph.decodeVertexList from the list 0, …, D.length - 1 of cities; it has length
m ^ 2 for instances of encoded length m. The verifier checks that the ordering lists every city
exactly once, and compares the length of its tour with the budget using the binary arithmetic of
CslibFrontier/Computability/Machines/Turing/MultiTape/Complexity/PolyTime/Nat/Binary.lean, so
distances and budgets of any size are handled without unary
expansion.
The reduction HamCycle.toTSP from HamCycle takes the distinct declared vertices of a graph as
cities, at distance 1 when they are adjacent and 2 otherwise, with the number n of cities as
the budget. A closed tour has n steps of length at least 1, so it has length at most n
exactly when every step joins adjacent vertices, that is, when it is a Hamiltonian cycle. Graphs
with fewer than three vertices have no Hamiltonian cycle and are mapped to a fixed no-instance.
Main definitions #
Cslib.Complexity.TSPInstance,Cslib.Complexity.encTSP: traveling salesman instances and their binary encoding.Cslib.Complexity.TSP.dist,Cslib.Complexity.TSP.tourLength,Cslib.Complexity.TSP.Cslib.Complexity.TSP.verifier.Cslib.Complexity.HamCycle.toTSP.
Main results #
Cslib.Complexity.TSP.tourLength_eq_sum: the tour length as a sum over the positions of the tour.Cslib.Complexity.TSP.computableInPolyTime_tourLength: tour lengths are polynomial-time.Cslib.Complexity.TSP.isVerifier,Cslib.Complexity.TSP.mem_NP:TSP ∈ NP encTSP.Cslib.Complexity.HamCycle.toTSP_mem_iff:toTSP G ∈ TSP ↔ G ∈ HamCycle.Cslib.Complexity.HamCycle.computableInPolyTime_toTSP: the reduction is polynomial-time.Cslib.Complexity.polyTimeReducible_HamCycle_TSP,Cslib.Complexity.TSP_npHard:HamCyclereduces toTSPin polynomial time, soTSPisNP-hard.Cslib.Complexity.TSP_npComplete:TSPisNP-complete.
References #
Instances For
Instances of the traveling salesman problem, encoded as framed lists of binary distances and a binary budget.
Instances For
The length of the closed tour visiting the cities of p in order: the sum of the distances
from each city of p to the next one, the last city returning to the first. A tour of one city
c has length dist D c c, and the empty tour has length 0.
Instances For
The traveling salesman problem: the instances x : TSPInstance such that some closed tour
visiting each city 0, …, x.dist.length - 1 exactly once has length at most x.bound
Papadimitriou, Section 9.3.
Instances For
Membership in NP #
The length of a tour is polynomial-time in the distance matrix and the tour, both with binary entries: it is a binary sum over the positions of the tour, and a city beyond the matrix is looked up at an index capped by the number of rows.
The verifier for TSP: decode a list of cities from the certificate (Graph.decodeVertexList
applied to the cities 0, …, n - 1) and check that it lists every city exactly once and that the
closed tour visiting the cities in this order has length at most the budget.
Instances For
TSP.verifier verifies TSP with certificates of length n ^ 2 for instances of encoded
length n.
The TSP verifier is polynomial-time.
The reduction from Hamiltonian cycles #
The reduction from HamCycle to TSP Papadimitriou, Section 9.3: the
cities are the distinct declared vertices, at distance 1 when they are adjacent and 2
otherwise, and the budget is the number n of cities. When n < 3 the graph has no Hamiltonian
cycle, and the reduction returns the no-instance of one city at distance 1 from itself with
budget 0.
Instances For
The reduction toTSP is polynomial-time: the cities are selected from the declared vertices,
and the distances and the budget are written in binary.
HamCycle reduces to TSP in polynomial time via HamCycle.toTSP.
TSP is NP-complete Papadimitriou, Section 9.3.