You are on page 1of 27

Traveling Salesman Problem

Traveling Salesman Problem (TSP)

Optimization problem: Given a complete weighted graph, find a minimum weight Hamiltonian cycle Decision Problem: Given a complete weighted graph and an integer k, is there a Hamiltonian cycle with total weight at most k?

TSP as a Combinatorial Optimization Problem

If n is the number of cities then (n-1)! is the total number of possible routes n=5 120 possible routes n=10 3,628,800 possible rotes n=20 2,432,902,008,176,640,000 possible routes TSP is a NP-Complete combinatorial optimization problem = non-deterministic polynomial time Scientific challenge for solving TSP $1 million prize for solving the TSP as one representative problem of a larger class of NP-complete combinatorial optimization problems has been offered by Clay Mathematics Institute of Cambridge (CMI)

The traveling-salesman problem

The triangle inequality: if for all vertices u, v, wV, cost function w satisfies w(u, w) w(u, v) + w(v, w). The traveling-salesman problem with the triangle inequality

ApproxMSTTSP(G) 1 select a vertex rV to be a "root" vertex 2 compute a minimum spanning tree T for G from root r using MSTPrim(G, w, r) 3 let L be the list of vertices visited in a preorder tree walk of T 4 return the hamiltonian cycle H that visits the vertices in the order L

Even with a simple implementation of MSTPrim, the running time of ApproxMSTTSP(G) is O(|V|2). Theorem ApproxMSTTSP(G) is a polynomial-time 2-approximation algorithm for the traveling salesman problem with the triangle inequality.

Proof. Let H* denote an optimal tour for the given set of vertices. Since we obtain a spanning tree by deleting any edge from a tour, the weight of the minimum spanning tree T is a lower bound on the cost of an optimal tour, that is, w(T) w(H*)-w(e) w(H*) A full walk of T lists the vertices when they are first visited and also whenever they are returned to after a visit to a subtree. Let us call this walk W . Since the full walk traverses every edge of T exactly twice, we have w(W)=2w(T)

w(W)2w(H*) and so the cost of W is within a factor of 2 of the cost of an optimal tour. Unfortunately, W is generally not a tour, since it visits some vertices more than once. By the triangle inequality, however, we can delete a visit to any vertex from W and the cost does not increase. By repeatedly applying this operation, we can remove from W all but the first visit to each vertex.

Let H be the cycle corresponding to this preorder walk. It is a hamiltonian cycle, since every vertex is visited exactly once, and in fact it is the cycle computed by ApproxMSTTSP(G). Since H is obtained by deleting vertices from the full walk W , we have w(H)w(W) So w(H)w(W) 2w(H*) .

Other heuristic strategies and Discussion

Nearest neighbor strategy

20

a
15 35 25

b
10 35

20

a
15

b
10 25

d
12

d
12

NearestNeighbor(G) 1 select an arbitrary vertex s to start the cycle H 2 u s 3 while there are vertices not yet in H do 4 select an edge (u,v) of minimum weight, where v is not in H. 5 add edge (u,v) to H 6 uv 7 Add the edge (u,s) to H 8 return H

H: (a, c), (c, b), (b, d), (d, a)


20 20

a
15 35 25

b
10 35

a
15

b
10 25

d
12 20

d
12 20

H=85 H*=72

a
15 35 25

b
10 35

a
15

b
10 25

d
12

d
12

1. Like Prims MST algorithm, starts with an arbitrary vertex u and adds edge (u,v) of minimum weight such that vertex v is not yet in the cycle. 2. However, it always adds edges from the endpoint of the cycle constructed so far. 3. Worst case time of O(|V|2) for a graph with |V| vertices.

Nearest Neighbor heuristic worst-case ratio: R(|I|) = (1+lg|V|) The ratio grows with |V|.

For (a):
w( H ) 10 R( I ) = = = 1.25. w( H *) 8

For(b):
w( H ) 4 + w R( I ) = = . w( H *) 8

Shortest link strategy


ShortestLinkedHeuristic(G) 1 H 2 E' E 3 while E' do 4 remove the lightest edge (u,v) from E' 5 if (u,v) does not make a cycle with edges in H and (u,v) would not be the third edge in H incident on u or v then 6 H H {u, v} 7 Add the edge connecting the endpoints of the path in H 8 return H

H: (b, c), (c, d), (b, a), (d, a)


20 20

a
15 35 25

b
10 35

a
15

b
10 25

H=77 H*=72

d
12 20

d
12

a
15 35 25

b
10 35

20

a
15

b
10 25

d
12

d
12

Shortest link strategy

1.Like Kruskal's MST algorithm, considers edges in order of cost, from shortest to longest. 2.Adds edge (u, v) if it does not make a cycle with edges in the path constructed so far and would not be the third edge in the path incident on u or v. 3.When |E|-1 edges have been added, connect the endpoints of the path to form a cycle. 4.Running time O(|E|lg|E|) for a graph with |E| edges.
19

Insertion heuristic
Nearest insertion(closest-point heuristic) The vertex closest to any of the vertices already in the tour H is inserted. Farthest insertion The vertex farthest to any of the vertices already in the tour H is inserted. Random insertion random insertion inserts a vertex uniformly at random.

When inserting a vertex between two vertices vi and vk, we want to minimize the added cost to the tour. Vertex vj is added to the tour by adding edges (vi, vj) and (vj, vk) while removing (vi, vk). We choose i and k as to minimize w(vi, vj) + w(vj, vk) w(vi, vk).

NearestInsertion(G) 1 Choose an arbitrary node vi and let the cycle H consist of only vi 2 while there are vertices not yet in H do 3 Find a node outside H closest to a node in H, call it vj. 4 5 Find an edge (vi, vj) in H such that w(vi, vk) + w(vk, vj) w(vi, vj) is minimal. Construct a new cycle H by replacing (vi, vj) with (vi, vk) and (vk, vj).

6 return H

H: (a, c), (c, d), (d, b), (b, a)


20 20

a
15 35 25

b
10 35

a
15

b
10 25

H=72 H*=72

d
12 20

d
12 (a, c): 35+1215=32 (b, c): 25+12-10=27 10 (a, b): 35+25-20=40

c
20

a
15 35 25

a
15 35 25

b
10

d
12

d
12

Theorem. Any insertion heuristic order gives a R(|I|)= . lg | V | + 1

Given a complete graph G=(V,E) with positive weights (distances) on its edges, The minimum traveling salesman problem consists of minimizing the cost of a Hamiltonian cycle, the cost of such a cycle being the sum of the weights on its edges. The maximum traveling salesman problem consists of maximizing the cost of a Hamiltonian cycle.

Homework
Exercises: Page 94 1,2,4 Experiments: Implement ApproxMSTTSP,NearestNeighbor, ShortestLinkedHeuristic, NearestInsertion and compare these algorithms

27

You might also like