name: Rule
about: Propose a new reduction rule
title: "[Rule] HamiltonianCircuit to TravelingSalesman"
labels: rule
assignees: ''
canonical_source_name: 'HamiltonianCircuit'
canonical_target_name: 'TravelingSalesman'
source_in_codebase: true
target_in_codebase: true
Source: HamiltonianCircuit
Target: TravelingSalesman
Motivation: Establishes NP-completeness of TravelingSalesman via one of the most classical and widely-taught polynomial-time reductions in complexity theory. The reduction embeds the graph into a complete weighted graph with distances 1 (for existing edges) and 2 (for non-edges); the optimal TSP tour has weight n if and only if the source graph has a Hamiltonian circuit. This is a textbook example appearing in virtually every algorithms course.
Reference: Garey & Johnson, Computers and Intractability, ND22, p.211
GJ Source Entry
[ND22] TRAVELING SALESMAN
INSTANCE: Set C of m cities, distance d(c_i,c_j)∈Z^+ for each pair of cities c_i,c_j∈C, positive integer B.
QUESTION: Is there a tour of C having length B or less, i.e., a permutation <c_{π(1)},c_{π(2)},...,c_{π(m)}> of C such that
(∑_{i=1}^{m-1} d(c_{π(i)},c_{π(i+1)})) + d(c_{π(m)},c_{π(1)}) ≤ B ?
Reference: Transformation from HAMILTONIAN CIRCUIT.
Comment: Remains NP-complete even if d(c_i,c_j)∈{1,2} for all c_i,c_j∈C. Special cases that can be solved in polynomial time are discussed in [Gilmore and Gomory, 1964], [Garfinkel, 1977], and [Syslo, 1973]. The variant in which we ask for a tour with "mean arrival time" of B or less is also NP-complete [Sahni and Gonzalez, 1976].
Reduction Algorithm
Summary:
Given a HamiltonianCircuit instance G = (V, E) with n = |V| vertices, construct a TravelingSalesman instance as follows:
-
Graph: Construct the complete graph K_n on vertex set V with n(n-1)/2 edges.
-
Edge weights: Assign weights to each edge of K_n:
- w(u, v) = 1 if {u, v} ∈ E (the edge exists in G)
- w(u, v) = 2 if {u, v} ∉ E (the edge does not exist in G)
-
Correctness (forward): If G has a Hamiltonian circuit v_1 → v_2 → ... → v_n → v_1, then selecting the corresponding n edges in K_n gives a tour of total weight n × 1 = n, since every consecutive pair {v_i, v_{i+1}} and {v_n, v_1} is an edge in G and thus has weight 1.
-
Correctness (reverse): If the optimal TSP tour has weight n, then since any tour visits all n vertices and uses exactly n edges, each with weight ≥ 1, the minimum possible weight is n. Achieving weight exactly n requires every edge in the tour to have weight 1, meaning every consecutive pair is an edge in G. Therefore, the tour is a Hamiltonian circuit in G.
Key invariant: The optimal TSP tour has weight exactly n if and only if it uses only edges of weight 1, which correspond exactly to the edges of G. Hence the minimum tour weight is n iff G has a Hamiltonian circuit.
Representation note: HamiltonianCircuit uses a vertex permutation representation (config[i] ∈ {0, ..., n-1}), while TravelingSalesman uses binary edge selection (config[e] ∈ {0, 1} for each edge). Solution extraction converts the TSP edge selection back to a vertex permutation: traverse the selected edges to recover the cycle ordering.
Time complexity of reduction: O(n^2) to construct the complete graph and assign weights.
Size Overhead
Symbols:
- n =
num_vertices of source HamiltonianCircuit instance (|V|)
- m =
num_edges of source HamiltonianCircuit instance (|E|)
| Target metric (code name) |
Polynomial (using symbols above) |
num_vertices |
num_vertices |
num_edges |
num_vertices * (num_vertices - 1) / 2 |
Derivation: The TSP instance has the same vertex set as the source graph (n vertices). The complete graph K_n has n(n-1)/2 edges.
Validation Method
- Closed-loop test: reduce a small HamiltonianCircuit instance G to TravelingSalesman, solve the TSP with BruteForce, extract the solution, verify that if the optimal tour weight equals n then the extracted edges form a Hamiltonian circuit in G, and vice versa.
- Test with known YES instance: the triangular prism (6 vertices, 9 edges) has a Hamiltonian circuit. The TSP instance should have an optimal tour of weight 6.
- Test with known NO instance: the Petersen graph has no Hamiltonian circuit. The TSP instance should have an optimal tour of weight > 10.
- Verify edge weights: all entries are 1 or 2, and edges in G have weight 1.
Example
Source instance (HamiltonianCircuit):
Graph G with 6 vertices {0, 1, 2, 3, 4, 5} and 9 edges:
- Edges: {0,1}, {1,2}, {2,3}, {3,4}, {4,5}, {5,0}, {0,3}, {1,4}, {2,5}
- (Triangular prism / prism graph)
- Hamiltonian circuit exists: 0 → 1 → 2 → 3 → 4 → 5 → 0
Constructed target instance (TravelingSalesman):
- 6 vertices, 15 edges (complete graph K_6)
- Edge weights:
- Weight 1 (edges in G): {0,1}, {1,2}, {2,3}, {3,4}, {4,5}, {0,5}, {0,3}, {1,4}, {2,5}
- Weight 2 (non-edges): {0,2}, {0,4}, {1,3}, {1,5}, {2,4}, {3,5}
Solution mapping:
- TSP optimal tour: edges {0,1}, {1,2}, {2,3}, {3,4}, {4,5}, {0,5} selected
- Tour weight: 1+1+1+1+1+1 = 6 = n
- All selected edges have weight 1 → all are edges in G → this is a Hamiltonian circuit in G
- Extracted HC solution (vertex permutation): [0, 1, 2, 3, 4, 5]
Alternative tour: edges {0,3}, {3,2}, {2,5}, {5,4}, {4,1}, {1,0} selected
- Tour weight: 1+1+1+1+1+1 = 6 = n
- Also a valid Hamiltonian circuit in G
- Extracted HC solution: [0, 3, 2, 5, 4, 1]
References
- [Gilmore and Gomory, 1964]: [
Gilmore1964] P. C. Gilmore and R. E. Gomory (1964). "Sequencing a one state-variable machine: a solvable case of the traveling salesman problem". Operations Research 12, pp. 655–679.
- [Garfinkel, 1977]: [
Garfinkel1977] R. S. Garfinkel (1977). "Minimizing wallpaper waste, {Part} 1: a class of traveling salesman problems". Operations Research 25, pp. 741–751.
- [Syslo, 1973]: [
Syslo1973] Maciej M. Syslo (1973). "A new solvable case of the traveling salesman problem". Mathematical Programming 4, pp. 347–348.
- [Sahni and Gonzalez, 1976]: [
Gonzalez1976] T. Gonzalez and S. Sahni (1976). "Open shop scheduling to minimize finish time". Journal of the Association for Computing Machinery 23, pp. 665–679.
name: Rule
about: Propose a new reduction rule
title: "[Rule] HamiltonianCircuit to TravelingSalesman"
labels: rule
assignees: ''
canonical_source_name: 'HamiltonianCircuit'
canonical_target_name: 'TravelingSalesman'
source_in_codebase: true
target_in_codebase: true
Source: HamiltonianCircuit
Target: TravelingSalesman
Motivation: Establishes NP-completeness of TravelingSalesman via one of the most classical and widely-taught polynomial-time reductions in complexity theory. The reduction embeds the graph into a complete weighted graph with distances 1 (for existing edges) and 2 (for non-edges); the optimal TSP tour has weight n if and only if the source graph has a Hamiltonian circuit. This is a textbook example appearing in virtually every algorithms course.
Reference: Garey & Johnson, Computers and Intractability, ND22, p.211
GJ Source Entry
Reduction Algorithm
Summary:
Given a HamiltonianCircuit instance G = (V, E) with n = |V| vertices, construct a TravelingSalesman instance as follows:
Graph: Construct the complete graph K_n on vertex set V with n(n-1)/2 edges.
Edge weights: Assign weights to each edge of K_n:
Correctness (forward): If G has a Hamiltonian circuit v_1 → v_2 → ... → v_n → v_1, then selecting the corresponding n edges in K_n gives a tour of total weight n × 1 = n, since every consecutive pair {v_i, v_{i+1}} and {v_n, v_1} is an edge in G and thus has weight 1.
Correctness (reverse): If the optimal TSP tour has weight n, then since any tour visits all n vertices and uses exactly n edges, each with weight ≥ 1, the minimum possible weight is n. Achieving weight exactly n requires every edge in the tour to have weight 1, meaning every consecutive pair is an edge in G. Therefore, the tour is a Hamiltonian circuit in G.
Key invariant: The optimal TSP tour has weight exactly n if and only if it uses only edges of weight 1, which correspond exactly to the edges of G. Hence the minimum tour weight is n iff G has a Hamiltonian circuit.
Representation note: HamiltonianCircuit uses a vertex permutation representation (config[i] ∈ {0, ..., n-1}), while TravelingSalesman uses binary edge selection (config[e] ∈ {0, 1} for each edge). Solution extraction converts the TSP edge selection back to a vertex permutation: traverse the selected edges to recover the cycle ordering.
Time complexity of reduction: O(n^2) to construct the complete graph and assign weights.
Size Overhead
Symbols:
num_verticesof source HamiltonianCircuit instance (|V|)num_edgesof source HamiltonianCircuit instance (|E|)num_verticesnum_verticesnum_edgesnum_vertices * (num_vertices - 1) / 2Derivation: The TSP instance has the same vertex set as the source graph (n vertices). The complete graph K_n has n(n-1)/2 edges.
Validation Method
Example
Source instance (HamiltonianCircuit):
Graph G with 6 vertices {0, 1, 2, 3, 4, 5} and 9 edges:
Constructed target instance (TravelingSalesman):
Solution mapping:
Alternative tour: edges {0,3}, {3,2}, {2,5}, {5,4}, {4,1}, {1,0} selected
References
Gilmore1964] P. C. Gilmore and R. E. Gomory (1964). "Sequencing a one state-variable machine: a solvable case of the traveling salesman problem". Operations Research 12, pp. 655–679.Garfinkel1977] R. S. Garfinkel (1977). "Minimizing wallpaper waste, {Part} 1: a class of traveling salesman problems". Operations Research 25, pp. 741–751.Syslo1973] Maciej M. Syslo (1973). "A new solvable case of the traveling salesman problem". Mathematical Programming 4, pp. 347–348.Gonzalez1976] T. Gonzalez and S. Sahni (1976). "Open shop scheduling to minimize finish time". Journal of the Association for Computing Machinery 23, pp. 665–679.