18: Shortest Paths IV - Speeding Lecture Dijkstra up

advertisement

Lecture 18 Shortest Paths IV: Speeding Up Dijkstra 6.006

Fall 2011

Lecture 18: Shortest Paths IV - Speeding up Dijkstra

Lecture Overview

• Single-source single-target Dijkstra

• Bidirectional search

• Goal directed search - potentials and landmarks

Readings

Wagner, Dorothea, and Thomas Willhalm.

”Speed-up Techniques for Shortest-Path

Computations.” Proceedings of the 24th International Symposium on Theoretical

Aspects of Computer Science (STACS 2007): 23-36.

Read up to Section 3.2.

DIJKSTRA single-source, single-target

Initialize()

Q ← V [ G ] while Q = φ do u ← EXTRACT MIN(Q) (stop if u = t !) for each vertex v t Adj [ u ] do RELAX ( u, v, w )

Observation: If only shortest path from s to t is required, stop when t is removed from Q , i.e., when u = t

1

Lecture 18 Shortest Paths IV: Speeding Up Dijkstra 6.006

Fall 2011

S t backward search forward search

Figure 1: Bi-directional Search Idea.

Bi-Directional Search

Note: Speedup techniques covered here do not change worst-case behavior, but reduce the number of visited vertices in practice.

Bi-D Search

Alternate forward search from s backward search from t d f d b

( u )

(follow edges backward) distances for forward search

( u ) distances for backward search

Algorithm terminates when some vertex w has been processed, i.e., deleted from the queue of both searches, Q f and Q b

Subtlety: After search terminates, find node x with minimum value of d f

( x ) + d b

( x ).

x may not be the vertex w that caused termination as in example to the left!

Find shortest path from s to x using Π using Π b f and shortest path backwards from t to x

.

Note: x will have been deleted from either Q f or Q b or both.

2

Lecture 18 Shortest Paths IV: Speeding Up Dijkstra 6.006

Fall 2011 u

3 u’

3

3 s t

5

5 w

Figure 2: Bi-D Search Example.

Minimum value for d f

( x ) + d one search (see

Figure 3 ):

b

( x ) over all vertices that have been processed in at least d f

( u ) + d b

( u ) = 3 + 6 = 9 d f

( u

'

) + d b

( u

'

) = 6 + 3 = 9 d f

( w ) + d b

( w ) = 5 + 5 = 10

3

Lecture 18 Shortest Paths IV: Speeding Up Dijkstra 6.006

Fall 2011

Goal-Directed Search or A

Modify edge weights with potential function over vertices.

w ( u, v ) = w ( u, v ) − λ ( u ) + λ ( v )

Search toward target as shown in

Figure 4 :

Correctness w ( p ) = w ( p ) − λ t

( s ) + λ t

( t )

So shortest paths are maintained in modified graph with w weights (see

Figure 5 ).

To apply Dijkstra, we need w ( u, v ) ≥ 0 for all ( u, v ).

Choose potential function appropriately, to be feasible.

Landmarks

Small set of landmarks LCV .

For all u ∈ V, l ∈ L , pre-compute δ ( u, l ).

Potential λ

CLAIM: λ

( l ) t

( l ) t

( u ) = δ ( u, l ) − δ ( t, l ) for each l .

is feasible.

Feasibility w ( u, v ) = w ( u, v ) − λ

( l ) t

( u ) + λ

( l ) t

( v )

= w ( u, v ) − δ ( u, l ) + δ ( t, l ) + δ ( v, l ) − δ ( t, l )

= w ( u, v ) − δ ( u, l ) + δ ( v, l ) ≥ 0 by the Δ -inequality

λ t

( u ) = max l E L

λ

( l ) t

( u ) is also feasible

4

Lecture 18 Shortest Paths IV: Speeding Up Dijkstra 6.006

Fall 2011

Forward u

3 u’ s d f

(s) = 0

3

5 d f

(u) = 3

5 w d f

(w) = 5

3 t

Forward u

3

3 d f

(u’) = 6 u’

3 d f

(u) = 3 s d f

(s) = 0

5

5 t w d f

(w) = 5

Backward u s

3

5

3 u’ d b

(u’) = 3

3

5 w d b

(w) = 5 t d b

(t) = 0

Backward s

3

5 u

3 d u’

(u’) = 3

3 d b

(u) = 6

5 t d b

(t) = 0 w d b

(w) = 5

Forward s d f

(s) = 0

3 u

5 w

3 d f

(u) = 3

5 u’ d f

(w) = 5 d f

(u’) = 6

Backward u

3 u’

3 s

3 d d f b

(u) = 3

(u) = 6 t d f

(t) = 10 d f

(s) = 0 d b

(s) = 10

5

5 w deleted from both queues

so terminate!

d b

(w) = 5 d f

(w) = 5

3 d b d f

(u’) = 3

(u’) = 6 t d b d f

(t) = 0

(t) = 10

Figure 3: Forward and Backward Search and Termination.

5

Lecture 18 Shortest Paths IV: Speeding Up Dijkstra 6.006

Fall 2011 v’ increase go uphill

5 v

5 decrease go downhill

Figure 4: Targeted Search s p t p’

Figure 5: Modifying Edge Weights.

6

MIT OpenCourseWare http://ocw.mit.edu

6.00

6 Introduction to Algorithms

Fall 201 1

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms .

Download