Algorihm ROBERT SEDGEWICK KEVIN WAYNE 6.4 MAXIMUM FLOW Algorihm F O U R T H E D I T I O N ROBERT SEDGEWICK KEVIN WAYNE hp://alg4.c.princeon.edu inroducion Ford Fulkeron algorihm maxflow mincu heorem analyi of running ime Java implemenaion (ee video) applicaion La updaed on 11/20/18 2:32 AM
6.4 MAXIMUM FLOW Algorihm ROBERT SEDGEWICK KEVIN WAYNE hp://alg4.c.princeon.edu inroducion Ford Fulkeron algorihm maxflow mincu heorem analyi of running ime Java implemenaion applicaion
Mincu problem Inpu. An edge-weighed digraph, ource verex, and arge verex. each edge ha a poiive capaciy capaciy 9 10 4 15 15 10 5 8 10 15 4 6 15 10 16 3
Mincu problem Def. A -cu (cu) i a pariion of he verice ino wo dijoin e, wih in one e A and in he oher e B. Def. I capaciy i he um of he capaciie of he edge from A o B. A 10 5 15 capaciy = 10 + 5 + 15 = 30 4
Mincu problem Def. A -cu (cu) i a pariion of he verice ino wo dijoin e, wih in one e A and in he oher e B. Def. I capaciy i he um of he capaciie of he edge from A o B. 10 8 A don' coun edge from B o A capaciy = 10 + 8 + 16 = 34 16 5
Mincu problem Def. A -cu (cu) i a pariion of he verice ino wo dijoin e, wih in one e A and in he oher e B. Def. I capaciy i he um of he capaciie of he edge from A o B. Minimum -cu (mincu) problem. Find a cu of minimum capaciy. 10 8 A 10 capaciy = 10 + 8 + 10 = 28 6
Maxflow: quiz 1 Wha i he capaciy of he -cu { A, E, F, G }? A. 11 (20 + 25 8 11 9 6) B. 34 (8 + 11 + 9 + 6) C. 45 (20 + 25) D. 79 (20 + 25 + 8 + 11 + 9 + 6) ource capaciy A 20 B 8 C 10 D 6 12 8 11 9 6 8 E 1 F 16 G 25 H arge 7
Mincu applicaion (RAND 1950) Free world goal. Cu upplie (if Cold War urn ino real war). rail nework connecing Sovie Union wih Eaern European counrie (map declaified by Penagon in 1999) 8
Maxflow problem Efficien Maximum Flow Algorihm by Andrew Goldberg and Bob Tarjan hp://vimeo.com/774435 9
Maxflow problem Inpu. An edge-weighed digraph, ource verex, and arge verex. each edge ha a poiive capaciy capaciy 9 10 4 15 15 10 5 8 10 15 6 4 15 10 16 10
v Maxflow problem Def. An -flow (flow) i an aignmen of value o he edge uch ha: Capaciy conrain: 0 edge flow edge capaciy. Local equilibrium: inflow = ouflow a every verex (excep and ). flow capaciy inflow a v = 5 + 5 + 0 = 10 5 / 9 ouflow a v = 10 + 0 = 10 0 / 4 5 / 15 5 / 10 5 / 5 5 / 8 1 0 / 4 0 / 6 10 / 16 11
Maxflow problem Def. An -flow (flow) i an aignmen of value o he edge uch ha: Capaciy conrain: 0 edge flow edge capaciy. Local equilibrium: inflow = ouflow a every verex (excep and ). Def. The value of a flow i he inflow a. we aume no edge poin o or from 5 / 9 0 / 4 5 / 15 5 / 10 5 / 5 5 / 8 value = 5 + 10 + 10 = 25 1 0 / 4 0 / 6 10 / 16 12
Maxflow problem Def. An -flow (flow) i an aignmen of value o he edge uch ha: Capaciy conrain: 0 edge flow edge capaciy. Local equilibrium: inflow = ouflow a every verex (excep and ). Def. The value of a flow i he inflow a. Maximum -flow (maxflow) problem. Find a flow of maximum value. 8 / 9 0 / 4 2 / 15 8 / 10 5 / 5 8 / 8 value = 8 + 10 + 10 = 28 13 / 15 0 / 4 3 / 6 13 / 16 13
Maxflow applicaion (Toloǐ 1930) Sovie Union goal. Maximize flow of upplie o Eaern Europe. flow capaciy rail nework connecing Sovie Union wih Eaern European counrie (map declaified by Penagon in 1999) 14
Summary Inpu. An edge-weighed digraph, ource verex, and arge verex. Mincu problem. Find a cu of minimum capaciy. Maxflow problem. Find a flow of maximum value. 5 / 5 13 / 15 0 / 4 0 / 4 8 / 9 2 / 15 8 / 8 3 / 6 13 / 16 value of flow = 28 capaciy of cu = 28 Remarkable fac. Thee wo problem are dual! 8 / 10 10 8 10 15
6.4 MAXIMUM FLOW Algorihm ROBERT SEDGEWICK KEVIN WAYNE hp://alg4.c.princeon.edu inroducion Ford Fulkeron algorihm maxflow mincu heorem analyi of running ime Java implemenaion applicaion
Ford Fulkeron algorihm Iniializaion. Sar wih 0 flow. iniializaion flow capaciy 0 / 9 0 / 10 0 / 4 0 / 10 value of flow 0 / 5 0 / 8 0 / 10 0 0 / 4 0 / 6 0 / 10 0 / 16 17
Idea: increae flow along augmening pah Augmening pah. Find an undireced pah from o uch ha: Can increae flow on forward edge (no full). Can decreae flow on backward edge (no empy). 1 augmening pah 0 / 9 boleneck capaciy = 10 10 0 / 10 10 0 / 4 10 0 / 10 0 / 5 0 / 8 10 0 / 10 0 + 10 = 10 0 / 4 0 / 6 0 / 10 0 / 16 18
Idea: increae flow along augmening pah Augmening pah. Find an undireced pah from o uch ha: Can increae flow on forward edge (no full). Can decreae flow on backward edge (no empy). 2 nd augmening pah 0 / 9 0 / 4 1 0 / 10 0 / 5 0 / 8 10 + 10 = 20 10 15 0 / 4 0 / 6 10 0 / 10 10 10 0 / 16 19
Idea: increae flow along augmening pah Augmening pah. Find an undireced pah from o uch ha: Can increae flow on forward edge (no full). Can decreae flow on backward edge (no empy). 3 rd augmening pah 5 0 / 9 backward edge (no empy) 0 / 4 5 10 / 15 5 0 / 10 10 5 0 / 5 5 0 / 8 20 + 5 = 25 1 0 / 6 0 / 4 10 / 16 20
Idea: increae flow along augmening pah Augmening pah. Find an undireced pah from o uch ha: Can increae flow on forward edge (no full). Can decreae flow on backward edge (no empy). 4 h augmening pah 8 5 / 9 backward edge (no empy) 0 / 4 2 5 / 15 8 5 / 10 10 5 / 5 8 5 / 8 25 + 3 = 28 13 10 10 / 15 15 3 0 / 6 0 / 4 13 10 / 16 21
Idea: increae flow along augmening pah Terminaion. All pah from o are blocked by eiher a Full forward edge. Empy backward edge. no more augmening pah 8 / 9 0 / 4 2 / 15 8 / 10 5 / 5 8 / 8 28 13 / 15 3 / 6 0 / 4 13 / 16 full forward edge empy backward edge 22
Maxflow: quiz 2 Which i he augmening pah of highe boleneck capaciy? A. A F G H B. A B C D H C. A F B G H D. A F B G C D H flow capaciy A 20 / 20 B 8 / 8 C 4 / 10 D ource 1 / 6 5 / 12 8 / 8 4 / 11 4 / 9 0 / 6 4 / 8 E 1 / 1 F 14 / 16 G 22 / 25 H arge 23
Ford Fulkeron algorihm Ford Fulkeron algorihm Sar wih 0 flow. While here exi an augmening pah: - find an augmening pah - compue boleneck capaciy - updae flow on ha pah by boleneck capaciy Fundamenal queion. How o find an augmening pah? How many augmening pah? Guaraneed o compue a maxflow? Given a maxflow, how o compue a mincu? 25
6.4 MAXIMUM FLOW Algorihm ROBERT SEDGEWICK KEVIN WAYNE hp://alg4.c.princeon.edu inroducion Ford Fulkeron algorihm maxflow mincu heorem analyi of running ime Java implemenaion applicaion
Relaionhip beween flow and cu Def. The ne flow acro a cu (A, B) i he um of he flow on i edge from A o B minu he um of he flow on i edge from B o A. ne flow acro cu = 5 + 10 + 10 = 25 5 / 9 0 / 4 5 / 15 5 / 10 5 / 5 5 / 8 value of flow = 25 1 0 / 4 0 / 6 10 / 16 27
Relaionhip beween flow and cu Def. The ne flow acro a cu (A, B) i he um of he flow on i edge from A o B minu he um of he flow on i edge from B o A. ne flow acro cu = 10 + 5 + 10 = 25 5 / 9 0 / 4 5 / 15 5 / 10 5 / 5 5 / 8 value of flow = 25 1 0 / 4 0 / 6 10 / 16 28
Relaionhip beween flow and cu Def. The ne flow acro a cu (A, B) i he um of he flow on i edge from A o B minu he um of he flow on i edge from B o A. ne flow acro cu = (10 + 10 + 5 + 10 + 0 + 0) (5 + 5 + 0 + 0) = 25 5 / 9 0 / 4 5 / 15 5 / 10 edge from B o A 5 / 5 5 / 8 value of flow = 25 1 0 / 4 0 / 6 10 / 16 29
Maxflow: quiz 3 Which i he ne flow acro he -cu { A, E, F, G }? A. 11 (20 + 25 8 11 9 6) B. 26 (20 + 22 8 4 4) C. 42 (20 + 22) D. 45 (20 + 25) flow capaciy A 20 / 20 B 8 / 8 C 4 / 10 D ource 1 / 6 5 / 12 8 / 8 4 / 11 4 / 9 0 / 6 4 / 8 E 1 / 1 F 14 / 16 G 22 / 25 H arge 30
Relaionhip beween flow and cu Flow value lemma. Le f be any flow and le (A, B) be any cu. Then, he ne flow acro (A, B) equal he value of f. Inuiion. Conervaion of flow. Pf. By inducion on he ize of B. Bae cae: B = { }. Inducion ep: remain rue by local equilibrium when moving any verex from A o B. Corollary. Ouflow from = inflow o = value of flow. 31
Relaionhip beween flow and cu Weak dualiy. Le f be any flow and le (A, B) be any cu. Then, he value of he flow f he capaciy of he cu (A, B). Pf. Value of flow f = ne flow acro cu (A, B) capaciy of cu (A, B). flow value lemma flow bounded by capaciy 8 / 9 0 / 4 2 / 15 8 / 10 10 5 / 5 7 / 8 9 / 10 5 12 / 15 0 / 4 2 / 6 15 12 / 16 value of flow = 27 capaciy of cu = 30 32
Maxflow mincu heorem Augmening pah heorem. A flow f i a maxflow iff no augmening pah. Maxflow mincu heorem. Value of he maxflow = capaciy of mincu. Pf. For any flow f, he following hree condiion are equivalen: i. f i a maxflow. ii. There i no augmening pah wih repec o f. iii. There exi a cu whoe capaciy equal he value of he flow f. [ i ii ] We prove conrapoiive: ~ii ~i. rong dualiy Suppoe ha here i an augmening pah wih repec o f. Can improve flow f by ending flow along hi pah. Thu, f i no a maxflow. 33
Maxflow mincu heorem Augmening pah heorem. A flow f i a maxflow iff no augmening pah. Maxflow mincu heorem. Value of he maxflow = capaciy of mincu. Pf. For any flow f, he following hree condiion are equivalen: i. f i a maxflow. ii. There i no augmening pah wih repec o f. iii. There exi a cu whoe capaciy equal he value of he flow f. [ iii i ] Suppoe ha (A, B) i a cu wih capaciy equal o he value of f. Then, he value of any flow f ' capaciy of (A, B) = value of f. Thu, f i a maxflow. weak dualiy by aumpion 34
Maxflow mincu heorem [ ii iii ] Le f be a flow wih no augmening pah. Le A be e of verice conneced o by an undireced pah wih no full forward or empy backward edge. By definiion of cu (A, B), i in A. By definiion of cu (A, B) and flow f, i in B. Capaciy of (A, B) = ne flow acro cu = value of flow f. A G backward edge from B o A (flow = 0) B flow value lemma forward edge from A o B (flow = capaciy) 35
Compuing a mincu from a maxflow To compue mincu (A, B) from maxflow f : By augmening pah heorem, no augmening pah wih repec o f. Compue A = e of verice conneced o by an undireced pah wih no full forward or empy backward edge. Capaciy of cu (A, B) = value of flow f. 8 / 9 0 / 4 2 / 15 8 / 10 5 / 5 8 / 8 A 13 13 / 15 15 3 / 4 6 / 6 forward edge (no full) 16 / 16 full forward edge empy backward edge backward edge (no empy) 36
Maxflow: quiz 4 Given he following maxflow, which i a mincu? A. S = { A }. B. S = { A, B, C, E, F }. C. Boh A and B. D. Neiher A nor B. flow capaciy A 20 / 20 B 8 / 9 C 8 / 8 D ource 1 / 1 11 / 13 4 / 8 8 / 8 0 / 9 0 / 6 8 / 8 E 1 / 1 F 16 / 16 G 24 / 25 H arge 37
6.4 MAXIMUM FLOW Algorihm ROBERT SEDGEWICK KEVIN WAYNE hp://alg4.c.princeon.edu inroducion Ford Fulkeron algorihm maxflow mincu heorem analyi of running ime Java implemenaion applicaion
Ford Fulkeron algorihm analyi (wih ineger capaciie) Imporan pecial cae. Edge capaciie are ineger beween 1 and U. Invarian. The flow i inegral hroughou Ford Fulkeron. Pf. [by inducion] Boleneck capaciy i an ineger. Flow on an edge increae/decreae by boleneck capaciy. Propoiion. Number of augmenaion he value of he maxflow. Pf. Each augmenaion increae he value by a lea 1. Inegraliy heorem. There exi an inegral maxflow. Pf. flow on each edge i an ineger criical for ome applicaion (ay uned) Propoiion + Augmening pah heorem FF erminae wih maxflow. Propoiion + Invarian FF erminae wih an inegral flow. 39
0 0 Bad cae for Ford Fulkeron Bad new. Even when edge capaciie are ineger, number of augmening pah could be very large. iniialize wih 0 flow 0 flow capaciy 0 1 0 40
Bad cae for Ford Fulkeron Bad new. Even when edge capaciie are ineger, number of augmening pah could be very large. 1 augmening pah 0 1 0 0 1 1 0 0 1 41
Bad cae for Ford Fulkeron Bad new. Even when edge capaciie are ineger, number of augmening pah could be very large. 2 nd augmening pah 1 0 1 1 1 0 0 1 1 42
Bad cae for Ford Fulkeron Bad new. Even when edge capaciie are ineger, number of augmening pah could be very large. 3 rd augmening pah 1 2 1 0 1 1 1 1 2 43
Bad cae for Ford Fulkeron Bad new. Even when edge capaciie are ineger, number of augmening pah could be very large. 4 h augmening pah 2 1 2 1 1 0 1 2 2 44
Bad cae for Ford Fulkeron Bad new. Even when edge capaciie are ineger, number of augmening pah could be very large.... 45
Bad cae for Ford Fulkeron Bad new. Even when edge capaciie are ineger, number of augmening pah could be very large. 199 h augmening pah 99 99 0 1 1 99 99 46
Bad cae for Ford Fulkeron Bad new. Even when edge capaciie are ineger, number of augmening pah could be very large. 200 h augmening pah 99 1 1 0 99 47
Bad cae for Ford Fulkeron Bad new. Even when edge capaciie are ineger, number of augmening pah could be very large. exponenial in inpu ize 0 1 48
How o chooe augmening pah? Good new. Clever choice lead o efficien algorihm. augmening pah number of pah implemenaion hore pah (fewe edge) ½ E V queue (BFS) fae pah (max boleneck capaciy) E ln(e U) prioriy queue flow nework wih V verice, E edge, and ineger capaciie beween 1 and U Theoreical Improvemen in Algorihmic Efficiency for Nework Flow Problem JACK EDMONDS Univeriy of Waerloo, Waerloo, Onario, Canada AND RICHARD M. KARP Univeriy of California, Berkeley, California ABSTRACT. Thi paper preen new algorihm for he maximum flow problem, he Hichcock ranporaion problem, and he general minimum-co flow problem. Upper bound on he number of ep in hee algorihm are derived, and are hown o compale favorably wih upper bound on he number of ep required by earlier algorihm. Edmond-Karp 1972 (USA) Dinic 1970 (Sovie Union) 49
6.4 MAXIMUM FLOW Algorihm ROBERT SEDGEWICK KEVIN WAYNE hp://alg4.c.princeon.edu inroducion Ford Fulkeron algorihm maxflow mincu heorem analyi of running ime Java implemenaion applicaion
Maxflow and mincu applicaion Maxflow/mincu i a widely applicable problem-olving model. Daa mining. Open-pi mining. Biparie maching. Nework reliabiliy. Baeball eliminaion. Image egmenaion. Nework conneciviy. Diribued compuing. Securiy of aiical daa. Egaliarian able maching. Muli-camera cene reconrucion. Senor placemen for homeland ecuriy. Many, many, more. liver and hepaic vacularizaion egmenaion 51
Biparie maching problem Problem. Given n people and n ak, aign he ak o people o ha: Every ak i aigned o a qualified peron. Every peron i aigned o exacly one ak. 52
Biparie maching problem Problem. Given a biparie graph, find a perfec maching (if one exi). biparie graph perfec maching 1 2 3 6 7 8 1 9 2 6 3 8 4 10 5 7 4 9 5 10 n ak n people peron 10 i qualified o perform ak 4 and 5 53
Maxflow formulaion of biparie maching Creae,, one verex for each ak, and one verex for each peron. Add edge from o each ak (of capaciy 1). Add edge from each peron o (of capaciy 1). Add edge from ak o qualified peron (of infinie capaciy). flow nework 1 6 1 1 2 7 3 8 4 9 5 10 n ak n people 54
Maxflow formulaion of biparie maching 1 1 correpondence beween perfec maching in biparie graph and inegral flow of value n in flow nework. Inegraliy heorem + 1 1 correpondence Maxflow formulaion i correc. flow nework 1 6 2 7 3 8 4 9 5 10 n ak n people 55
Maxflow: quiz 5 How many augmenaion doe he Ford Fulkeron algorihm make o find a perfec maching in a biparie graph wih n verice per ide? A. n value of flow n B. n 2 C. n 3 D. n 4 56
Maximum flow algorihm: heory (Ye anoher) holy grail for heoreical compuer cieni. year mehod wor cae dicovered by 1951 implex E 3 U Danzig 1955 augmening pah E 2 U Ford Fulkeron 1970 hore augmening pah E 3 Diniz, Edmond Karp 1970 fae augmening pah E 2 log E log( E U ) Diniz, Edmond Karp 1977 blocking flow E 5/2 Cherkaky 1978 blocking flow E 7/3 Galil 1983 dynamic ree E 2 log E Sleaor Tarjan 1985 capaciy caling E 2 log U Gabow 1997 lengh funcion E 3/2 log E log U Goldberg Rao 2012 compac nework E 2 / log E Orlin?? E? maxflow algorihm for pare nework wih E edge, ineger capaciie beween 1 and U 57
Maximum flow algorihm: pracice Warning. Wor-cae order-of-growh i generally no ueful for predicing or comparing maxflow algorihm performance in pracice. Be in pracice. Puh relabel mehod wih gap relabeling: E 3/2. Compuer viion. Specialized algorihm for problem wih pecial rucure. On Implemening Puh-Relabel Mehod for he Maximum Flow Problem Bori V. Cherkaky 1 and Andrew V. Goldberg 2 1 Cenral Iniue for Economic and Mahemaic, Kraikova S. 32, 117418, Mocow, Ruia cher@eemi.mk.u 2 Compuer Science Deparmen, Sanford Univeriy Sanford, CA 94305, USA goldberg ~c. anford, edu Abrac. We udy efficien implemenaion of he puh-relabel mehod for he maximum flow problem. The reuling code are faer han he previou code, and much faer on ome problem familie. The peedup i due o he combinaion of heuriic ued in our implemenaion. We alo exhibi a family of problem for which he running ime of all known mehod eem o have a roughly quadraic growh rae. ELSEVIER European Journal of Operaional Reearch 97 (1997) 509-542 Theory and Mehodology EUROPEAN JOURNAL OF OPERATIONAL RESEARCH Compuaional inveigaion of maximum flow algorihm Ravindra K. Ahuja a, Murali Kodialam a b, Ajay K. Mihra c, Jame B. Orlin d,. Deparmen ~'lndurial and Managemen Engineering. Indian Iniue of Technology. Kanpur, 208 016, India b AT& T Bell Laboraorie, Holmdel, NJ 07733, USA c KA'F-Z Graduae School of Buine, Univeriy of Piburgh, Piburgh, PA 15260, USA d Sloun School of Managemen, Maachue Iniue of Technology. Cambridge. MA 02139. USA Received 30 Augu 1995; acceped 27 June 1996 58
Summary Mincu problem. Find an -cu of minimum capaciy. Maxflow problem. Find an -flow of maximum value. Dualiy. Value of he maxflow = capaciy of mincu. Proven ucceful approache. Ford Fulkeron (variou augmening-pah raegie). Preflow puh (variou verion). Open reearch challenge. Pracice: olve real-world maxflow/mincu problem in linear ime. Theory: prove i for wor-cae inpu. Sill much o be learned! 59