Está en la página 1de 3

Branch-and-Bound and the TSP

CS 341 Notes by D.R. Stinson

A Backtracking Algorithm for the TSP

The Travelling Salesperson problem, or TSP, is dened as follows. We are given an undirected graph G = (V, E) and a weight function w : E Z+ . We are required to nd a hamiltonian cycle H in G such that w(H) = w(e)
eH

is minimized. (A hamiltonian cycle in a graph G = (V, E) is a simple cycle in G consisting of n = |V | vertices.) A hamiltonian cycle can be represented as a permutation of the vertices, say X = [x1 , . . . , xn ], such that x1 x2 xn x1 is a cycle in the graph G. To be concrete, suppose that V = {1, . . . , n}. A backtracking algorithm will construct all the n-tuples corresponding to hamiltonian cycles and determine which one is optimal. Because a hamiltonian cycle uses every vertex in V , we can stipulate without loss of generality that x1 = 1. (This ensures that the algorithm constructs any given hamiltonian cycle once and only once.) In the backtracking algorithm, the parameter denotes the current coordinate being selected, i.e., X has the form X = [x1 , . . . , x 1 ]. When n, this partial feasible solution corresponds to a simple path in G consisting of 2 edges. When = n + 1, we have constructed a hamiltonian cycle, so we compute its weight and update the optimal cycle and weight if the current cycle represents an improvement. There is also a parameter , denoted Used , which keeps track of the vertices that have already occurred in X. That is, Used = {x1 , . . . , x 1 }, where X = [x1 , . . . , x 1 ]. When we want to choose a value for x , we need to ensure that x Used and that {x 1 , x } E. In addition, if = n, then we are nding the last vertex to complete the cycle, so we also have to check that {x , x1 } E. Algorithm 1.1: TSP1( , Used) global X, OptX , OptW if = n 1 + n1 CurW w[xi , xi+1 ] + w[xn , x1 ] i=1 then if CurW < OptW then OptW CurW ; OptX [x1 , . . . , xn ] for j 2 to n ag (j Used ) and ({x 1 , j} E) else do if ( = n) then ag ag and ({j, x1 } E) if ag then x j; TSP1( + 1, Used {j}) 1

Initally, we dene x1 = 1, and call TSP1(2, {1}). This means that the rst vertex in the cycle is equal to 1, as discussed above.

A Bounding Function

Suppose that we have a feasible partial solution X = [x1 , . . . , x 1 ], where 2. Because the TSP is a minimization problem, we want to nd a lower bound on the weight of the best feasible solution that extends X. Observe that X corresponds to a path in G from x1 to x 1 having 2 edges. Any completion of X to a hamiltonian cycle consists of the following components: 1. the path determined by the partial solution X 2. an edge from x1 to a vertex xn V \Used 3. an edge from x 1 to a vertex x V \Used 4. a simple path in Used from x to xn , consisting of n edges. We can obtain a bounding function by nding a lower bound on the weights of each of these four components. One possibility is to dene B(X) to consist of the sum of the following four quantities:
2

B1.
i=1

w[xi , xi+1 ]

B2. min{w[x1 , x] : x Used } B3. min{w[x 1 , x] : x Used } B4. The weight of a minimum spanning tree in the subgraph of G induced by the vertices in the set V \Used , with weight function w. Clearly, B1 is the weight of item 1, and B2 and B3 are lower bounds on the weights of items 2 and 3, respectively. Finally, the simple path in 4 is a spanning tree in the subgraph of G induced by the vertices in the set V \Used . Hence, its weight is bounded below by the weight of the minimum spanning tree in this graph. So B(X), as dened above, is a bounding function. It can also be computed fairly quickly because there are ecient algorithms to nd minimum spanning trees (e.g., Kruskal or Prim).

Branch and Bound

Suppose that we have a feasible partial solution X = [x1 , . . . , x 1 ] and a bounding function B for the TSP. Let X consist of all the feasible partial solutions X = [x1 , . . . , x ] extending 2

X by choosing the value of one additional coordinate. There can be as many as n + 1 choices for x , so |X | n + 1. The idea of the branch-and bound strategy is to specify ahead of time an intelligent ordering of the dierent extensions X in the set X . It may be plausible to expect that X is more likely to lead to an optimal solution than X if B(X ) < B(X ). Therefore, it makes sense to perform the recursive call to X before we perform the recursive call to X . More precisely, here is how the branch-and-bound strategy is carried out: 1. Suppose that we have a feasible partial solution X = [x1 , . . . , x 1 ], where a bounding function B. n, and that

2. Let X consist of all the feasible partial solutions X = [x1 , . . . , x ] of length extend X.

3. For each X X , compute B(X ) (this is done before making any recursive calls to the next level of the backtracking algorithm). 4. Sort the list of values B(X ) (X X ) in increasing order. 5. Perform the recursive calls in the order determined by the result of step 4. If it is discovered that any time that P(X) B(X ), then we perform no more recursive calls from the current partial solution X.

También podría gustarte