Maximum Flow Notation 1 Maximum Flow Assumptions 1. Network is directed 2. All capacities are non-negative integers 3. Network does not have a path from s to t with all arcs having infinite capacity 4. If (i, j) A then (j, i) A Nonrestrictive because we allow arcs with capacity = 0 5. Network has no parallel arcs 2 Applications Feasible flow problem (application 6.1) j: i , j A xij x 0 xij uij As before, we assume that ji j: j ,i A bi for i N , for all (i, j ) A i N bi 0 Introduce two new nodes A source node s and a sink node t. For each node i with b(i)>0, we add an arc (s, i) with capacity b(i). For each node i with b(i)<0, we add an arc (i, t) with capacity -b(i). We refer to the new network as the transformed network. Then we solve a maximum flow problem from node s to node t in the transformed network. If the maximum flow saturates all the source and sink arcs, problem (6.2) has a feasible solution; otherwise, it is infeasible. 3 Additional Applications 1. Pipeline 1 3 s t 2 4 4 Definitions and Notation Residual Network Given a flow x, the residual capacity, rij, of an arc (i, j)A is the maximum additional flow that can be put on (i, j). Note that there will also be an rji [recall assumption] rij has two components (1) uij - xij unused capacity of (i, j) (2) xji flow on (j, i) which we can cancel to increase the flow from i to j rij = uij - xij + xji xij, uij Example i j 2 1 4 3 rij Residual network i j 2 1 4 3 5 s - t cut Cut partition N into two sets, S and s = N - S Notation: [S, s ] or arcs with one endpoint in S and one in s-t cut if s S & t s s Forward arc of cut if (i, j) i S j Backward arc of cut if (i, j) i jS s s set denoted (S, s) set denoted ( s , S) Example 2 4 s t 3 (S, s ) = (2, 4), (3, 4), (3, t) ( s , S) = 6 Capacity of an s - t cut u S, S (i, j )( S , S ) uij Minimum cut Residual capacity of s - t cut r s, s rij i, j s, s 7 Flow across s - t cut v xij xij i, j s,s i, j s ,s Property 6.1 The value of any flow is less than or equal to the capacity of any s - t cut Property 6.1 implies that if we find a flow x that equals the capacity of some cut [S, s ] then x is a maximum flow and [S, s ] is a minimum cut. We will reference this in the max-flow min cut theorem. 8 We can also state property 6.1 in terms of the residual capacity. Suppose x has a flow value of v x has a flow value of v + v v v v 0 u i , j s ,s (6.5) ij Then 6.5 minus 6.3 Recall that 6.3 says: (v xij xij ) i, j s, s i, j s , s Gives v uij xij xij i, j s, s i, j s , s or v u i , j s , s v ij xij u i , j s , s ij x i , j s , s ji xij x ji rij s ,s Thus we get Property 6.2 For any flow x of value v in a network, the additional flow that can be sent from s to t is less than or equal to the residual capacity of any s - t cut. 9 Generic Path Augmenting Algorithm Definition: Augmenting Path: directed path from s to t in the residual network Residual capacity of an augmenting path: minimum residual capacity of any arc in the augmenting path. 1 2 s t 3 4 1 2 s t 3 4 If the minimum residual capacity along an augmenting path is > 0 then we can push more flow along that path. We can build an algorithm that works by finding paths and pushing the maximum flow on them. 10 algorithm augmenting path; begin x : = 0; while G(x) contains a directed path from node s to node t do begin identify an augmenting path P from node s to node t; : min rij : i, j P; augment units of flow along P and update G(x); end; end; Figure 6.12 Generic augmenting path algorithm. 11 1 2 s t 3 4 1 2 s t 3 4 1 2 s t 3 4 1 2 s t 3 4 12 Relationship between the original and residual networks We can keep track of xij or rij, because they have an equivalence. Augmenting path in original: Path P (need not be directed) from s to t such that xij < uij for forward arcs and xji > 0 for backward arcs. Can show equivalence to directed path in residual network. When we updated the flows we increased the xij values on the forward arcs and decreased the xji values on the backward arcs. 13 If we use rij's how do we get xij's? Recall rij = uij - xij + xji or uij - rij = xij - xji if uij > rij let xij = uij - rij and xji = 0 if uij < rij let xij = 0 and xji = rij - uij 14 Explanation of path augmenting when there are backward arcs. 15 Labeling algorithm & maximum flow minimum cut theorem Discuss augmenting path algorithm in more detail. Specifically 1. How do we know if there are any more augmenting paths? 2. Will the algorithm terminate in an infinite number of steps? 3. Will the algorithm terminate at opt.? In general the algorithm fans out from s labeling nodes - we can label a node if we can reach that node in the residual network (that is there is a path with rij > 0 for all arcs in the path). When we label the sink, stop and augment flow. If we can't label the sink stop. 16 algorithm labeling; begin label node t; while t is labeled do begin unlabel all nodes; set pred (j) : = 0 for each jN; label node s and set LIST : = {s}; while LIST and t is unlabeled do begin remove a node i from LIST; for each arc (i, j) in the residual network emanating from node i do if rij > 0 and node j is unlabeled then set pred (j) : = i , label node j, and add j to LIST; end; if t is labeled then augment end; end; procedure augment; begin use the predecessor labels to trace back from the sink to the source to obtain an augmenting path P from node s to node t; : min rij : i, j P; augment units of flow along P and update the residual capacities; end; 17 Example 1 2 s t 3 LIST 4 Pred s 1 1 3 4 t 3 4 t 2 s t 3 LIST 2 4 Pred s 1 2 18 1 2 s t 3 LIST s 1, 3 2, 3 (Note 2 tries to label only 3) 3 4 4 Pred s 1 0 s 2 0 1 3 s 4 0 t 0 3 4 The algorithm labels t, augment flow = min {2, 3, 5} = 2 1 2 s t 3 LIST 4 Pred s 1 2 3 4 t 19 1 2 s t 3 4 Can't label anything but s. Original arcs 1 2 s t 3 4 20 Correctness of the algorithm When it stops how do we know we have an optimal solution? When we stop we can't label the sink. Let S = set of labeled nodes S = set of unlabeled nodes sS t S Since no node in S can be labeled by a node in S this implies rij = 0 for all (i, j) (S, Since S) rij uij xij x ji xij uij & x ji 0 what do we know about xij and xji? 21 Plug into equation 6.3 v x i , j s , s ij x i , j s , s ij u i , j s , s ij us, s Current flow = capacity of cut [s, s ] By Property 6.1 this implies that x is a maximum flow and [s, s ] is a minimum cut. This establishes the algorithm correctness and the max-flow min-cut theorem. Theorem 6.3 (Max-Flow Min-Cut Theorem). The maximum value of the flow from a source node s to a sink node t in a capacitated network equals the minimum capacity among all s-t cuts. Similarly, we can show Theorem 6.4 (Augmenting Path Theorem). A flow x* is a maximum flow if and only if the residual network G(x*) contains no augmenting path. We can also show Theorem 6.5 (Integrality Theorem). If all arc capacities are integer, the maximum flow problem has an integer maximum flow. 22 Complexity 0(m) per augmentation max nU (increase flow by 1 each time) 0(nmU) If there are infinite capacity arcs just set uij very large but finite. 23 Drawbacks of the Ford-Fulkerson method 1. 2. 3. Empirically Ford-Fulkerson does well but can construct pathological problems (see book). Irrational capacities cause complications "Forgetfulness" - start labeling over each time - we will discuss improvements. 24 Flows with Lower Bounds lij 0 max v s.t. v i s x x ij ji 0 i N s, t j:i, j A j: j,i A v i t lij xij uij i, j Two key steps 1. Show that a feasible flow exists (lij, uij) (6, 9) Infeasible Example 1 (4, 5) 2 3 2. Find the maximum flow 25 Consider finding maximum flow first. Assume we have a feasible flow. Now with one modification we can use prior algorithms. Let rij=(uij - xij) + (xji - lji) Since the flow is feasible => lij xij uij = > rij 0 Our algorithms work with rij values (not arc flows, capacities, or lower bounds) so we can still use them. 26 One way to construct maximum flows, xij values, from rij values For (i, j) let uij = uij - lij xij = xij - lij rij = rij recall rij = (uij - xij) + (xji - lji) equivalently rij = (uij - xij + xji) similarly rji = (uji - xji + xij) compute x as before xij = max (uij - rij, 0) xji = max (uji - rji, 0) In original variables xij = lij + max (uij - rij - lij, 0) xji = lji + max (uji - rji - lji, 0) Using the modified rij values we will find an optimal solution and can prove theorem 6.10 Theorem 6.10 (Generalized Max-Flow Min-Cut Theorem). If the capacity of an s-t cut [s, s ] in a network with both lower and upper bounds on arc flows is defined by (6.7), the maximum value of flow from node s to node t equals the minimum capacity among all s-t cuts. (6.7) us, s u i , j s ,s ij l ij i , j s ,s 27 How find a feasible flow? First transform to a circulation problem. Add (t, s) with uts = Find a flow satisfying x ij j: i , j x ji j: j ,i 0 i N lij xij uij i, j (6.11) let xij = xij - lij Now xij x ji bi j :i, j j : j, i i, j A u ij lij 0 xij bi Note l ji j: j ,i l i N (6.2) ij j: i , j bi 0 iN Like feasible flow in application 6.1. The maximum flow problem has a feasible solution iff the circulation has a feasible flow. 28 Can show theorem 6.11 Theorem 6.11 (Circulation Feasibility Conditions). A circulation problem with nonnegative lower bounds on arc flows is feasible if and only if for every set S of nodes l u ij i , j s , s i , j s ,s ij Theorem 6.12. The feasible flow problem stated in (6.2) has a feasible solution if and only if for every subset s N , bs us, s 0 , where bs is bi 29 So, an algorithm to check feasibility works like this: Can start with zero flow, look at infeasible arcs (xij < lij) Increase xij to lij by finding an augmenting path from j to i. Continue until 1. All xij lij 2. Can't find the augmenting path you need which implies the problem is infeasible because theorem 6.11 is violated. 30