finding the shortest route - weeblygvmath.weebly.com/uploads/5/6/5/3/56539921/5.3... · the...

8
Lesson 5.3 The traveling salesperson problem asks that a Hamiltonian circuit of least total weight be found for a graph. What if you didn’t need to visit every vertex in the graph and return back to the starting point, but instead you needed only to find the shortest path from one vertex in the graph to another? Does an efficient method of solving this type of problem exist? The answer is yes, and one algorithm used in finding the shortest path from a given vertex of a graph to any other vertex in that graph is attributed to E. W. Dijkstra. Edsger W. Dijkstra (1930–2002) Professor Dijkstra is considered one of the original theorists of modern computer science. He is well known for his amazingly efficient shortest path algorithm that was first published in 1959. Throughout his career, Dijkstra received many honors and awards. He held the Schlumberger Centennial Chair in Computing Sciences at the University of Texas at Austin, 1984–1999, and retired as Professor Emeritus in 1999. Mathematician of Note Finding the Shortest Route

Upload: others

Post on 07-Mar-2020

14 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Finding the Shortest Route - Weeblygvmath.weebly.com/uploads/5/6/5/3/56539921/5.3... · The following algorithm is a modification of Dijkstra’s algorithm. Example Use the shortest

Lesson 5.3

The traveling salesperson problem asks that a Hamiltonian circuit of leasttotal weight be found for a graph. What if you didn’t need to visit everyvertex in the graph and return back to the starting point, but instead youneeded only to find the shortest path from one vertex in the graph toanother?

Does an efficient method of solving this type of problem exist? Theanswer is yes, and one algorithm used in finding the shortest path from agiven vertex of a graph to any other vertex in that graph is attributed toE. W. Dijkstra.

Edsger W. Dijkstra (1930–2002)

Professor Dijkstra is consideredone of the original theorists ofmodern computer science. He iswell known for his amazinglyefficient shortest path algorithmthat was first published in 1959.Throughout his career, Dijkstra received manyhonors and awards. He held the SchlumbergerCentennial Chair in Computing Sciences at theUniversity of Texas at Austin, 1984–1999, andretired as Professor Emeritus in 1999.

Mathematician of Note

Finding the ShortestRoute

DM05_Final.qxp:DM05.qxp 5/12/14 8:35 AM Page 247

Page 2: Finding the Shortest Route - Weeblygvmath.weebly.com/uploads/5/6/5/3/56539921/5.3... · The following algorithm is a modification of Dijkstra’s algorithm. Example Use the shortest

248 Chapter 5 • More Graphs, Subgraphs, and Trees

The following algorithm is a modification of Dijkstra’s algorithm.

ExampleUse the shortest path algorithm to find the shortest path from A to F in thegraph.

Solution:

Begin by labeling vertex A with an S. Circle the S. Then examine allvertices that are adjacent to S.

Shortest Path Algorithm1. Label the starting vertex S and circle it. Examine all edges that

have S as an endpoint. Darken the edge with the shortest lengthand circle the vertex at the other endpoint of the darkenededge.

2. Examine all uncircled vertices that are adjacent to the circledvertices in the graph.

3. Using only circled vertices and darkened edges between thevertices that are circled, find the lengths of all paths from S toeach vertex being examined. Choose the vertex and the edgethat yield the shortest path. Circle this vertex and darken thisedge. Ties are broken arbitrarily.

4. Repeat steps 2 and 3 until all vertices are circled. The darkenededges of the graph form the shortest routes from S to every othervertex in the graph.

A

C E

F

3

6

5

2 3

54

4

2

B D

DM05_Final.qxp:DM05.qxp 5/12/14 8:35 AM Page 248

Page 3: Finding the Shortest Route - Weeblygvmath.weebly.com/uploads/5/6/5/3/56539921/5.3... · The following algorithm is a modification of Dijkstra’s algorithm. Example Use the shortest

249Lesson 5.3 • Finding the Shortest Route

Adjacent Path from S LengthVertices to Vertex of Path

Adjacent to S B SB 5C SC 2

1. Circle C, darken edge SC.Adjacent to S B SB 5Adjacent to C B SCB 4

E SCE 8D SCD 6

