0% found this document useful (0 votes)
86 views27 pages

Chapter 5-The-Traveling-Salesman-Problem

The document discusses the traveling salesman problem (TSP), which is an optimization problem to find the shortest route to visit all cities on a list and return to the origin city. It is NP-complete. The document covers several heuristic algorithms to approximate solutions to the TSP, including using a minimum spanning tree, nearest neighbor insertion, shortest link insertion, and their running times and performance guarantees. It also notes that exactly solving large TSP instances remains a challenge area in computer science.

Uploaded by

Tihitna Tsegaye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views27 pages

Chapter 5-The-Traveling-Salesman-Problem

The document discusses the traveling salesman problem (TSP), which is an optimization problem to find the shortest route to visit all cities on a list and return to the origin city. It is NP-complete. The document covers several heuristic algorithms to approximate solutions to the TSP, including using a minimum spanning tree, nearest neighbor insertion, shortest link insertion, and their running times and performance guarantees. It also notes that exactly solving large TSP instances remains a challenge area in computer science.

Uploaded by

Tihitna Tsegaye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 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, w∈V, 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 r∈V 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 20
a b a b
15 15
35 10 35 10
25 25
d c d c
12 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 u←v
7 Add the edge (u,s) to H
8 return H
H: (a, c), (c, b), (b, d), (d, a)

20 20
a b a b
15 15
35 10 35 10
25 25 H=85
d c d c H*=72
12 12

20 20
a b a b
15 15
35 10 35 10
25 25
d c d c
12 12
1. Like Prim‘s 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 b a b H=77
15 15 H*=72
35 10 35 10
25 25
d c d c
12 12

20 20
a b a b
15 15
35 10 35 10
25 25
d c d c
12 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 Find an edge (vi, vj) in H such that w(vi, vk) + w(vk,
vj) – w(vi, vj) is minimal.
5 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 b
H=72
a b
15 15 H*=72
35 10 35 10
25 25
d c d c
12 12
20
20 (a, c): 35+12-
a b a b
15=32 15
15 (b, c): 25+12-10=27
35 10
35 10
(a, b): 35+25-20=40 25
25
d d c
c 12
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
Experiments:
Implement ApproxMSTTSP,NearestNeighbor,
ShortestLinkedHeuristic, NearestInsertion and compare
these algorithms
 Consider the vehicle routing problem:
 One is given a set of customers with known positive
demands. A fleet of homogeneous vehicles of known
capacity is available at a given depot to perform this
service. The objective is to find a set of closed routes
(or tours) that start and end at the depot, such that the
total cost of performing the service is minimized.

27

You might also like