TSP problem
Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city exactly once and returns to the origin city?
It is an NP-hard problem in combinatorial optimization. We will discuss 2 category of solutions:
- Exact algorithms
- Heuristic and approximation algorithms
Exact algorithms
Brute force search, which the run time is O(n!), which is impossible for 20 cities.
DP Held–Karp algorithm. O(n^2 x 2^n).
Branch-and-bound algorithm. This can process 40-60 cities.
Heuristic and approximation algorithms
Greedy, or Nearest Neighbour algorithm. (an improved version is called Nearest Fragment algorithm, which connect NN in groups)
Minimum Spanning Tree (MST), build the MST using Kruskal’s algorithm and then do a Depth-first Tree Tour. link to video.
Sort all edges from small to large, then add edges into MST as long as no cycle is created. In the end, a MST is achieved.
Do Depth-first Tree Tour(DFTT)
Length of DFTT is 2 x weight of MST.
Skip some nodes that’s only visited once.
We get an legitimate solution.
Iterative improvement
Now these are the solutions. However we can improve it by doing 2-opt Swap.
It means selecting 2 edges at random. If swapping results in an improvement, then keep it. Keep doing this. link to video.