Top Banner
Finding Minimal Weight Paths in a Graph Michael Walker
23

Michael Walker. From Maps to Graphs Make Intersections Vertices Make Roads Edges Result is Weighted Directed Graph Weights: Speed Limit Length.

Dec 13, 2015

Download

Documents

Bryan Reed
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Michael Walker. From Maps to Graphs  Make Intersections Vertices  Make Roads Edges  Result is Weighted Directed Graph  Weights: Speed Limit Length.

Finding Minimal Weight Paths in a Graph

Michael Walker

Page 2: Michael Walker. From Maps to Graphs  Make Intersections Vertices  Make Roads Edges  Result is Weighted Directed Graph  Weights: Speed Limit Length.

From Maps to Graphs

Make Intersections Vertices Make Roads Edges Result is Weighted Directed Graph Weights:

Speed LimitLengthTolls, Number of Lanes, Traffic Information

Page 3: Michael Walker. From Maps to Graphs  Make Intersections Vertices  Make Roads Edges  Result is Weighted Directed Graph  Weights: Speed Limit Length.
Page 4: Michael Walker. From Maps to Graphs  Make Intersections Vertices  Make Roads Edges  Result is Weighted Directed Graph  Weights: Speed Limit Length.

Data Structures

• Queue

• Stack

• Priority Queue

Page 5: Michael Walker. From Maps to Graphs  Make Intersections Vertices  Make Roads Edges  Result is Weighted Directed Graph  Weights: Speed Limit Length.

Queue

First In First Out (FIFO) Think checkout line at a store Efficient

Addition and removal are constant time

A B C D

Page 6: Michael Walker. From Maps to Graphs  Make Intersections Vertices  Make Roads Edges  Result is Weighted Directed Graph  Weights: Speed Limit Length.

Stack

First in Last Out (FILO)Alternatively Last in First out (LIFO)

Think stack of plates Also efficient

Addition and removal are constant time

A

B

C

D

Page 7: Michael Walker. From Maps to Graphs  Make Intersections Vertices  Make Roads Edges  Result is Weighted Directed Graph  Weights: Speed Limit Length.

Priority Queue

Each element has priority Highest priority removed first

A15

B20

C10

D25

Page 8: Michael Walker. From Maps to Graphs  Make Intersections Vertices  Make Roads Edges  Result is Weighted Directed Graph  Weights: Speed Limit Length.

Where to Start?

Start with finding ANY path Find a spanning tree Algorithm Idea:

From start, create tree going outwardsDepth First SearchBreadth First SearchShortest Edge First (Prim’s Algorithm)

Page 9: Michael Walker. From Maps to Graphs  Make Intersections Vertices  Make Roads Edges  Result is Weighted Directed Graph  Weights: Speed Limit Length.

Depth First Search (DFS)

Continue down one path until reaching a “dead end”

Then backtrack and choose a different path Programmatically:

Remove vertex from stack, set as “current vertex”

Add current vertex to spanning tree if it not present (if present skip next step)

Add adjacent vertices to stack if not in tree

Page 10: Michael Walker. From Maps to Graphs  Make Intersections Vertices  Make Roads Edges  Result is Weighted Directed Graph  Weights: Speed Limit Length.
Page 11: Michael Walker. From Maps to Graphs  Make Intersections Vertices  Make Roads Edges  Result is Weighted Directed Graph  Weights: Speed Limit Length.

Breadth First Search (DFS)

Explore all paths in order of # of edges Programmatically:

Remove vertex from queue, set as “current vertex”

Add current vertex to spanning tree if it not present (if present skip next step)

Add adjacent vertices to queue if not in tree

Page 12: Michael Walker. From Maps to Graphs  Make Intersections Vertices  Make Roads Edges  Result is Weighted Directed Graph  Weights: Speed Limit Length.
Page 13: Michael Walker. From Maps to Graphs  Make Intersections Vertices  Make Roads Edges  Result is Weighted Directed Graph  Weights: Speed Limit Length.

Prim’s Algorithm

Shortest Edge First Creates Minimal Spanning Tree

Spanning tree with the lowest possible sum of the edge weights

Uses Priority QueueInstead of highest removed, lowest is removed

Page 14: Michael Walker. From Maps to Graphs  Make Intersections Vertices  Make Roads Edges  Result is Weighted Directed Graph  Weights: Speed Limit Length.

.4

.1.05

.05

.1

.1

.1

.3

.3

.3.4

.2

.2

.05

.025

.1

.1

.3

.1.1

.1.2

.1

Page 15: Michael Walker. From Maps to Graphs  Make Intersections Vertices  Make Roads Edges  Result is Weighted Directed Graph  Weights: Speed Limit Length.

