!talk.ppt
- Количество слайдов: 46
Engineering shortest path algorithms (a round trip between theory and experiments) Camil Demetrescu University of Rome “La Sapienza” Giuseppe F. Italiano University of Rome “Tor Vergata”
Why Engineering Algorithms? Theory In theory, theory and practice are the same.
Why Engineering Algorithms? The real world out there. . . In practice, theory and practice may be quite different…
Programs are first class citizens as well Theory Practice Number types: N, R int, float, double Only asymptotics matter Seconds do matter Abstract algorithm description Non-trivial implementation decisions, error-prone Unbounded memory, unit access cost Elementary operations take constant time Memory hierarchy / bandwidth Instruction pipelining, …
The Algorithm Engineering Cycle Algorithm design Deeper insights Theoretical analysis Bottlenecks, Heuristics Algorithm implementation Experimental analysis More realistic models Hints to refine analysis
Fully Dynamic all-pairs shortest paths Given a weighted directed graph G=(V, E, w), perform any intermixed sequence of the following operations: cost of edge (u, v) to w Update(u, v, w): update edges incident to v [w( )] Update(v, w): Query(x, y): return distance from x to y (or shortest path from x to y)
State of the Art First fully dynamic algorithms date back to the 60’s • P. Loubal, A network evaluation procedure, Highway Research Record 205, 96 -109, 1967. • J. Murchland, The effect of increasing or decreasing the length of a single arc on all shortest distances in a graph, TR LBS-TNT-26, Transport Network Theory Unit, London Business School, 1967. • V. Rodionov, A dynamization of the all-pairs least cost problem, USSR Comput. Math. And Math. Phys. 8, 233 -277, 1968. • …
State of the Art # papers 65 -69 70 -74 75 -79 80 -84 85 -89 90 -94 95 -99 00 -
State of the Art Until 1999, none of them was better in the worst case than recomputing APSP from scratch (~ cubic time!) Graph Weight Update Query Ramaling. &Reps 96 general real O(n 3) O(1) King 99 general [0, C] O(n 2. 5 (C log n)0. 5) O(1) D. & Italiano 01 general S real O(n 2. 5 (S log 3 n)0. 5) O(1) general real ? < o(n 3) O(1)
Fully Dynamic APSP Edge insertions (edge cost decreases) 10 x y 10 j i 10 10 For each pair x, y check whether d(x, i) + w(i, j) + d(j, y) < d(x, y) Quite easy: O(n 2)
Fully Dynamic APSP • Edge insertions (edge cost decreases) Quite easy: O(n 2) • Edge deletions (edge cost increases) Seem the hard operations • When edge (shortest path) deleted: need info about second shortest path? (3 rd, 4 th, …) • Now we take a little break from this problem…
Engineering Dijkstra’s AP Shortest Path The algorithm: Run Dijkstra from all vertices “in parallel” Edge scanning bottleneck for dense graphs [Goldberg] 1. Extract shortest pair (x, y) from heap: y’ 2. Scan all neighbors y’ of y x y 3. Possibly insert (x, y’) into heap or decrease its priority Can we do better? 1. Extract shortest pair (x, y) from heap: y’ 2. Scan only y’ for which (a, y’) shortest x y a 3. Possibly insert (x, y’) into heap or decrease priority (suboptimality)
Definition: Locally Shortest Paths [DI’ 03] A path is locally shortest if all of its proper subpaths are shortest paths πxy x y Locally Shortest path shortest path Shortest
Locally Shortest Paths By optimal-substructure property of shortest paths: Shortest paths Locally shortest paths
How much do we gain? Running time on directed graphs with real edge weights O( #LS-paths + n 2 log n) time O(n 2) space Q. : How many locally shortest paths ? A. : #LS-paths ≤ mn. No gain in asymptopia… Q. : How much can we gain in practice?
How many LS paths in a graph?
What about real-world graphs?
US road networks
Can we exploit this in practice?
What we have seen so far Algorithm design Deeper insights Theoretical analysis Bottlenecks, Heuristics Algorithm implementation Experimental analysis More realistic models Hints to refine analysis
Return trip to Theory Algorithm design Deeper insights Theoretical analysis Bottlenecks, Heuristics Algorithm implementation Experimental analysis More realistic models Hints to refine analysis
Back to Fully Dynamic APSP Given a weighted directed graph G=(V, E, w), perform any intermixed sequence of the following operations: Update(u, v, w): update cost of edge (u, v) to w Query(x, y): return distance from x to y (or shortest path from x to y)
Recall Fully Dynamic APSP • Hard operations seem edge deletions (edge cost increases) • When edge (shortest path) deleted: need info about second shortest path? (3 rd, 4 th, …) • Hey… what about locally shortest paths? πxy x y Shortest path shortest path Locally Shortest Candidate for being shortest path?
Locally shortest paths for dynamic APSP Idea: Maintain all the locally shortest paths of the graph How do locally shortest paths change in a dynamic graph?
Assumptions behind the analysis No two paths share the same weight. Locally shortest paths πxy are internally vertex-disjoint π1 x π2 π3 y
Tie breaking Assumptions Shortest paths are unique In theory, tie breaking is not a problem Practice In practice, tie breaking can be subtle
Appearing Locally Shortest Paths Fact 1 At most mn (n 3) paths can START being locally shortest after an increase 10 20 x 100 30 40 y
Disappearing Locally Shortest Paths Fact 2 At most n 2 paths can STOP being locally shortest after an increase if π stops being locally shortest after increase of e subpath of π (was shortest path) must contain e shortest paths are unique: at most n 2 contain e
Maintaining Locally Shortest Paths # Locally shortest paths appearing after increase: < n 3 # Locally shortest paths disappearing after increase: < n 2 The amortized number of changes in the set of locally shortest paths at each update in an increase-only sequence is O(n 2)
An Increase-only update Algorithm This gives (almost) immediately: O(n 2 log n) amortized time per increase O(mn) space
Maintaining Locally Shortest Paths What about fully dynamic sequences? 10 20 x 100 30 40 y
How to pay only once? x y This path remains the same while flipping between being LS and non-LS: Would like to have update algorithm that pays only once for it until it is further updated. . .
Looking at the substructure x y It is not dead! This path remains a shortest path This path is no longer a shortest path after the insertion… after the …but if we removed the same edge it would be a shortest path again!
Historical Paths A path is historical if it was shortest at some time since it was last updated historical path x y
Locally Historical Paths Shortest path Locally shortest path πxy x y Shortest path Historical path x Locally historical πxy path y Historical path
Key idea for Partially Dynamic SP LSP
Key idea for Fully Dynamic HP LHP
Key Idea for Fully Dynamic HP SP LHP
Putting things into perspective: HP SP LHP LSP
The fully dynamic update algorithm Idea: Maintain all the locally historical paths of the graph Fully dynamic update algorithm very similar to partially dynamic, but maintains locally historical paths instead of locally shortest paths (+ performs some other operations) O(n 2 log 3 n) amortized time per update O(mn log n) space
Experiments (update time)
What about real graphs? (update time)
Experiments on US road networks Relative time performance D-RLL/D-LHP (on different platforms) DE 2. 4 D-LHP faster than D-RRL NV IBM Power 4 Sun Ultra. SPARC IIi AMD Athlon AZ 2. 2 MT 2. 0 NH (32 MB L 3 cache) (2 MB L 2 cache) (256 KB L 2 cache) ME 1. 8 ID CT ND 1. 6 MA CO MD NM NJ NE AR LA 1. 4 MS KY MI IN KS 1. 2 IA AL MN MO CA IBM Power 4 OH NC 1. 0 0. 8 Sun Ultra. SPARC IIi 0. 6 D-LHP slower than D-RRL 0. 4 1 2 3 AMD Athlon 4 5 6 Number of edges (x 100) 7 8 9 10
Cache effects 2. 0 11. 12 Colorado road network Simulated cache miss ratio D-RRL/D-LHP Performance ratio D-RRL/D-LHP on real architectures 1. 83 Power 4 1. 59 1. 6 1. 41 1. 30 1. 2 1. 17 1. 0 Xeon 0. 87 0. 75 0. 69 128 KB 0. 92 Ultra. SPARC IIi Athlon 0. 8 0. 6 1. 00 0. 84 0. 71 256 KB 512 KB 1 MB 2 MB Cache size 4 MB 8 MB 16 MB 32 MB
Conclusions and open problems… C Code publicly available at http: //www. dis. uniroma 1. it/~demetres/experim/dsp O(n 2) space too much for applications Trading-off space and (query) time? Fully dynamic single source shortest path problem?
The world is not perfect…
!talk.ppt