470 likes | 486 Views
Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin. Algorithmic ideas from the previous lecture. Augmenting path algorithm an improvement algorithm that is guaranteed to be optimal Max-Flow Min-Cut:
E N D
Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin
Algorithmic ideas from the previous lecture • Augmenting path algorithm • an improvement algorithm that is guaranteed to be optimal • Max-Flow Min-Cut: • using a variation of LP duality to establish optimality and distance from optimality. • Scaling • Solving a sequence of problems that converges to the original problem. • Efficient when reoptimizing can be done quickly. • Simple data structures • keeping track of distance labels and current arcs sped up the algorithm
Algorithmic Ideas in this lecture • Preflows: • A relaxation of flows that leads to improved algorithms. • A new scaling algorithm • Potential function analysis • a method of establishing a faster running time by using “global” information about the algorithm.
Running times for max flow algorithms • O(nm2) Edmonds and Karp (1972) • O(n2m) Dinic (1970) • O(n3) Karzanov (1974) Malhotra, Kumar & Maheshwari (1977) • O(n2 m½ ) Cherkasky (1977) • O(nm log2 n) Galil and Naaman (1980) • O(nm log n) Sleator and Tarjan (1983) • O(nm log n2/m) Goldberg and Tarjan (1988)
More Improvements in running time • O(nm+ n2+ε ) King Rao and Tarjan (1992) • O(nm logα n ) King Rao and Tarjan (1994) α = m/(n log n) • O(n3 / log n ) Cheriyan, Hagerup, and Mehlhorn (1996) • O(nm) O. (2011) • O(nm / log n) O. (2011) if m = O(n) and under some other conditions. • Remark 1: The max flow problem is solvable in O(nm / log n) steps when m = Ω(n2) and when m = O(n). • Remark 2: The improvements by O. (2011) are very involved.
Weakly polynomial running times • O(nm log U) Gabow (1985) • O(nm + n2 log U) Ahuja and Orlin (1989) • O(nm + n2 log½ U) Ahuja, Orlin, and Tarjan (1989) • O(m3/2 log n log U) Goldberg and Rao (1998) • O(n2/3 m log(n2/m) log U) Goldberg and Rao (1998) • O(n2/3 m log U) O. (2011) • Further improvements if log Umax/Umin = O(n1/3) • Remark: The improvement by O. (2011) is very simple
Preflows • At each intermediate stages we permit more flow arriving at nodes than leaving (except for s) • A preflow is a function x: A → R s.t. 0 ≤ x ≤ u and such that • e(i) = ∑j∈N xji - ∑j∈N xij ≥ 0, for all i ∈ N – {s, t}. • i.e., e(i) = excess at i = net excess flow into node i. • The excess is required to be nonnegative.
2 2 5 2 3 1 3 2 s 4 t 3 2 3 A Feasible Preflow 2 0 The excesse(j) at each node j ≠ s, t is the flow in minus the flow out. 0 Note: total excess = flow out of s minus flow into t. 1 In preflow push algorithms, we typically send flow in only one arc at a time.
Converting a preflow into a flow 0 1 2 1 Any preflow can be converted into a flow that preserves the flow into t. 2 2 5 2 2 3 1 2 3 2 s 4 t Run flow decomposition and then keep only the paths from s to t. 3 0 2 2 3 1
Distances • We will maintain distance labels. • Next: how to maintain distance labels efficiently.
Exact Distance Labels • Distance labels d( ) are exact for G(x) if for all j with a path to t, d(j) is the length of the shortest path from j to t. An arc is (i, j) is admissibleif d(i) = d(j) + 1. d( ) 4 4 3 3 2 1 0 Lemma. Suppose all distance labels are exact. Then, an arc (i, j) is admissible if and only if it is on a shortest path from i to t. i t P = the shortest path from i to t in G(x)
Maintaining Exact Distance Labels • At each iteration, CurrentArc(i) is the first admissible arc in A(i). The current arcs form a tree (or forest), whose arcs are directed into node t. 7 6 5 4 3 2 1 0 We will update CurrentArc(i) if it is inadmissible. We will update d(i) if there is no admissible arc out of i. 6 1 4 Suppose CurrentArc(i) = (i, j). Arc (i, j) may become inadmissible if • (i, j) is saturated or • the distance label of j is increased. 5 7 2 3 8 t
An update of CurrentArc • Example 1. Suppose that flow is sent in (7, 2) and the arc is saturated. 7 6 5 4 3 2 1 0 Then (7, 3) becomes admissible. 6 1 6 Tail Head Res. Cap 7 2 0 7 3 1 7 4 4 7 6 2 7 8 0 4 4 5 7 7 2 3 2 3 8 8 t
Example 2: there is a cascading effect • Example 2. Suppose now that (3, 8) is saturated. Node 3 increases its distance label to 4. (3, 5) is admissible. (7, 3) is inadmissible and node 7 is updated next. 7 6 5 4 3 2 1 0 6 1 Tail Head Res. Cap 3 5 6 3 7 2 3 8 0 4 5 7 2 3 8 t
Example 3: a gap is created • Example 3. Suppose now that (5, 2) is saturated. Node 5 increases its distance label to 5. But now there is no node with distance label 3. 7 6 5 4 3 2 1 0 6 1 7 4 3 Tail Head Res. Cap 5 2 0 5 3 3 5 4 6 5 2 8 t
Example 3: continued ∞ 7 6 5 4 3 2 1 0 1 3 4 5 6 7 When a gap is created, all nodes with distance level above the gap have their distance level set to ∞. 2 8 t
Time for updating distance labels • Lemma. • The arc list of each node i is scanned at most once between updates of d(i). • The arc list is scanned once if d(i) needs to be updated. • d(i) is updated at most n-1 times for each i. • Conclusion. Each arc is scanned O(n) times. The total running time for updating CurrentArc and d( ) is O(nm).
On the order in which things are done • Typically, the generic preflow push algorithm is presented before the excess scaling algorithm. • But not here.
Scaling Algorithms • Define a concept called Δ-optimal, where Δ is some positive integer, and where a 1-optimal solution is optimal for the original problem. • Develop a subroutine that efficiently determines Δ0-optimum solution where • Δ0 is some (possibly large) power of 2 • Develop a subroutine Improve-Approx that transforms a Δ-optimal solution into a Δ/2-optimal solution. Generic Scaling Algorithm Δ := 2K for some selected value K determine a Δ-optimal solution x while Δ > 1 do y := ImproveApprox(x, Δ) x := y Δ := Δ/2
Initialize Determine exact distance labels for each node. For each arc (s, j), send usj units of flow from s to j. This results in an excess e(j) = usj. d(s) := ∞; Choose Δ0 to be the minimum power of 2 that is greater than max (usj : j ∈ N}. e(5) = us5 5 s d(s) := ∞ e(7) = us7 7
Excess- Scaling Preliminaries • A preflow x is called Δ-optimal if • 0 ≤ e(i) < Δ for all i with 1 ≤ d(i) < ∞. • the distance labels are exact • d(s) = ∞; that is, there is no path from s to t in G(x). • Subroutine ImproveApprox(x,Δ): takes a flow that is Δ-maximum and outputs a flow that is Δ/2-maximum. • ImproveApprox terminates when e(i) < Δ/2 for all i with 1 ≤ d(i) < ∞. • After initialization, the flow is Δ0-optimal.
Push-Relabel(i) INPUT: a node i with e(i) ≥ Δ/2. Push-Relabel(i) begin while e(i) > 0 do if there is an admissible arc (i, j) thensend min {e(i), Δ - e(j) – 1, rij) units of flow in (i, j) else replace d(i) by 1 + min{d(j) : rij > 0} update r, e, CurrentArc, and d( ); end
Examples of Push-Relabel level Δ = 64 Case 1. e(7) = 62 r73 = 40 e(3) = 10 k+2 6 Case 2. e(7) = 62 r73 = 40 e(3) = 30 k+1 4 k 7 62 Case 3. e(7) = 62 r73 = 0 40 k-1 3 10 22 62 29 62 0 40 7 0 52 30 63 30
Excess Scaling Algorithm • Procedure Improve-Approx(r, Δ) • begin • while there is a Δ/2-active node do • begin • let i = argmin (d(i) : i is Δ/2-active} • Push-Relabel(i) • end • end;
s 9 j 32 ≤ e(j) < 64 “large excess” 8 e(i) < 32 i 7 6 62 5 7 4 6 2 40 3 9 3 8 4 5 2 2 s 7 s 0 25 1 4 5 5 5 0 t Pushing in the 64-scaling phase Choose a large excess node i at minimum distance level. For each admissible arc (i,j), j is not large excess.
62 7 j 32 ≤ e(j) < 64 “large excess” 2 40 e(i) < 32 i 4 5 0 28 25 7 2 5 35 4 5 2 63 Pushing in the 64-scaling phase. Rule: push as before, except that no node excess can exceed Δ-1. Push 2 units in (7,4). Then push 35 units in (7,5) Send min{e(i), rij, Δ-e(j)-1} units of flow in (i,j) Any non-saturating push has at least Δ/2 units of flow
Bounding the number of pushes • Each arc (i, j) has at most one saturating push in between relabels of i. It may have several non-saturating pushes. • We will show that the number of non-saturating pushes per scaling phase is O(n2). • We will use a potential function argument. • We will define a potential function Φ. • Each non-saturating push will decrease Φ by .5. We will bound this number by bounding the total increase in Φ over all iterations.
Elevators movements 10 9 8 7 6 5 4 3 2 1 0 An elevator is in a building that is n stories high. It can go up multiple floors at a time, but it can only go down one floor at a time. In m movements of the elevator, how many floors can it travel upwards? Note: it can travel n floors in a single move.
UP ≤ DOWN + n. 10 9 8 7 6 5 4 3 2 1 0 It can go up at most n floors more than it goes down. It can go down at most m floors in m moves. In m moves, it can travel at most 2m + n floors. If m > n, it travels at most 3m floors, or fewer than 3 floors per move on average.
Finding a min-distance Δ/2-active node. 10 9 8 7 6 5 4 3 2 1 0 For each distance level store a doubly linked list of Δ/2-active nodes. After pushing flow from a node i, the next push is from a node with d(j) ≥ d(i) – 1. Start with distance level d(i) – 1 and seek the first distance level with a Δ/2-active node. Number of steps in m pushes is at most 2m + n. Δ/2-active nodes at level k {j, j’} ∅ ∅ ∅ {i} ∅ ∅
Next: Bounding the number of pushes • We will create a potential function Φ. • We will use the up and down argument to bound the amount of decrease in Φ over all iterations. • This will bound the number of pushes.
s 9 8 7 6 5 4 6 3 9 3 8 2 2 s 7 s 1 4 5 5 5 0 t A potential function for excess-scaling Φ = ∑j∈N e(j) d(j) / Δ Φ = 384 / 64 = 6 The potential is the “gravitational potential” measured in units of Δ
Increases in the potential function s Φ = ∑j∈N e(j) d(j) / Δ 9 8 Relabels: Φ increases by at most k if d(j) increases by k. Φ increases by O(n2) over all relabels. 7 6 5 4 6 Start of scaling phase. Φ doubles when Δ is replaced by Δ/2. Φ increases by O(n2 log U) over all scaling phases. 3 9 3 8 2 2 s s 7 1 4 5 5 5 0 t
Decreases in the potential function s Φ = ∑j∈N e(j) d(j) / Δ 9 8 Push: Φ decreases by δ/Δ if δ units of flow are sent in (i, j) Φ decreases by at least ½ in any large push 7 6 5 4 6 Conclusion: number of large pushes is at most 2n2 plus the total increase in Φ. This is O(n2 log U) large pushes. 3 9 3 8 2 2 s s 7 1 4 5 5 5 0 t
Summary of Excess Scaling Algorithm • Converts Δ-optimal flows into Δ/2-optimal flows • O(nm) running time (excluding time for large pushes) • O(n2) time for large pushes per scaling phase. • O(nm + n2 log U) time overall.
On the analysis of the potential function • Note: the potential function Φ increased O(n2) because of relabels, and increased O(n2 log U) when Δ was replaced by Δ/2. • Speeding up the algorithm: • If we can reduce the total flow at the end of the algorithm to O(nΔ/K) for some K, then the potential increase would be O( (n2 log U)/K). • We will show how to do this for K = log½ U. • Another bottleneck appears; so one cannot make K any larger.
General Algorithmic Rule Single bottleneck rule If the bottleneck in an algorithmis caused by one “thing”, then try to speed up the “thing.”
Excess Scaling with Waves • Carry out a sequence of “waves” during a scaling phase. • Rules for the wave. • Select the lowest level Δ/2-active node, if one exists. Else, select the highest level node i with 1 < e(i) < Δ/2. Push flow from the selected node. • If a node has no admissible arcs, then delete it from G(x) for the rest of the wave (and add it back after the wave). • The wave ends when there are no nodes with positive excess remaining. • After the wave, update the distance labels and the CurrentArc( ).
Excess Scaling with Waves Procedure Improve-Approx(r, Δ) begin while the total excess is greater than nΔ / log½ U do perform a wave update distance labels and current arcs end;
Examples of Pushes During a Wave There are no Δ/2-active nodes. Node 7 is the highest level node with excess. Arcs (7, 3) and (7, 4) are admissible. Δ = 64 level Example 2 Example 3 30 20 0 30 10 30 7 7 7 7 7 7 k 0 5 15 4 15 15 20 0 0 6 20 0 k-1 20 16 40 28 8 10 3 3 3 3 3 3 4 4 4 4 4 4 5 5 9 5 5 15 Example 1 Case 1. Send 20 units in arc (7, 3). Node 3 becomes Δ/2-active. Case 2. Send 20 units in arc (7, 3). Send 10 units in arc (7, 4). Delete node 7 from LIST. Case 3. Send 6 units in arc (7, 3). Send 4 units in arc (7, 4). Delete node 7 from LIST.
Waves during the Δ-scaling Phase • No node is ever Δ-active during the Δ-scaling phase. • At the end of the wave, each active node j (that is, e(j) > 0) will increase its distance label. (There is no path from j to t of admissible arcs). An arc may become inadmissible when it is saturated. This can cause a “cascading effect of deletions. 4 6 3 7 3 2 2 1 1 e.g., suppose (1, 5) is saturated. 4 5 5 0 t suppose (2, 4) is saturated.
Waves during the Δ-scaling Phase • There is at most one non-saturating push from a node with e(i) < Δ/2. If the Δ-scaling phase does not end after a wave, there were at least n/log½ U distance increases. 4 6 If no nodes are Δ/2 active, then the highest level active node will never receive any more flow during the wave. At the end of the wave, each node with excess will be relabeled. If the Δ-scaling phase didn’t end, then the total excess is at least nΔ/log½ U. 3 7 3 2 2 1 1 4 5 5 0 t If e(6) := 0, then e(6) = 0 for the rest of the wave.
Putting it all together • There are O(log U + n log½ U ) waves. Each wave leads to O(n) small non-saturating pushes. • Total run time because of the waves is O(n2 log½ U ), if log U < n2 Each non-saturating push from a Δ/2-active node decreases Φ by at least .5 Φ increases byO(n2 / log½ U ) following a scaling phase. It increases by O(n2 log½ U ) in total. Conclusion: Number of non-saturating pushes is O(n2 log½ U ).
summary of techniques • Preflows: A relaxation of flows that leads to improved algorithms. It is quite common to solve problems by solving relaxations. • Potential function analysis • a method of establishing a faster running time by using “global” information about the algorithm. • surprisingly useful in analyzing data structures and algorithms • Excess scaling • Excess scaling with waves. (If there is a single bottleneck operation or a single cause of the bottleneck, sometimes the running time can be improved by combining two approaches.)
Research notes on preflow push • Pushing from the active node with the largest distance label leads to O(n2 m.5) nonsaturating pushes. • A very efficient data structure called dynamic trees reduces the running time to O(nm log n2/m). Goldberg-Tarjan (1986) • The “excess scaling technique” of Ahuja and Orlin (1989)reduced the running time to O(nm + n2 log U). • Ahuja, Orlin, and Tarjan (1989): further very small improvements. • Goldberg and Rao (1998). An even more efficient algorithm for max flows. • Orlin [2011] max flows in O(nm) time and sometimes less.