Download presentation
Presentation is loading. Please wait.
Published byBertina Sherman Modified over 9 years ago
1
Reducing Knapsack to TSP Pasi Fränti
2
Knapsack problem Input: knapsack instance {2,3,5,7,11} Size of the knapsack S=15.
3
Step 1: Create one node for every item 2 3 7 11 5 Input: knapsack instance {2,3,5,7,11} Create a node for every knapsack element.
4
N+2 nodes needed to represent the knapsack instance 2 3 7 11 5 0n+1 Step 2: Add start and end points Input: knapsack instance {2,3,5,7,11} Add node 0 as the home. Add node N+1 as the turning point.
5
Step 3: Create forward links Input: knapsack instance {2,3,5,7,11} Draw links from smaller nodes to bigger ones. Set weights according to the bigger node: w(i,j)=j. 2 3 7 11 5 0n+1 2 5 3 7 5 5 11 7 7 7 3
6
Step 4: Create forward links for node N+1 2 3 7 11 5 0 2 5 3 7 5 5 7 7 7 3 n+1 0 0 0 0 0 Input: knapsack instance {2,3,5,7,11} Draw links to N+1 with weights w(i,N+1)=0.
7
2 3 7 11 5 0n+1 0 0 0 0 0 Step 5: Create backward links Input: knapsack instance {2,3,5,7,11} Draw backward links from bigger to smaller nodes. Set weight of the link as w(j,i)=0. 0 0 0 0 0 0 0 0 0 0 0 0 0
8
Solution for KP Solution for TSP 2 3 7 11 5 KP = {3,5,7} 3 5 7 n+10 0 0 0 0 TSP = 0-3-5-7-(N+1)-11-2-0 (S=15) Visit the nodes in an increasing order !
9
Solution for TSP Solution for KP TSP = 0-3-5-7-(N+1)-11-2-0 KP = {3,5,7} (all nodes which arrival cost > 0) 2 3 7 11 5 3 5 7 n+10 0 0 0 0 Select nodes with entrance w>0 ! 3 7 5
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.