dynamic all pairs shortest paths

40
Dynamic All Pairs Shortest Paths Based on the following resources: Camil Demetrescu and Giuseppe F. Italiano (2004) A New Approach to Dynamic All Pairs Shortest Paths. Journal of the Association for Computing Machinery (JACM) , 51(6), 968-992. C. Demetrescu and G.F. Italiano (2003) A New Approach to Dynamic All Pairs Shortest Paths. STOC’03, C. Demetrescu and G.F. Italiano. Presention on dynamic all pairs shortest paths. Presented by: Qingwu Yang

Upload: tamal

Post on 20-Jan-2016

48 views

Category:

Documents


0 download

DESCRIPTION

Dynamic All Pairs Shortest Paths. Based on the following resources: Camil Demetrescu and Giuseppe F. Italiano (2004) A New Approach to Dynamic All Pairs Shortest Paths . Journal of the Association for Computing Machinery (JACM) , 51 (6), 968-992. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Dynamic All Pairs Shortest Paths

Dynamic All Pairs Shortest Paths

Based on the following resources:• Camil Demetrescu and Giuseppe F. Italiano (2004) A New Approach to

Dynamic All Pairs Shortest Paths. Journal of the Association for Computing Machinery (JACM), 51(6), 968-992.

• C. Demetrescu and G.F. Italiano (2003) A New Approach to Dynamic All Pairs Shortest Paths. STOC’03,

• C. Demetrescu and G.F. Italiano. Presention on dynamic all pairs shortest paths.

Presented by: Qingwu Yang

Page 2: Dynamic All Pairs Shortest Paths

Dynamic All Pairs Shortest Paths

Given a weighted directed graph G=(V,E,w),

perform any intermixed sequence of the following

operations:

return distance from x to yDistance(x,y):

update weight of edge (u,v) to wUpdate(u,v,w):

return shortest path from x to yPath(x,y):

Page 3: Dynamic All Pairs Shortest Paths

Previous work on fully dynamic APSP

general reals ? < o(n3) O(1)

QueryUpdateGraph Weight

Update recomputingfrom scratch general

realsO(1)

O(n3)~

O(n2.575 C0.681)~[0,C]

King 99 general [0,C] O(n2.5 (C log n)0.5) O(1)

O(n9/7 log(nC))Henzinger et al. 97 planar [0,C]

O(n9/5 log13/5 n)Fackcharoemphol, Rao 01

planar reals

D, Italiano 01 general S reals O(n2.5 (S log3 n)0.5) O(1)

Page 4: Dynamic All Pairs Shortest Paths

Contributions of This Paper

• A completely new approach to dynamic APSP.• A fully dynamic algorithm for APSP on

general directed graphs with nonnegative real-valued edge weights.

• Supporting any sequence of operations in O(n2log3n) amortized time per update,unit worst-case time per distance query,and optimal worst-case time for returning any shortest path.

Page 5: Dynamic All Pairs Shortest Paths

(n2) changes per update

(n) (n)+1-1+1

Page 6: Dynamic All Pairs Shortest Paths

A new approach

New combinatorial properties of graphs:

Locally shortest paths

Uniform paths

Page 7: Dynamic All Pairs Shortest Paths

Definition of Locally shortest paths

A path πxy is locally shortest in G if either:• πxy consists of a single vertex, or• every proper subpath of πxy is a shortest path in G

x yπxy

x yπxy

Locally Shortest

NOT

Locally Shortest

Shortest path Shortest pathNot a shortest path

Shortest path

Page 8: Dynamic All Pairs Shortest Paths

Properties of Locally shortest paths

• In a locally shortest path, all proper subpaths are shortest paths: however, the path itself may not necessarily be shortest.

xπxy y

Shortest pathShortest pathLocally shortest path

Shortest path

u v

Page 9: Dynamic All Pairs Shortest Paths

Locally shortest paths

Properties of Locally shortest paths

Theorem I

Shortest paths Locally shortest paths

Shortest paths

Page 10: Dynamic All Pairs Shortest Paths

Properties of Locally shortest paths

For the sake of simplicity, we assume that no two paths in the graph have the same weight.(Ties can be broken by adding a tiny fraction to theweight of each edge)

Theorem II

Locally shortest paths πxy are internally vertex-disjoint

x y

π1

π3

π2

Page 11: Dynamic All Pairs Shortest Paths

Properties of Locally shortest paths

Theorem III

There are at most n-1 Locally shortest paths connecting x,y

x y This is a consequence of vertex-disjointess…

Page 12: Dynamic All Pairs Shortest Paths

Properties of Locally shortest paths

