






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







How to get from here to there (when you’re not a crow)
Groups:
Send me list of people in your group
Pick a group name (optional)
Schedule weekly progress meetings w/ me
First step: pin down precisely what we’re talking about
Let G =< V , E > be a graph with vertex set V and edge set E
In P3: G is complete map
V is set of cells (locations where a UNIT can be)
E is transitions between those cells (N, S, E, W)
Let every edge, ( v i , v j )∈ E have an associated weight :
w ( v i , v j ) == distance to go from v i to v j
Caveat: w ( v i , v j )≥ 0 ∀ v i , v j
In P3: weight == move cost*move rate
Given:
Source node, s ∈ V (UNIT’s current location)
Terminal node, t ∈ V (UNIT’s goal location)
Find:
Path
Such that total weight (length or cost) of path,
is minimized
|p|− 1
i=
At the end of the algorithm, we’ll want to know 2 things:
Distance from s to every node along the shortest path
The shortest path from s to t itself
As a side-effect, we’ll also know:
Distance and shortest path from s to all points along p
Distance and shortest path from s to a whole bunch of other stuff in the graph (map)
To handle the accounting info, maintain 2 different data structs:
d [ v ]==shortest path estimate from s to v
Upper bound -- can be greater than true shortest dist during execution of alg.
π [ v ]==predecessor of v along (current best- known) shortest path from s to v
Written as arrays, but that’s not necessarily the best representation...
At termination of alg, d [ v ] will be exact shortest- path distance and π [ v ] will be exact shortest path
function relax( u , v , w ): // u : current node // v : successor node // w : weight function if d [ u ]+ w ( u , v )< d [ v ] { d [ v ]= d [ u ]+ w ( u , v ); π [ v ]= u ; }
function dijkstraSSP( G , w , s ): // G : complete graph // w : weight function // s : source node (start location) initializeSSPDataStructs(); Set S=new Set(); Queue Q=new PriorityQueue( G. V , d ); while (!Q.isEmpty()) { Vertex u =Q.extractMin(); S.add( u ); for (Iterator i= u .neighbors();i.hasNext();) { Vertex v =i.next(); relax( u , v , w ); } }