2. Circle B, darken edge CB.Adjacent to C E SCE 8

D SCD 6Adjacent to B D SCBD 7

3. Circle D, darken edge CD.Adjacent to C E SCE 8Adjacent to D E SCDE 11

F SCDF 104. Circle E, darken edge CE.Adjacent to E F SCEF 11Adjacent to D F SCDF 10

5. Circle F, darken edge DF.

The shortest route from A to F is A,C,D,F, and the length is 10. Thedarkened edges also show the shortest routes from A to the other verticesin the graph.

E

B

C

A F

D

S

2

5

24

3

6

5

4

3

Step 1

Step 2

Step 4Step 3

Step 5

DM05_Final.qxp:DM05.qxp 5/12/14 8:35 AM Page 249

Page 4: Finding the Shortest Route - Weeblygvmath.weebly.com/uploads/5/6/5/3/56539921/5.3... · The following algorithm is a modification of Dijkstra’s algorithm. Example Use the shortest

Exercises1.

Julian began using the shortest path algorithm to find the shortestroute from A to E for the preceding graph. The work that he wasable to complete before he had to stop is shown here.

1. SB – 2

SC – 5 Circle B, darken SB.

SG – 12

2. SBC – 6

SG – 12 Circle H, darken SH.

SH – 5

3. SBC – ?

SG – ? Circle ?, darken ?

SHG – ?

Fill in the missing distances, vertex, and edge in step 3. Thencomplete Julian’s problem of using the shortest path algorithm tofind the shortest path from A to E.

250 Chapter 5 • More Graphs, Subgraphs, and Trees

B D

C

EA

H F

G

2

4 4

63

5

4265

12

2

4 4

63

5

4265

12

C

B D

E

FH

ASG

DM05_Final.qxp:DM05.qxp 5/12/14 8:35 AM Page 250

Page 5: Finding the Shortest Route - Weeblygvmath.weebly.com/uploads/5/6/5/3/56539921/5.3... · The following algorithm is a modification of Dijkstra’s algorithm. Example Use the shortest

251Lesson 5.3 • Finding the Shortest Route

2. Use the shortest path algorithm to find the shortest route from A to F.

3. When might it not be necessary to repeat the procedure in thealgorithm until all of the vertices are circled?

4. Use the shortest path algorithm to determine the shortest distancefrom S to each of the other vertices in the following graph.

5.

a. Use the shortest path algorithm to find the shortest route fromAlbany to Ladue in the preceding graph.

b. Assume that it is necessary to travel from Albany to Fenton todeliver a package and then to continue from there to Ladue.Find the shortest route for this trip. Explain why the solution tothis question might be different than the shortest route fromAlbany to Ladue.

E

8

F

3

5

D

1

3

2 C

6

8 A

2

B

L

3

N M

S

K

J2

5

1 1

3

22

4

KG

BAlbany

C

2

E

FentonLadue

J

H

D

3

1

3

2

1

4

32

33

36

35

5

4

DM05_Final.qxp:DM05.qxp 5/12/14 8:35 AM Page 251

Page 6: Finding the Shortest Route - Weeblygvmath.weebly.com/uploads/5/6/5/3/56539921/5.3... · The following algorithm is a modification of Dijkstra’s algorithm. Example Use the shortest

252 Chapter 5 • More Graphs, Subgraphs, and Trees

6. In the shortest path algorithm, each time you examine theuncircled vertices that are adjacent to the circled ones, you have torecalculate the lengths of the paths from the starting vertex.Explain how the efficiency of the algorithm might be improved bymodifying it to avoid such recalculation.

7. What is the shortest distance from S to X in the following graph?

a. 6.7

b. 7.5

c. 7.6

d. 10.9

8. The shortest path algorithm can be applied to digraphs if slightmodifications are made. Make the appropriate changes, and tryyour revised algorithm on the following digraph to find the shortestroute from A to F.

R 1.2

S

T

U

3.4 X

3.62.1

1.43.0

2.7

V

2.6 3.1

4.0

W

2.5

1.8

Y

1.7

6

44

4

8

2

4

68

E

D

C

B

F

A

DM05_Final.qxp:DM05.qxp 5/12/14 8:35 AM Page 252

