Max Flow, Min Cut Two Very Rich Algorithmic Problems
Total Page:16
File Type:pdf, Size:1020Kb
Maximum Flow and Minimum Cut Max flow and min cut. Max Flow, Min Cut Two very rich algorithmic problems. Cornerstone problems in combinatorial optimization. Beautiful mathematical duality. Minimum cut Nontrivial applications / reductions. Network connectivity. Maximum flow Network reliability. Bipartite matching. Max-flow min-cut theorem Security of statistical data. Data mining. Ford-Fulkerson augmenting path algorithm Distributed computing. Open-pit mining. Edmonds-Karp heuristics Egalitarian stable matching. Airline scheduling. Bipartite matching Distributed computing. Image processing. Many many more . Project selection. Baseball elimination. Princeton University • COS 226 • Algorithms and Data Structures • Spring 2004 • Kevin Wayne • http://www.Princeton.EDU/~cos226 2 Soviet Rail Network, 1955 Minimum Cut Problem Network: abstraction for material FLOWING through the edges. Directed graph. Capacities on edges. Source node s, sink node t. Min cut problem. Delete "best" set of edges to disconnect t from s. 2 9 5 15 10 4 15 10 source s 5 3 8 6 10 t sink capacity 15 4 6 15 10 Source: On the history of the transportation and maximum flow problems. 4 30 7 Alexander Schrijver in Math Programming, 91: 3, 2002. 3 4 Cuts Cuts A cut is a node partition (S, T) such that s is in S and t is in T. A cut is a node partition (S, T) such that s is in S and t is in T. capacity(S, T) = sum of weights of edges leaving S. capacity(S, T) = sum of weights of edges leaving S. 2 9 5 2 9 5 10 10 4 15 15 10 4 15 15 10 s 5 3 8 6 10 t s 5 3 8 6 10 t S S 4 6 15 4 6 15 15 10 15 10 Capacity = 30 Capacity = 62 4 30 7 4 30 7 5 6 Minimum Cut Problem Maximum Flow Problem A cut is a node partition (S, T) such that s is in S and t is in T. Network: abstraction for material FLOWING through the edges. capacity(S, T) = sum of weights of edges leaving S. Directed graph. same input as min cut problem Capacities on edges. Min cut problem. Find an s-t cut of minimum capacity. Source node s, sink node t. Max flow problem. Assign flow to edges so as to: Equalize inflow and outflow at every intermediate vertex. 2 9 5 Maximize flow sent from s to t. 10 2 9 5 4 15 15 10 15 10 4 15 10 s 5 3 8 6 10 t source s 5 3 8 6 10 t sink 4 6 15 10 S 15 capacity 15 4 6 15 10 Capacity = 28 4 30 7 4 30 7 7 8 Flows Flows A flow f is an assignment of weights to edges so that: A flow f is an assignment of weights to edges so that: Capacity: 0 ? f(e) ? u(e). Capacity: 0 ? f(e) ? u(e). Flow conservation: flow leaving v = flow entering v. Flow conservation: flow leaving v = flow entering v. except at s or t except at s or t 0 6 2 9 5 2 9 5 4 10 0 0 0 6 10 10 4 4 15 15 0 10 4 4 15 15 0 10 0 4 4 3 8 8 s 5 3 8 6 10 t s 5 3 8 6 10 t 0 0 1 10 4 0 6 15 0 4 0 6 15 0 capacity 15 10 capacity 15 10 flow 0 flow 11 0 Value = 4 11 Value = 24 4 30 7 4 30 7 9 10 Maximum Flow Problem Flows and Cuts Max flow problem: find flow that maximizes net flow into sink. Observation 1. Let f be a flow, and let (S, T) be any s-t cut. Then, the net flow sent across the cut is equal to the amount reaching t. 9 6 2 9 5 2 9 5 10 10 1 9 0 6 10 10 4 0 15 15 0 10 4 4 15 15 0 10 4 8 9 4 8 8 s 5 3 8 6 10 t s 5 3 8 6 10 t S 4 10 10 0 10 4 0 6 15 0 4 0 6 15 0 capacity 15 10 15 10 flow 14 14 Value = 28 10 Value = 24 4 30 7 4 30 7 11 12 Flows and Cuts Flows and Cuts Observation 1. Let f be a flow, and let (S, T) be any s-t cut. Then, the Observation 1. Let f be a flow, and let (S, T) be any s-t cut. Then, the net flow sent across the cut is equal to the amount reaching t. net flow sent across the cut is equal to the amount reaching t. 6 6 2 9 5 2 9 5 10 10 0 6 0 6 10 10 4 4 15 15 0 10 4 4 15 15 0 10 4 8 8 4 8 8 s 5 3 8 6 10 t s 5 3 8 6 10 t S S 10 0 10 10 0 10 4 0 6 15 0 4 0 6 15 0 15 10 15 10 10 Value = 24 10 Value = 24 4 30 7 4 30 7 13 14 Flows and Cuts Max Flow and Min Cut Observation 2. Let f be a flow, and let (S, T) be any s-t cut. Then the Observation 3. Let f be a flow, and let (S, T) be an s-t cut whose capacity value of the flow is at most the capacity of the cut. equals the value of f. Then f is a max flow and (S, T) is a min cut. Cut capacity = 28 Flow value ? 28 Cut capacity = 30 Flow value ? 30 Flow value = 28 9 2 9 5 2 9 5 10 1 9 10 4 15 15 0 10 10 0 4 15 15 10 4 8 9 s 5 3 8 6 10 t s 5 3 8 6 10 t 4 S S 15 10 4 0 6 15 0 15 10 4 6 15 15 10 15 4 30 7 4 30 7 15 16 Max-Flow Min-Cut Theorem Towards an Algorithm Max-flow min-cut theorem. (Ford-Fulkerson, 1956): In any network, Find s-t path where each arc has f(e) < u(e) and "augment" flow along it. the value of max flow equals capacity of min cut. Proof IOU: we find flow and cut such that Observation 3 applies. Flow value = 0 Min cut capacity = 28 Max flow value = 28 flow 4 capacity 5 9 0 2 9 5 0 4 0 4 10 0 4 1 9 10 4 4 0 15 15 0 10 0 0 0 s 10 2 13 3 10 t 4 8 9 s 5 3 8 6 10 t S 15 4 10 4 0 6 15 0 15 10 15 4 30 7 17 18 Towards an Algorithm Towards an Algorithm Find s-t path where each arc has f(e) < u(e) and "augment" flow along it. Find s-t path where each arc has f(e) < u(e) and "augment" flow along it. Greedy algorithm: repeat until you get stuck. Greedy algorithm: repeat until you get stuck. Fails: need to be able to "backtrack." flow Flow value = 10 flow Flow value = 10 4 5 4 5 0 capacity 0 capacity 0 4 0 0 4 0 4 4 0 4 0 4 4 4 X0 10 X0 10 X0 10 X0 10 X0 10 X0 10 s 10 2 13 3 10 t s 10 2 13 3 10 t 4 5 Flow value = 14 Bottleneck capacity of path = 10 4 4 4 4 4 4 4 4 10 6 10 s 10 2 13 3 10 t 19 20 Residual Graph Augmenting Paths Augmenting path = path in residual graph. flow = f(e) Original graph. Increase flow along forward edges. 6 Flow f(e). Decrease flow along backward edges. v 17 w Edge e = v-w capacity = u(e) 4 5 4 4 Residual edge. residual 4 4 Edge e = v-w or w-v. s 10 2 10 3 10 t "Undo" flow sent. residual capacity = u(e) – f(e) 3 Residual graph. v 11 w 4 5 All the edges that have 6 4 X0 4 0X strictly positive residual capacity. residual capacity = f(e) 4 X0 4 original 4 4 X0 4 10 4 10X 6 10 s 10 2 13 3 10 t 21 22 Augmenting Paths Ford-Fulkerson Augmenting Path Algorithm Observation 4. If augmenting path, then not yet a max flow. Ford-Fulkerson algorithm. Generic method for solving max flow. Q. If no augmenting path, is it a max flow? while (there exists an augmenting path) { 4 5 Find augmenting path P 4 Compute bottleneck capacity of P 4 residual 4 Augment flow along P 4 } s 10 2 6 3 10 t 7 Questions. Does this lead to a maximum flow? yes 4 5 Flow value = 14 4 X0 How do we find an augmenting path? s-t path in residual graph 4 0X 4 X0 4 original 4 How many augmenting paths does it take? 4 X0 4 How much effort do we spending finding a path? 10 4 10X 6 10 s 10 2 13 3 10 t 23 24 Max-Flow Min-Cut Theorem Proof of Max-Flow Min-Cut Theorem Augmenting path theorem. A flow f is a max flow if and only if there (ii) (iii).