Maximum Flow
Total Page:16
File Type:pdf, Size:1020Kb
Algorithms ROBERT SEDGEWICK | KEVIN WAYNE 6.4 MAXIMUM FLOW ‣ introduction ‣ Ford-Fulkerson algorithm Algorithms ‣ maxflow-mincut theorem FOURTH EDITION ‣ analysis of running time ‣ Java implementation ROBERT SEDGEWICK | KEVIN WAYNE http://algs4.cs.princeton.edu ‣ applications 6.4 MAXIMUM FLOW ‣ introduction ‣ Ford-Fulkerson algorithm Algorithms ‣ maxflow-mincut theorem ‣ analysis of running time ‣ Java implementation ROBERT SEDGEWICK | KEVIN WAYNE http://algs4.cs.princeton.edu ‣ applications Mincut problem Input. An edge-weighted digraph, source vertex s, and target vertex t. each edge has a positive capacity capacity 9 4 15 15 10 10 s 5 8 10 t 15 4 6 15 10 16 3 Mincut problem Def. A st-cut (cut) is a partition of the vertices into two disjoint sets, with s in one set A and t in the other set B. Def. Its capacity is the sum of the capacities of the edges from A to B. 10 s 5 t 15 capacity = 10 + 5 + 15 = 30 4 Mincut problem Def. A st-cut (cut) is a partition of the vertices into two disjoint sets, with s in one set A and t in the other set B. Def. Its capacity is the sum of the capacities of the edges from A to B. 10 s 8 t don't count edges from B to A 16 capacity = 10 + 8 + 16 = 34 5 Mincut problem Def. A st-cut (cut) is a partition of the vertices into two disjoint sets, with s in one set A and t in the other set B. Def. Its capacity is the sum of the capacities of the edges from A to B. Minimum st-cut (mincut) problem. Find a cut of minimum capacity. 10 s 8 t 10 capacity = 10 + 8 + 10 = 28 6 Mincut application (RAND 1950s) "Free world" goal. Cut supplies (if cold war turns into real war). rail network connecting Soviet Union with Eastern European countries (map declassified by Pentagon in 1999) Figure 2 7 From Harris and Ross [1955]: Schematic diagram of the railway network of the Western So- viet Union and Eastern European countries, with a maximum flow of value 163,000 tons from Russia to Eastern Europe, and a cut of capacity 163,000 tons indicated as ‘The bottleneck’. Potential mincut application (2010s) Government-in-power’s goal. Cut off communication to set of people. 8 Maxflow problem Input. An edge-weighted digraph, source vertex s, and target vertex t. each edge has a positive capacity capacity 9 15 10 4 15 10 s 5 8 10 t 15 6 4 15 10 16 9 Maxflow problem Def. An st-flow (flow) is an assignment of values to the edges such that: ・Capacity constraint: 0 ≤ edge's flow ≤ edge's capacity. ・Local equilibrium: inflow = outflow at every vertex (except s and t). flow capacity inflow at v = 5 + 5 + 0 = 10 5 / 9 outflow at v = 10 + 0 = 10 5 / 15 5 / 10 0 / 4 0 / 15 10 / 10 s 5 / 5 5 / 8 v 10 / 10 t 10 / 15 0 / 6 0 / 4 0 / 15 10 / 10 10 / 16 10 Maxflow problem Def. An st-flow (flow) is an assignment of values to the edges such that: ・Capacity constraint: 0 ≤ edge's flow ≤ edge's capacity. ・Local equilibrium: inflow = outflow at every vertex (except s and t). Def. The value of a flow is the inflow at t. we assume no edges point to s or from t 5 / 9 5 / 15 5 / 10 0 / 4 0 / 15 10 / 10 s 5 / 5 5 / 8 10 / 10 t value = 5 + 10 + 10 = 25 10 / 15 0 / 6 0 / 4 0 / 15 10 / 10 10 / 16 11 Maxflow problem Def. An st-flow (flow) is an assignment of values to the edges such that: ・Capacity constraint: 0 ≤ edge's flow ≤ edge's capacity. ・Local equilibrium: inflow = outflow at every vertex (except s and t). Def. The value of a flow is the inflow at t. Maximum st-flow (maxflow) problem. Find a flow of maximum value. 8 / 9 2 / 15 8 / 10 0 / 4 0 / 15 10 / 10 s 5 / 5 8 / 8 10 / 10 t value = 8 + 10 + 10 = 28 13 / 15 3 / 6 0 / 4 0 / 15 10 / 10 13 / 16 12 Maxflow application (Tolstoǐ 1930s) Soviet Union goal. Maximize flow of supplies to Eastern Europe. flow capacity rail network connecting Soviet Union with Eastern European countries (map declassifiedFigure by Pentagon2 in 1999) 13 From Harris and Ross [1955]: Schematic diagram of the railway network of the Western So- viet Union and Eastern European countries, with a maximum flow of value 163,000 tons from Russia to Eastern Europe, and a cut of capacity 163,000 tons indicated as ‘The bottleneck’. Potential maxflow application (2010s) "Free world" goal. Maximize flow of information to specified set of people. facebook graph 14 Summary Input. A weighted digraph, source vertex s, and target vertex t. Mincut problem. Find a cut of minimum capacity. Maxflow problem. Find a flow of maximum value. 8 / 9 2 / 15 8 / 10 0 / 4 0 / 15 10 10 / 10 s 5 / 5 8 / 8 10 / 10 t s 8 t 13 / 15 0 / 4 3 / 6 0 / 15 10 10 / 10 13 / 16 value of flow = 28 capacity of cut = 28 Remarkable fact. These two problems are dual! 15 6.4 MAXIMUM FLOW ‣ introduction ‣ Ford-Fulkerson algorithm Algorithms ‣ maxflow-mincut theorem ‣ analysis of running time ‣ Java implementation ROBERT SEDGEWICK | KEVIN WAYNE http://algs4.cs.princeton.edu ‣ applications Ford-Fulkerson algorithm Initialization. Start with 0 flow. flow capacity initialization 0 / 9 0 / 10 0 / 4 0 / 15 0 / 15 0 / 10 value of flow s 0 / 5 0 / 8 0 / 10 t 0 0 / 15 0 / 4 0 / 6 0 / 15 0 / 10 0 / 16 17 Idea: increase flow along augmenting paths Augmenting path. Find an undirected path from s to t such that: ・Can increase flow on forward edges (not full). ・Can decrease flow on backward edge (not empty). 1st augmenting path bottleneck capacity = 10 0 / 9 10 0 / 10 0 / 4 —0 / 15 0 / 15 10 —0 / 10 10 s 0 / 5 0 / 8 —0 / 10 t 0 + 10 = 10 0 / 15 0 / 4 0 / 6 0 / 15 0 / 10 0 / 16 18 Idea: increase flow along augmenting paths Augmenting path. Find an undirected path from s to t such that: ・Can increase flow on forward edges (not full). ・Can decrease flow on backward edge (not empty). 2nd augmenting path 0 / 9 0 / 10 0 / 4 10 / 15 0 / 15 10 / 10 s 0 / 5 0 / 8 10 / 10 t 10 + 10 = 20 10 —0 / 15 0 / 4 0 / 6 0 / 15 10 —0 / 10 10 —0 / 16 19 Idea: increase flow along augmenting paths Augmenting path. Find an undirected path from s to t such that: ・Can increase flow on forward edges (not full). ・Can decrease flow on backward edge (not empty). 3rd augmenting path backward edge 5 —0 / 9 (not empty) 5 5 —0 / 10 0 / 4 10— / 15 0 / 15 10 / 10 5 5 s —0 / 5 —0 / 8 10 / 10 t 20 + 5 = 25 10 / 15 0 / 4 0 / 6 0 / 15 10 / 10 10 / 16 20 Idea: increase flow along augmenting paths Augmenting path. Find an undirected path from s to t such that: ・Can increase flow on forward edges (not full). ・Can decrease flow on backward edge (not empty). 4th augmenting path backward edge 8 —5 / 9 (not empty) 2 8 —5 / 10 0 / 4 —5 / 15 0 / 15 10 / 10 8 s 5 / 5 —5 / 8 10 / 10 t 25 + 3 = 28 13 10— / 15 3 0 / 4 —0 / 6 0 / 15 10 / 10 13 10— / 16 21 Idea: increase flow along augmenting paths Termination. All paths from s to t are blocked by either a ・Full forward edge. ・Empty backward edge. no more augmenting paths 8 / 9 8 / 10 0 / 4 2 / 15 0 / 15 10 / 10 s 5 / 5 8 / 8 10 / 10 t 28 13 / 15 0 / 4 3 / 6 0 / 15 10 / 10 full forward edge 13 / 16 empty backward edge 22 Ford-Fulkerson algorithm Ford-Fulkerson algorithm Start with 0 flow. While there exists an augmenting path: - find an augmenting path - compute bottleneck capacity - increase flow on that path by bottleneck capacity Questions. ・How to compute a mincut? ・How to find an augmenting path? ・If FF terminates, does it always compute a maxflow? ・Does FF always terminate? If so, after how many augmentations? 23 6.4 MAXIMUM FLOW ‣ introduction ‣ Ford-Fulkerson algorithm Algorithms ‣ maxflow-mincut theorem ‣ analysis of running time ‣ Java implementation ROBERT SEDGEWICK | KEVIN WAYNE http://algs4.cs.princeton.edu ‣ applications Relationship between flows and cuts Def. The net flow across a cut (A, B) is the sum of the flows on its edges from A to B minus the sum of the flows on its edges from B to A. net flow across cut = 5 + 10 + 10 = 25 5 / 9 5 / 15 5 / 10 0 / 4 0 / 15 10 / 10 s 5 / 5 5 / 8 10 / 10 t value of flow = 25 10 / 15 0 / 6 0 / 4 0 / 15 10 / 10 10 / 16 25 Relationship between flows and cuts Def. The net flow across a cut (A, B) is the sum of the flows on its edges from A to B minus the sum of the flows on its edges from B to A. net flow across cut = 10 + 5 + 10 = 25 5 / 9 5 / 15 5 / 10 0 / 4 0 / 15 10 / 10 s 5 / 5 5 / 8 10 / 10 t value of flow = 25 10 / 15 0 / 6 0 / 4 0 / 15 10 / 10 10 / 16 26 Relationship between flows and cuts Def.