1 / 76

Sadna in Algorithms

Explore and implement algorithms related to shortest path, maximum flow, and min cost flow problems. Discover interesting graph classes and unknown solutions.

jola
Download Presentation

Sadna in Algorithms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Sadna in Algorithms Haim Kaplan and Svetlana Olonetsky Tel Aviv University, fall 07/08

  2. Suggested topics • Shortest path • Maximum flow • Min cost flow

  3. What do you have to do: • Choose algorithms to implement • Understand them well • Choose the graphs you’d run on • The structure/language of your program What is the purpose ? Why do you do it ? There should be a goal, something that you do not know in advance, interesting graph classes

  4. Inspiration There has been a lot of work recently on so called “algorithm engineering”: • Three yearly conferences: • WAE • ALENEX • ESA (track B)

  5. Some examples

  6. v u Distances and Shortest Paths

  7. There are many variations graph is undirected/directed weights: negative/nonnegative real/integer given pair(s)/single source/all pairs one shot/build a data structure or spaner exact/approximate randomized/deterministic

  8. Dijkstra’s shortest path algorithm Let G = (V,E) be a weighted (weights are non-negative) undirected/directed graph, let s  V. Want to find the distance (length of the shortest path), d(s,v) from s to every other vertex. 3 3 s 2 1 3 2

  9. Dijkstra: Maintain an upper bound d(v) on d(s,v). • Every vertex is either scanned, labeled, or unlabeled. • Initially: d(s) = 0 and d(v) =  for every v  s. • s is labeled and all others are unlabeled. • Pick a labeled vertex with d(v) minimum. Make v scanned. • For every edge (v,w) if d(v) + w(v,w) < d(w) then • 1) d(w) := d(v) + w(v,w) • 2) label w if it is not labeled already

  10. Dijkstra’s shortest path algorithm (implementation) Maintain the labeled vertices in a heap, using d(v) as the key of v. We perform n delete-min operations and n insert operations on the heap. O(n log(n)) For each edge we may perform a decrease-key. With regular heaps O(m log (n)). But if you can do decrease-key in O(1) time then you can implement Dijkstra’s algorithm to run in O(n log(n) + m) time !

  11. Dial’s implementation • Assume that weights are small integers • Maintain vertices in an array according to their distance label

  12.  0    1 An Example Initialize distance labels Initialize array 4 2 4 2 2 2 1 3 1 6 4 2 3 3 5

  13. Scan vertex 1 2   4 2 4 2 2 0 2 1 3  1 6 4 2 3 3 5   4 1 3 2

  14. 2 Scan vertex 2 2   4 2 4 2 2 0 2 1 3  1 6 4 2 3 3 5   4 3 1 3 2

  15. 2 Scan vertex 2 2   4 2 4 2 2 0 2 1 3  1 6 4 2 3 3 5   4 4 3 1 2 3 5

  16. Analysis • Let C-1 be the maximum length of an arc • What should be the length of the array ? • What is the running time ? • How can you do better ?

  17. 2-level buckets 0 C-1 ......... .........

  18. 2-level buckets 0 C-1 ......... .........

  19. 2-level buckets 0 C-1 ......... .........

  20. Analysis • What is the running time ? • How can you do better ?

  21. Goldberg et al • Has done extensive experimental work on Dijkstra’s algorithm • It may be interesting to repeat some of them ? Run on different graph classes, check new ideas, etc

  22. k simple shortest paths s a g b c d e f t

  23. Maintain a trie that described the paths found so far s s a sgt g t b c d e f t

  24. The heap s s a sgt g t b c d e f sabeft sgft t

  25. s s sg a g gft gt g t b t c d e f sabeft t

  26. s s sabeft sg a t g gft gt g t b t c d e f t

  27. s s sabeft sg a t g gft gt g t b t c d e f saceft t

  28. s sa s a sg aceft a g abeft gft gt g t t b t t c d e f sabdft sacdft t

  29. s sa s a sg aceft a g ab gft gt b g t t b t c bdft beft d e t t f sacdft t

  30. s sa s a sg aceft a g ab gft gt b g t t b t c bdft beft d e t t f sacdft t

  31. Point to point shortest paths

  32. Running Dijkstra...

  33. Bidirectional Dijkstra

  34. A* search • Define potential function π(v) and modify lengths: • – ℓ(v,w) = c(v,w) − π(v) + π(w) • – ℓ(v,w): reduced cost of arc (v,w). • All s-t paths change by same amount: π(t) − π(s). • A* search: • – Equivalent to Dijkstra on the modified graph: • correct if ℓ(v,w) ≥ 0 (π is feasible). • Take π(v) to be lower bounds on dist(v, t)

  35. Bidirectional A* • Could be made to work • Need to be careful: lower bounds must be consistent

  36. Where do we get lower bounds ? • Use landmarks dist(v,w) ≥ dist(A,w) − dist(A,v) dist(v,w) ≥ dist(v,A) − dist(w,A) A A v v w w

  37. Query with landmarks

  38. Landmark selection • There has been research on it: • selection at preprocessing • selection for the query

  39. Reach s t v • Reach of v with respect to P: • reach(v, P) = min{ dist(s, v) , dist(v, t) } • • Reach of v with respect to the whole graph: • reach(v) = maxP {reach(v, P)}, • over all shortest paths P that contain v [Gutman’04]. • • Intuition: • – vertices on highways have high reach; • – vertices on local roads have low reach.

  40. How do you use reaches • While scanning an edge (v,w): – If reach(w) < min{d(s, v) + ℓ(v,w), LB(w, t)}, then w can be pruned. w v s t • The lower bound is natural if the search is bidirectional

  41. Shortcuts • Consider a sequence of vertices of degree two on the path below: • – they all have high reach; 1000 1000 10 10 10 10 10 10 10 10 s s 1000 t 1010 1000 1020 1030 1040 1020 1010 1030

  42. Shortcuts Add a shortcut: – single edge bypassing a path (with same length). – assume ties are broken by taking path with fewer nodes. 80 1000 1000 10 10 10 10 10 10 10 10 s s 1000 t 1010 1000 1020 1030 1040 1020 1010 1030

  43. Shortcuts Decrease reaches 80 1000 1000 10 10 10 10 10 10 10 10 s s 1000 t 60 1000 50 30 50 60 40 40

  44. Shortcuts Can add more nested shortcuts 80 1000 1000 40 40 10 10 10 10 10 10 10 10 s s 1000 t 60 1000 50 30 50 60 40 40

  45. Shortcuts Can add more nested shortcuts 80 1000 1000 40 40 10 10 10 10 10 10 10 10 s s 1000 t 20 1000 10 30 10 20 20 20

  46. Reaches + shortcuts

  47. Combine reaches+shortcuts and landmarks

  48. Spanners Let G be a weighted undirected graph. A subgraph H of G is a t-spanner of G iff u,vG, H(u,v) tG(u,v) . Awerbuch ’85 Peleg-Schäffer ‘89

  49. Example

More Related