Skip to content

[Rule] HAMILTONIAN CIRCUIT to QUADRATIC ASSIGNMENT PROBLEM #373

@isPANN

Description

@isPANN

Source: HAMILTONIAN CIRCUIT
Target: QUADRATIC ASSIGNMENT PROBLEM
Motivation: Establishes NP-completeness of the QUADRATIC ASSIGNMENT PROBLEM (QAP) via polynomial-time reduction from HAMILTONIAN CIRCUIT. Sahni and Gonzalez (1976) used this reduction to prove that QAP is strongly NP-hard and that no polynomial-time ε-approximation exists unless P = NP, making QAP one of the "hardest of the hard" combinatorial optimization problems.

Reference: Garey & Johnson, Computers and Intractability, ND43, p.218

GJ Source Entry

[ND43] QUADRATIC ASSIGNMENT PROBLEM
INSTANCE: Non-negative integer costs c_{ij}, 1≤i,j≤n, and distances d_{kl}, 1≤k,l≤m, bound B∈Z^+.
QUESTION: Is there a one-to-one function f:{1,2,…,n}→{1,2,…,m} such that
Σ_{i=1}^{n} Σ_{j=1, j≠i}^{n} c_{ij} d_{f(i)f(j)} ≤ B ?
Reference: [Sahni and Gonzalez, 1976]. Transformation from HAMILTONIAN CIRCUIT.
Comment: Special case in which each d_{kl}=k−l and all c_{ji}=c_{ij}∈{0,1} is the NP-complete OPTIMAL LINEAR ARRANGEMENT problem. The general problem is discussed, for example, in [Garfinkel and Nemhauser, 1972].

Reduction Algorithm

Summary:
Given a HAMILTONIAN CIRCUIT instance consisting of a graph G = (V, E) with n = |V| vertices, construct a QUADRATIC ASSIGNMENT PROBLEM instance (cost matrix C, distance matrix D) as follows. The construction follows Sahni and Gonzalez (1976), §2, problem (viii), p. 561.

Note on framing: The G&J entry formulates QAP as a decision problem with bound B. In our codebase, QuadraticAssignment is an optimization problem (minimize). The reduction works because: if G has a Hamiltonian circuit, the optimal QAP cost is exactly n; if G has no Hamiltonian circuit, the optimal cost is ≥ n − 1 + ω (strictly greater than n for ω ≥ 2). Thus a Hamiltonian circuit exists iff the optimal QAP cost equals n.

  1. Cost matrix (cycle adjacency) C: Define the n × n cost matrix C as the directed cycle adjacency matrix on n locations:

    c_{i,j} = 1 if j = (i mod n) + 1 (using 1-indexed positions), and c_{i,j} = 0 otherwise.

    This gives exactly n nonzero entries: c_{1,2} = c_{2,3} = ⋯ = c_{n−1,n} = c_{n,1} = 1. The matrix C encodes n locations arranged in a directed cycle 1 → 2 → ⋯ → n → 1.

  2. Distance matrix (graph-based) D: Define the n × n distance matrix D from the graph G:

    d_{k,l} = 1 if {v_k, v_l} ∈ E (vertices k and l are adjacent in G), and d_{k,l} = ω otherwise (where ω ≥ 2 is a penalty value; e.g., ω = n + 1).

    Diagonal entries d_{k,k} = 0. The matrix D is symmetric since G is undirected.

  3. QAP objective: The total cost for an assignment γ (a permutation mapping locations to vertices) is:

    f(γ) = Σ_{i≠j} c_{i,j} · d_{γ(i),γ(j)}

    Since c_{i,j} = 1 only for the n directed cycle edges, this simplifies to:

    f(γ) = Σ_{i=1}^{n} d_{γ(i),γ((i mod n)+1)}

    This sums the graph-distances between vertices assigned to consecutive cycle locations.

  4. Correctness:

    • Forward direction: If G has a Hamiltonian circuit v_{σ(1)} → v_{σ(2)} → ⋯ → v_{σ(n)} → v_{σ(1)}, define γ(i) = σ(i). Then consecutive locations map to consecutive circuit vertices, which are all graph-adjacent: d_{γ(i),γ(i+1)} = 1 for each i. So f(γ) = n.
    • Backward direction: If f(γ) = n, then every term d_{γ(i),γ((i mod n)+1)} = 1 (since each term is ≥ 1 and there are n terms). This means every pair of vertices at consecutive cycle locations is graph-adjacent. Reading γ(1) → γ(2) → ⋯ → γ(n) → γ(1) gives a Hamiltonian circuit in G.
    • No Hamiltonian circuit: If G has no Hamiltonian circuit, then for every permutation γ, at least one pair of consecutive cycle locations maps to non-adjacent vertices, contributing ω instead of 1. So f(γ) ≥ n − 1 + ω > n.
  5. Solution extraction: Given the optimal assignment γ, the Hamiltonian circuit is γ(1) → γ(2) → ⋯ → γ(n) → γ(1). If the optimal cost is > n, no Hamiltonian circuit exists.

