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
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):
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)
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.
(n2) changes per update
(n) (n)+1-1+1
A new approach
New combinatorial properties of graphs:
Locally shortest paths
Uniform 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
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
Locally shortest paths
Properties of Locally shortest paths
Theorem I
Shortest paths Locally shortest paths
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
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…
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
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.
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
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
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.
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.
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?
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
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!
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
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...
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…
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.
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(π)).
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).
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.
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.
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.
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.
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
Locally historical paths
Properties of Locally historical paths
Theorem
Locally shortest paths Locally historical paths
Locally shortest paths
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)
(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)
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))
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…
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
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
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.
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.)