liveBook · Manning

Traveling Salesman problem

As explained in Advanced Algorithms and Data Structures

The travelling salesman problem asks for the shortest route that visits each specified location exactly once and returns to the starting location.

The Traveling Salesman Problem (TSP) asks for a tour through specified locations that visits each one exactly once and returns to the starting point. Model locations as graph vertices, connections as weighted edges, and the tour cost as the sum of distances between adjacent vertices. section 17.2

TSP is an NP-complete problem: candidate tours can be checked in polynomial time, but no known deterministic algorithm solves every instance in polynomial time. Exhaustive search quickly becomes impractical, with 10 cities producing about 3.6 million sequences, 15 producing about 1.3 trillion, and 20 producing about 2.4 × 10^18. section 17.2

A practical TSP workflow separates representation, evaluation, and search:

  • Encode each candidate as a permutation of the graph’s vertices, with every vertex appearing once. section 18.2.1
  • Evaluate a candidate by summing the distances between adjacent vertices; minimize this cost. section 18.2.1
  • Use simulated annealing or genetic algorithms when exhaustive enumeration grows too large. section 17.0 section 18.2.1

A small permutation space

For six cities, there are 720 possible vertex permutations, making it feasible to display the complete cost landscape or brute-force the minimum. A larger map with 10 cities already takes several minutes to enumerate all 3.6 million permutations. section 17.2.2

Figure 17.8 An example map, mixing the DC Universe’s cities and other real ones, with some distances: because this is a complete graph with close to fifty edges, we are only showing a few numbers, almost only for the edges in the best tour (the thicker edges).

Use the map to inspect a weighted city graph and the highlighted edges forming a low-cost tour. section 17.2

TSP reasoning applies to delivery, school-bus routing, mail services, farming, service-call scheduling, printed-circuit-board drilling and soldering, and genome sequencing. Exact optimization trades rapidly increasing computation for certainty; approximation trades certainty for workable planning. section 17.2.6 section 17.2

How Advanced Algorithms and Data Structures covers it

How deep it goes
Explains graph representation, permutation encoding, cost evaluation, search difficulty, and heuristic alternatives, without developing an exact polynomial-time algorithm.
Examples
Uses delivery routes, a six-city complete graph, city-map tours, and applications in transport, logistics, manufacturing, and sequencing.
What it assumes
Assumes graph vertices, weighted distances, permutations, and optimization concepts while making the route model explicit.
What you can do after
Apply it via simulated annealing or genetic algorithms to represent, evaluate, and search large route-planning instances.
How it connects
Connects graph theory, combinatorial optimization, simulated annealing, genetic algorithms, fitness functions, and cost landscapes.

Also explained in

Compare how 6 books explain Traveling Salesman problem →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Advanced Algorithms and Data Structures. The section links point to the parts of the book it draws on.