Upload
ginger-hutchinson
View
213
Download
1
Embed Size (px)
Citation preview
The Travelling Salesman Algorithm
A Salesman has to visit lots of different stores and return to the starting base
On a graph this means visiting every vertex and returning to the start
Unlike the postman problem you do not have to go along every edge
There is not a method for finding the shortest route but there are 2 methods which will home in on the answer
Nearest Neighbour Algorithm This is used to find an Upper Bound
This is a value which represents the largest distance that needs to be covered.
It may be possible to do the problem in a shorter distance but this algorithm gives a quick answer to a possible solution
Nearest Neighbour Algorithm
1. Start with any vertex
2. Look for the shortest edge that joins this vertex to a vertex not on the tree and add this to the tree.
3. Keep joining vertices to the last chosen vertex using the smallest edge available. Repeat until all the vertices are joined to the tree.
4. Join the last chosen vertex to the first chosen.
Note DO NOT visit any vertex twice on the outward route
B
A D
C3
2 14
8
E
G
F2
46
5
310
7
9
If it is not possible to return to the start directly then it will be necessary to revisit certain vertices on the return route.
Starting at A visit every vertex and return to A
B
A D
C3
2 14
8
E
G
F2
46
5
310
7
9
1. Choose vertex A2. Choose vertex B as it is the Nearest Neighbour3. Next choose vertex C, as it is the Nearest Neighbour4. Repeat to get vertex D, then E, then F, then G5. Return to A using the shortest route i.e 9
B
A D
C3
2 14
8
E
G
F2
46
5
310
7
9
Total distance = 24
B
A D
C3
2 14
8
E
G
F2
46
5
310
7
9Starting at F1. Choose vertex G as it is the Nearest Neighbour2. Next choose vertex E, as it is the Nearest Neighbour3. Repeat to get vertex D, then C, then B, then A4. Return to F using the shortest route i.e 4+1+2+4
Total distance = 28
B
A D
C3
2 14
8
E
G
F2
46
5
310
7
9
Since the first route gave a better answer this means that the answer is 24 or less
24 is called an Upper Bound
The smaller the Upper Bound the better
B
A D
C3
2 14
8
E
G
F2
46
5
310
7
9
In fact for this problem the shortest route is 24
Applet