Theorem IV

If shortest paths are unique in G, then there can be at most m·n locally shortest paths in G.

x yv

≤ m choices ≤ n choices× ≤mn

Page 13: Dynamic All Pairs Shortest Paths

Dynamic graphs

We call dynamic graph a sequence of graphs <G0,

…,Gk> such that, for any t, Gt-1 and Gt differ in the

weight of exactly one edge, 0≤t≤k.

Page 14: Dynamic All Pairs Shortest Paths

Locally shortest paths in dynamic graphs

An Locally shortest path in Gt is appearing if it is not Locally shortest in Gt-1

x y

x yGt

Gt-1

u v

u v

p

q

p

q

Page 15: Dynamic All Pairs Shortest Paths

Locally shortest paths in dynamic graphs

A Locally shortest path in Gt is disappearing if it is not Locally shortest in Gt+1

Gt+1

Gtx y

x y

u v

u v

p

p

q

q

Page 16: Dynamic All Pairs Shortest Paths

Locally shortest paths in dynamic graphs

Proof• A path can stop being locally shortest only if any of its proper

subpaths stops being shortest. • In case of increases, this can happen only if the subpath contains the

updated vertex, say vertex v. • By theorem II, at most O(n2) shortest paths contain v as an internal

vertex. • At most O(n2) locally shortest paths starting or ending at v.

Theorem V

Let G be a graph subject to a sequence of vertex updates. If shortest paths are unique in G, then in the worst case at most O(n2) paths can stop being locally shortest due to a vertex increase.

Page 17: Dynamic All Pairs Shortest Paths

Locally shortest paths in dynamic graphs

Proof of (2)• Assume that initially there are x0 locally shortest paths. x0 = O(mn).• Assume that there are k updates, k≥m/n. By Theorem V, O(k n2) paths can

stop being locally shortest. • xk ≤ mn. • Assume the total number of paths that start being locally shortest is y. • x0 - O(k n2)+ y ≤ xk

y ≤ O(k n2)+ xk- x0 = O(k n2) + O(mn)-O(mn) = O(k n2) + O(mn)= O(k n2)y/k ≤ O(n2)

Theorem VILet G be a graph subject to a sequence Σ of increase-only vertex updates and let m be the maximum number of edges in G throughout the sequence Σ. If shortest paths are unique in G, then the number of paths that start being locally shortest after each update is:(1)O(mn) in the worst case.(2)O(n2) amortized over Ω(m/n) updates.

Page 18: Dynamic All Pairs Shortest Paths

Locally shortest paths in dynamic graphs

The weights of Locally shortest paths that disappear andthen reappear do not change…

x y

10

20

30

40

x y100

10

20

30

40

What about fully dynamic sequences?

Page 19: Dynamic All Pairs Shortest Paths

Shortest paths and edge weight updates

How does a shortest path change after an update?

The shortest path is the same, but has different weight:

x y

The shortest path is different (update = decrease):

x y

-

EASY

EASY

Page 20: Dynamic All Pairs Shortest Paths

Shortest paths and edge weight updates

The shortest path is different (update = increase):

x y+

HARDa b

If we look closer, we realize that the new shortest path from a to b was already Locally shortest before the update!

Page 21: Dynamic All Pairs Shortest Paths

A new approach to dynamic APSP

Are we done?

Main idea:For each pair x,y, maintain in a data structure Locally shortest paths connecting x to y

The combinatorial properties of Locally shortest paths imply that only a small piece of information needs to be updated at each time…NO

Page 22: Dynamic All Pairs Shortest Paths

x y

How to pay only once?

x yx y

This path stays the same while flipping between Locally shortest and non-Locally shortest:

We would like to have an update algorithm that pays only once for it over the whole sequence...

Page 23: Dynamic All Pairs Shortest Paths

x y

Looking at the substructure

x y

…but if we removed the edge it would get a shortest path again!

mayresurrect!

This path remains a shortest pathafter the insertionThis path is no longer a shortest path

after the insertion…

Page 24: Dynamic All Pairs Shortest Paths

Breaking Ties

• If shortest paths in the graph are not unique, the properties of locally shortest paths don’t hold.

• Using an arbitrary tie-breaking strategy may lead to incorrect results.

Page 25: Dynamic All Pairs Shortest Paths

Breaking Ties – Basic idea

• Without loss of generality, assume that V = {1, 2, …, n}.

• Assign to each edge (u, v) a unique number ID(u, v) (e.g. ID(u, v)=u+nv).

• For each path π, define ID(π) as the maximum ID of its edges.

