220 likes | 848 Views
Traveling Salesman Problems Repetitive Nearest-Neighbor and Cheapest-Link Algorithms. Chapter: 6. Repetitive Nearest-Neighbor Algorithm. Let A be any vertex. Apply the nearest-neighbor algorithm using A as the starting vertex and calculate the total cost associated with the circuit.
E N D
Traveling Salesman ProblemsRepetitive Nearest-Neighbor and Cheapest-Link Algorithms Chapter: 6
Repetitive Nearest-Neighbor Algorithm • Let A be any vertex. Apply the nearest-neighbor algorithm using A as the starting vertex and calculate the total cost associated with the circuit. • Repeat the process using each of the other vertices (B,C, D, E) of the graph as the staring vertex. • Keep the best one from all the Hamilton circuits. If there is a designated starting vertex, rewrite this circuit with that vertex as the reference point.
Repetitive Nearest-Neighbor Algorithm • Step 1: • Let A be any vertex . • Apply nearest-neighbor Algo. • Calculate the cost of circuit A $185 $133 B $200 $119 $152 E $121 At point A: EdgeWeight AE $133 AD $152 AC $119 Min AB $185 $120 $150 C $199 $174 D
$185 $133 $200 $119 $152 $121 $120 $150 $199 $174 Repetitive Nearest-Neighbor Algorithm • Step 1: • Let A be any vertex . • Apply nearest-neighbor Algo. • Calculate the cost of circuit A B E At point C: EdgeWeight CB $121 CA $119 Already visited CE $120 Min CD $174 C D
$185 $133 $200 $119 $152 $121 $120 $150 $199 $174 Repetitive Nearest-Neighbor Algorithm • Step 1: • Let A be any vertex . • Apply nearest-neighbor Algo. • Calculate the cost of circuit A B E At point E: EdgeWeight EA $133 Cannot revisit A as all vertices are visited yet EB $200 EC $120 Already visited ED $199 Min C D
$185 $133 $200 $119 $152 $121 $120 $150 $199 $174 Repetitive Nearest-Neighbor Algorithm • Step 1: • Let A be any vertex . • Apply nearest-neighbor Algo. • Calculate the cost of circuit A B E At point D: EdgeWeight DE $199 DA $152 DB $150 Min DC $174 C D
$185 $133 $200 $119 $152 $121 $120 $150 $199 $174 Repetitive Nearest-Neighbor Algorithm • Step 1: • Let A be any vertex . • Apply nearest-neighbor Algo. • Calculate the cost of circuit A B E At point B: From the last vertex (B), return to the starting point (A). All vertices have been visited Selected edge: BA C D
$185 $133 $200 $119 $152 $121 $120 $150 $199 $174 Repetitive Nearest-Neighbor Algorithm • Step 1: • Let A be any vertex . • Apply nearest-neighbor Algo. • Calculate the cost of circuit A Using the Nearest-Neighbor algorithm with A as the starting vertex, we got: Hamilton circuit: A, C, E, D, B, A Cost associated with the Hamilton circuit: $119+$120+$199+ $150+$185 = $773 B E C D
$185 A $133 $200 $119 $152 B $121 $120 $150 E $199 C $174 D Repetitive Nearest-Neighbor Algorithm Step 2: Repeat the process using each of the other vertices (B,C, D, E) of the graph as the staring vertex.
$185 A $133 $200 $119 $152 B $121 $120 $150 E $199 C $174 D Repetitive Nearest-Neighbor Algorithm • Step 3: • Keep the best one from all the Hamilton circuits. If there is a designated starting vertex, rewrite this circuit with that vertex as the reference point.
$185 A $133 $200 $119 $152 B $121 $120 $150 E $199 C $174 D Repetitive Nearest-Neighbor Algorithm • Step 3: • Keep the best one from all the Hamilton circuits. If there is a designated starting vertex, rewrite this circuit with that vertex as the reference point. The Best one from all Hamilton circuits: • B, C, A, E, D, B • C, A, E, D, B, C • D, B, C, A, E, D B, C, A, E, D, B Rewrite with A as the starting vertex A, E, D, B, C, A B, C, A, E, D, B Rewrite with C as the starting vertex C, A, E, D, B, C B, C, A, E, D, B Rewrite with E as the starting vertex E, D, B, C, A, E Tie: Select randomly
$185 A $133 $200 $119 $152 B $121 $120 $150 E $199 C $174 D Cheapest-Link Algorithm • Pick the edge with the smallest weight first. Mark the edge (say in red). • Pick the next “cheapest” edge and mark the edge in red. • Continue picking the “cheapest” edge available and mark the edge in red except when • It closes a circuit • It results in three edges coming out of a single vertex • When there are no more vertices to join, close the red circuit.
$185 A $133 $119 $200 B $152 $121 $120 E $150 $199 C $174 D Cheapest-Link Algorithm Step 1: Pick the edge with the smallest weight first. Mark the edge (say in red). Edge AC (Weight: $119)
$185 A $133 $119 $200 B $152 $121 $120 E $150 $199 C $174 D Cheapest-Link Algorithm Step 2: Pick the next “cheapest” edge. Mark the edge (say in red). Edge EC (Weight: $120)
$185 A $133 $119 $200 B $152 $121 $120 E $150 $199 C $174 D Cheapest-Link Algorithm Step 3: Continue picking the next “cheapest” edge. Mark the edge (say in red) except when it results in 3 edges coming out of a single vertex. Edge BC Weight ($121)
$185 A $133 $119 $200 B $152 $121 $120 E $150 $199 C $174 D Cheapest-Link Algorithm Step 3: Continue picking the next “cheapest” edge. Mark the edge (say in red) except when it closes a circuit. Edge AE Weight ($133)
Cheapest-Link Algorithm A $185 B Step 3: Continue picking the next “cheapest” edge. Mark the edge (say in red). Edge BD Weight ($150) $119 $200 $152 E $120 $150 C $199 $174 D
Cheapest-Link Algorithm A $185 B Step 3: Continue picking the next “cheapest” edge. Mark the edge (say in red). Edge AD Weight ($152) $119 $200 $152 E $120 $150 C $199 $174 D
Cheapest-Link Algorithm A $185 B Step 4: When there are no more vertices to join, close the red circuit Edge EB Weight ($200) $119 $200 $152 E $120 $150 C $199 $174 D
A $185 B $200 $152 $119 E $120 $150 C $199 $174 D Summary of Cheapest-Link Algorithm