270 likes | 286 Views
This chapter explores the LP formulation of the maximum flow problem, the dual LP formulation, and polynomial algorithms for solving maximum flow problems using LP duality.
E N D
Max-flow Min-Cut Theorem and LP Duality • Consider the LP formulation of the maximum flow problem: (P) Maximize v subject to {j: (i, j)A} xij - {j: (j, i)A} xji = v, for i = s = 0, for i N\{s, t} = -v, for i = t xij uij for all (i, j)A xij 0 for all (i, j)A • As for the shortest path case, multiply (-1) on both sides of the constraints, then get {j: (j, i)A} xji - {j: (i, j)A} xij = -v, for i = s = 0, for i N\{s, t} = v, for i = t i.e consider (inflow to i) – (outflow from i)
(P) Maximize v {j: (j, i)A} xji - {j: (i, j)A} xij = -v, for i = s = 0, for i N\{s, t} = v, for i = t xij uij for all (i, j)A xij 0 for all (i, j)A • The dual of (P) is (D) minimize (i, j)A uijwij subject to yj - yi + wij 0 for all (i, j) A ys – yt 1 wij 0 for all (i, j) A, yi unrestricted for all iN
(D) minimize (i, j)A uijwij subject to yj - yi + wij 0 for all (i, j) A ys – yt 1 wij 0 for all (i, j) A, yi unrestricted for all iN • Let [S, S] be a minimum s-t cut, and consider a dual solution yi = 1, if iS = 0, if iS wij = 1, if iS, j S = 0, otherwise This solution is dual feasible and its objective value is equal to the capacity of the cut. From max-flow min-cut theorem, the objective value is equal to the maximum s-t flow. By strong duality of LP, the solution is optimal to (D). • The formulation for minimum cut may be used as part of some other formulations if we need to use min cut as part of some solution (possibly with binary restrictions on the variables)
7.1 Introduction • Deficiencies of generic augmenting path algorithm: • Running time is O(nmU) • May converge to a nonoptimal solution for irrational data (no max-flow min-cut proof) • Remedies • Capacity scaling algorithm • Shortest path augmentation • Preflow-push algorithm (relax mass balance eq.)
7.2 Distance Labels • Distance function d: N → Z+ {0} with respect to the residual capacities rij. A distance function is valid w.r.t a flow x if d(t) = 0 (7.1) d(i) d(j) + 1 for every arc (i, j) in the residual network G(x). (7.2) d(i): distance label (7.1), (7.2): validity conditions • Property 7.1. valid d(i) is a lower bound on the length (number of arcs) of the shortest (directed) i-t path in the residual network. Pf) Let i = i1 – i2 - … - ik – ik+1 = t be any path of length k from node i to node t in the residual network. d(ik) d(ik+1) + 1 = d(t) + 1 = 1 d(ik-1) d(ik) + 1 2 …. d(i) = d(i1) d(i2) + 1 = k.
Property 7.1 implies that if there exists a path P from node i to node t such that d(i) = d(j) + 1, for all (i, j)P, then it is a shortest i-t path. • Property 7.2. If d(s) n, the residual network contains no directed path from s to t. • Terminology: • We say that the distance labels are exact if for each node i, d(i) equals the length of the shortest path from node i to node t in the residual network. Can determine exact distance labels for all nodes in O(m) by backward breadth-first search (using queue) starting at the sink node. • Arc (i, j) in G(x) is called admissible if d(i) = d(j) + 1, otherwise inadmissible. • s-t path is called admissible path if all arcs in the path are admissible arcs. • Property 7.3. An admissible path is a shortest augmenting path from the source to the sink.
7.3 Capacity Scaling Algorithm • Idea: Augment flows using arcs in G(x) with sufficiently large capacities. • G(x, ): -residual network. A network containing arcs whose residual capacity is at least . • -scaling phase: phase of the algorithm during which remains constant. (Each augmentation carries at least units of flow)
Capacity Scaling Algorithm algorithm capacity scaling; begin x := 0; := 2log U; while 1 do begin while G(x, ) contains a path from node s to node t do begin identify a path P in G(x, ); := min{rij : (i, j)P} augment units of flow along P and update G(x, ); end; := /2; end; end;
Consider the flow at the end of the -scaling phase. Let x’ be this flow and v’ denote its flow value. Let S be the set of nodes reachable from s in G(x’, ). Then, tS and [S, S] forms an s-t cut. The residual capacity of every arc in [S, S] is strictly less than , so the residual capacity of the cut [S, S] is at most m. Consequently, v* - v’ m. In the next scaling phase, each augmentation carries at least /2 units of flow number of augmentation is at most 2m. Labeling algorithm takes O(m) to identify an augmenting path, and updating the -residual network takes O(m) • Thm 7.4. The capacity scaling algorithm solves the max flow problem within O(m log U) augmentations and runs in O(m2 log U) time. • Can be reduced to O(nm log U) using ideas of the shortest augmenting path.
7.4 Shortest Augmenting Path Algorithm • If use simple implementation of the shortest augmenting path: Find shortest s-t path in G(x) for each augmentation. (Use breadth first search – O(m)/iteration) It can be shown that total number of augmentation is at most nm O(nm2) However, use of distance labels can reduce O(m) O(n) in augmentation and total number of augmentation is at most nm/2. gives O(n2m) (times for other necessary operations are bounded by the time O(n2m)) • Algorithm proceeds by augmenting flows along admissible paths. We start with exact distance labels obtained by performing the backward breadth-first search starting at the sink node. (The labels are valid too) The algorithm maintains a partial admissible path and iteratively performs advance or retreat operations from the last node of the partial path. If sink node t is reached, we augment flow.
algorithm shortest augmenting path; begin x := 0; obtain the exact distance labels d(i); i := s; while d(s) < n do begin if i has an admissible arc then begin advance(i); if i = t thenaugment and set i = s end elseretreat(i) end; end;
procedure advance(i); begin let (i, j) be an admissible arc in A(i); pred(j) := i and i := j; end; procedure retreat(i); (relabel) begin d(i) := min{d(j) + 1: (i, j)A(i) and rij > 0}; if i s then i := pred(i); end; procedure augment; begin using the predecessor indices identify an augmenting path P from the source to the sink; := min{rij: (i, j)P}; augment units of flow along path P; end;
d(i) d(j) rij 1 1’ 1 2 1 1 4 2 2 0 3 2 1 1 2 2 s t 2 5 2 2 2 1 1 3 6 1 2 1 1 4 1 1 1 1 0 3 2 1 1 2 2 s t 2 5 2 2 2 1 1 3 6 Illustrating the shortest augmenting path algorithm
Correctness of the algorithm: • Lemma 7.5. The shortest path augmenting path algorithm maintains valid distance labels at each step. Moreover, each relabel (or, retreat) operation strictly increases the distance labels of a node. Pf) Induction on the number of augment and relabel operations (advance operation does not change any residual capacity or distance label). Initially, have valid distance labels. Assume, inductively, that the distance labels are valid prior to an operation. Consider (a) augment, and (b) relabel. (a) flow augmentation on arc (i, j) might remove this arc from G(x), but does not affect the validity of the labels. Augmentation on arc (i, j) might create an additional arc (j, i) with rji > 0 and therefore create an additional inequality d(j) d(i) + 1. This is satisfied since d(i) = d(j) + 1 by the admissibility property of the augmenting path. (b) Show each incoming and outgoing arc satisfy the condition with respect to the new distance label, say d’(i).
(continued) Relabel node i when it has no admissible arc, i.e. no (i, j)A(i) satisfies d(i) = d(j) + 1 and rij > 0. Also labels satisfy validity conditions d(i) d(j) + 1, hence d(i) < d(j) + 1 for (i, j)A(i) with a positive residual capacity. Therefore, d(i) < min{d(j) + 1: (i, j)A(i) and rij > 0} = d’(i). Hence, d’(i) strictly increases and it satisfies validity conditions for all outgoing arcs in A(i) with a positive residual capacity. Finally, every incoming arc (k, i) satisfies the inequality d(k) d(i) + 1. Since d(i) < d’(i), validity condition satisfied for incoming arc (k, i). • Algorithm terminates when d(s) > n, indicating that the network contains no augmenting path. Hence, the flow is maximum. • Thm 7.6. The shortest augmenting path algorithm correctly computes a maximum flow.
Complexity of the Algorithm: Use current-arc data structure for A(i) Starting from the current arc in A(i), scan the list to find an admissible arc. Note that if an arc (i, j) is inadmissible in previous iterations, it remains inadmissible until d(i) increases. (Exer. 7.13) Therefore, we can start the scan from the current arc. When we reach the end of the arc list, we relabel and set the current arc as the first arc in the list. The relabel operation also examines the list once to compute the new distance label, which is same as the time it spends in identifying admissible arcs at node i in one scan of the arc list. • Property 7.7. If the algorithm relabels any node at most k times, the total time spent in finding admissible arcs and relabeling the nodes is O(kiN |A(i)|) = O(km).
Lemma 7.8. If the algorithm relabels any node at most k times, the algorithm saturates arcs (i.e. reduces their residual capacity to zero) at most km/2 times. (Note that relabel strictly increases d(i) values and d(i) < n in any partial admissible path. Hence increase of node label at most n times saturation of arcs at most nm/2 times each augmentation saturates at least one arc number of augmentation is at most nm/2 and each augmentation is O(n) ) Pf) Show that between two consecutive saturations of an arc (i, j), both d(i) and d(j) must increase by at least 2 units. Then, if the algorithm relabels any node at most k times, the algorithm saturates any arc at most k/2 times. Therefore, the total number of arc saturations would be at most km/2. Suppose that an augmentation saturates an arc (i, j). Since (i, j) is admissible, d(i) = d(j) +1. Before the algorithm saturates the arc (i, j) again, it must send flow back from node j to node i. At this time the distance labels d’(i) and d’(j) satisfy d’(j) = d’(i) + 1. In the next saturation, we must have d’’(i) = d’’(j) + 1.
(continued) Therefore, d’’(i) = d’’(j) + 1 d’(j) + 1 = d’(i) + 2 d(i) + 2. Similarly, for d’’(j) d(j) + 2. So, between two consecutive saturations of the arc (i, j), both d(i) and d(j) increase by at least 2 units. • Lemma 7.9. (a) In the shortest path algorithm each distance label increases at most n times. Consequently, the number of relabel operations is at most n2. (b) The number of augment operation is at most nm/2 Pf) Each relabel increases d(i) by at least one. If d(i) n, the algorithm never select node i during an advance operation since for every node k in the partial admissible path, d(k) < d(s) < n. Thus the algorithm relabels a node at most n times and the total number of relabel operations is bounded by n2. The algorithm saturates at most nm/2 arcs. Since each augmentation saturates at least one arc,the total number of augmentation is at most nm/2.
Thm 7.10. The shortest augmenting path algorithm runs in O(n2m) time. Pf) From Lemmas 7.9 and 7.7, total effort spent in finding admissible arcs and in relabeling the nodes is O(nm). Total number of augmentation is O(nm) and each augmentation is O(n) O(n2m) for augmentation Each retreat operation relabels a node, so the total number of retreat operation is O(n2). Advance operations: Each advance operation adds one arc to the partial admissible path, and each retreat operation deletes one arc. Total number of advance operations is O(n2 + n2m). First term comes from retreat operations, and the second term from the number of augmentations.
A Practical Improvement: Algorithm may take too much time to get the terminating condition d(s) n, although a maximum flow is obtained. Ex) 1 4 1 1 4 1 1 1 1 0 3 4 1 1 1 1 s t 2 5 1 1 1 1 2 1 1 1 1 3 6
Use an n-dimensional array numb, whose indices vary from 0 to (n-1). numb(k) is the number of nodes whose distance label equals k. Start with initial distance labels. At this point, the positive entries in the array numb are consecutive (starting from numb(0), up to numb(l) for some l). Subsequently, when the algorithm increases the distance label of a node from k1 to k2, we subtract 1 form numb(k1), add 1 to numb(k2) and check whether numb(k1) = 0. If numb(k1) = 0, the algorithm terminates. • Correctness: Let S = {iN: d(i) > k1} and S = {iN: d(i) < k1}. Have sS and tS. Consider the s-t cut [S, S]. The definition of S and S imply that d(i) > d(j) + 1 for all (i, j)[S, S]. The validity condition implies that rij = 0 for each arc (i, j) [S, S]. Therefore, [S, S] is a minimum cut and the current flow is a maximum flow.
Application to Capacity Scaling Algorithm: Can improve O(m2 log U) running time of capacity scaling algorithm. (recall algorithm works on G(x, ). O(m) for identifying an augmenting path. At termination for G(x, ), have v* - v’ m, hence 2m augmentations in the next scaling phase.) Use shortest augmenting path algorithm for G(x, ). O(m) augmentations for each scaling phase is guaranteed. (Compare with O(nm) augmentations for general algorithm). Hence the time for augmentation reduces from O(n2m) to O(nm) and all other operations, as before, require at most O(nm) time. O(nm log U) • Further worst-case Improvements: The bound O(nm) on the number of augmenting paths is tight. Using dynamic trees data structure reduces the average time for each augmentation from O(n) to O(log n), hence O(nm log n).
7.5 Distance Labels and Layered Networks (Dinic’s Alg.) • Dinic’s algorithm: send flows along shortest paths in layered networks and establish blocking flow. • Layered network V with respect to flow x: Determine the exact distance labels d in G(x). The layered network consists of arcs (i, j) in G(x) satisfying the condition d(i) = d(j) + 1 (admissible arcs). Eliminate some arcs not contained in any s-t path in layered network V. Nodes in V are partitioned into layers of nodes V0, V1, V2, … , Vl; layer k contains the nodes whose distance labels equal k. Furthermore, every arc (i, j) in V, iVk and jVk-1 for some k. Let the source node have distance label l. Dinic’s algorithm proceeds by augmenting flows in the layered network. Augmenting flow on arc (i, j) may create arc (j, i) in the residual network, but each arc of the layered network is admissible. So we don’t add (j, i).
(continued) Finding an augmenting path can be done in O(n) on average. Each augmentation saturates at least one arc in V, hence at most m augmentations. If no more augmentation possible, current flow is called a blocking flow. Can obtain a blocking flow in O(nm). If blocking flow obtained, Dinic’s algorithm recomputes exact distance labels, forms a new layered network, and repeats these computations. It is possible to show that every time Dinic’s algorithm forms a new layered network, the distance label of the source node strictly increases. So at most n layered networks formed, and running time is O(n2m)
How to view Dinic’s Algorithm as a modified version of the shortest augmenting path algorithm • Modification 1: In operation retreat(i), we do not change the distance label of node i, but subsequently term the node i as blocked. A blocked node has no admissible path to the sink node. • Modification 2: We define an arc (i, j) to be admissible if d(i) = d(j) + 1, rij > 0, and node j is not blocked. • Modification 3: When the source node is blocked, by performing a backward breadth-first search we recompute the distance labels of all nodes exactly.
We term the computations within two successive recomputations of distance labels as occurring within a single phase. Following facts about the modified shortest augmenting path algorithm • At the beginning of a phase, when the algorithm recomputes the distance labels d(), the set of admissible arcs defines a layered network. • Each arc (i, j) in the admissible path satisfies d(i) = d(j) + 1; therefore, arc (i, j) joins two successive layers of the layered network. As a result, every admissible path is an augmenting path in the layered network. • Since we do not update distance labels within a phase, every admissible path has length equal to d(s). • The algorithm performs at most m augmentations within a phase because each augmentation causes at least one arc to become inadmissible by reducing its residual capacity to zero, and the algorithm does not create new admissible arcs. • A phase ends when the network contains no admissible path from node s to node t. Hence, when the algorithm recomputes distance labels at the beginning of the next phase, d(s) must increase.