# 2 TSP algorithms: (1) AP+B&B, (2) min spanning tree.

## Presentation on theme: "2 TSP algorithms: (1) AP+B&B, (2) min spanning tree."— Presentation transcript:

2 TSP algorithms: (1) AP+B&B, (2) min spanning tree.
The assignment problem is a relaxation of the TSP Indices: i, j = city. Parameter: cij = cost to go from city i to city j. Variables: xij = 1 if we drive from city i to city j, else 0. Model TSP: 1. Minimise total cost: min ij cij xij , 2. Enter each city once: i xij = 1 for all j. 3. Leave each city once: j xij = 1 for all i. 4. Binary integrality: xij  {0, 1} for all i, j. 5. No subtours: i,jS xij  |S| – 1, for every subset S. (1) to (4) is the assignment problem AP, which is easy. Every solution to TSP is a solution to AP, but not vice versa. AP is a relaxation of TSP, and AP gives a lower bound. AP

One way to break subtours: B&B
We can break subtours by adding constraints: x3,2 + x2,4 + x4,3  2. After solving again, other subtours appear. Instead, we can branch on a variable in the subtour: Create an assignment subproblem with x4,3 = 0. This is a B&B algorithm specialised for the TSP. 3 3 1 1 4 4

Example, Winston (2003), pp When we solve subproblem S1, we get subtours , In the optimal solution, either x3,4 = 0 or x4,3 = 0. So let’s make 2 subproblems, S2 for x3,4=0, and S3 for x4,3=0.

With x3,4 = 0, we get 1-4-3-1 instead of 1-3-4-1.
We also have the subtour Let’s branch on x2,5=0 for S4. (To do list: S3 with x4,3 = 0.)

So we have an upper bound of 668.
S4 gives a tour! So we have an upper bound of 668. The optimum is 668 or less.

The complete B&B tree S1: ov=495, 1-2-5-1, 1-3-4-1. x3,4 = 0 x4,3 = 0
, 2-5-2 S3: ov=652 , 2-5-2 x2,5 = 0 x5,2 = 0 x2,5 = 0 x5,2 = 0 S4: ov=668, S5: ov=704, S6: ov= 704, S7: ov=910, 1-3-1, At S4, we found a tour of length 668. The tours at S5 and S6 are worse, so they are not optimal. S7 has subtours, but more constraints cannot help 910, so we quit. So S4 gives the optimal tour, So we can solve the TSP with B&B, with AP as the subproblem. Each AP subproblem was a relaxation. Are there other relaxations?

Another TSP relaxation: the one-tree
First some definitions. Tree: connected graph with no loops. One-tree: a tree plus one loop. Hey! This one tree is a tour! Every tour is a one-tree, but not every one-tree is a tour. 

The minimum spanning tree problem (MST)
MST: Find the shortest tree that connects all the dots. Not a good one! This is much better: Many applications: telecommunications, road networks. How do we find the minimum spanning tree? 2 ways, Prim’s algorithm or Kruskal’s algorithm.

Prim’s algorithm Find the closest node that doesn’t make a loop
Step 0. Sort all the arcs in increasing order. The tree is empty except for node 1. Step 1. Find the smallest arc i, j or j, i that connects to any node i in the tree. If arc i, j makes a loop, skip it. Else add it to the tree. Step 2. If all the nodes are connected, you’re done. Else, go back to Step 1. See

Kruskal’s algorithm: Find the smallest arc that doesn’t make a loop
Step 0. Sort all the arcs in increasing order. The tree is empty. Step 1. Find the shortest arc on the list. If it makes a loop, delete it. Else add it to the tree. Step 2. If all the nodes are connected, you’re done. Else, go back to Step 1. See

Demo of each algorithm 5 3 Prim – closest node 7 4 6 2 8 9 5 1
From To Length Prim Kruskal 5 3 Prim – closest node 7 4 2 6 8 9 5 1 Kruskal – smallest arc 3 7 4 2 6 8 9 Exercise: Label the arcs in the order added.  1

