Algorihm ROBERT SEDGEWICK KEVIN WAYNE. MAXIMUM FLOW. MAXIMUM FLOW inroducion inroducion Ford-Fulkeron algorihm Ford-Fulkeron algorihm Algorihm F O U R T H E D I T I O N maxflow-mincu heorem analyi of running ime Algorihm maxflow-mincu heorem analyi of running ime ROBERT SEDGEWICK KEVIN WAYNE hp:alg.c.princeon.edu Java implemenaion applicaion ROBERT SEDGEWICK KEVIN WAYNE hp:alg.c.princeon.edu Java implemenaion applicaion Mincu problem Mincu problem Inpu. An edge-weighed digraph, ource verex, and arge verex. each edge ha a poiive capaciy 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. capaciy capaciy = + + =
Mincu problem 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. 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. 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. don' coun edge from B o A capaciy = + + = capaciy = + + = Maxflow: quiz Mincu applicaion (RAND ) Wha i he capaciy of he -cu A, E, F, G? "Free world" goal. Cu upplie (if cold war urn ino real war). A. ( + + + ) B. ( + ) C. ( + + + + + ) D. I don' know. ource capaciy A B C D E F G H ink rail nework connecing Sovie Union wih Eaern European counrie (map declaified by Penagon in )
Poenial mincu applicaion () Maxflow problem Governmen-in-power goal. Cu off communicaion o e of people. Efficien Maximum Flow Algorihm by Andrew Goldberg and Tarjan hp:vimeo.com Maxflow problem Maxflow problem Inpu. An edge-weighed digraph, ource verex, and arge verex. Def. An -flow (flow) i an aignmen of value o he edge uch ha: Capaciy conrain: edge' flow edge' capaciy. Local equilibrium: inflow = ouflow a every verex (excep and ). each edge ha a poiive capaciy capaciy flow capaciy inflow a v = + + = ouflow a v = + v =
Maxflow problem Maxflow problem Def. An -flow (flow) i an aignmen of value o he edge uch ha: Def. An -flow (flow) i an aignmen of value o he edge uch ha: Capaciy conrain: edge' flow edge' capaciy. Local equilibrium: inflow = ouflow a every verex (excep and ). Capaciy conrain: edge' flow edge' capaciy. Local equilibrium: inflow = ouflow a every verex (excep and ). Def. The value of a flow i he inflow a. Def. The value of a flow i he inflow a. we aume no edge poin o or from Maximum -flow (maxflow) problem. Find a flow of maximum value. value = + + = value = + + = Maxflow applicaion (Toloǐ ) Poenial maxflow applicaion () Sovie Union goal. Maximize flow of upplie o Eaern Europe. "Free world" goal. Maximize flow of informaion o pecified e of people. flow capaciy facebook graph rail nework connecing Sovie Union wih Eaern European counrie (map declaified by Penagon in ) Figure From Harri and Ro []: Schemaic diagram of he railway nework of he Weern Sovie Union and Eaern European counrie, wih a maximum flow of value, on from Ruia o Eaern Europe, and a cu of capaciy, on indicaed a The boleneck.
Summary Inpu. A weighed digraph, ource verex, and arge verex. Mincu problem. Find a cu of minimum capaciy. Maxflow problem. Find a flow of maximum value.. MAXIMUM FLOW value of flow = capaciy of cu = Algorihm ROBERT SEDGEWICK KEVIN WAYNE hp:alg.c.princeon.edu inroducion Ford-Fulkeron algorihm maxflow-mincu heorem analyi of running ime Java implemenaion applicaion Remarkable fac. Thee wo problem are dual! Ford-Fulkeron algorihm Idea: increae flow along augmening pah Iniializaion. Sar wih flow. 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). iniializaion flow capaciy augmening pah boleneck capaciy = value of flow + =
Idea: increae flow along augmening pah 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). 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). nd augmening pah rd augmening pah backward edge (no empy) + = + = Idea: increae flow along augmening pah 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). Terminaion. All pah from o are blocked by eiher a Full forward edge. Empy backward edge. h augmening pah backward edge (no empy) no more augmening pah + = full forward edge empy backward edge
Maxflow: quiz Ford-Fulkeron algorihm Which i an augmening pah of highe boleneck capaciy? A. A F G H B. A F B G H C. A F B G D H D. I don' know. Ford-Fulkeron algorihm Sar wih flow. While here exi an augmening pah: - find an augmening pah - compue boleneck capaciy - increae flow on ha pah by boleneck capaciy ource A B flow capaciy C D Fundamenal queion. How o compue a mincu? How o find an augmening pah? If FF erminae, doe i alway compue a maxflow? Doe FF alway erminae? If o, afer how many augmenaion? E F G H ink 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.. MAXIMUM FLOW Algorihm ROBERT SEDGEWICK KEVIN WAYNE hp:alg.c.princeon.edu inroducion Ford-Fulkeron algorihm maxflow-mincu heorem analyi of running ime Java implemenaion applicaion ne flow acro cu = + + = value of flow =
Relaionhip beween flow and cu 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. 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 = + + = ne flow acro cu = ( + + + + + ) ( + + + ) = edge from B o A value of flow = value of flow = Relaionhip beween flow and cu 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. Weak dualiy. Le f be any flow and le (A, B) be any cu. Then, he value of he flow he capaciy of he cu. Inuiion. Conervaion of flow. Pf. Value of flow f = ne flow acro cu (A, B) capaciy of cu (A, B). 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. flow-value lemma flow bounded by capaciy Corollary. Ouflow from = inflow o = value of flow. value of flow = capaciy of cu =
Maxflow-mincu heorem 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. Augmening pah heorem. A flow f i a maxflow iff no augmening pah. Maxflow-mincu heorem. Value of he maxflow = capaciy of mincu. Pf. The following hree condiion are equivalen for any flow f : i. There exi a cu whoe capaciy equal he value of he flow f. ii. f i a maxflow. iii. There i no augmening pah wih repec o f. Pf. The following hree condiion are equivalen for any flow f : i. There exi a cu whoe capaciy equal he value of he flow f. ii. f i a maxflow. iii. There i no augmening pah wih repec o f. [ i ii ] 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 [ ii iii ] We prove conrapoiive: ~iii ~ii. 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. Maxflow-mincu heorem Compuing a mincu from a maxflow [ iii i ] 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, i in A. By definiion of cu A and flow f, i in B. Capaciy of cu = ne flow acro cu = value of flow f. G A backward edge from B o A (flow = ) B 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. flow-value lemma A forward edge from A o B (flow = capaciy) forward edge (no full) backward edge (no empy) full forward edge empy backward edge
Ford-Fulkeron algorihm Ford-Fulkeron algorihm Algorihm ROBERT SEDGEWICK KEVIN WAYNE hp:alg.c.princeon.edu. MAXIMUM FLOW inroducion Ford-Fulkeron algorihm maxflow-mincu heorem analyi of running ime Java implemenaion applicaion Fundamenal queion. How o compue a mincu? Eay. How o find an augmening pah? BFS work well. Sar wih flow. While here exi an augmening pah: - find an augmening pah - compue boleneck capaciy - increae flow on ha pah by boleneck capaciy If FF erminae, doe i alway compue a maxflow? Ye. Doe FF alway erminae? If o, afer how many augmenaion? ye, provided edge capaciie are ineger (or augmening pah are choen carefully) require clever analyi Ford-Fulkeron algorihm wih ineger capaciie Bad cae for Ford-Fulkeron Imporan pecial cae. Edge capaciie are ineger beween and U. flow on each edge i an ineger Bad new. Even when edge capaciie are ineger, number of augmening pah could be equal o he value of he maxflow. Invarian. The flow i inegral hroughou Ford-Fulkeron. Pf. [by inducion] Boleneck capaciy i an ineger. Flow on an edge increaedecreae by boleneck capaciy. Propoiion. Number of augmenaion he value of he maxflow. iniialize wih flow flow capaciy Pf. Each augmenaion increae he value by a lea. criical for ome applicaion (ay uned) Inegraliy heorem. There exi an inegral maxflow. Pf. Ford-Fulkeron erminae and maxflow ha i find i ineger-valued.
Bad cae for Ford-Fulkeron Bad cae for Ford-Fulkeron Bad new. Even when edge capaciie are ineger, number of augmening pah could be equal o he value of he maxflow. Bad new. Even when edge capaciie are ineger, number of augmening pah could be equal o he value of he maxflow. ieraion nd ieraion Bad cae for Ford-Fulkeron Bad cae for Ford-Fulkeron Bad new. Even when edge capaciie are ineger, number of augmening pah could be equal o he value of he maxflow. Bad new. Even when edge capaciie are ineger, number of augmening pah could be equal o he value of he maxflow. rd ieraion h ieraion
Bad cae for Ford-Fulkeron Bad cae for Ford-Fulkeron Bad new. Even when edge capaciie are ineger, number of augmening pah could be equal o he value of he maxflow. Bad new. Even when edge capaciie are ineger, number of augmening pah could be equal o he value of he maxflow. h ieraion... Bad cae for Ford-Fulkeron Bad cae for Ford-Fulkeron Bad new. Even when edge capaciie are ineger, number of augmening pah could be equal o he value of he maxflow. Bad new. Even when edge capaciie are ineger, number of augmening pah could be equal o he value of he maxflow. can be exponenial in inpu ize Good new. Thi cae i eaily avoided. [ ue horefae pah ] h ieraion
w v How o chooe augmening pah? How o chooe augmening pah? Chooe augmening pah wih: Shore pah: fewe number of edge. Fae pah: max boleneck capaciy. Ue care when elecing augmening pah. Some choice lead o exponenial algorihm. Clever choice lead o polynomial algorihm. augmening pah number of pah implemenaion Theoreical Improvemen in Algorihmic Efficiency for Nework Flow Problem random pah E U randomized queue DFS pah E U ack (DFS) 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. hore pah ½ E V queue (BFS) fae pah E ln(e U) prioriy queue flow nework wih V verice, E edge, and ineger capaciie beween and U Edmond-Karp (USA) Dinic (Sovie Union) Flow nework repreenaion Flow edge daa ype. Aociae flow f e and capaciy c e wih edge e = v w. flow fe capaciy ce. MAXIMUM FLOW Algorihm ROBERT SEDGEWICK KEVIN WAYNE hp:alg.c.princeon.edu inroducion Ford-Fulkeron algorihm maxflow-mincu heorem analyi of running ime Java implemenaion applicaion Flow nework daa ype. Mu be able o proce edge e = v w in eiher direcion: include e in adjacency li of boh v and w. Reidual (pare) capaciy. Forward edge: reidual capaciy = ce fe. Backward edge: reidual capaciy = fe. Augmen flow. Forward edge: add. Backward edge: ubrac. reidual capaciy w v forward edge backward edge
w w v v Flow nework repreenaion Flow edge API Reidual nework. A ueful view of a flow nework. include all edge wih poiive reidual capaciy public cla FlowEdge original nework FlowEdge(in v, in w, double capaciy) creae a flow edge v w in from() verex hi edge poin from in o() verex hi edge poin o in oher(in v) oher endpoin double capaciy() capaciy of hi edge reidual nework backward edge (no empy) double flow() flow in hi edge double reidualcapaciyto(in v) reidual capaciy oward v void addreidualflowto(in v, double dela) add dela flow oward v Key poin. Augmening pah in original nework are in one-o-one correpondence wih direced pah in reidual nework. forward edge (no full) flow fe capaciy ce reidual capaciy v forward edge w backward edge Flow edge: Java implemenaion Flow edge: Java implemenaion (coninued) public cla FlowEdge privae final in v, w; privae final double capaciy; privae double flow; from and o capaciy flow public FlowEdge(in v, in w, double capaciy) hi.v = v; hi.w = w; hi.capaciy = capaciy; public in from() reurn v; public in o() reurn w; public double capaciy() reurn capaciy; public double flow() reurn flow; flow variable (muable) public double reidualcapaciyto(in verex) if (verex == v) reurn flow; ele if (verex == w) reurn capaciy - flow; ele hrow new IllegalArgumenExcepion(); public void addreidualflowto(in verex, double dela) if (verex == v) flow -= dela; ele if (verex == w) flow += dela; ele hrow new IllegalArgumenExcepion(); forward edge backward edge forward edge backward edge public in oher(in verex) if (verex == v) reurn w; ele if (verex == w) reurn v; ele hrow new IllegalArgumenExcepion(); public double reidualcapaciyto(in verex)... public void addreidualflowto(in verex, double dela)... nex lide flow fe capaciy ce reidual capaciy v forward edge w backward edge
Flow nework API Flow nework: Java implemenaion public cla FlowNework FlowNework(in V) creae an empy flow nework wih V verice FlowNework(In in) conruc flow nework inpu ream void addedge(flowedge e) add flow edge e o hi flow nework Ierable<FlowEdge> adj(in v) forward and backward edge inciden ofrom v Ierable<FlowEdge> edge() all edge in hi flow nework in V() number of verice in E() number of edge Sring osring() ring repreenaion public cla FlowNework privae final in V; privae Bag<FlowEdge>[] adj; public FlowNework(in V) hi.v = V; adj = (Bag<FlowEdge>[]) new Bag[V]; for (in v = ; v < V; v++) adj[v] = new Bag<FlowEdge>(); public void addedge(flowedge e) in v = e.from(); in w = e.o(); adj[v].add(e); adj[w].add(e); ame a EdgeWeighedGraph, bu adjacency li of FlowEdge inead of Edge add forward edge add backward edge Convenion. Allow elf-loop and parallel edge. public Ierable<FlowEdge> adj(in v) reurn adj[v]; Flow nework: adjacency-li repreenaion Finding a hore augmening pah (cf. breadh-fir earch) Mainain verex-indexed array of FlowEdge li (ue Bag abracion). inyfn.x V E........ adj[]........ Noe. Adjacency li include edge wih reidual capaciy. (reidual nework i repreened implicily) reference o he ame FlowEdge objec........................ Bag objec privae boolean haaugmeningpah(flownework G, in, in ) edgeto = new FlowEdge[G.V()]; marked = new boolean[g.v()]; Queue<Ineger> queue = new Queue<Ineger>(); queue.enqueue(); marked[] = rue; while (!queue.iempy()) in v = queue.dequeue(); for (FlowEdge e : G.adj(v)) found pah from o w in he reidual nework? in w = e.oher(v); if (!marked[w] && (e.reidualcapaciyto(w) > ) ) reurn marked[]; edgeto[w] = e; marked[w] = rue; queue.enqueue(w); ave la edge on pah o w; mark w; add w o he queue i reachable from in reidual nework?
Ford-Fulkeron: Java implemenaion public cla FordFulkeron privae boolean[] marked; rue if ->v pah in reidual nework privae FlowEdge[] edgeto; la edge on ->v pah privae double value; value of flow public FordFulkeron(FlowNework G, in, in ) compue edgeto[] and marked[] value =.; while (haaugmeningpah(g,, )) compue double bole = Double.POSITIVE_INFINITY; boleneck capaciy for (in v = ; v!= ; v = edgeto[v].oher(v)) bole = Mah.min(bole, edgeto[v].reidualcapaciyto(v)); for (in v = ; v!= ; v = edgeto[v].oher(v)) edgeto[v].addreidualflowto(v, bole); value += bole; privae boolean haaugmeningpah(flownework G, in, in ) * See previou lide. * public double value() reurn value; augmen flow Algorihm ROBERT SEDGEWICK KEVIN WAYNE hp:alg.c.princeon.edu. MAXIMUM FLOW inroducion Ford-Fulkeron algorihm maxflow-mincu heorem analyi of running ime Java implemenaion applicaion public boolean incu(in v) reurn marked[v]; i v reachable from in reidual nework? Maxflow and mincu applicaion Biparie maching problem Maxflowmincu i a widely applicable problem-olving model. N uden apply for N job. 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 Each ge everal offer. I here a way o mach all uden o job? biparie maching problem Facebook Facebook
Biparie maching problem Given a biparie graph, find a perfec maching. perfec maching (oluion) biparie graph biparie maching problem Nework flow formulaion of biparie maching Creae,, one verex for each uden, and one verex for each job. Add edge from o each uden (capaciy ). Add edge from each job o (capaciy ). Add edge from uden o each job offered (infinie capaciy). flow nework biparie maching problem Facebook N uden N companie Facebook Facebook N uden N companie Facebook Facebook Nework flow formulaion of biparie maching Wha he mincu ell u - correpondence beween perfec maching in biparie graph and ineger-valued maxflow of value N. Goal. When no perfec maching, explain why. flow nework biparie maching problem N uden N companie Facebook Facebook no perfec maching exi S =,, T =, uden in S can be mached only o companie in T S > T
Wha he mincu ell u Baeball eliminaion problem Mincu. Conider mincu (A, B). Le S = uden on ide of cu. Le T = companie on ide of cu. Fac: S > T ; uden in S can be mached only o companie in T. Q. Which eam have a chance of finihing he eaon wih he mo win? i eam win loe o play ATL PHI NYM WAS Alana Philly New York S =,, T =, Wahingon uden in S can be mached only o companie in T S > T Wahingon i mahemaically eliminaed. Wahingon finihe wih win. Alana already ha win. no perfec maching exi Boom line. When no perfec maching, mincu explain why. Baeball eliminaion problem Baeball eliminaion problem Q. Which eam have a chance of finihing he eaon wih he mo win? Q. Which eam have a chance of finihing he eaon wih he mo win? i eam win loe o play ATL PHI NYM WAS Alana Philly New York Wahingon i eam win loe o play NYY BAL BOS TOR DET New York Balimore Boon Torono Deroi AL Ea (Augu, ) Philadelphia i mahemaically eliminaed. Philadelphia finihe wih win. Eiher New York or Alana will finih wih win. Obervaion. Anwer depend no only on how many game already won and lef o play, bu on whom hey're again. Deroi i mahemaically eliminaed. Deroi finihe wih win. Win for R = NYY, BAL, BOS, TOR =. Remaining game among NYY, BAL, BOS, TOR = + + + + =. Average eam in R win =. game.
Baeball eliminaion problem: maxflow formulaion Maximum flow algorihm: heory Inuiion. Remaining game flow from o. (Ye anoher) holy grail for heoreical compuer cieni. year mehod wor cae dicovered by implex E U Danzig game lef beween and eam can ill win hi many more game augmening pah E U Ford-Fulkeron hore augmening pah E Diniz, Edmond-Karp g w + r w fae augmening pah E log E log( E U ) Diniz, Edmond-Karp blocking flow E Cherkaky blocking flow E Galil dynamic ree E log E Sleaor-Tarjan game verice (each pair of eam oher han ) eam verice (each eam oher han ) capaciy caling E log U Gabow lengh funcion E log E log U Goldberg-Rao compac nework E log E Orlin Fac. Team no eliminaed iff all edge poining from are full in maxflow.?? E? maxflow algorihm for pare nework wih E edge, ineger capaciie beween and U Maximum flow algorihm: pracice Summary Warning. Wor-cae order-of-growh i generally no ueful for predicing Mincu problem. Find an -cu of minimum capaciy. or comparing maxflow algorihm performance in pracice. Maxflow problem. Find an -flow of maximum value. Dualiy. Value of he maxflow = capaciy of mincu. Be in pracice. Puh-relabel mehod wih gap relabeling: E. On Implemening Puh-Relabel Mehod for he Maximum Flow Problem Bori V. Cherkaky and Andrew V. Goldberg Cenral Iniue for Economic and Mahemaic, Kraikova S.,, Mocow, Ruia cher@eemi.mk.u Compuer Science Deparmen, Sanford Univeriy Sanford, CA, 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 () - 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,, India b AT& T Bell Laboraorie, Holmdel, NJ, USA c KA'F-Z Graduae School of Buine, Univeriy of Piburgh, Piburgh, PA, USA d Sloun School of Managemen, Maachue Iniue of Technology. Cambridge. MA. USA Received Augu ; acceped June Proven ucceful approache. Ford-Fulkeron (variou augmening-pah raegie). Preflow-puh (variou verion). Open reearch challenge. Pracice: olve real-world maxflowmincu problem in linear ime. Theory: prove i for wor-cae inpu. Sill much o be learned!