06 Radix Heaps
06 Radix Heaps
855J
Shortest Paths 2:
Application to lot-sizing
R-Heaps
1
Application 19.19. Dynamic Lot Sizing (1)
K periods of demand for a product. The demand
is dj in period j. Assume that dj > 0 for j = 1 to K.
Cost of producing pj units in period j: aj + bjpj
hj : unit cost of carrying inventory from period j
2
Application 19.19. Dynamic Lot Sizing (1)
D
0
1 2 3 4 K-1 K
-d1 -d2 -d3 -d4 -dK-1 -dK
4 5 6 7 K-1 K
-d4 -d5 -d6 -d7 -dK-1 -dK
4
D
0
4 5 6 7 K-1 K
-d4 -d5 -d6 -d7 -dK-1 -dK
The cost of sending units of flow around C is linear (ignoring the fixed
charge for production). Let Q = b4 + h4 + h5 + h6 – b7.
If Q < 0, then the solution can be improved by sending a unit of flow
around C.
If Q > 0, then the solution can be improved by decreasing flow in C
by a little.
If Q = 0, then the solution can be improved by increasing flow around
C by x07 units (and thus eliminating the fixed cost a 7).
This contradiction establishes the lemma.
Corollary. Production in period i satisfies demands
exactly in periods i, i+1, …, j-1 for some j.
0 D
1 2 3 4 K K+1
1 6 8 11 K+1
2 Potential
2 4 4 Bottleneck:
2 2 Scanning
0
1 1 2 3 6 empty
4 2 buckets.
3 3 5
4
0 1 2 3 4 5 6 7
2 3
8
Using a bucket with a larger “width”
22 If costs are
2 45 4 larger, one can
22 29
0
make larger
1 14 26 3 6 buckets. But
41 27 then, how does
one do a “find
3 31 5 min?”
41
10 - 20 - 30 - 40 - 50 - 60 - 70 -
0-9 19 29 39 49 59 69 79
2 3
width = 10
9
A comment on buckets
The bucket implementation
Finding the first node in a bucket takes O(1) time
If the buckets have width 1, then each node has
minimum label
If the buckets have width > 1, then we need to find
the node in the bucket with min d(j).
Finding the node in the bucket with min d(j) can
take O(n) time if there are a fraction of n nodes in
the bucket.
10
A Special Purpose Data Structure
RADIX HEAP: a specialized implementation of
priority queues for the shortest path problem.
11
Radix Heap Example
Buckets: 5
2 4
bucket sizes grow 15 2
13
exponentially
ranges change 1 6
dynamically
20
0
8
9
3 5
2 4 8 16 32
0 1 7 15 31 63
3 Radix Heap
Animation
12
Some General Comments
The Update Step seems fairly routine, but
reinserting a node can take O(K) steps, where K
is the number of buckets.
13
On the number of buckets
Let K = Number of Buckets.
Running time is O(m + nK).
The initial widths of the buckets are 1, 1, 2, 4, 8,
…, 2K-2
K =2+ log (C+1)
Note that Bucket K has width at least C
Further improvements are possible.
14
Algorithm Outline
Initialization:
Initializes the buckets with bucket ranges 0, 1,
2-3, 4-7, 8-15, etc;
Initializes d( );
places node j in the bucket whose range
contains d(j);
Update(i)
d(j) = min(d(j), d(i) + cij) for (i,j) A(i)
Reinsert(j) if necessary: that is move it to the
bucket whose range contains d(j);
15
Algorithm outline (continued)
Select min
scans buckets to find the min non-empty
bucket, say bucket B (e.g., B = 4)
scans B to find d*, the min temporary label
redistributes the ranges in bucket B to
buckets 1 to B-1, starting with value d*
reinserts nodes that were in bucket B into the
previous 1 to B-1 so that node j is in the
bucket whose range contains d(j)
selects a node from Bucket 1.
16
Algorithm running time: Initialization
Initializes the buckets with bucket ranges 0, 1, 2-3, 4-
7, 8-15, etc;
O(K) steps
Initializes d( );
O(n)
places node j in the bucket whose range contains d(j);
O(n) assuming that d(1) = 0 and d(j) = for j > 1.
17
Initialization step
5
Initialize 2 4
distance labels 13
15 2
0
Initialize buckets
1 6
and their ranges.
20
0
8
Insert nodes into 9
3 5
buckets.
2 4 8 16 32
0 1 7 15 31 63 2
3 3
4
1 5
6
18
Update(i) Analysis
d(j) = min(d(j), d(i) + cij) for (i,j) A(i)
O(m) time in total
19
More on update
20 22 26 32
18 19 21 25 31 63
1 2 3 4 5 6 7 20
Select Min (step 1)
scans buckets to find the min non-empty bucket,
say bucket B (e.g., B = 4)
O(K) steps per find min,
O(nK) steps in total
2
11
13
8 16 32
0
9
13 1
10
14 12
15 15 15 31 63
3
6
8
21
Select Min (step 3)
scans B to find d*, the min temporary label
will be analyzed later
redistributes the ranges in bucket B to buckets 1
to B-1, starting with value d*
O(K) steps per find min,
O(nK) steps in total
e.g, suppose d(6) = 19, d(8) = 25;
2
11
21 13
23
8
27 16
32
0
9
13
19 1
10
14
20 12
15
22 15
26 15
31 31 63
3
6
8
22
Select Min (steps 4, 5)
reinserts nodes that were in bucket B into the
previous 1 to B-1 so that node j is in the bucket
whose range contains d(j)
O(K) over all select min for each node j
O(nK) in total
2
11
21 13
23
8
27 16
32
0
9
13
19 1
10
14
20 12
15
22 15
26 15
31 31 63
3
6 8 6
8
d(6) = 19, d(8) = 25 23
Select Min (Step 2): a dominance argument
scans B to find d*, the min temporary label
Suppose that there are n’ nodes in bucket B.
O(n’) steps to determine d*
But the n’ nodes then are reinserted
at least n’ steps to reinsert these nodes
2
11
21 13
23
8
27 16
32
0
9
13
19 1
10
14
20 12
15
22 15
26 15
31 31 63
3
6
8
B
24
Summary of Running Time
O(m) for scanning arcs in update
O(nK) for finding the minimum non-empty bucket
O(nK) for redistributing the ranges
O(nK) for Reinserting nodes into (different)
buckets.
O(nK) for finding the minimum distance value in
buckets
25
On choosing K
Rule for last bucket: always keep its width equal to C.
Example: C = 30
Suppose we need to redistribute range of bucket 7
2
11
21 13
23
8
27 16
32
0
9
13
19 1
10
14
20 12
15
22 15
26 15
31 31 61
3
6 9
8 4
1 2 3 4 5 6 7
26
Distributing bucket 7
Usually, the bucket being distributed is left empty with
no range.
For the last bucket, we keep its width equal to C
2
11
21
34 13
23
36
8
27
40 16
48 32
62
0
9
13
19
32 1
10
14
20
33 12
15
22
35 15
26
39 15
31
47 31
61 61
91
3
6 9
8 4
1 2 3 4 5 6 7
27
Summary
Dynamic Lot-Sizing: reduces to a shortest path
problem.
28
Running Time Analysis
One of the key features will be in determining
what steps to count and what steps do not
need to be counted.
Analyze on a global level, if possible The
number of steps at a particular find min may
be O(nK). But that is also the number of steps
over all iterations.
29