Kruskal’s Algorithm

Also finds minimum spanning tree Builds a forest that forms a tree Algorithm:

Select smallest unprocessed edgeIf two vertices are not part of the same tree,

then add edge to forestRepeat until all vertices are in forest

Page 16: Michael Walker. From Maps to Graphs  Make Intersections Vertices  Make Roads Edges  Result is Weighted Directed Graph  Weights: Speed Limit Length.

.4

.1.05

.05

.1

.1

.1

.3

.3

.3.4

.2

.2

.05

.025

.1

.1

.3

.1.1

.1.2

.1

Page 17: Michael Walker. From Maps to Graphs  Make Intersections Vertices  Make Roads Edges  Result is Weighted Directed Graph  Weights: Speed Limit Length.

Dijkstra’s Algorithm Resembles Prim’s Algorithm

Total cost is used instead of edge costTentative costs are maintained and updated

Algorithm Loop:Vertex with next lowest tentative distance is

“current” vertex.For vertices adjacent to current vertex○ Compare tentative distance to current vertex distance +

edge○ If new distance is lower, replace tentative distance

Add current vertex to spanning tree.

Page 18: Michael Walker. From Maps to Graphs  Make Intersections Vertices  Make Roads Edges  Result is Weighted Directed Graph  Weights: Speed Limit Length.

.4

.1.05

.05

.1

.1

.1

.3

.3

.3.4

.2

.2

.05

.025

.1

.1

.3

.1.1

.1.2

.1

Board Example

Page 19: Michael Walker. From Maps to Graphs  Make Intersections Vertices  Make Roads Edges  Result is Weighted Directed Graph  Weights: Speed Limit Length.

A* Algorithm

Improvement to Dijkstra’s Algorithm Roadmaps are not abstract mathematical

constructions Possible to add heuristic from real world Heuristic Conditions:

Must only underestimate, never overestimateOverestimation runs faster, but produces non

optimal paths

Page 20: Michael Walker. From Maps to Graphs  Make Intersections Vertices  Make Roads Edges  Result is Weighted Directed Graph  Weights: Speed Limit Length.

A* Algorithm

Algorithm Loop:Vertex with next lowest tentative distance +

heuristic distance is “current” vertex.For vertices adjacent to current vertex○ Compare tentative distance to current vertex

distance + edge○ If new distance is lower, replace tentative distance

Add current vertex to spanning tree.

Page 22: Michael Walker. From Maps to Graphs  Make Intersections Vertices  Make Roads Edges  Result is Weighted Directed Graph  Weights: Speed Limit Length.

Further Exploration

Bi-Directional SearchSimultaneously run A* from both start and end

Reduce Dataset: Multi-Leveled MapsOne graph for large citiesOne graph for county/city levelOne graph for town/borough levelGoogle seamlessly does this with shortcuts

Multi-point and simultaneous path finding Incomplete data path finding (D*)

Page 23: Michael Walker. From Maps to Graphs  Make Intersections Vertices  Make Roads Edges  Result is Weighted Directed Graph  Weights: Speed Limit Length.

References Johnsonbaugh, Richard, and Marcus Schaefer. Algorithms. Upper Saddle River,

NJ: Pearson Education, 2004. Print. Khuller, Samir, Balaji Raghavachari, and Neal Young. "Balancing Minimum

Spanning and Shortest Path Trees." 243-50. Web. 29 Apr. 2011. <http://delivery.acm.org/10.1145/320000/313760/p243-khuller.pdf?key1=313760&key2=3323924031&coll=DL&dl=ACM&ip=74.214.101.229&CFID=20611540&CFTOKEN=65740846>.

Kruskal, Joseph B. "On The Shortest Spanning Subtree Of A Graph And The Traveling Salesman Problem." AMS Journal (1955). Web. 29 Apr. 2011. <http://www.ams.org/journals/proc/1956-007-01/S0002-9939-1956-0078686-7/S0002-9939-1956-0078686-7.pdf>.

Patel, Amit J. "Amit’s Game Programming Information." Amit’s Patel's Personal Website. Stanford, 2010. Web. 29 Apr. 2011. <http://www-cs-students.stanford.edu/~amitp/gameprog.html>.

Prim, R. C. "Shortest Connection Networks And Some Generalizations." (1957): 1389-401. Web. 29 Apr. 2011. <http://www.alcatel-lucent.com/bstj/vol36-1957/articles/bstj36-6-1389.pdf>.

Sanders, Peter. "Fast Route Planning." Google Tech Talk. 23 Mar. 2009. Lecture.