6.4: the brute-force algorithms list all of the possible hamilton circuits calculate the total...

13
6.4: The Brute-Force Algorithms • List all of the possible Hamilton circuits • Calculate the total weights for each of the possible Hamilton circuit • Choose an optimal circuit (cheapest, shortest, or fastest…)

Upload: spencer-warren

Post on 13-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

6.4: The Brute-Force Algorithms

• List all of the possible Hamilton circuits

• Calculate the total weights for each of the possible Hamilton circuit

• Choose an optimal circuit (cheapest, shortest, or fastest…)

1) A,B,C,D,E,A = 812

2) A,B,C,E,D,A = 777

3) A,B,D,C,E,A = 762

4) A,B,D,E,C,A = 773

5) A,B,E,C,D,A = 831

6) A,B,E,D,C,A = 877

7) A,C,B,D,E,A = 722

8) A,C,B,E,D,A = 791

9) A,C,D,B,E,A = 776

10) A,C,E,B,D,A = 741

11) A,D,B,C,E,A = 676

12) A,D,C,B,E,A = 780

The Brute-Force AlgorithmsThere are 5 vertices so we have (5-1)! = 24 Hamilton circuits

Optimal routePlus 12 mirror images

The Brute-Force Algorithms• Start at C

C,A,B,D,C =70+20+10+50=150

C,A,D,B,C =70+30+10+15=125

C,B,A,D,C =15+20+30+50=115

C,B,D,A,C =125

C,D,A,B,C =115

C,D,B,A,C =150Therefore: optimal circuits are

C,B,A,D,C or C,D,A,B,C

If the problem asks to start at A then the optimal circuits are

A,D,C,B,A or A,B,C,D,A

A

BC

D

30

70 20

50

15

10Mirror images

6.5: The Nearest-Neighbor Algorithm

• From the starting vertex, go to its nearest neighbor (the edge has the smallest weight)

• Repeating step 1 with the next vertex and the next vertex until there is no more vertex to visit

• From the last vertex, return to the starting point

The Nearest-Neighbor Algorithm

Start at A, pick AC = 119From C, pick CE = 120From E, pick ED = 199From D, pick DB = 150No more vertex left so

connect B and A, with BA=185

Therefore the trip is: A,C,E,D,B,A = 773 dollars

The Nearest-Neighbor Algorithm

• Start at C, pick CB = 15

• From B, pick BD = 10• From D, pick DA = 30• No more vertex left,

so connect A and C, with AC = 70

• Therefore, the route is

C,B,D,A,C = 125

Practice with the Nearest Neighbor

Apply the Nearest Neighbor Algorithm to find the way to go to the bank, dry cleaner, post office, and Wegmans starting and ending

at home. The mileage chart is shown below.

HOME

B

D

P

W

6.7 The repetitive Nearest-Neighbor Algorithm

• The Brute-Force Algorithm: optimal but inefficient algorithm

• The Nearest-Neighbor Algorithm and Repetitive Nearest-Neighbor: efficient but not optimal algorithms.

The Repetitive Nearest-Neighbor Algorithm

• Apply the Nearest Neighbor Algorithm to each of the vertices to calculate the total weights.

• Choose the best circuit. If there is a designated starting vertex, rewrite the circuit using that vertex as the reference point

The Repetitive Nearest-Neighbor Algorithm

• From A: A, C, E, D, B, A = 773• From B:B, C, A, E, D, B = 722• From C:C, A, E, D, B, C = 722 • From D:D, B, C, A, E, D = 722• From E:E, C, A, D, B, E = 741Therefore, one of the best routes is

B, C, A, E, D, B so we rewrite it so the starting point is at A (his home): A, E, D, B, C, A

The Repetitive Nearest-Neighbor Algorithm

• From A:A, B, D, C, A = 20+10+50+70= 150• From B:B, D, A, C, B = 10+30+70+15= 125• From C:C, B, D, A, C = 15+10+30+70= 125• From D:D, B, C, A, D = 10+15+70+30 = 125One of the best routes is C,B,D,A,C

= 125 or if re-write with starting point A:A,C,B,D,A