1 / 19

15.082J & 6.855J & ESD.78J

15.082J & 6.855J & ESD.78J. Shortest Paths 2: Bucket implementations of Dijkstra’s Algorithm R-Heaps. A Simple Bucket-based Scheme. Let C = 1 + max(c ij : (i,j) ∈ A); then nC is an upper bound on the minimum length path from 1 to n.

dian
Télécharger la présentation

15.082J & 6.855J & ESD.78J

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. 15.082J & 6.855J & ESD.78J Shortest Paths 2: Bucket implementations of Dijkstra’s Algorithm R-Heaps

  2. A Simple Bucket-based Scheme Let C = 1 + max(cij : (i,j) ∈ A); then nC is an upper bound on the minimum length path from 1 to n. RECALL: When we select nodes for Dijkstra's Algorithm we select them in increasing order of distance from node 1. SIMPLE STORAGE RULE. Create buckets from 0 to nC. Let BUCKET(k) = {i ∈ T: d(i) = k}. Buckets are sets of nodes stored as doubly linked lists. O(1) time for insertion and deletion.

  3. Dial’s Algorithm • Whenever d(j) is updated, update the buckets so that the simple bucket scheme remains true. • The FindMin operation looks for the minimum non-empty bucket. • To find the minimum non-empty bucket, start where you last left off, and iteratively scan buckets with higher numbers. Dial’s Algorithm

  4. Running time for Dial’s Algorithm • C = 1 + max(cij : (i,j) ∈ A). • Number of buckets needed. O(nC) • Time to create buckets. O(nC) • Time to update d( ) and buckets. O(m) • Time to find min. O(nC). • Total running time. O(m+ nC). • This can be improved in practice; e.g., the space requirements can be reduced to O(C).

  5. Additional comments on Dial’s Algorithm • Create buckets when needed. Stop creating buckets when each node has been stored in a bucket. • Let d* = max {d*(j): j ∈ N}. Then the maximum bucket ever used is at most d* + C. d*+C d*+C+1 d* d*+1 d*+2 d*+3 j ∅ Suppose j ∈ Bucket( d* + C + 1) after update(i). But then d(j) = d(i) + cij≤ d* + C

  6. A 2-level bucket scheme • Have two levels of buckets. • Lower buckets are labeled 0 to K-1 (e.g., K = 10) • Upper buckets all have a range of K. First upper bucket’s range is K to 2K – 1. • Store node j in the bucket whose range contains d(j). 1 1 5 2 distance label 3 21 10-19 20-29 30-39 40-49 50-59 60-69 70-79 80-89 90-99 5 0 1 2 3 4 5 6 7 8 9 2

  7. Find Min • FindMin consists of two subroutines • SearchLower: This procedure searches lower buckets from left to right as in Dial’s algorithm. When it finds a non-empty bucket, it selects any node in the bucket. • SearchUpper: This procedure searches upper buckets from left to right. When it finds a bucket that is non-empty, it transfers its elements to lower buckets. • FindMin • If the lower buckets are non-empty, then SearchLower; • Else, SearchUpper and then SearchLower.

  8. More on SearchUpper • SearchUpper is carried out when the lower buckets are all empty. • When SearchUpper finds a non-empty bucket, it transfers its contents to lower buckets. First it relabels the lower buckets. 2-Level Bucket Algorithm 4 54 3 5 33 30 10-19 20-29 30-39 40-49 50-59 60-69 70-79 80-89 90-99 3 4 5 0 1 2 3 4 5 6 7 8 9 30 31 32 33 34 35 36 37 38 39

  9. Running Time Analysis • Time for SearchUpper: O(nC/K) • O(1) time per bucket • Number of times that the Lower Buckets are filled from the upper buckets: at most n. • Total time for FindMin in SearchLower • O(nK); O(1) per bucket scanned. • Total Time for scanning arcs and placing nodes in the correct buckets: O(m) • Total Run Time: O(nC/K + nK + m). • Optimized when K = C.5 • O(nC.5 + m)

  10. More on multiple bucket levels • Running time can be improved with three or more levels of buckets. • Runs great in practice with two levels • Can be improved further with buckets of range (width) 1, 1, 2, 4, 8, 16 … • Radix Heap Implementation

  11. A Special Purpose Data Structure • RADIX HEAP: a specialized implementation of priority queues for the shortest path problem. • A USEFUL PROPERTY (of Dijkstra's algorithm): The minimum temporary label d( ) is monotonically non-decreasing. The algorithm labels node in order of increasing distance from the origin. • C = 1 + max length of an arc

  12. 5 2 4 15 2 13 1 6 20 0 8 9 3 5 Radix Heap Example Buckets: • bucket sizes grow exponentially • ranges change dynamically 0 1 2-3 4-7 8-15 16-31 32-63 Radix Heap Animation

  13. Analysis: FindMin • Scan from left to right until there is a non-empty bucket. If the bucket has width 1 or a single element, then select an element of the bucket. • Time per find min: O(K), where K is the number of buckets 2-3 4-7 8-15 16-31 32-63 0 1 2 5 4

  14. Analysis: Redistribute Range • Redistribute Range: suppose that the minimum non-empty bucket is Bucket j. Determine the min distance label d* in the bucket. Then distribute the range of Bucket j into the previous j-1 buckets, starting with value d*. • Time per redistribute range: O(K). It takes O(1) steps per bucket. • Time for determining d*: see next slide. 9 10 11-12 13-15 2-3 4-7 8-15 16-31 32-63 0 1 2 5 4 d(5) = 9 (min label)

  15. Analysis: Find min d(j) for j in bucket • Let b the the number of items in the minimum bucket. The time to find the min distance label of a node in the bucket is O(b). • Every item in the bucket will move to a lower index bucket after the ranges are redistributed. • Thus, the time to find d* is dominated by the time to update contents of buckets. • We analyze that next

  16. Analysis: Update Contents of Buckets • When a node j needs to move buckets, it will always shift left. Determine the correct bucket by inspecting buckets one at a time. • O(1) whenever we need to scan the bucket to the left. • For node j, updating takes O(K) steps in total. d(5) = 9 9 10 11-12 13-15 2-3 4-7 8-15 16-31 32-63 0 1 2 5 4

  17. Running time analysis • FindMin and Redistribute ranges • O(K) per iteration. O(nK) in total • Find minimum d(j) in bucket • Dominated by time to update nodes in buckets • Scanning arcs in Update • O(1) per arc. O(m) in total. • Updating nodes in Buckets • O(K) per node. O(nK) in total • Running time: O(m + nK) O(m + n log nC) • Can be improved to O(m + n log C)

  18. Summary • Simple bucket schemes: Dial’s Algorithm • Double bucket schemes: Denardo and Fox’s Algorithm • Radix Heap: A bucket based method for shortest path • buckets may be redistributed • simple implementation leads to a very good running time • unusual, global analysis of running time

  19. MITOpenCourseWare http://ocw.mit.edu 15.082J / 6.855J / ESD.78J Network Optimization Fall 2010 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

More Related