Traveling Salesman Problem III

advertisement
Traveling Salesman Problem
Approximate solutions for TSP
NNA, RNN, SEA
Greedy Heuristic Algorithms
Spring 2015
Mathematics in
Management Science
Traveling Salesman Problem
Given a complete weighted graph, find
a minimum weight Hamilton circuit.
A Hamilton circuit visits each
vertex exactly once.
A complete graph has one
edge btwn each pair of vtxs.
A weighted graph has a
weight (cost) for each edge.
Solving a TSP
Brute Force Algorithm –
exhaustive search
Nearest Neighbor Algorithm
Repetitive Nearest Neighbor
Algorithm
Sorted Edges Algorithm
Counting Hamilton Circuits
The complete graph KN with N vertices has
(N – 1)!/2 distinct Hamilton circuits.
Here (N – 1)!/2 =(N-1)x(N-2)x···3x2x1.
For N=30, the number of HCs is
4,420,880,996,869,850,977,271,808, 000,000 .
Generating 1 million HCs per second, say, it
would take over 10 billion years to
generate all of them. 
The BFA will take a loooong time to finish.
Approximate Solutions
Number of HCs in even modest sized
problems is so large that we cannot
examine them all to find exact solutions
by brute force.
Instead we must rely on fast algorithms
that find approximate solutions.
NNA, RRN, SEA
Go Cheap – NNA
Start from the home city.
Go to the city that is the cheapest to
get to. Repeat this.
From each new city go to the next city
that is the cheapest to get to.
When there are no more new cities to
go to, go back home
Nearest Neighbor Algorithm
From a vertex, go to nearest vertex not
already visited. Repeat until no more
new vtxs; then go home.
An example of a greedy algorithm:
– doesn’t look at the “big picture”,
– goes for immediate/short-term gains
– can paint itself into a corner and be
forced to accept a bad solution
From Chicago, find shortest route that
visits each of Minneapolis, St. Louis,
and Cleveland, and returns to Chicago.
Repetitive Nearest Neighbor
Do NNA with each vertex of the graph
as the starting vertex.
Of all the circuits obtained, keep the
best one.
If there is a designated starting vertex,
rewrite this best circuit using that
vertex as the reference point.
From Chicago, find shortest route that
visits each of Minneapolis, St. Louis,
and Cleveland, and returns to Chicago.
Sorted Edges Algorithm
Start with minimum cost edge.
At each stage, use the cheapest (least
cost) edge which is OK.
Stop when have an HC.
An edge is NOT OK if
It closes a circuit that is not an HC, or
It meets a vertex that already has 2 edges
which have been chosen.
Sorted Edges Algorithm
Pick the cheapest link (edge with
smallest weight) available.
Continue picking next cheapest link
available that does not
close a circuit which is not an HC, nor
create three edges coming out of a single
vertex.
Done when get a Hamilton circuit.
Sorted Edges Algorithm
Sort edges in order of increasing cost.
Select edges in order from this list to
subject to these rules:
never reuse an edge
skip edges that connect to vtx already
having two used edges meeting there
skip edges that create “premature” loops,
(small circuits in graph that don’t include
all vtxs). No circuits created until last edge
is added!
Comparison of Algorithms
Both are approximate; typically give
different approximate solutions; typically
neither is the “real” solution.
Neither better than the other.
NNA adds edges in order as you would
traverse the circuit.
SEA adds edges “at random” in the graph.
Neither algorithm says what to do in the
case of a “tie”.
Example
Find an approximate solution to the
following TSP using the Sorted-Edges
Algorithm.
A
E
B
60
80
20
10
D
70
40
C
Example
First (smallest) edge: acceptable.
A
E
B
60
80
70
20
10
D
40
C
Example
Second (next smallest) edge: acceptable.
A
E
B
60
80
70
20
10
D
40
C
Example
Third edge: acceptable.
A
E
B
60
80
70
20
10
D
40
C
Example
Fourth edge: reject (creates premature
loop; three edges into one vertex)
A
E
B
60
80
70
20
10
D
40
C
Example
Fifth edge: reject (creates premature loop)
A
E
B
60
80
70
20
10
D
40
C
Example
Sixth edge: reject (three edges at one vtx)
A
E
B
60
80
20
10
D
70
40
C
Example
Seventh edge: acceptable
A
E
B
60
80
20
10
D
70
40
C
Example
Already added 4 of 5 edges. Only one
possible to close up loop.
A
E
B
60
80
70
20
10
D
40
C
Example do NNA from B
600
A
700
950
B
500
650
750
E
550
C
850
400
800
D
TSP – Conclusion
How does one find an optimal
Hamilton circuit in a complete
weighted graph?
NNA & SEA are fairly simple
strategies for attacking TSPs,
which quickly give good HCs.
The search for an optimal and
efficient general algorithm….
Download