Exact

Bellman–Held–Karp

Aliasbhk, bellman_karp
TypeExact
ComplexityO(2ⁿ · n²) time, O(2ⁿ · n) space

Description

Dynamic programming algorithm that solves TSP exactly. It builds up solutions for subsets of cities, combining the optimal sub-tour results to find the globally optimal tour. Returns the provably shortest Hamiltonian circuit.

Do not use on more than ~20 cities — memory and runtime grow exponentially with city count.

Usage

teeline solve bhk -i ./data/discopt/tsp_5_1.tsp
teeline solve bellman_karp -i ./data/discopt/tsp_5_1.tsp --verbose

References