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, 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. 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 = + + = Mincu applicaion (RAND ) Poenial mincu applicaion () "Free world" goal. Cu upplie (if cold war urn ino real war). Governmen-in-power goal. Cu off communicaion o e of people. 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.
v Maxflow problem Maxflow problem Inpu. An edge-weighed digraph, ource verex, and arge verex. each edge ha a poiive capaciy 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 flow capaciy / inflow a v = + + = ouflow a v = + = / / / / / / / / / / / / Maxflow problem Maxflow problem 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 ). Def. The value of a flow i he inflow a. 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 ). 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.. M AXIMUM F LOW / / / / / / / / / / / / / / inroducion Ford-Fulkeron algorihm Algorihm / value of flow = R OBERT S EDGEWICK K EVIN W AYNE capaciy of cu = hp://alg.c.princeon.edu Remarkable fac. Thee wo problem are dual! maxflow-mincu heorem analyi of running ime Java implemenaion applicaion
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 Ford-Fulkeron algorihm Queion. How o compue a mincu? How o find an augmening pah? 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 If FF erminae, doe i alway compue a maxflow? Doe FF alway erminae? If o, afer how many augmenaion? 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
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 = + + = / / / / / / / / / / / / / value of flow = / / / 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. 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. ne flow acro cu = ( + + + + + ) ( + + + ) = / 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. edge from B o A / / / / / / / value of flow = Corollary. Ouflow from = inflow o = value of flow. / / / / /
Relaionhip beween flow and cu Maxflow-mincu heorem 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. Augmening pah heorem. A flow f i a maxflow iff no augmening pah. Maxflow-mincu heorem. Value of he maxflow = capaciy of mincu. Pf. Value of flow f = ne flow acro cu (A, B) capaciy of cu (A, B). flow-value lemma flow bounded by capaciy 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 / / / / / 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. Augmening pah heorem. A flow f i a maxflow iff no augmening pah. Maxflow-mincu heorem. Value of he maxflow = capaciy of mincu. Maxflow-mincu heorem. Value of he maxflow = capaciy of mincu. Pf. The following hree condiion are equivalen for any flow 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. i. There exi a cu whoe capaciy equal he value of he flow f. ii. f i a maxflow. ii. f i a maxflow. iii. There i no augmening pah wih repec o f. iii. There i no augmening pah wih repec o f. [ 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. [ iii i ] Suppoe ha here i no augmening pah wih repec o f. Le (A, B) be a cu where A i he e of verice conneced o by an undireced pah wih no full forward or empy backward edge. By definiion of cu, i in A. Since no augmening pah, i in B. Capaciy of cu = ne flow acro cu = value of flow f. forward edge full; backward edge empy flow-value lemma
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. A forward edge (no full) / / / / / / / / / / / / / / full forward edge empy backward edge 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 backward edge (no empy) Ford-Fulkeron algorihm Ford-Fulkeron algorihm wih ineger capaciie 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 Imporan pecial cae. Edge capaciie are ineger beween and U. Invarian. The flow i ineger-valued hroughou Ford-Fulkeron. Pf. [by inducion] flow on each edge i an ineger Boleneck capaciy i an ineger. Flow on an edge increae/decreae by boleneck capaciy. Queion. How o compue a mincu? Eay. How o find an augmening pah? BFS work well. 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 Propoiion. Number of augmenaion he value of he maxflow. Pf. Each augmenaion increae he value by a lea. criical for ome applicaion (ay uned) Inegraliy heorem. There exi an ineger-valued 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. iniialize wih flow ieraion flow capaciy 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. nd ieraion rd 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. h ieraion h ieraion
Bad cae for Ford-Fulkeron How o chooe augmening pah? 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 hore/fae pah] Ue care when elecing augmening pah. Some choice lead o exponenial algorihm. Clever choice lead o polynomial algorihm. augmening pah number of pah implemenaion random pah E U randomized queue DFS pah E U ack (DFS) hore pah ½ E V queue (BFS) fae pah E ln(e U) prioriy queue digraph wih V verice, E edge, and ineger capaciie beween and U How o chooe augmening pah? Chooe augmening pah wih: Shore pah: fewe number of edge. Fae pah: max boleneck capaciy.. MAXIMUM FLOW 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. Algorihm ROBERT SEDGEWICK KEVIN WAYNE hp://alg.c.princeon.edu inroducion Ford-Fulkeron algorihm maxflow-mincu heorem analyi of running ime Java implemenaion applicaion Edmond-Karp (USA) Dinic (Sovie Union)
w v Flow nework repreenaion Flow nework repreenaion Flow edge daa ype. Aociae flow fe and capaciy ce wih edge e = v w. Reidual nework. A ueful view of a flow nework. include all edge wih poiive reidual capaciy flow fe capaciy ce original nework / / / / / / / 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 nework backward edge (no empy) Reidual (pare) capaciy. Forward edge: reidual capaciy = ce fe. Backward edge: reidual capaciy = fe. Augmen flow. Forward edge: add. Backward edge: ubrac. reidual capaciy v forward edge w backward edge Key poin. Augmening pah in original nework are in - correpondence wih direced pah in reidual nework. forward edge (no full) Flow edge API Flow edge: Java implemenaion public cla FlowEdge 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 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 / w v 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; flow variable (muable) public in from() reurn v; public in o() reurn w; public double capaciy() reurn capaciy; public double flow() reurn flow; flow fe capaciy ce reidual capaciy v forward edge w 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
w v w v Flow edge: Java implemenaion (coninued) Flow nework API 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 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 o v Ierable<FlowEdge> edge() all edge in hi flow nework in V() number of verice in E() number of edge Sring osring() ring repreenaion flow fe capaciy ce reidual capaciy forward edge / backward edge Convenion. Allow elf-loop and parallel edge. Flow nework: Java implemenaion Flow nework: adjacency-li 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 Mainain verex-indexed array of FlowEdge li (ue Bag abracion). inyfn.x V E........ adj[]........ reference o he ame FlowEdge objec........................ Bag objec public Ierable<FlowEdge> adj(in v) reurn adj[v]; Noe. Adjacency li include edge wih reidual capaciy. (reidual nework i repreened implicily)
Finding a hore augmening pah (cf. breadh-fir earch) Ford-Fulkeron: Java implemenaion 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) > ) ) edgeto[w] = e; marked[w] = rue; queue.enqueue(w); ave la edge on pah o w; mark w; add w o he queue 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[] value =.; while (haaugmeningpah(g,, )) compue boleneck capaciy double bole = Double.POSITIVE_INFINITY; 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 reurn marked[]; i reachable from in reidual nework? public boolean incu(in v) reurn marked[v]; i v reachable from in reidual nework? Maxflow and mincu applicaion Maxflow/mincu i a widely applicable problem-olving model. 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 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
Biparie maching problem Biparie maching problem N uden apply for N job. Given a biparie graph, find a perfec maching. biparie maching problem perfec maching (oluion) biparie graph biparie maching problem Each ge everal offer. I here a way o mach all uden o job? Facebook Facebook Facebook N uden N companie Facebook Facebook 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 Nework flow formulaion of biparie maching - correpondence beween perfec maching in biparie graph and ineger-valued maxflow of value N. flow nework biparie maching problem N uden N companie Facebook Facebook N uden N companie Facebook Facebook
Wha he mincu ell u Wha he mincu ell u Goal. When no perfec maching, explain why. 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. S =,, T =, S =,, T =, uden in S can be mached only o companie in T S > T uden in S can be mached only o companie in T S > T no perfec maching exi 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 MON Alana Philly New York Monreal i eam win loe o play ATL PHI NYM MON Alana Philly New York Monreal Monreal i mahemaically eliminaed. Monreal finihe wih win. Alana already ha win. 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.
Baeball eliminaion problem Baeball eliminaion problem: maxflow formulaion Q. Which eam have a chance of finihing he eaon wih he mo win? Inuiion. Remaining game flow from o. i eam win loe o play NYY BAL BOS TOR DET New York Balimore game lef beween and eam can ill win hi many more game Boon Torono Deroi g w + r w AL Ea (Augu, ) 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. game verice (each pair of eam oher han ) eam verice (each eam oher han ) Fac. Team no eliminaed iff all edge poining from are full in maxflow. Maximum flow algorihm: heory Maximum flow algorihm: pracice (Ye anoher) holy grail for heoreical compuer cieni. Warning. Wor-cae order-of-growh i generally no ueful for predicing year mehod wor cae dicovered by or comparing maxflow algorihm performance in pracice. implex E U Danzig augmening pah E U Ford-Fulkeron Be in pracice. Puh-relabel mehod wih gap relabeling: E /. hore augmening pah E Diniz, Edmond-Karp 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 capaciy caling E log U Gabow lengh funcion E / log E log U Goldberg-Rao compac nework E / log E Orlin?? 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 maxflow algorihm for pare digraph wih E edge, ineger capaciie beween and U
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!