lecture 17: shortest paths iv - speeding up...

5
Lecture 17 Shortest Paths IV: Speeding Up Dijkstra 6.006 Fall 2009 Lecture 17: 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 = φ 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

Upload: others

Post on 31-Jul-2020

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 17: Shortest Paths IV - Speeding up Dijkstracourses.csail.mit.edu/6.006/fall09/lecture_notes/lecture17.pdfLecture 17 Shortest Paths IV: Speeding Up Dijkstra 6.006 Fall 2009

Lecture 17 Shortest Paths IV: Speeding Up Dijkstra 6.006 Fall 2009

Lecture 17: 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 fromQ, i.e., when u = t

1

Page 2: Lecture 17: Shortest Paths IV - Speeding up Dijkstracourses.csail.mit.edu/6.006/fall09/lecture_notes/lecture17.pdfLecture 17 Shortest Paths IV: Speeding Up Dijkstra 6.006 Fall 2009

Lecture 17 Shortest Paths IV: Speeding Up Dijkstra 6.006 Fall 2009

Bi-Directional Search

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

S t

forward search

backward search

Figure 1: Bi-directional Search.

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 queueof both searches, Qf and Qb

s

3u u’

t

3 3

5 5

w

Figure 2: Bi-D Search.

2

Page 3: Lecture 17: Shortest Paths IV - Speeding up Dijkstracourses.csail.mit.edu/6.006/fall09/lecture_notes/lecture17.pdfLecture 17 Shortest Paths IV: Speeding Up Dijkstra 6.006 Fall 2009

Lecture 17 Shortest Paths IV: Speeding Up Dijkstra 6.006 Fall 2009

Subtlety: After search terminates, find node x with minimum value of df (x)+db(x). x maynot 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.

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.

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

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

3

Page 4: Lecture 17: Shortest Paths IV - Speeding up Dijkstracourses.csail.mit.edu/6.006/fall09/lecture_notes/lecture17.pdfLecture 17 Shortest Paths IV: Speeding Up Dijkstra 6.006 Fall 2009

Lecture 17 Shortest Paths IV: Speeding Up Dijkstra 6.006 Fall 2009

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

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

Goal-Directed Search or A∗

Modify edge weights with potential function over vertices.

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

Search toward target:

vv’

5 5increasego uphill

decreasego downhill

Figure 4: Targeted Search

Correctness

w(p) = w(p)− λt(s) + λt(t)

So shortest paths are maintained in modified graph with w weights.

p

p’

s t

Figure 5: Modifying Edge Weights.

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.

4

Page 5: Lecture 17: Shortest Paths IV - Speeding up Dijkstracourses.csail.mit.edu/6.006/fall09/lecture_notes/lecture17.pdfLecture 17 Shortest Paths IV: Speeding Up Dijkstra 6.006 Fall 2009

Lecture 17 Shortest Paths IV: Speeding Up Dijkstra 6.006 Fall 2009

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

5