You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add the decision version of Hamiltonian Cycle, one of Karp's 21 NP-complete problems. Complements the existing TravelingSalesman (optimization version) and enables classic reductions from 3-SAT and other decision problems.
Definition
Name: HamiltonianCycle Reference:
Karp, R. M. (1972). "Reducibility among combinatorial problems." In Complexity of Computer Computations.
Garey & Johnson (1979), "Computers and Intractability", Problem [GT37]
Given an undirected graph G=(V,E) where V is the vertex set and E is the edge set, determine whether there exists a simple cycle C that visits every vertex exactly once. Formally, does there exist a permutation (v₁, v₂, ..., vₙ) of V such that (vᵢ, vᵢ₊₁) ∈ E for all i ∈ {1, ..., n-1}, (vₙ, v₁) ∈ E, and all vertices are distinct?
Note: This is the decision version (returns bool), distinct from TravelingSalesman which is the optimization version (returns minimum weight). Issue #47 implemented the optimization version.
Variables
Count: m = |E| (one variable per edge)
Per-variable domain: binary {0, 1}
Meaning: xₑ = 1 if edge e is in the Hamiltonian cycle, 0 otherwise
Schema (data type)
Type name: HamiltonianCycle Variants: graph topology (SimpleGraph, PlanarGraph, BipartiteGraph, etc.)
Field
Type
Description
graph
G
The undirected graph G=(V,E)
Complexity
Classic exact algorithm: O(2ⁿ · n²) by Bellman-Held-Karp dynamic programming (1962), where n = |V|
References:
Held, M., & Karp, R. M. (1962). "A dynamic programming approach to sequencing problems." Journal of SIAM, 10(1), 196-210.
Woeginger, G. J. (2003). "Exact algorithms for NP-hard problems: A survey."
Motivation
Add the decision version of Hamiltonian Cycle, one of Karp's 21 NP-complete problems. Complements the existing
TravelingSalesman(optimization version) and enables classic reductions from 3-SAT and other decision problems.Definition
Name: HamiltonianCycle
Reference:
Given an undirected graph G=(V,E) where V is the vertex set and E is the edge set, determine whether there exists a simple cycle C that visits every vertex exactly once. Formally, does there exist a permutation (v₁, v₂, ..., vₙ) of V such that (vᵢ, vᵢ₊₁) ∈ E for all i ∈ {1, ..., n-1}, (vₙ, v₁) ∈ E, and all vertices are distinct?
Note: This is the decision version (returns bool), distinct from
TravelingSalesmanwhich is the optimization version (returns minimum weight). Issue #47 implemented the optimization version.Variables
Schema (data type)
Type name: HamiltonianCycle
Variants: graph topology (SimpleGraph, PlanarGraph, BipartiteGraph, etc.)
Complexity
Extra Remark
Relationship to TravelingSalesman:
TravelingSalesman(Issue [Model] HamiltonianCycle #47):OptimizationProblem, finds minimum-weight Hamiltonian cycleHamiltonianCycle(this issue):SatisfactionProblem, determines if any Hamiltonian cycle existsboolinstead ofSolutionSize<W>Historical significance: One of Karp's original 21 NP-complete problems (1972), fundamental in computational complexity theory.
Special cases:
Implementation notes: Should implement
SatisfactionProblemtrait. Can reuse validation logic fromTravelingSalesman::is_valid_hamiltonian_cycle().How to solve
Example Instance
Instance 1: Hypercube graph Q₃ (YES)
Instance 2: Path graph P₄ (NO)