CS 473G Lecure 1: Max-Flow Algorihm and Applicaion Fall 200 1 Max-Flow Algorihm and Applicaion (November 1) 1.1 Recap Fix a direced graph G = (V, E) ha doe no conain boh an edge u v and i reveral v u, and fix a capaciy funcion c : E IR +. For any flow funcion f : E IR 0, he reidual capaciy i defined a c(u v) f(u v) if u v E c f (u v) = f(v u) if v u E. 0 oherwie The reidual graph G f = (V, E f ), where E f i he e of edge whoe non-zero reidual capaciy i poiive. 0/ /20 / 0/1 / /1 1 0/ /20 1 / / A flow f in a weighed graph G and i reidual graph G f. In he la lecure, we proved he Max-flow Min-cu Theorem: In any weighed direced graph nework, he value of he maximum (, )-flow i equal o he co of he minimum (, )-cu. The proof of he heorem i conrucive. If he reidual graph conain a pah from o, hen we can increae he flow by he minimum capaciy of he edge on hi pah, o we mu no have he maximum flow. Oherwie, we can define a cu (S, T ) whoe co i he ame a he flow f, uch ha every edge from S o T i auraed and every edge from T o S i empy, which implie ha f i a maximum flow and (S, T ) i a minimum cu. / 1 /20 / 0/1 0/ /1 1 / /20 / / An augmening pah in G f and he reuling (maximum) flow f. 1.2 Ford-Fulkeron I no hard o realize ha hi proof ranlae almo immediaely o an algorihm, fir developed by Ford and Fulkeron in he 190: Saring wih he zero flow, repeaedly augmen he flow along any pah in he reidual graph, unil here i no uch pah. If every edge capaciy i an ineger, hen every augmenaion ep increae he value of he flow by a poiive ineger. Thu, he algorihm hal afer f ieraion, where f i he acual 1
CS 473G Lecure 1: Max-Flow Algorihm and Applicaion Fall 200 maximum flow. Each ieraion require O(E) ime, o creae he reidual graph G f and perform a whaever-fir-earch o find an augmening pah. Thu, in he word cae, he Ford-Fulkeron algorihm run in O(E f ) ime. If we muliply all he capaciie by he ame (poiive) conan, he maximum flow increae everywhere by he ame conan facor. I follow ha if all he edge capaciie are raional, hen he Ford-Fulkeron algorihm evenually hal. However, if we allow irraional capaciie, he algorihm can loop forever, alway finding maller and maller augmening pah. Wore ye, hi infinie equence of augmenaion may no even converge o he maximum flow! One of he imple example of hi effec wa dicovered by Uri Zwick. Conider he graph hown below, wih ix verice and nine edge. Six of he edge have ome large ineger capaciy, wo have capaciy 1, and one ha capaciy φ = ( 1)/2 0.618034, choen o ha 1 φ = φ 2. To prove ha he Ford-Fulkeron algorihm can ge uck, we wach he reidual capaciie of he hree horizonal edge a he algorihm progree. (The reidual capaciie of he oher ix edge will alway be a lea 3.) 1 1 φ A B C Uri Zwick non-erminaing flow example, and hree augmening pah. The Ford-Fulkeron algorihm ar by chooing he cenral augmening pah, hown in he large figure above. The hree horizonal edge,, in order from lef o righ, now have reidual capaciie 1, 0, φ. Suppoe he horizonal reidual capaciie are φ k 1, 0, and φ k for ome nonnegaive ineger k. 1. Augmen along B, adding φ k o he flow; he reidual capaciie are now φ k+1, φ k, 0. 2. Augmen along C, adding φ k o he flow; he reidual capaciie are now φ k+1, 0, φ k. 3. Augmen along B, adding φ k+1 o he flow; he reidual capaciie are now 0, φ k+1, φ k+2. 4. Augmen along A, adding φ k+1 o he flow; he reidual capaciie are now φ k+1, 0, φ k+2. Thu, afer 4n + 1 augmenaion ep, he reidual capaciie are φ 2n 2, 0, φ 2n 1. A he number of augmenaion ep grow o infiniy, he value of he flow converge o 1 + 2 i=1 φ i = 1 + 2 1 φ = 4 + < 7, even hough he maximum flow value i clearly 2 + 1. 2
CS 473G Lecure 1: Max-Flow Algorihm and Applicaion Fall 200 Picky uden migh wonder a hi poin why we care abou irraional capaciie; afer all, compuer can repreen anyhing bu (mall) ineger or (dyadic) raional exacly. Good queion! One reaon i ha he ineger rericion i lierally arificial; i an arifac of acual compuaional hardware 1, no an inheren feaure of he abrac mahemaical problem. Anoher reaon, which i probably more convincing o mo pracical compuer cieni, i ha he behavior of he algorihm wih irraional inpu ell u omehing abou i wor-cae behavior in pracice given floaing-poin capaciie errible! Even wih very reaonable capaciie, a carele implemenaion of Ford-Fulkeron could ener an infinie loop imply becaue of round-off error! 1.3 Edmond-Karp: Fa Pipe The Ford-Fulkeron algorihm doe no pecify which alernaing pah o ue if here i more han one. In 1972, Jack Edmond and Richard Karp analyzed wo naural heuriic for chooing he pah. The fir i eenially a greedy algorihm: Chooe he augmening pah wih large boleneck value. I a fairly eay o how ha he maximum-boleneck (, )-pah in a direced graph can be compued in O(E log V ) ime uing a varian of Jarník minimum-panning-ree algorihm, or of Dijkra hore pah algorihm. Simply grow a direced panning ree T, rooed a. Repeaedly find he highe-capaciy edge leaving T and add i o T, unil T conain a pah from o. Alernaely, once could emulae Krukal algorihm iner edge one a a ime in decreaing capaciy order unil here i a pah from o alhough hi i le efficien. We can now analyze he algorihm in erm of he value of he maximum flow f. Le f be any flow in G, and le f be he maximum flow in he curren reidual graph G f. (A he beginning of he algorihm, G f = G and f = f.) Le e be he boleneck edge in he nex augmening pah. Le S be he e of verice reachable from hrough edge wih capaciy greaer han c(e) and le T = V \ S. By conrucion, T i non-empy, and every edge from S o T ha capaciy a mo c(e). Thu, he co of he cu (S, T ) i a mo c(e) E. On he oher hand, S, T f, which implie ha c(e) f /E. Thu, augmening f along he maximum-boleneck pah in G f muliplie he maximum flow value in G f by a facor of a mo 1 1/E. In oher word, he reidual flow decay exponenially wih he number of ieraion. Afer E ln f ieraion, he maximum flow value in G f i a mo f (1 1/E) E ln f < f e ln f = 1. (Tha Euler conan e, no he edge e. Sorry.) In paricular, if all he capaciie are ineger, hen afer E ln f ieraion, he maximum capaciy of he reidual graph i zero and f i a maximum flow. We conclude ha for graph wih ineger capaciie, he Edmond-Karp fa pipe algorihm run in O(E 2 log E log f ) ime. 1.4 Dini/Edmond-Karp: Shor Pipe The econd Edmond-Karp heuriic wa acually propoed by Ford and Fulkeron in heir original max-flow paper, and fir analyzed by he Ruian mahemaician Dini (omeime ranlieraed Dinic) in 1970. Edmond and Karp publihed heir independen and lighly weaker analyi in 1972. So naurally, almo everyone refer o hi algorihm a Edmond-Karp. 1...or perhap he law of phyic. Yeah, righ. Whaever. Like realiy acually maer in hi cla. 3
CS 473G Lecure 1: Max-Flow Algorihm and Applicaion Fall 200 Chooe he augmening pah wih fewe edge. The correc pah can be found in O(E) ime by running breadh-fir earch in he reidual graph. More urpriingly, he algorihm hal afer a polynomial number of ieraion, independen of of he acual edge capaciie! The proof of hi upper bound relie on wo obervaion abou he evoluion of he reidual graph. Le f i be he curren flow afer i augmenaion ep, le G i be he correponding reidual graph. In paricular, f 0 i zero everywhere and G 0 = G. For each verex v, le level i (v) denoe he unweighed hore pah diance from o v in G i, or equivalenly, he level of v in a breadh-fir earch ree of G i rooed a. Our fir obervaion i ha hee level can only increae over ime. Lemma 1. level i+1 (v) level i (v) for all verice v and ineger i. Proof: The claim i rivial for v =, ince level i () = 0 for all i. Chooe an arbirary verex v, and le p u v be a hore pah from o v in G i+1. (If here i no uch pah, hen level i+1 (v) =, and we re done.) Becaue hi i a hore pah, we have level i+1 (v) = level i+1 (u) + 1, and he inducive hypohei implie ha level i+1 (u) level i (u). We now have wo cae o conider. If u v i an edge in G i, hen level i (v) level i (u) + 1, becaue he level are defined by breadh-fir raveral. On he oher hand, if u v i no an edge in G i, hen v u mu be an edge in he ih augmening pah. Thu, v u mu lie on he hore pah from o in G i, which implie ha level i (v) = level i (u) 1 level i (u) + 1. In boh cae, we have level i+1 (v) = level i+1 (u) + 1 level i (u) + 1 level i (v). Whenever we augmen he flow, he boleneck edge in he augmening pah diappear from he reidual graph, and ome oher edge in he reveral of he augmening pah may (re-)appear. Our econd obervaion i ha an edge canno appear or diappear oo many ime. Lemma 2. During he execuion of he Dini/Edmond-Karp algorihm, any edge u v diappear from he reidual graph G f a mo V/2 ime. Proof: Suppoe u v i in wo reidual graph G i and G j+1, bu no in any of he inermediae reidual graph G i+1,..., G j, for ome i < j. Then u v mu be in he ih augmening pah, o level i (v) = level i (u)+1, and v u mu be on he jh augmening pah, o level j (v) = level j (u) 1. By he previou lemma, we have level j (u) = level j (v) + 1 level i (v) + 1 = level i (u) + 2. In oher word, he diance from o u increaed by a lea 2 beween he diappearance and reappearance of u v. Since every level i eiher le han V or infinie, he number of diappearance i a move V/2. Now we can derive an upper bound on he number of ieraion. Since each edge can diappear a mo V/2 ime, here are a mo EV/2 edge diappearance overall. Bu a lea one edge diappear on each ieraion, o he algorihm mu hal afer a mo EV/2 ieraion. Finally, ince each ieraion require O(E) ime, Dini algorihm run in O(V E 2 ) ime overall. 4
CS 473G Lecure 1: Max-Flow Algorihm and Applicaion Fall 200 1. Maximum Maching in Biparie Graph Perhap one of he imple applicaion of maximum flow i in compuing a maximum-ize maching in a biparie graph. A maching i a ubgraph in which every verex ha degree a mo one, or equivalenly, a collecion of edge uch ha no wo hare a verex. The problem i o find he large maching in a given biparie graph. We can olve hi problem by reducing i o a maximum flow problem a follow. Le G be he given biparie graph wih verex e V = U W, uch ha every edge join a verex in U o a verex in W. We creae a new direced graph G by (1) oriening each edge from U o W, (2) adding wo new verice and, (3) adding edge from o every verex in U, and (4) adding edge from each verex in W o. Finally, we aign every edge in G a capaciy of 1. Any maching M in G can be ranformed ino a flow f M in G a follow: For each edge (u, w) in M, puh one uni of flow along he pah u w. Thee pah are dijoin excep a and, o he reuling flow aifie he capaciy conrain. Moreover, he value of he reuling flow i equal o he number of edge in M. Converely, conider any (, )-flow f in G compued uing he Ford-Fulkeron augmening pah algorihm. Becaue he edge capaciie are ineger, he Ford-Fulkeron algorihm aign an ineger flow o every edge. (Thi i eay o verify by inducion hin hin.) Moreover, ince each edge ha uni capaciy, he compued flow eiher aurae (f(e) = 1) or avoid (f(e) = 0) every edge in G. Finally, ince a mo one uni of flow can ener any verex in U or leave any verex in W, he auraed edge from U o W form a maching in G. The ize of hi maching i exacly f. Thu, he ize of he maximum maching in G i equal o he value of he maximum flow in G, and provided we compue he maxflow uing augmening pah, we can conver he acual maxflow ino a maximum maching. The maximum flow ha value a mo min{ U, W } = O(V ), o he Ford-Fulkeron algorihm run in O(V E) ime. A maximum maching in a biparie graph G, and he correponding maximum flow in G 1.6 Edge-Dijoin Pah Similarly, we can compue he maximum number of edge-dijoin pah beween wo verice and in an graph uing maximum flow. A e of pah in G i edge-dijoin if each edge in G appear in a mo one of he pah. (Several pah may pa hrough he ame verex, however.) If we give each edge capaciy 1, hen he maxflow from o aign a flow of eiher 0 or 1 o every edge. Moreover, even if he original graph i undireced, he maxflow algorihm will aign a direcion o every auraed edge. Thu, he ubgraph S of auraed edge i he union of everal edge-dijoin pah; he number of pah i equal o he value of he flow. Exracing he acual pah from S i eay: Ju follow any direced pah in S from o, remove ha pah from S, and recure. The overall running ime i O(V E), ju like for maximum biparie maching.
CS 473G Lecure 1: Max-Flow Algorihm and Applicaion Fall 200 Converely, we can ranform any collecion of edge-dijoin pah ino a flow by puhing one uni of flow along each pah from o ; he value of he reuling flow i equal o he number of pah in he collecion. I follow ha he maxflow algorihm acually compue he large poible e of edge-dijoin pah. 6