Comp 260: Avne Algorihms Tufs Universiy, Spring 2016 Prof. Lenore Cowen Srie: Alexner LeNil Leure 2: Nework Flow 1 Flow Neworks s 16 12 13 10 4 20 14 4 Imgine some nework of pipes whih rry wer, represene s grph where noes re junions n eges re pipes. Now imgine wer is oming in noe s n I wn o ge s muh wer s possile o. Junions (noes) oviously n sore wer. The ege weighs re flow piies, he volume of wer whih n rverse ny given pipe per uni ime. Then his grph is flow nework, formlly: iree grph G = (V, E) suh h G onins soure noe s n sink noe. every verex v V is on some ph from s o every ege (u, v) hs piy 0 noes hve no sorge piy. Noe: There exis generlizions of his prolem where here is sorge he noes. We ren going o over hem. 1
1.1 Flow Funions Definiion 1.1.1. A flow f in nework G is funion h ssigns rel numers o iree eges numers suh h he following onsrins re sisfie: Cpiy Consrin: I n pu more suff in he pipes hn will fi, i.e. for ll (u, v) E, f(u, v) (u, v) (where is piy). Skew Symmery: for ll (u, v) E, f(u, v) = f(v, u) Flow Conservion: for ll (u, v) whih re no s or, u v f(u, v) = 0 Definiion 1.1.2. The vlue of flow f, f = v V f(s, v) = u V f(u, ) Definiion 1.1.3. We n lso efine he flow ross ses of noes. If X n Y re ses of noes: f(x, Y ) = f(x, y) x X y Y Lemm 1.1.4. f(x, X) = 0 Lemm 1.1.5. f(x, Y ) = f(y, X) Lemm 1.1.6. if X Y = hen f((x Y ), Z) = f(x, Z) + f(y, Z) f(z, X Y ) = f(z, X) + f(z, Y ) Now imgine he following flow: (Cn you improve i?) s /16 /12 0/10 0/4 11/13 0/ / 16/20 11/14 4/4 2
The vlue of he ove flow f = 20. We inuiively know we n improve his flow. The es flow is elow: s 10/16 12/12 2/10 0/4 13/13 0/ / 1/20 11/14 4/4 The vlue of his flow is 23. We know we n o eer hn 24 sine he egree of he inoming eges o is 24, u i urns ou 23 is our mximum. For lrger neworks, where inuiion is iffiul, we use lgorihms. To explin his lgorihm, we nee o inroue noher kin of flow nework. 1.2 Resiul Neworks Consier he firs of he wo flows, he su-opiml flow. Imgine flow nework whih ouns he ville flow lef in he originl flow nework: s 2 10 4 3 4 3 An furher imgine we e kwrs negive eges o inie wh flow oul e reverse if nee e. 3
s 11 16 11 4 Definiion 1.2.1. : G f (V, E f ) suh h The resiul nework is flow nework, enoe E f = {(u, v) C f (u, v) > 0} where C f (u, v) = (u, v) f(u, v) Sine he resiul nework is kin of flow nework, i lso ies y he properies of flow neworks. Le s visulize he enire resiul nework. s 11 3 16 2 10 4 4 11 4 3 There exiss simple rule for improving flow using resiul neworks: If G f onsins ph p from s o hen p is n ugemening ph wih respe o he flow h forme G f. If we fin suh n ugmening ph, we n inrese he vlue of f [f]+(p) where (p) = min{ f (u, v)for(u, v) p}. 4
1.3 Grph Cuing When we si we n o eer hn 24, we were looking he inoming piy for. In some sense, we were uing he grph, sepring from he reminer of he nework, n exmining he mximum possile flow ross he ounry. Formlly: Definiion 1.3.1. A u of G(V, E) is priion of V ino S n T suh h s S is on one sie of u n T is on he oher sie of he u. S T = V ; S T = This efiniion egs he quesion: how muh n I push ross ounry? Definiion 1.3.2. The piy of u (S, T ), (S, T ) = w S v T (u, v) We look muliple us of our exmple nework n mesure he piy of eh u. I s usully in he mi-20s or upper-20s. A is minimum, i s 23. We n lso exmine, given flow, he flow over he u (s oppose o he mximum flow piy of h u). Clim 1.3.3. Any u sepring s from hs he ol flow from s o s he flow over he u. Clim 1.3.4. Any priion of he flow nework (even non-oninuous us), hs he ol flow from s o s he flow over he priion. Try i wih he flows we efine ove. I s unnny. 5
1.4 Mx-Flow, Min-Cu Theorem 1.4.1. Mx-Flow Min-Cu Theorem: Given nework G(V, E) n flow f, he following re equivlen: 1. f is mximum flow in G 2. The resiul nework G f onsins no ugmening phs 3. u suh h he vlue of he flow equls he piy of he u: f = (S, T ) This implies h he minimum u n he mximum flow mee in he mile. This is prigm lle uliy, whih is exremely powerful in lgorihms. This prolem is speil euse we n ge i in polynomil ime. A lo of hese sors of prolems re NP-hr. Proof. Proof sruure: 1 2. 2 3. 3 1. This will prove hey re ll equivlen. 1 2: If here were n ugmening ph, we n inrese he flow. Hene if f is he mximum flow, hen here oes no exis n ugmening ph. 2 3: If G f hs no ugmening ph, here is no onnee ph from s o in G f. Le S = {v V v is rehle from s G f }. Le T = V S. Th s he u. Noie h s S u / S. Then he flow over he u is he vlue of he flow: u S, v T, f(u, v) = (u, v) f = f(s, T ) = f(u, v) = (u, v) = (S, T ) u U v V u U v V 6
3 1: Assume h I hve u whose piy is he vlue of he flow; f = (S, T ) This is he u where our es flow uses ll he piy ross h u, mening he resiul nework is ionnee long his u. We know he flow from s o is oune ove y he piy of his u: f (S, T ) u we lso know h f = (S, T ). Le f e flow h hieves he mximum possile vlue. Then: f f (S, T ) hen f = f 1.5 For-Fulkerson Algorihm Algorihm: Inpu: G, s, 1. Iniie flow f o 0. 2. While here exiss n ugmening ph p in G f : Augmen f long p. 3. Reurn f. This lgorihm lwys ermines n lwys eermines he mx flow, u i isn h effiien. Complexiy of fining n ugmening ph is oune ove y O(E) (BFS). The while loop ourrs O( f ) imes mos, mening he omplexiy of his lgorihm is O(E f ) This n hve runime in he se where here re oh lrge n smll flow piies in he sme nework. Here s onrive exmple h emonsres when For-Fulkerson migh e hevily su-opiml.
s 1M 1M 1 1M 1M If we hoose he ugmening ph from s o h psses hrough ege (, ) we only inrese he flow y 1. We n hen hoose he ugmening ph hrough (, ) n inrese he flow y 1 gin. Alerning in his wy, i will ke us M seps o ge up o he mx flow of M. Noie if we h gone irely from s hrough o we woul hve goen o M in one sep! Cn we hoose he es ugmening ph inse of jus n ugmening ph? Wh if we lwys hoose he shores ugmening ph firs? where shores is he les numer of eges irregrless of ege weigh. 1.6 Emons-Krp Algorihm Algorihm: Inpu: G, s, 1. Iniie flow f o 0. 2. While here exiss n ugmening ph p in G f : Augmen f long he shores of he ugmening phs, oune in numer of hops. 3. Reurn f. Clim: If his lgorihm is run on flow nework wih soure s n sink, hen for ll veries v V {s, }, he shores ph isne from s o v n only inrese in he resiul nework. 8
Proof. Proof y onriion: Suppose No. Consier f f, he firs ime he resiul nework isne from s o v ereses in n ierion of Emons-Krp. Wihou loss of generliy, le v e loses verex o s for whih his ours, n le u e he immeie preeessor of v in he new shores ph in E f. s...... u v If he resiul nework isne (numer of hops) from s o v lowere in n ierion, hen n ege mus hve ppere in he resiul nework whih ypsse some numer of eges whih use o e pr of he shores ph from s o v. So (u, v) E f u (u, v) / E f euse he shores ph from s o u in f n f re ienil in lengh (oherwise we woul hve hosen u o e our v). So Ef (s, u) = Ef (s, u). Suppose (u, v) exise in E f. Then Ef (s, v) Ef (s, u) + 1 = Ef (s, v), u we ssume he isnes from s o v ws GREATER in E f, onriion! Now, s resul of his propery of Emons-Krp, we n mke sserions ou is sympoi performne. Bu firs, we ll nee noher efiniion: Definiion 1.6.1. We sy ege (u, v) in resiul nework G f is riil on ugmening ph p, if he resiul piy of p is he resiul piy of (u, v). Theorem 1.6.2. Emons-Krp is oune ove y O( V E ) ierions. Proof. Le u, v e veries in V onnee y n ege in E. We lim h: From he ime (u, v) is riil o he ime i s riil gin, he isne o s mus inrese y 2 eges. Le f e he flow where (u, v) is firs riil. Th mens (u, v) is on he shores ph, hen i vnishes. I n ome k unil v, u is on he shores ph, u if v, u is on he shores ph, hen s v is reple wih s u.
Le E f e he resiul nework for flow f where (u, v) goes riil. Then (u, v) is missing in E f ; for i o repper in some ler f s ugmening ph, hen some ugmening ph pushes flow from v o u, i.e. (v, u) mus e on he shores ph from s o in E f, in oher wors E f (s, u) = E f (s, v)+1. (*) Bu, y he lim ove, sine isnes only inrese in he resiul neworks, we hve E f (s, u) Ef (s, u) so susiuing ino (*) we ge Ef (s, u) E f (s, v) + 1 so Ef (s, u) E f (s, u) + 2. Sine he isne from s o u inreses y les wo eges every ime (u, v) eomes riil, hen he ege n eome riil mos V /2 1 imes. If eh ege n eome riil mos O( V ) imes, hen he runime of Emons-Krp is oune ove y O( V E ). Emons-Krp is jus one wy o speify whih ugmening ph you ke eh ime, so in some sense i s merely speifi wy of running For- Fulkerson. However, epening on he relive sizes of f n V, eiher he oun O(E f ) from our originl nlysis of For-Fukerson or our new oun of O( V E ) on he numer of ierions migh e eer oun on he performne of Emons-Krp, epening on how lrge he mximum flow vlue ully is. 10