Page 7: Finding the Shortest Route - Weeblygvmath.weebly.com/uploads/5/6/5/3/56539921/5.3... · The following algorithm is a modification of Dijkstra’s algorithm. Example Use the shortest

9. Mail Packages, Inc., ships from certain cities in the United States toothers. A table of the company’s shipping costs follows.

To

Albany Biloxi Center Denver Evert Fargo Gale

Albany ___ 7 ___ ___ 4 ___ ___

Biloxi ___ ___ ___ ___ ___ ___ 6Center 2 ___ ___ ___ 2 ___ ___

Denver ___ ___ 1 ___ ___ ___ ___

Evert ___ ___ ___ ___ ___ ___ 4Fargo ___ ___ ___ ___ 3 ___ 2Gale 1 6 ___ ___ ___ 1 ___

Since a package can’t be shipped directly from Denver to Biloxi,construct a digraph to represent the cost table and apply theshortest path algorithm to find the least charge for shipping the package.

Project10. Interview several firefighters,

ambulance drivers, or paramedics inyour community to find out how theydetermine the shortest route from theirfacility to an emergency situation.Write a short report on your findings.

253Lesson 5.3 • Finding the Shortest Route

From

DM05_Final.qxp:DM05.qxp 5/12/14 8:35 AM Page 253

Page 8: Finding the Shortest Route - Weeblygvmath.weebly.com/uploads/5/6/5/3/56539921/5.3... · The following algorithm is a modification of Dijkstra’s algorithm. Example Use the shortest

254 Chapter 5 • More Graphs, Subgraphs, and Trees

How Bumblebees Tackle the Traveling Salesman Problem

Science DailyFebruary 8, 2013

It is a mathematical puzzle which has vexedacademics and traveling salesmen alike, butnew research from Queen Mary’s School ofBiological and Chemical Sciences can revealhow bumblebees effectively plan their routebetween the most rewarding flowers whiletraveling the shortest distances.

The research, led by Dr. Mathieu Lihoreauand published in the British EcologicalSociety’s journal Functional Ecology, exploredthe movement of bumblebees as theycollected nectar from five artificial flowersvarying in reward value.

According to Dr. Lihoreau, “Animals whichforage on resources that are fixed in spaceand replenish over time, such as flowerswhich refill with nectar, often visit theseresources in repeatable sequences called trap-lines. While trap-lining is a common foragingstrategy found in bees, birds, and primates,we still know very little about how animalsattempt to optimize the routes they travel.”

Research into optimizing routes based ondistance and the size of potential rewards isreminiscent of the well known TravelingSalesman problem in mathematics, whichwas first formulated in 1930, but remains oneof the most intensively studied problems inoptimization.

Co-author Dr. Nigel Raine explained,“Computers solve the problem by comparingthe length of all possible routes and choosingthe shortest. However, bees solve simpleversions of it without computer assistanceusing a brain the size of grass seed.”

The team set up a bee nest-box, markingeach bumblebee with numbered tags tofollow their behavior when allowed to visit

five artificial flowers which were arranged ina regular pentagon. “When the flowers allcontain the same amount of nectar, beeslearned to fly the shortest route to visit themall,” said Dr.Lihoreau.However, bymaking oneflower muchmore rewardingthan the rest, weforced the bees todecide betweenfollowing theshortest route orvisiting the mostrewarding flowerfirst.”

In a feat of spatial judgment the beesdecided that if visiting the high rewardflower added only a small increase in traveldistance, they switched to visiting it first.However, when visiting the high rewardadded a substantial increase in traveldistance, they did not.

The results revealed a trade-off betweeneither prioritizing visits to high rewardflowers or flying the shortest possible route.Individual bees attempted to optimize bothtravel distance and nectar intake as theygained experience of the flowers.

“We have demonstrated that bumblebeesmake a clear trade-off between minimizingtravel distance and prioritizing high rewardswhen considering routes with multiplelocations,” concluded co-author Lars Chittka.“These results provide the first evidence thatanimals use a combined memory of both thelocation and profitability of locations whenmaking complex routing decisions, giving usa new insight into the spatial strategies oftrap-lining animals.”

DM05_Final.qxp:DM05.qxp 5/12/14 8:35 AM Page 254