6.854 Advanced Algorihm Lecure 6: 9/4/003 Lecurer: Erik Demaine, David Karger Scribe: Alexandr Andoni, edied by Sara Muin 9//06 Nework Flow 6. The Maximum Flow Problem In hi ecion we define a flow nework and eup he problem we are rying o olve in hi lecure: he maximum flow problem. Definiion A nework i a direced graph G = (V, E) wih a ource verex V and a ink verex V. Each edge e = (v, w) from v o w ha a defined capaciy, denoed by u(e) or u(v, w). I i ueful o alo define capaciy for any pair of verice (v, w) E wih u(v, w) = 0. Figure 6.: An example of a nework wih n = 4 verice and m = 6 edge. The capaciie of he edge are hown. In a nework flow problem, we aign a flow o each edge. There are wo way of defining a flow: raw (or gro) flow and ne flow. Definiion Raw flow i a funcion r(v, w) ha aifie he following properie: Conervaion: The oal flow enering v mu equal he oal flow leaving v for all vericle excep and. r(w, v) r(v, w) = 0, for all v V \ {, }. w V }{{} incoming flow w V }{{} ougoing flow 6-
Lecure 6: 9/4/003 6- Capaciy conrain: The flow along any edge mu be poiive and le han he capaciy of ha edge. 0 r(v, w) u(v, w). Figure 6.: An example of a raw flow for he nework above. The flow ha a value of. Wih a raw flow, we can have flow going boh from v o w and flow going from w o v. In a ne flow formulaion however, we only keep rack of he difference beween hee wo flow. Definiion 3 Ne flow i a funcion ha aifie he following condiion: Skew ymmery: f(v, w) = f(w, v). Conervaion: w V f(v, w) = 0, for all v V \ {, }. Capaciy conrain: f(v, w) u(v, w) for all v, w V. A raw flow r(v, w) can be convered ino a ne flow via he formula f(v, w) = r(v, w) r(w, v). For example, if we have 7 uni of flow from v o w and 4 uni of flow from w o v, hen he ne flow from v o w i f(v, w) = 3. Skew ymmery follow direcly from hi formula relaing raw flow and ne flow. Becaue we can conver from raw flow o ne flow, for he re of he lecure we conider only ne flow problem. Alhough kew ymmery relae f(v, w) and f(w, v), i i imporan o noe ha he capaciy in one direcion u(v, w) i independen of he capaciy in he revere direcion, u(w, v). The value of a flow i he um of he flow on all edge leaving he ource. We laer how ha hi i equivalen o he um of all he flow going ino he ink. The value of a flow repreen how much we can ranpor from he ource o he ink. Our goal in hi lecure i o olve he maximum flow problem. Definiion 4 The value of a flow f i defined a f = v V f(, v). Definiion 5 Maximum flow problem: Given a nework G = (V, E), find a feaible flow f wih maximum value.
Lecure 6: 9/4/003 6-3 6. Flow Decompoiion and Cu In hi ecion, we how ha any feaible flow can be decompoed ino pah from he ource o he ink and cycle. We ue hi fac o derive an upper bound on he maximum flow value in erm of cu of he nework. Lemma Flow decompoiion: We can decompoe any feaible flow f on a nework G ino a mo m cycle and - pah. Proof: The following algorihm exrac he m pah and cycle.. Find a pah wih poiive flow from he node o node. (If he flow i non-zero, here exi a lea one uch pah.). Ani-augmen he flow on hi pah ha i, reduce he flow in he pah unil he flow on ome edge become 0. 3. Add hi pah a an elemen of he flow decompoiion. 4. Coninue hee operaion unil here are no more pah from o wih poiive flow. 5. If here are ill ome edge wih non-zero flow, he remaining flow can be decompoed ino cycle. Find a cycle in he following way: ake any edge wih non-zero flow and follow an ougoing edge wih non-zero flow unil a cycle i found. 6. Ani-augmen on he cycle found. 7. Add he cycle a an elemen of he flow decompoiion. 8. Coninue finding cycle unil here are no more edge wih non-zero flow. Each ime we ani-augmen a pah or a cycle, we zero ou he flow on ome edge. There are a mo m ani-augmenaion, and, conequenly, m pah/cycle in he flow decompoiion. In a nework flow problem, i i ueful o work wih a cu of he graph, paricularly an - cu. Definiion 6 An - cu of nework G i a pariion of he verice V ino group: S and S = V \S uch ha S and S. Ë Ë Figure 6.3: An illuraion of an - cu. There migh be boh edge from S o S and from S o S. We will uually repreen a cu a he pair (S, S), or ju S. We generalize he concep of he ne flow and he capaciy of an edge o define he ne flow and capaciy of a cu.
Lecure 6: 9/4/003 6-4 Definiion 7 The ne flow along cu (S, S) i defined a f(s) = v S Definiion 8 The value (or capaciy) of a cu i defined a u(s) = v S w S f(v, w). w S u(v, w). In ummary, he value (or capaciy) of a cu i he um of all value (capaciie) of edge ha go from S o S. Noe ha direcion i imporan in hee definiion. Capaciy along an edge in he revere direcion, from w S o v S, doe no coun. Figure 6.4: An example of a cu in a nework. The - cu i repreened by a dahed line. The value (capaciy) of he cu i equal o 3. Thi i one of he minimum - cu. Working wih cu i ueful becaue of he following lemma: Lemma Given a flow f, for any cu S, f(s) = f. In oher word, all - cu carry he ame flow: he value of he flow f. Proof: We can ue Lemma o prove hi aemen direcly. We decompoe he flow ino - pah and cycle. Each - pah mu end up in S, o i mu go from e S o S one more ime han i goe from S o S. Therefore, an - pah carring x flow along ha pah conribue exacly x o he value of he cu. A cycle mu go from S o S he ame number of ime a i goe from S o S, conribuing 0 o he value of he cu. Therefore he oal value of he cu S i equal o he um of he flow along every - pah, which i equal o f. Alernaively, we can prove he lemma by inducion on he ize of he e S. For S =, he claim i rue. Now, uppoe we move one verex v from S o S. The value f(s) change in he following way: f(s) increae by f(v, S). f(s) decreae by f(s, v) = f(v, S). In concluion, he oal change in he value of f(s) afer moving he verex v from S o S i equal o f(v, S) + f(v, S) = f(v, V ) = 0 (by conervaion of flow). For a flow nework, we define a minimum cu o be a cu of he graph wih minimum capaciy. Then, Lemma 3 give u an upper bound on he value of any flow.
Lecure 6: 9/4/003 6-5 Lemma 3 If f i a feaible flow, hen f u(s) for any cu S. Proof: For all edge e, f(e) u(e), o f(s) u(s) (he flow acro any cu S i no more han he capaciy of he cu). By Lemma, f = f(s), o f u(s) for any cu S. If we pick S o be a minimum cu, hen we ge an upper bound on he maximum flow value. 6.3 Max-Flow Min-Cu Theorem In hi ecion, we how ha he upper bound on he maximum flow given by Lemma 3 i exac. Thi i he max-flow min-cu heorem. To prove he heorem, we inroduce he concep of a reidual nework and an augmening pah. Definiion 9 Le f be a feaible flow on a nework G. The correponding reidual nework, denoed G f, i a nework ha ha he ame verice a he nework G, bu ha edge wih capaciie u f (v, w) = u(v, w) f(v, w). Only edge wih non-zero capaciy, u f (v, w) > 0, are included in G f. Noe ha he feaibiliy condiion imply ha u f (v, w) 0 and u f (v, w) u(v, w) + u(w, v). Thi mean all capaciie in he reidual nework will be non-negaive. Definiion 0 An augmening pah i a direced pah from he node o node in he reidual nework G f. Figure 6.5: An example of a reidual nework. Thi reidual nework correpond o he nework depiced in Figure 6. and he flow in Figure 6.. The dahed line correpond o a poible augmening pah. Noe ha if we have an augmening pah in G f, hen hi mean we can puh more flow along uch a pah in he original nework G. To be more precie, if we have an augmening pah (, v, v,...v k, ), he maximum flow we can puh along ha pah i min{u f (, v ), u f (v, v ), u f (v, v 3 ),... u f (v k, v k ), u f (v k, )}. Therefore, for a given nework G and flow f, if here exi an augmening pah in G f, hen he flow f i no a maximum flow. More generally, if f i a feaible flow in G f, hen f + f i a feaible flow in G. The flow f + f ill aifie conervaion becaue flow conervaion i linear. The flow f + f i feaible becaue we can
Lecure 6: 9/4/003 6-6 rearrange he inequaliy f (e) u f (e) = u(e) f(e) o ge f (e) + f(e) u(e). Converely, if f i a feaible flow in G, hen he flow f f i a feaible in G f. Uing reidual nework and augmening pah, we can ae and prove he max-flow min-cu heorem. Theorem (Max-flow min-cu heorem). In a flow nework G, he following condiion are equivalen:. A flow f i a maximum flow.. The reidual nework G f ha no augmening pah. 3. f = u(s) for ome cu S. Thee condiion imply ha he value of he maximum flow i equal o he value of he minimum - cu: max f f = min S u(s), where f i a flow and S i a - cu. Proof: We how ha each condiion implie he oher wo. : If here i an augmening pah in G f, hen we previouly argued ha we can puh addiional flow along ha pah, o f wa no a maximum flow. i he conrapoiive of hi aemen. 3: If he reidual nework G f ha no augmening pah, and mu be diconneced. Le S = {verice reachable from in G f }. Since i no reachable, he e S decribe a - cu. Ë Figure 6.6: Nework G f i diconneced. The e S conain all he node ha are reachable from. By conrucion, all edge (v, w) croing he cu have reidual capaciy 0. Thi mean in he original nework G, hee edge have f(v, w) = u(v, w). Therefore, f = f(s) = u(s). 3 : If for ome cu S, f = u(s), we know f mu be a maximum flow. Oherwie, we would have a flow g wih g > u(s), conradicing Lemma 3. From () and (3), we know ha he maximum flow canno be le han he value of he minimum cu, becaue for ome S, f = u(s) and u(s) i a lea a big a he minimum cu value. Lemma 3 ell u ha he maximum flow can no be greaer han he minimum cu value. Therefore, he maximum flow value and he minimum cu value are he ame.
Lecure 6: 9/4/003 6-7 6.4 Ford-Fulkeron Algorihm The Ford-Fulkeron algorihm olve he problem of finding a maximum flow for a given nework. The decripion of he algorihm i a follow:. Sar wih f(v, w) = 0.. Find an augmening pah from o in G f (uing, for example, a deph fir earch or imilar algorihm). 3. Ue he augmening pah found in he previou ep o increae he flow. 4. Repea unil here are no more augmening pah in G f. If he capaciie are all ineger, hen he running ime i O(m f ). Thi i rue becaue finding an augmening pah and updaing he flow ake O(m) ime, and every augmening pah we find mu increae he flow by an ineger ha i a lea. In general, if we have inegral capaciie, hen our oluion aifie an inegraliy propery: here exi an inegral maximal flow. Thi happen becaue every augmening pah increae flow by an ineger amoun. Since he running ime i direcly proporional o he value of he maximal flow, hi paricular algorihm i only good for cae when he value f i mall. For example, when all capaciie are a mo, he maximum flow f i a mo n. In general, he algorihm may be a bad a linear in unary repreenaion of he inpu. Figure 6.7 illurae a bad cae for hi form of he Ford-Fulkeron algorihm. We decribe uch an algorihm a being peudo-polynomial, becaue i i polynomial in erm of variable we care abou (bu no necearily he inpu). ¾ ¾ ¾ ¾ ¾¾ ¾ ¾ Figure 6.7: An example for which he Ford-Fulkeron, in he aed form, migh perform very badly. The algorihm run lowly if a each ep, he augmenaion pah i eiher or (hown wih dahed line). A an augmenaion, he flow will increae by a mo. If he capaciie are raional, hen i can be hown ha he algorihm will finih. I migh, however, require more han O(m f ) ime. If he capaciie are real, he algorihm migh never finih, or even converge o a non-opimal value.
Lecure 6: 9/4/003 6-8 If we eup beer rule for elecing he augmenaion pah however, we migh ge beer reul. Before howing ome improvemen o he Ford-Fulkeron algorihm, we will inroduce ome new noion on he running ime of algorihm. Definiion An algorihm i puedo-polynomial if i i polynomial in he unary repreenaion of he inpu. Definiion An algorihm i weakly polynomial if i i polynomial in he binary repreenaion of he inpu. Definiion 3 An algorihm i rongly polynomial if i i polynomial in combinaorial complexiy of inpu. (For example, in he cae of max-flow problem, he algorihm would have o be polynomial in n and m.) 6.4. Improvemen o he Ford-Fulkeron Algorihm The are a lea wo poible idea for improving he Ford-Fulkeron algorihm. Boh of he improvemen rely on a beer choice of an augmening pah (raher han a random elecion of an augmening pah).. Uing breadh-fir earch, we can chooe hore-lengh augmening pah. Wih hi pahelecion rule, he number of augmenaion i bounded by n m, and hu he running ime of he algorihm goe down o O(nm ) ime.. We can alo chooe he maximum-capaciy augmening pah: he augmening pah among all augmening pah ha increae he flow he mo (max-capaciy augmening pah). I i poible o find uch a pah in O(m log n) ime uing a modified Dijkra algorihm (ignoring he cycle). The number of augmenaion will be a mo m ln f m ln(nu), where U = max{u(v, w)} (for inegral capaciie). In hi lecure we prove he ime bound for he econd improvemen. Conider he maximum flow f in he curren reidual nework. We apply he flow-decompoiion lemma, Lemma (dicarding he cycle becaue hey do no modify f ). There are a mo m pah carrying all he flow, o here mu be a lea one pah carrying a lea f m flow. Therefore, he augmening pah wih maximum capaciy increae he flow in he original nework by a lea f m. Thi decreae he maximum poible flow in he reidual graph from f o ( m ) f (remember, he maller i he maximum poible flow in he reidual graph, he greaer i he correponding flow in he original graph). We need o decreae he flow f by a facor of ( m ) abou m ln f ime before we decreae he max flow in he reidual graph o. Thi i becaue ( f m) mln f ( ) ln f f. e
Lecure 6: 9/4/003 6-9 In one more ep, he reidual graph will have a maximum flow of 0, meaning ha he correponding flow in he original graph i maximal. Thu, we need O(m ln f ) augmenaion. Since one augmenaion ep ake abou O(m log n) ime, he oal running ime i O(m ln f lnn). Thi algorihm i weakly polynomial, bu no rongly polynomial. 6.4. Scaling Algorihm We can alo improve he running ime of he Ford-Fulkeron algorihm by uing a caling algorihm. The idea i o reduce our max flow problem o he imple cae, where all edge capaciie are eiher 0 or. The caling idea, decribed by Gabow in 985 and alo by Dinic in 973, i a follow:. Scale he problem down omehow by rounding off lower order bi.. Solve he rounded problem. 3. Scale he problem back up, add back he bi we rounded off, and fix any error in our oluion. In he pecific cae of he maximum flow problem, he algorihm i:. Sar wih all capaciie in he graph a 0.. Shif in he higher-order bi of each capaciy. Each capaciy i hen eiher 0 or. 3. Solve hi maximum flow problem. 4. Repea hi proce unil we have proceed all remaining bi. Thi decripion of he algorihm ell u how o cale down he problem. However, we alo need o decribe how o cale our algorihm back up and fix he error. To cale back up:. Sar wih ome max flow for he caled-down problem. Shif he bi of each capaciy by, doubling all he capaciie. If we hen double all our flow value, we ill have a maximum flow.. Incremen ome of he capaciie. Thi reore he lower order bi ha we runcaed. Find augmening pah in he reidual nework o re-maximize he flow. We will need o find a mo m augmening pah. Before we caled our problem back up, we had olved a maximum flow problem, o ome cu in he reidual nework had 0 capaciy. Doubling all he capaciie and flow keep hi he ame. When we incremen he edge however, we increae he cu capaciy by a mo m: once for each edge. Each augmening pah we find increae he flow by a lea, o we need a mo m augmening pah.
Lecure 6: 9/4/003 6-0 Each augmening pah ake a mo O(m) ime o find, o we pend O(m ) ime in each ieraion of he caling algorihm. If he capaciy of any edge i a mo U, which i an O(lg U) bi number, we require O(lg U) ieraion of he caling algorihm. Therefore he oal running ime of he algorihm i O(m lg U). Thi algorihm i alo a weakly polynomial algorihm.