Download - Lecture 18: Shortest Paths IV - Speeding up Dijkstra · 2011-11-16 · Lecture 18 Shortest Paths IV: Speeding Up Dijkstra 6.006 Fall 2011 S t forward search backward search Figure

Transcript
Page 1: Lecture 18: Shortest Paths IV - Speeding up Dijkstra · 2011-11-16 · Lecture 18 Shortest Paths IV: Speeding Up Dijkstra 6.006 Fall 2011 S t forward search backward search Figure

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 paper on website, (upto Section 3.2)

DIJKSTRA single-source, single-target

Initialize()

Q← V [G]

while Q 6= φ

do u← EXTRACT MIN(Q) (stop if u = t!)

for each vertex v ε 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

Page 2: Lecture 18: Shortest Paths IV - Speeding up Dijkstra · 2011-11-16 · Lecture 18 Shortest Paths IV: Speeding Up Dijkstra 6.006 Fall 2011 S t forward search backward search Figure

Lecture 18 Shortest Paths IV: Speeding Up Dijkstra 6.006 Fall 2011

S t

forward search

backward 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

(follow edges backward)

df (u) distances for forward search

db(u) distances for backward search

Algorithm terminates when some vertex w has been processed, i.e., deleted from the

queue of both searches, Qf and Qb

Subtlety: After search terminates, find node x with minimum value of df (x) + db(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 Πf and shortest path backwards from t to x

using Πb. Note: x will have been deleted from either Qf or Qb or both.

2

Page 3: Lecture 18: Shortest Paths IV - Speeding up Dijkstra · 2011-11-16 · Lecture 18 Shortest Paths IV: Speeding Up Dijkstra 6.006 Fall 2011 S t forward search backward search Figure

Lecture 18 Shortest Paths IV: Speeding Up Dijkstra 6.006 Fall 2011

s

3u u’

t

3 3

5 5

w

Figure 2: Bi-D Search Example.

Minimum value for df (x) +db(x) over all vertices that have been processed in at least

one search (see Figure 3):

df (u) + db(u) = 3 + 6 = 9

df (u′) + db(u

′) = 6 + 3 = 9

df (w) + db(w) = 5 + 5 = 10

3

Page 4: Lecture 18: Shortest Paths IV - Speeding up Dijkstra · 2011-11-16 · Lecture 18 Shortest Paths IV: Speeding Up Dijkstra 6.006 Fall 2011 S t forward search backward search Figure

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 λ(l)t (u) = δ(u, l)− δ(t, l) for each l.

CLAIM: λ(l)t 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) = maxl ε L

λ(l)t (u) is also feasible

4

Page 5: Lecture 18: Shortest Paths IV - Speeding up Dijkstra · 2011-11-16 · Lecture 18 Shortest Paths IV: Speeding Up Dijkstra 6.006 Fall 2011 S t forward search backward search Figure

Lecture 18 Shortest Paths IV: Speeding Up Dijkstra 6.006 Fall 2011

3u

3 3

5 5df (s) = 0

df (u) = 3

df (w) = 5

Forward 3

3 3

5 5db(t) = 0

db(u’) = 3

db (w) = 5

Backward

3

3 3

5 5df (s) = 0

df (u’) = 6

df (t) = 10

Forward 3

3 3

5 5db(t) = 0

db(u) = 6

db (w) = 5

Backward

df (u) = 3

df (w) = 5

df (s) = 0db (s) = 10

df (w) = 5

df (u) = 3

db(u’) = 3df (u’) = 6

df (t) = 10

u

uu

u’

u’ u’

u’

s

s s

s

ww

w w

t

t t

t

3

3 3

5 5df (s) = 0

df (u’) = 6

Forward 3

3 3

5 5db(t) = 0

db(u) = 6

db (w) = 5

Backward

df (u) = 3

df (w) = 5

db(u’) = 3uu u’ u’

s s

w w

t t

deleted from both queues so terminate!

Figure 3: Forward and Backward Search and Termination.

5

Page 6: Lecture 18: Shortest Paths IV - Speeding up Dijkstra · 2011-11-16 · Lecture 18 Shortest Paths IV: Speeding Up Dijkstra 6.006 Fall 2011 S t forward search backward search Figure

Lecture 18 Shortest Paths IV: Speeding Up Dijkstra 6.006 Fall 2011

vv’

5 5increasego uphill

decreasego downhill

Figure 4: Targeted Search

p

p’

s t

Figure 5: Modifying Edge Weights.

6