Skip to main content
Examonaut

Topic 3 · Lesson 2 of 3

The travelling salesman problem

Classical and practical problems

The travelling salesman problem asks for the shortest tour that visits every vertex and returns to the start.

  • In the classical problem, each vertex is visited exactly once: the tour is a Hamiltonian cycle.
  • In the practical problem, each vertex is visited at least once: you may pass through a vertex again if that is shorter.

To turn a practical problem into a classical one, replace the network by a complete network of least distances: a table giving the shortest distance between every pair of vertices, by any route (by inspection, or by Floyd's algorithm). In this table the triangle inequality holds: for any three vertices, d(X,Z)≤d(X,Y)+d(Y,Z)d(X, Z) \leq d(X, Y) + d(Y, Z); the direct distance is never longer than going via a third vertex. A classical tour in the table corresponds to a practical tour in the real network, possibly passing through some vertices more than once.

No efficient algorithm is known that always finds the optimal tour: checking every tour of nn vertices means 12(n−1)!\frac{1}{2}(n - 1)! tours, far too many for large nn. So you trap the optimal length TT between bounds.

ABCDEA–19283130B19–91223C289–625D31126–21E30232521–

Upper bounds: the nearest neighbour algorithm

  1. Choose a starting vertex.
  2. Go to the nearest vertex not yet visited.
  3. Repeat until every vertex is visited, then return to the start.

The length of this tour is an upper bound: the optimal tour can be no longer. Starting from different vertices gives different upper bounds; the best upper bound is the smallest.

In the table above, from A: A to B (19), B to C (9), C to D (6), D to E (21), E back to A (30). Tour A B C D E A, length 85.

Upper bounds: doubling a minimum spanning tree

Walking all the way round a minimum spanning tree, along each arc twice, visits every vertex and returns to the start, so twice the weight of the minimum spanning tree is an upper bound. You can improve it with shortcuts: whenever the walk would return to a vertex already visited, go straight to the next new vertex instead. By the triangle inequality, a shortcut is never longer.

In the table above, a minimum spanning tree is CD, BC, AB, DE, of weight 55, giving an upper bound of 110. Walking round it from A gives A B C D E D C B A. Shortcutting from E straight back to A gives the tour A B C D E A, of length 85.

Lower bounds: the residual minimum spanning tree

  1. Delete a vertex X and all its arcs.
  2. Find a minimum spanning tree of the remaining vertices (the residual minimum spanning tree).
  3. Add the two shortest arcs from X.

The total is a lower bound. It works because any tour, with X removed, becomes a path through all the other vertices (a spanning tree, so at least as long as the minimum spanning tree), and the tour uses exactly two arcs at X (at least as long as the two shortest). Deleting different vertices gives different lower bounds; the best lower bound is the largest.

In the table above, delete A. The minimum spanning tree of B, C, D, E is CD 6, BC 9, DE 21 (BD is rejected), weight 36. The two shortest arcs from A are 19 and 28. Lower bound 36+19+28=8336 + 19 + 28 = 83.

Putting the bounds together

With the best upper bound 85 and the best lower bound 83, the optimal tour length satisfies

83≤T≤8583 \leq T \leq 85

If the best lower bound equals an upper bound, the tour giving that upper bound is optimal. If the residual tree, with the two arcs added, happens to form a Hamiltonian cycle, it is itself an optimal tour.

Practise this topic

Both are part of Premium.