3.3 the traveling-salesman problem
TRANSCRIPT
-
8/2/2019 3.3 the Traveling-salesman Problem
1/27
Traveling Salesman Problem
-
8/2/2019 3.3 the Traveling-salesman Problem
2/27
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 integerk, is there
a Hamiltonian cycle with total weight at most k?
-
8/2/2019 3.3 the Traveling-salesman Problem
3/27
TSP as a Combinatorial
Optimization Problem
Ifn is the number of cities then (n-1)! is the total number ofpossible 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 TSPas one representative problem of alarger class of NP-completecombinatorial optimization problemshas been offered by ClayMathematics Institute of Cambridge
(CMI)
-
8/2/2019 3.3 the Traveling-salesman Problem
4/27
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 thetriangle inequality
-
8/2/2019 3.3 the Traveling-salesman Problem
5/27
ApproxMSTTSP(G
)1 select a vertex rVto be a "root" vertex
2 compute a minimum spanning tree TforG from root r
using MSTPrim(G, w, r)
3 letLbe the list of vertices visited in a preorder tree walk
ofT
4 returnthe hamiltonian cycleHthat visits the vertices in
the orderL
-
8/2/2019 3.3 the Traveling-salesman Problem
6/27
-
8/2/2019 3.3 the Traveling-salesman Problem
7/27
Even with a simple implementation ofMSTPrim, the running time of
ApproxMSTTSP(G) is O(|V|
2
). TheoremApproxMSTTSP(G) is a
polynomial-time 2-approximation
algorithm for the traveling salesmanproblem with the triangle inequality.
-
8/2/2019 3.3 the Traveling-salesman Problem
8/27
Proof. LetH* denote an optimal tour for the given set ofvertices. Since we obtain a spanning tree by deleting anyedge from a tour, the weight of the minimum spanningtree Tis a lower bound on the cost of an optimal tour,
that is, w(T) w(H*)-w(e) w(H*)A full walkofTlists the vertices when they are firstvisited and also whenever they are
returned to after a visit to a subtree. Let us call this walkW
. Since the full walk traverses every edge ofTexactlytwice, we have
w(W)=2w(T)
-
8/2/2019 3.3 the Traveling-salesman Problem
9/27
w(W)2w(H*)
and so the cost ofWis within a factor of 2 of the cost of
an optimal tour.
Unfortunately, Wis generally not a tour, since it visitssome vertices more than once. By the triangle inequality,
however, we can delete a visit to any vertex from Wand
the cost does not increase. By repeatedly applying this
operation, we can remove from Wall but the first visit to
each vertex.
-
8/2/2019 3.3 the Traveling-salesman Problem
10/27
LetHbe 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). SinceHisobtained by deleting vertices from the full walkW,
we have
w(H)w(W)
So w(H)w(W) 2w(H*).
-
8/2/2019 3.3 the Traveling-salesman Problem
11/27
Other heuristic strategies and Discussion
Nearest neighbor strategy
a b
d c
15
20
35
25
12
10
a b
d c
15
20
35
25
12
10
-
8/2/2019 3.3 the Traveling-salesman Problem
12/27
NearestNeighbor(G)1 select an arbitrary vertexs to start the cycleH
2 us
3 whilethere are vertices not yet inHdo
4 select an edge (u,v) of minimum weight, where v isnot inH.
5 add edge (u,v) toH
6 u v7 Add the edge (u,s) toH
8 returnH
-
8/2/2019 3.3 the Traveling-salesman Problem
13/27
a b
d c
15
20
35
25
12
10
a b
d c
15
20
35
25
12
10
a b
d c
15
20
35
25
12
10
a b
d c
15
20
35
25
12
10
H: (a, c), (c, b), (b, d), (d, a)
H=85
H*=72
-
8/2/2019 3.3 the Traveling-salesman Problem
14/27
1. Like Prims MST algorithm, starts with an arbitraryvertex 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.
-
8/2/2019 3.3 the Traveling-salesman Problem
15/27
Nearest Neighbor heuristic worst-case ratio:
R(|I|) = (1+lg|V|)
The ratio grows with |V|.
-
8/2/2019 3.3 the Traveling-salesman Problem
16/27
For (a):
For(b):
.25.18
10
*)(
)()( ===
Hw
HwIR
.
8
4
*)(
)()(
w
Hw
HwIR
+==
-
8/2/2019 3.3 the Traveling-salesman Problem
17/27
Shortest link strategy
ShortestLinkedHeuristic(G)
1H
2E' E
3 whileE' do
4 remove the lightest edge (u,v) fromE'
5 if(u,v) does not make a cycle with edges inH
and (u,v) would not be the third edge inHincident on u or
vthen
6 HH { u, v}
7 Add the edge connecting the endpoints of the path inH
8 returnH
-
8/2/2019 3.3 the Traveling-salesman Problem
18/27
a b
d c
15
20
35
25
12
10
H: (b, c), (c, d), (b, a), (d, a)
H=77H*=72
a b
d c
15
35
25
12
10
20
a b
dc
15
35
25
12
10
20
a b
d c
15
35
25
12
10
20
-
8/2/2019 3.3 the Traveling-salesman Problem
19/27
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 edgesin the path constructed so far and would not be the third
edge in the path incident on u orv.
3.When |E|-1 edges have been added, connect theendpoints of the path to form a cycle.
4.Running time O(|E|lg|E|) for a graph with |E| edges.
19
-
8/2/2019 3.3 the Traveling-salesman Problem
20/27
Insertion heuristic
Nearest insertion(closest-point heuristic)
The vertex closest to any of the vertices already in the
tourHis inserted.
Farthest insertion
The vertex farthest to any of the vertices already in the
tourHis inserted.
Random insertionrandom insertion inserts a vertex uniformly at random.
-
8/2/2019 3.3 the Traveling-salesman Problem
21/27
When inserting a vertex between twovertices 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).
-
8/2/2019 3.3 the Traveling-salesman Problem
22/27
NearestInsertion(G)
1 Choose an arbitrary node viand let the cycleH
consist of only vi
2 whilethere are vertices not yet inHdo
3 Find a node outsideHclosest to a node inH,
call it vj.
4 Find an edge (vi, vj)inHsuch that w(vi, vk) +
w(vk, vj) w(vi, vj)is minimal.
5 Construct a new cycleHby replacing (vi, vj)
with (vi, vk)and (vk, vj).
6 returnH
-
8/2/2019 3.3 the Traveling-salesman Problem
23/27
a b
d c
15
20
35
25
12
10
H: (a, c), (c, d), (d, b), (b, a)
H=72H*=72
a b
d c
15
20
35
25
12
10
a b
d c
15
20
35
25
12
10
(a, c): 35+12-
15=32(b, c): 25+12-10=27
(a, b): 35+25-20=40
a b
d c
15
20
35
25
12
10
-
8/2/2019 3.3 the Traveling-salesman Problem
24/27
Theorem. Any insertion heuristic order gives aR(|I|)=
. 1||lg +V
-
8/2/2019 3.3 the Traveling-salesman Problem
25/27
Given a complete graph G=(V,E) with positive weights
(distances) on its edges,
The minimum traveling salesman problem consists ofminimizing 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.
-
8/2/2019 3.3 the Traveling-salesman Problem
26/27
Homework
Exercises: Page 94
1,2,4
Experiments:
Implement ApproxMSTTSP,NearestNeighbor,ShortestLinkedHeuristic, NearestInsertion and compare
these algorithms
-
8/2/2019 3.3 the Traveling-salesman Problem
27/27