michael walker. from maps to graphs make intersections vertices make roads edges result is...

23
Finding Minimal Weight Paths in a Graph Michael Walker

Upload: bryan-reed

Post on 13-Dec-2015

220 views

Category:

Documents


0 download

TRANSCRIPT

Finding Minimal Weight Paths in a Graph

Michael Walker

From Maps to Graphs

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

Speed LimitLengthTolls, Number of Lanes, Traffic Information

Data Structures

• Queue

• Stack

• Priority Queue

Queue

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

Addition and removal are constant time

A B C D

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

Priority Queue

Each element has priority Highest priority removed first

A15

B20

C10

D25

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)

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

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

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

.4

.1.05

.05

.1

.1

.1

.3

.3

.3.4

.2

.2

.05

.025

.1

.1

.3

.1.1

.1.2

.1

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

.4

.1.05

.05

.1

.1

.1

.3

.3

.3.4

.2

.2

.05

.025

.1

.1

.3

.1.1

.1.2

.1

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.

.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

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

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.

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*)

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.