traveling salesman problem (tsp). an example a truck needs to leave node 1, visit each of the other...
TRANSCRIPT
![Page 1: Traveling Salesman Problem (TSP). An Example A truck needs to leave node 1, visit each of the other nodes one and only one time, and back to node 1 –What](https://reader036.vdocuments.net/reader036/viewer/2022070415/5697bf771a28abf838c81606/html5/thumbnails/1.jpg)
Traveling Salesman Problem (TSP)
![Page 2: Traveling Salesman Problem (TSP). An Example A truck needs to leave node 1, visit each of the other nodes one and only one time, and back to node 1 –What](https://reader036.vdocuments.net/reader036/viewer/2022070415/5697bf771a28abf838c81606/html5/thumbnails/2.jpg)
An Example
• A truck needs to leave node 1, visit each of the other nodes one and only one time, and back to node 1 – What is the best route?
• Difference from the shortest path problem– In shortest path problems, we only care the source and
destination, and leave enough freedom to intermediate nodes
1
2
3
4
5 6
7
12
10
8
12
1110
9
113
912
7
6 1
2
3
4
5 6
7
12
10
8
12
1110
9
113
912
7
6
![Page 3: Traveling Salesman Problem (TSP). An Example A truck needs to leave node 1, visit each of the other nodes one and only one time, and back to node 1 –What](https://reader036.vdocuments.net/reader036/viewer/2022070415/5697bf771a28abf838c81606/html5/thumbnails/3.jpg)
TSP and Shortest Path
Finding a route like this (routing arbitrarily) is TSP
1
2
3
4
5
6
7
8
9
A
B
C
Finding a route like this (forward only) can be modeled as a shortest path problem
![Page 4: Traveling Salesman Problem (TSP). An Example A truck needs to leave node 1, visit each of the other nodes one and only one time, and back to node 1 –What](https://reader036.vdocuments.net/reader036/viewer/2022070415/5697bf771a28abf838c81606/html5/thumbnails/4.jpg)
The Traveling Salesman Problem• A network G=(N,A)
– The network may be directed or undirected, which defines two versions of TSP
• Symmetric or asymmetric TSP• If not explicitly mentioned, our discussion applies to
both versions
• Each arc (i,j) has a cost cij
– Assumption 1: cij ≥0• What can we do if some cij < 0?
– Assumption 2: There is an arc between any two nodes. If there is no arc (i,j), we simply let the cost cij be a very large number
![Page 5: Traveling Salesman Problem (TSP). An Example A truck needs to leave node 1, visit each of the other nodes one and only one time, and back to node 1 –What](https://reader036.vdocuments.net/reader036/viewer/2022070415/5697bf771a28abf838c81606/html5/thumbnails/5.jpg)
The Traveling Salesman Problem• A tour is defined as a sequence of the nodes in
N– The cost of a tour is the total cost for the loop that
visits all nodes along the sequence of the tour– Each node is visited one and only one time
• The TSP problem is to find a tour with the minimum cost
![Page 6: Traveling Salesman Problem (TSP). An Example A truck needs to leave node 1, visit each of the other nodes one and only one time, and back to node 1 –What](https://reader036.vdocuments.net/reader036/viewer/2022070415/5697bf771a28abf838c81606/html5/thumbnails/6.jpg)
An Example
• The optimal tour with total cost = 12+12+10+9+7+3+10=63
• The tour can be represented by (1,2,4,6,7,5,3) or equivalently (2,4,6,7,5,3,1), …– Starting node for the tour does not matter because it is a loop
1
2
3
4
5 6
7
12
10
8
12
1110
9
113
912
7
6 1
2
3
4
5 6
7
12
10
8
12
1110
9
113
912
7
6
![Page 7: Traveling Salesman Problem (TSP). An Example A truck needs to leave node 1, visit each of the other nodes one and only one time, and back to node 1 –What](https://reader036.vdocuments.net/reader036/viewer/2022070415/5697bf771a28abf838c81606/html5/thumbnails/7.jpg)
Visiting a Node Multiple Times?
• In practice, sometimes it may be more cost-effective if we allow to visit some nodes multiple times– (1,2,4,3,1) with cost=64 v.s. (1,2,4,2,3,1) with cost=54
• Any TSP allowing multiple-time visit can be converted into a TSP not allowing multiple-time visit– Find the shortest-path cost d[i,j] for all pairs of (i,j)– Use d[i,j] to replace cij for all pairs of (i,j)
1
2
3
412
10
8
12
30
1
2
3
412
10
8
12
20
1
2
3
412
10
8
12
30
![Page 8: Traveling Salesman Problem (TSP). An Example A truck needs to leave node 1, visit each of the other nodes one and only one time, and back to node 1 –What](https://reader036.vdocuments.net/reader036/viewer/2022070415/5697bf771a28abf838c81606/html5/thumbnails/8.jpg)
Background• Applications
– In transportation• Delivery/pickup for a set of customers
– In production scheduling• To determined the processing sequence for n jobs on a
single machine• There is a setup cost/delay cij if job j follows job i• The goal is to minimize the total setup cost
• Time complexity– There are up to O(n!) different tours– The TSP problem is NP-hard
![Page 9: Traveling Salesman Problem (TSP). An Example A truck needs to leave node 1, visit each of the other nodes one and only one time, and back to node 1 –What](https://reader036.vdocuments.net/reader036/viewer/2022070415/5697bf771a28abf838c81606/html5/thumbnails/9.jpg)
Algorithms
• Optimal Algorithms– Formulating and solving an integer programming– Time consuming
• Heuristic algorithms– Nearest neighbor algorithm– Cheapest insertion algorithm– Others
![Page 10: Traveling Salesman Problem (TSP). An Example A truck needs to leave node 1, visit each of the other nodes one and only one time, and back to node 1 –What](https://reader036.vdocuments.net/reader036/viewer/2022070415/5697bf771a28abf838c81606/html5/thumbnails/10.jpg)
Nearest Neighbor Algorithm• Choose one node as the starting node• Repeatedly go to the closest unvisited node until all
nodes are visited– Return to the starting node
City 1 City 2 City 3 City 4 City 5
City 1 132 217 164 58
City 2 132 290 201 79
City 3 217 290 113 303
City 4 164 201 113 196
City 5 58 79 303 196
Start from node 1
Along (1,5) to node 5
Along (5,2) to node 2
Along (2,4) to node 4
Along (4,3) to node 3
Along (3,1) to return to node 1
Solution found: (1,5,2,4,3) with cost=668
It happens to be the optimal tour.
![Page 11: Traveling Salesman Problem (TSP). An Example A truck needs to leave node 1, visit each of the other nodes one and only one time, and back to node 1 –What](https://reader036.vdocuments.net/reader036/viewer/2022070415/5697bf771a28abf838c81606/html5/thumbnails/11.jpg)
Nearest Neighbor Algorithm• The nearest neighbor algorithm may not find an optimal tour
– For example, if we choose node 3 as the starting node, the solution found is not optimal.
• Multi-start Heuristics– Choose different nodes as the starting nodes, and solve the problem n
times. Use the best solution.
City 1 City 2 City 3 City 4 City 5
City 1 132 217 164 58
City 2 132 290 201 79
City 3 217 290 113 303
City 4 164 201 113 196
City 5 58 79 303 196
Start from node 3
Along (3,4) to node 4
Along (4,1) to node 1
Along (1,5) to node 5
Along (5,2) to node 2
Along (2,3) to return to node 3
Solution found: (3,4,1,5,2) with cost=704
It is not the optimal tour.
![Page 12: Traveling Salesman Problem (TSP). An Example A truck needs to leave node 1, visit each of the other nodes one and only one time, and back to node 1 –What](https://reader036.vdocuments.net/reader036/viewer/2022070415/5697bf771a28abf838c81606/html5/thumbnails/12.jpg)
Nearest Neighbor Algorithm• Choose one node as the starting node• Repeatedly go to the closest unvisited node until all
nodes are visited– Return to the starting node
• Time complexity– It takes n iterations, to determine one node in each iteration
– In each iteration, it takes O(n) comparison to find the nearest node
– Overall complexity is O(n2)
![Page 13: Traveling Salesman Problem (TSP). An Example A truck needs to leave node 1, visit each of the other nodes one and only one time, and back to node 1 –What](https://reader036.vdocuments.net/reader036/viewer/2022070415/5697bf771a28abf838c81606/html5/thumbnails/13.jpg)
Nearest Neighbor Algorithm• The nearest neighbor algorithm may find a solution that is very
bad– Starting from node 1, the nearest neighbor algorithms has to use a large-
cost arc (7,4) to go to node 4
• For a heuristic solution, define the relative error as (Cost of heuristic solution - Cost of optimal solution) / Cost of optimal solution
• The relative error of the nearest neighbor tour may be very large
1
2
3
4
5 6
7
12
10
8
12
1110
9
113
912
7
6 1
2
3
4
5 6
7
12
10
8
12
1110
9
113
912
7
6
![Page 14: Traveling Salesman Problem (TSP). An Example A truck needs to leave node 1, visit each of the other nodes one and only one time, and back to node 1 –What](https://reader036.vdocuments.net/reader036/viewer/2022070415/5697bf771a28abf838c81606/html5/thumbnails/14.jpg)
Cheapest Insertion Algorithm
1
2
3
4
5 6
7
12
10
8
12
1110
9
113
912
7
6
7
1
2
3
12
10
8
912
• Start from a loop with two nodes– For example, (1,3) and (3,1)
• Repeat the following steps– For each arc (i,j) on the loop, try to replace it with two arcs (i,k) and
(k,j) for an unvisited node k• We try to insert node k to the loop
– Find the node k with the smallest cost increase
1
2
3
12
10
8
From arc (1,3), only nodes 2 and 7 can be inserted
If node 2 is inserted, the cost increase is 12+8-10=10
If node 7 is inserted, the cost increase is 12+9-10=11
So node 2 is to be selected
![Page 15: Traveling Salesman Problem (TSP). An Example A truck needs to leave node 1, visit each of the other nodes one and only one time, and back to node 1 –What](https://reader036.vdocuments.net/reader036/viewer/2022070415/5697bf771a28abf838c81606/html5/thumbnails/15.jpg)
Cheapest Insertion Algorithm
1
2
3
4
5 6
7
12
10
8
12
1110
9
113
912
7
61
2
3
7
12 8
912
1
2
3
7
12
10
8
912
412
11
• From loop (1,2,3), nodes 4 and 7 can be inserted• If node 4 is inserted, the cost increase is 12+11-8=15• If node 7 is inserted, the cost increase is 12+9-10=11• So node 7 is to be inserted, which leads to a new loop (1,2,3,7)
![Page 16: Traveling Salesman Problem (TSP). An Example A truck needs to leave node 1, visit each of the other nodes one and only one time, and back to node 1 –What](https://reader036.vdocuments.net/reader036/viewer/2022070415/5697bf771a28abf838c81606/html5/thumbnails/16.jpg)
Cheapest Insertion Algorithm
1
2
3
4
5 6
7
12
10
8
12
1110
9
113
912
7
6 1
2
3
7
12 8
912
412
11
53
7
1
2
3
7
12 8
12
412
11
5
3
7
11
6
9
6 1
2
3
7
12 8
12
5
3
6
9
6
1
2
3
7
12 8
12
53
7
Node 5 is inserted
Node 6 is inserted.
Note that Node 4 can be inserted in two different ways.
![Page 17: Traveling Salesman Problem (TSP). An Example A truck needs to leave node 1, visit each of the other nodes one and only one time, and back to node 1 –What](https://reader036.vdocuments.net/reader036/viewer/2022070415/5697bf771a28abf838c81606/html5/thumbnails/17.jpg)
Cheapest Insertion Algorithm
1
2
3
7
12 8
12
412
11
5
3 11
6
9
6
10 10
The cheapest insertion tour has a finite error bound with the triangle inequality assumption, i.e.,
Cost of cheapest insertion solution ≤ 2 Cost of optimal solution
(We omit the proof.)
1
2
3
7
12 8
12
4
5
3 11
6
9
Final solution (not optimal)
1
2
3
4
5 6
7
12
10
8
12
1110
9
113
912
7
6
![Page 18: Traveling Salesman Problem (TSP). An Example A truck needs to leave node 1, visit each of the other nodes one and only one time, and back to node 1 –What](https://reader036.vdocuments.net/reader036/viewer/2022070415/5697bf771a28abf838c81606/html5/thumbnails/18.jpg)
How about start from loop (6,7)
1
2
3
4
5 6
7
12
10
8
12
1110
9
113
912
7
6
3
4
5 6
7
10
9
113
9 7
6
13
4
5 6
7
1011
10
9
113
912
6 To be continued…
![Page 19: Traveling Salesman Problem (TSP). An Example A truck needs to leave node 1, visit each of the other nodes one and only one time, and back to node 1 –What](https://reader036.vdocuments.net/reader036/viewer/2022070415/5697bf771a28abf838c81606/html5/thumbnails/19.jpg)
Cheapest Insertion Algorithm
• Start from a loop with two nodes• Repeat the following steps
– For each arc (i,j) on the loop, try to replace it with two arcs (i,k) and (k,j) for an unvisited node k
• We try to insert node k to the loop
– Find the node k with the smallest cost increase
• Time complexity– There are O(n) iterations, one node is selected in each iteration– Inside each iteration, there are O(n2) possible different insertion– Overall time complexity O(n3)– Question: can you improve it?
![Page 20: Traveling Salesman Problem (TSP). An Example A truck needs to leave node 1, visit each of the other nodes one and only one time, and back to node 1 –What](https://reader036.vdocuments.net/reader036/viewer/2022070415/5697bf771a28abf838c81606/html5/thumbnails/20.jpg)
Group Project• Each group (3-5 students) will be assigned an article to read.
These articles are about how vehicle routing techniques have helped in various industrial applications. Please read carefully and prepare to introduce the article to the class.– A sample article has been uploaded at canvas, for your references.
• Deliverables– Presentation: Each group is expected to report the content of the
article, including, for example, the background of the application, what is the problem, what formulation and techniques have been used, any challenges, what is the impact, what can we learn, any other related stories/follow-ups beyond the article.
– Evaluation: Each group is required to evaluate the presentation of other groups. Details will be announced later.
• Actions to take– Sign up project groups at canvas by Oct 15.– Please send email to TA, Mr. Yifu LI ([email protected]) for you cannot
find a group to join.