Size Overhead

Symbols:

  • n = number of vertices in source Hamiltonian Circuit instance (num_vertices)
Target metric (code name) Polynomial (using symbols above)
num_facilities num_vertices
num_locations num_vertices

Derivation:

  • The cost matrix C is n × n (directed cycle adjacency)
  • The distance matrix D is n × n (graph-based distances with penalty ω)
  • Both matrices have the same dimension n, equal to the number of vertices in G
  • Total data size: O(n²) — two n × n matrices
  • The reduction is clearly polynomial: constructing C takes O(n) time, and D requires reading the adjacency structure of G in O(n²) time.

Validation Method

  • Closed-loop test: reduce HamiltonianCircuit instance to QuadraticAssignment, solve target with BruteForce (enumerate all n! permutations), extract solution, verify the assignment corresponds to a valid Hamiltonian circuit on source
  • Compare with known results from literature
  • Test with both Hamiltonian and non-Hamiltonian graphs
  • Verify that the QAP optimal cost equals exactly n for graphs with Hamiltonian circuits
  • Verify that the QAP optimal cost is > n for non-Hamiltonian graphs

Example

Source instance (HAMILTONIAN CIRCUIT):
Graph G with 6 vertices {1, 2, 3, 4, 5, 6} and 9 edges (prism graph):

  • Edges: {1,2}, {2,3}, {3,4}, {4,5}, {5,6}, {6,1}, {1,4}, {2,5}, {3,6}
  • Hamiltonian circuit exists, e.g.: 1 → 2 → 3 → 6 → 5 → 4 → 1

Constructed target instance (QUADRATIC ASSIGNMENT):

Cost matrix C (6×6, directed cycle adjacency on 6 locations):

     1  2  3  4  5  6
1  [ 0  1  0  0  0  0 ]
2  [ 0  0  1  0  0  0 ]
3  [ 0  0  0  1  0  0 ]
4  [ 0  0  0  0  1  0 ]
5  [ 0  0  0  0  0  1 ]
6  [ 1  0  0  0  0  0 ]

Distance matrix D (6×6, graph-based with ω = 7):

     1  2  3  4  5  6
1  [ 0  1  7  1  7  1 ]
2  [ 1  0  1  7  1  7 ]
3  [ 7  1  0  1  7  1 ]
4  [ 1  7  1  0  1  7 ]
5  [ 7  1  7  1  0  1 ]
6  [ 1  7  1  7  1  0 ]

Optimal assignment (cost = 6):
Using Hamiltonian circuit 1 → 2 → 3 → 6 → 5 → 4 → 1, define γ(1)=1, γ(2)=2, γ(3)=3, γ(4)=6, γ(5)=5, γ(6)=4.

Verify cost: f(γ) = d_{γ(1),γ(2)} + d_{γ(2),γ(3)} + d_{γ(3),γ(4)} + d_{γ(4),γ(5)} + d_{γ(5),γ(6)} + d_{γ(6),γ(1)}
= d_{1,2} + d_{2,3} + d_{3,6} + d_{6,5} + d_{5,4} + d_{4,1} = 1 + 1 + 1 + 1 + 1 + 1 = 6 = n ✓

Suboptimal assignment (cost = 18):
Non-Hamiltonian permutation γ = (1,3,2,4,5,6):
f(γ) = d_{1,3} + d_{3,2} + d_{2,4} + d_{4,5} + d_{5,6} + d_{6,1} = 7 + 1 + 7 + 1 + 1 + 1 = 18 > 6

The pair (1,3) at consecutive locations are not graph-adjacent, contributing ω = 7 instead of 1. Similarly (2,4) contributes 7.

Solution extraction:
From the optimal γ = (1,2,3,6,5,4), read the Hamiltonian circuit: 1 → 2 → 3 → 6 → 5 → 4 → 1 ✓

Statistics:

  • 6 distinct undirected Hamiltonian circuits in the prism graph
  • 720 total permutations; optimal cost 6 achieved only by HC permutations
  • Suboptimal costs: 18 (432 permutations, 2 non-edges at consecutive positions) and 30 (216 permutations, 4 non-edges)

References

  • [Sahni and Gonzalez, 1976]: S. Sahni and T. Gonzalez (1976). "P-Complete Approximation Problems". Journal of the ACM 23(3), pp. 555–565. DOI: 10.1145/321958.321975.
  • [Garfinkel and Nemhauser, 1972]: R. S. Garfinkel and G. L. Nemhauser (1972). "Integer Programming". John Wiley & Sons, New York. ISBN 978-0-471-29195-4.

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoodAn issue passed all checks.ruleA new reduction rule to be added.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions