22
Dynamic Single- source Shortest Paths Camil Demetrescu University of Rome “La Sapienza”

Dynamic Single-source Shortest Paths

  • Upload
    kalona

  • View
    75

  • Download
    0

Embed Size (px)

DESCRIPTION

Dynamic Single-source Shortest Paths. Camil Demetrescu University of Rome “La Sapienza”. Let:. G = (V,E,w). weighted directed graph. w(u,v). weight of edge (u,v). source vertex. s  V. Perform intermixed sequence of operations:. Increase weight w(u,v) by . Increase(u,v,  ):. - PowerPoint PPT Presentation

Citation preview

Page 1: Dynamic Single-source Shortest Paths

Dynamic Single-source Shortest Paths

Camil DemetrescuUniversity of Rome “La Sapienza”

Page 2: Dynamic Single-source Shortest Paths

Fully dynamic SSSP

Perform intermixed sequence of operations:

s V source vertex

G = (V,E,w) weighted directed graphLet:

Increase(u,v,): Increase weight w(u,v) by

Decrease(u,v,): Decrease weight w(u,v) by

Query(v): Return distance (or sh. path)from s to v in G

w(u,v) weight of edge (u,v)

Page 3: Dynamic Single-source Shortest Paths

Ramalingam & Reps’ approach

Maintain a shortest paths tree throughoutthe sequence of updates

Querying a shortest paths or distance takesoptimal time

Update operations work only on the portion oftree affected by the update

Each update may take as long as a static SSSP computation in the worst case!

Very efficient in practice

Page 4: Dynamic Single-source Shortest Paths

Increase(u,v,

v

T(v)T(s)

s

u

+

Shortest pathstree before the update

Page 5: Dynamic Single-source Shortest Paths

v

w

T'(v)T'(s)

+

s

u

Increase(u,v,

+

Shortest pathstree after the update

Page 6: Dynamic Single-source Shortest Paths

Graph G

Ramalingam & Reps’ approach

u

v

s

sPerform SSSPonly on the subgraphand source s

+

Subgraph induced by vertices in T(v)

Page 7: Dynamic Single-source Shortest Paths

Exercise 1

Let G=(V,E,w) be a weighted directed graph, let s be a source vertex, and let T be a shortest path tree of G rooted at s.

Let A be the set of vertices in the subtree of T rooted at v. Prove that no edge from A to V-A can become part of T as a result of an increase(u,v,) operation that increases the weight of edge (u,v) by positive amount .

Page 8: Dynamic Single-source Shortest Paths

Non-negative vs. negative edge weights

Non-negative edge weights: No dynamic algorithm better than rebuilding from scratch (in the worst case) Main open problem!

Arbitrary edge weights: Best static algorithm as high as O(m√n log M), O(mn) in general

update operations in the same bounds as static computations with non-negative weights (e.g., O(m+n log n) using Dijkstra)

Dynamic algorithms instead much faster than rebuilding from scratch:

Page 9: Dynamic Single-source Shortest Paths

Gh = (V,E,wh)

Reweighting

Graph reweighting using reduced weights

G = (V,E,w) w : E

Nice fact: P is a shortest path in G P is a shortest path in Gh

h : V (potential func.)wh(u,v) = w(u,v) + h(u) - h(v)

Page 10: Dynamic Single-source Shortest Paths

d(v) ≤ w(u,v) + d(u) [Bellman cond.]

Proof:

Getting non-negative reduced weights

0 ≤ w(u,v) + d(u) - d(v) = wd(u,v)

If we choose:h(v) := d(v) = distance from s to v in G

Claim:wd(u,v) = w(u,v) + d(u) - d(v) ≥ 0

Page 11: Dynamic Single-source Shortest Paths

A cute property of Gd

Claim:For any v, the distance dd(v) from s to v in Gd is zero:

P = <s, v1, v2, …, vk, v> = shortest path from s to v

Proof:

w(P) + d(s) - d(v) = w(P) + 0 - w(P) = 0

w(s,v1) +…+ w(vk,v) + d(s) - d(v1) + d(v1) - d(v2) +…=

wd(s,v1) + … + wd(vk,v) =

dd(v) = wd(P) =

Page 12: Dynamic Single-source Shortest Paths

An increase algorithm

3. Compute for each v its distance dd(v) from s in Gd

4. For each v, update d(v) d(v) + dd(v)

Exercise 2: prove that d(v)’s are correctly updated

2. Build Gd ( wd is obviously non-negative )

1. Update G by letting: w w +

increase(: E +) = any non-neg. function

Maintain G and d subject to the operation:

O(m)

O(m)

O(n)

e.g., O(m+ n log n)

Page 13: Dynamic Single-source Shortest Paths

s

u

v

Gd

A decrease algorithm

3. Compute for each v its distance dd(v) from s in Gd

4. For each v, update d(v) d(v) + dd(v)

2. Build Gd, then remove (u,v) from it andadd (s,v) with wd(s,v) wd(u,v)

1. Update G by letting: w(u,v) w(u,v) -

decrease(u, v, )

O(1)

O(m)

O(n)

O(?)

s

u

v

-

Gwd(u,v)

Page 14: Dynamic Single-source Shortest Paths

Exercises

Exercise 4: how can we detect negative cycles?

Exercise 5: prove that d(v)’s are correctly updated

Exercise 3: how fast can step 3 be implemented?

Exercise 6: can we extend this to decrease (1) edgesat the same time within the same time bounds?Would that be a breakthrough result?

Page 15: Dynamic Single-source Shortest Paths

Theory and practice

O(m·n) O(m+n·log n)

In theory, for arbitrary edge weights, we can do much better than rebuilding from scratch

In practice, can we get fast codes?Two tricks:

• Only work for vertices affected by the update (Ramalingam-Reps’ approach)

• Avoid to build Gd explicitly

Page 16: Dynamic Single-source Shortest Paths

A fast implem. (RRL) [Dem.’01]

increase(u,v,)

let H be a priority queueadd x T(v) to H with priority: p(x) = min(z,x):z T(v) d(z) + w(z,x) - d(x)

if (u,v) T(v) then return

while (H ≠ )x extract min priority vertex from Hd(x) d(x) + p(x)for each (x,y)

if d(x) + w(x,y) - d(y) < p(y) then p(y) d(x) + w(x,y) - d(y)

w(u,v) w(u,v) + Exercise 7: write decrease(u,v,)

Page 17: Dynamic Single-source Shortest Paths

Experimental setup

- Random graphs & random update sequences(we used potentials technique to avoid negative cycles)

Test sets:

- C++ using LEDA, g++ compiler- UNIX Solaris on SPARC Ultra 10 at 300 Mhz

Experimental platform:

Performance indicators:- Running time (msec)- Number of updated vertices per operation

Page 18: Dynamic Single-source Shortest Paths

Static vs. dynamic

0.1

1

10

100

1000

0 100 200 300 400 500 600Number of vertices

Average running time per operation (msec)

m=0.5n2 , Edge Weights in [-1000,1000]

BFM

RRL

7.3836.108

0.807

2.191

3.966

17.984

625.325

353.704

175.012

67.831

BFM

RRL

Page 19: Dynamic Single-source Shortest Paths

Can we do any better?

Output-bounded cost model (Ramalingam-Reps):an optimal algorithm should spend time proportional to actual change in output solution due to update operation(e.g., changes in the shortest paths tree)

Ramalingam & Reps (and later Frigioni et al.)have devised algorithms in this model for dynamic SSSP

If shortest paths are not unique, not all the vertices in T(v) may actually change distance +

Page 20: Dynamic Single-source Shortest Paths

Static vs. dynamic

RR

10.784

1.137

RR

8.9185.79

3.34

0.1

1

10

100

1000

0 100 200 300 400 500 600Number of vertices

Average running time per operation (msec)

m=0.5n2 , Edge Weights in [-1000,1000]

BFM

RRL

7.3836.108

0.807

2.191

3.966

17.984

625.325

353.704

175.012

67.831

BFM

RRL

Page 21: Dynamic Single-source Shortest Paths

0

1

2

3

4

5

6

2 4 6 8 10 12

Edge weight interval [-2k,2 k]

Average processed vertices per operation

n=300, m=0.5n 2=45000

RRL

RR4.89

2.09 2.14

2.843.21

3.78

4.35 4.45

5.16

0.78 0.9

1.46

2.03

2.84

3.65

4.02

RRLRR

Number of updated vertices

+

Page 22: Dynamic Single-source Shortest Paths

Further readings

Ramalingam & Reps’ approach + RR algorithm: [Ramalingam-Reps’96] G. Ramalingam, Thomas W. Reps: An Incremental Algorithm for a Generalization of the Shortest-Path Problem. J. Algorithms 21(2): 267-305 (1996)

RRL algorithm + experiments:[Demetrescu’01] C. Demetrescu, Fully Dynamic Algorithms for Path Problems on Directed Graphs, Ph.D. Dissertation, University of Rome “La Sapienza”, April 2001

Other computational study (not covered in this lecture):Luciana S. Buriol, Mauricio G. C. Resende and Mikkel Thorup, Speeding up dynamic shortest pathshttp://citeseer.ist.psu.edu/689842.html