• For a path π , extended weight ew(π) = (w(π), ID(π)).

Page 26: Dynamic All Pairs Shortest Paths

Breaking Ties – Comparing two ew’s

Compare the extended weights of two paths π1 and π2

ew(π1) ≤ ew(π2) if and only if (1) w(π1) < w(π2) or(2) w(π1) = w(π2) and ID(π1) ≤ ID(π2).

Page 27: Dynamic All Pairs Shortest Paths

Breaking Ties

Definition of Sew

Let G be a graph with real-valued edge weights and let ew be the extended weight function. We define Sew as follows:

Note: Sew contains every path in G that has minimum extended weight and whose subpaths have minimum extended weight as well.

Page 28: Dynamic All Pairs Shortest Paths

Breaking Ties

Lemma IFor each pair of vertices x and y in G, there can be at most one path connecting them.

Lemma II

For each pair of vertices x and y in G, there is a path .

• Sew contains exactly one shortest path between each pair of vertices connected in G. • |Sew| ≤ n2.• Sew is a complete set of unique shortest paths in G.•We can always ensure uniqueness of shortest paths by dealing with paths in Sew.

Page 29: Dynamic All Pairs Shortest Paths

Historical paths

Definition of Historical paths

Let πxy be a path in G at time t, and let t’ ≤ t be the time of the latest vertex update on πxy. We say that πxy is HISTORICAL at time t if it has been a shortest path at least once in the time interval [t’, t].

Note: A shortest path is also a historical path. Althoughit may stop being a shortest path at some point, it keeps on being a historical path until a vertex update occurs on it.

Page 30: Dynamic All Pairs Shortest Paths

Locally historical paths

Definition of Locally historical paths

We say that a path πxy is Locally Historical in G at time t if either:(i) πxy consists of a single vertex, or(ii) Every proper subpath of πxy is a historical path in G at time t.

Page 31: Dynamic All Pairs Shortest Paths

Locally historical paths vs. Locally shortest paths

shortest path

shortest path

x

yπxyLocally shortest path

shortest or historical path

shortest or historical path

x

yπxy

Locally historical path

Relaxed notion of Locally historical: Subpaths do not need to be shortest at the same time

Page 32: Dynamic All Pairs Shortest Paths

Locally historical paths

Properties of Locally historical paths

Theorem

Locally shortest paths Locally historical paths

Locally shortest paths

Shortest paths

Page 33: Dynamic All Pairs Shortest Paths

Properties of Locally historical paths

Theorem

O(zn2) historical paths at any time

O(zn2) new Locally historical paths per update

(Assume there are at most z historical paths between each pair of vertices)

Page 34: Dynamic All Pairs Shortest Paths

(n)(n)

(n)

100

How many historical paths can we have?

A lot!We can construct a dynamic graph with

(n3) historical paths at any time, amortized.

100

90

# h paths = (n2) +(n2)

100

90

80

+(n2)

100

90

80

70

= (n3)

(n)

Page 35: Dynamic All Pairs Shortest Paths

Reducing # of historical paths: Smoothing

At each update we pick an edge with the maximum number of historical paths passing through it, and we remove and reinsert it

(n)(n)

(n)

100

# h paths =

100

90

(n2)

90

100

90

(n2)

100

90

80

100

80

100

90

80

(n2)

100

90

80

70

100

90

70

100

90

80

70

0 (in general, O(n2))

Page 36: Dynamic All Pairs Shortest Paths

A new approach to dynamic APSP (II)

Main idea:For each pair x,y, maintain in a data structure the Locally historical paths connecting x to y

The combinatorial properties of Locally historical paths imply that, if we do smoothing, we have only O(n2) new Locally historical paths per update, amortized…

Page 37: Dynamic All Pairs Shortest Paths

Handling the hard case

The shortest path is different (update = increase):

x y+

If we maintain Locally historical paths using priority queues,

we can find this path in O(1) time!

EASY

Page 38: Dynamic All Pairs Shortest Paths

The update algorithm

Remove from the data structure all Locally historical paths containing the updated edge1

Use remaining Locally historical paths to find an upper bound to the distances after the update2

Propagate changes in waves from the updatededge, finding the new Locally historical pathsand the new distances

3

Page 39: Dynamic All Pairs Shortest Paths

Conclusions

Locally historical paths are the heart of dynamic shortest paths

O(n2 log3 n) amortized time per fully-update operation

Distance and path query in optimal time.

Page 40: Dynamic All Pairs Shortest Paths

Homework – 4

Formulate a practical problem as a fully dynamic all pairs shortest paths problem. (please don’t use railway or highway systems as examples.)