We can make an MST, how about a 1-tree?
To make a minimum 1-tree: Step 1. Find the MST of all nodes except node 1. Step 2. Add the 2 smallest arcs that connect to node 1. This is easy work. You can do it for 100 cities in a few minutes by hand. 1 2 3 4 7 8 9 6 5

The 1-tree length is a lower bound on the TSP
But not a very good one, typically only 63% of the optimum. Our example is only 67% of the optimum. What is wrong with the minimum 1-tree? In the TSP, every node has 2 arcs, one in and one out. In the min 1-tree, some nodes have 1 arc, some have more than 2. We can improve the lower bound as follows: Solve the 1-tree problem, but add a penalty to each arc that comes into a node with the wrong number of arcs.  length=194.5 length=287.1 5 5 3 3 7 7 4 4 2 6 2 8 6 8 9 9 1 1

Recall the symmetric TSP formulation
1. Minimise total cost: min ij>i cij xij , 2. Enter each city once: j<i xji + j>i xij = 2 for all i. 3. Subtour breaking: i,jS xij  |S| – 1, for each subset S. 4. Binary integrality: xij  {0, 1} for all i, j. Subtours (set 3) are not the problem with the min 1-tree. Entering each city (set 2) once is the problem with the min 1-tree. Another way to put the TSP: 2. Enter each city once: j<i xji + j>i xij = 2 for all i. (λi) 3. Must be a 1-tree: x T, where T is the set of all 1-trees. Let’s relax set 2, as for a Dantzig-Wolfe subproblem: 1. Minimise total cost: min ij>i cij xij + iλi(j<i xji + j>i xij – 2) = min ij>i (cij + λi + λj)xij – 2i λi 3. Must be a 1-tree: x T, where T is the set of all 1-trees. 

TSP lower bound with subgradient optimisation
Step 0. Set λi = 0. (Cleverer to start with AP’s dual prices.) Pick a jump size tk between 0.5 and 2. Set a small ending tolerance  > 0. Set k = 1. Step 1. Solve the min 1-tree problem. 1-tree(λik): min ij>i cij xij + iλi(j<i xji + j>i xij – 2) x T, where T is the set of all 1-trees. Step 2. Let dik be number of arcs coming into node i at iteration k. If node i is good, dik = 2, keep the penalty: set λik+1 = λik. If node i is bad, dik ≠ 2, change the penalty: set λik+1 = λik + tk (dik − 2). Step 3. If |k+1 – k| < , stop. Else set tk+1 = tk ·0.9, set k = k+1 and go to Step 1.  Excellent animated examples: /~mertens/TSP/

Still no promises, but not bad.
Subgradient opt gets a better lower bound than plain 1-tree, often 99%. But it can take a long time. No guarantee we get an optimum. Example: Starting with step size=5, then 1, then 0.5, we get λk = {-41.0, -12.5, -27.5, -19.0, -45.5, -27.5, -20.0, -19.0, -22.0}, and the optimal tour: Why are the prices negative? Not hard to do in AMPL, even possible with Excel & Visual Basic. Another B&B scheme: use 1-trees for subproblems. Branch on arcs that go into nodes with degree ≠ 2. 1 2 3 4 7 8 9 6 5

The 1-tree gives 2 lower bounds – bad & good
At the beginning, with all λi=0, we get a bad lower bound. This is just the smallest 1-tree. During subgradient optimisation, we can say nothing about bounds. At the end of subgradient optimisation, with the optimal λ’s, we get a good lower bound. The lower bound is the penalised length, not the ordinary length of the 1-tree. The ordinary (unpenalised) length of the optimised 1-tree could be longer than the optimal tour! If all nodes have degree 2, penalised length = ordinary length, and we have the optimal tour. Ref: Held, M., & Karp, R., “The Traveling-Salesman Problem and Minimum Spanning Trees” Ops Research, v.18, n.6, Nov-Dec 1970. Next: more on subtours & trees. We’ll also cover this in tutorial.