Maximum Flow Reied 09/09/200 Main Reference: Secion 26.-26. in CLRS. Inroducion Definiion Muli-Source Muli-Sink The Ford-Fulkeron Mehod Reidual Nework Augmening Pah The Max-Flow Min-Cu Theorem The Edmond-Karp algorihm Max Biparie Maching Odd and End
Maximum Flow Main Reference: Secion 26.-26. in CLRS. Gien a direced graph, G = (V, E) : flow nework Source (producer) and deinaion. Inernal Node are warehoue Edge co are capaciie Maximum amoun ha can be hipped oer edge All good hipped ino a warehoue mu leae he warehoue Goal: Ship Maximum amoun (flow) from o. 2
6 2 20 0 9 7 2 A Flow Nework wih capaciie /6 0 / 6/2 /9 6/7 8/20 6/ / 2 9/ A flow wih alue /6 0 / 2/2 /9 7/7 /20 8/ / 2 / A max-flow: alue i 9
A flow nework i a graph G = (V, E). Source V,, ink V,. Eery edge (u, ) E ha capaciy, c(u, ) 0. Aume ha for eery V here i a pah from o and from o. A FLOW i a funcion f : V V R aifying: Capaciy Conrain: u,, V, f(u, ) c(u, ). Skew Symmery: u,, V, f(u, ) = f(, u). Flow Coneraion: u V {, }, V f(u, ) = 0. The VALUE of flow i f = V f(, ).. MAXIMUM-FLOW PROBLEM: Gien G, c,,, find f ha maximize f.
Muli-Source Muli-Sink Problem The baic Max-Flow problem aume ha here i only one ource, and one ink. Suppoe ha here are muliple ource, 2,..., k and muliple ink, 2,..., l. The definiion of a flow remain he ame excep ha he Flow Coneraion propery now become u V {, 2,..., k,, 2,..., l }, V f(u, ) = 0 and our goal i o maximize f = k i= V f( i, ). Thi problem can be reduced o he original one by inroducing a uperource 0, a uperink 0 and edge i ( 0, i ) and j ( j, 0 ), all of which hae capaciy.
A muli-ource muli-ink problem and i equialen ingle-ource ingle-ink erion. 0 2 2 8 6 20 2 7 2 8 0 2 2 8 6 20 2 7 2 8 6
Manipulaing Flow Le X, Y V. We define f(x, Y ) = x X y Y f(x, y). The flow-coneraion conrain hen ju ay u V {, }, f(u, V ) = 0. Lemma: (Proof in Homework) X V, f(x, X) = 0. X, Y V, f(x, Y ) = f(y, X). X, Y, Z V wih X Y = f(x Y, Z) = f(x, Z) + f(y, Z) and f(z, X Y ) = f(z, X) + f(z, Y ) 7
Flow f wa defined a amoun ha leae ource. We now ee ha hi i he ame a amoun ha ener ink.. f = f(, V ) definiion = f(v, V ) f(v, V ) preiou page = f(v, V ) preiou page = f(v, V ) preiou page = f(v, ) + f(v, V ) preiou page = f(v, ) flow coneraion 8
In eery opimizaion problem we hae o deal wih he queion: How can we proe ha our oluion i opimal (maximal/minimal)? A common echnique (for max problem) i o find a good upper-bound on he co of an opimal oluion and hen how ha our oluion aifie ha bound. A CUT S, T of G i a pariion of he erice V = S T, S T =, S, and T. The flow acro he cu i f(s, T). The capaciy of a cu i C(S, T) = x S,y T c(x, y). Noe ha for any cu, f(s, T) c(s, T). 9
/6 0 / 2/2 /9 7/7 /20 8/ / S T 2 / Cu (S, T): S = {,, 2 }, T = {,, }. The flow alue i f = 9 and C(S, T) = 26. Noe ha F C(S, T). 0
Lemma: If S, T i any cu, f any flow hen f C(S, T). Proof: f = f(, V ) = f(, V ) + f(s, V ) = f(s, V ) = f(s, V ) f(s, S) = f(s, V S) = f(s, T) c(s, T) We will now deelop he Ford-Fulkeron mehod for finding max-flow. When FF erminae i proide a flow f and a cu S, T uch ha f = C(S, T), o f i maximal.
The Ford-Fulkeron Mehod I ieraie. Sar wih flow f = 0, ( u,, f(u, ) = 0) A each ep Conruc a reidual nework G f of f indicaing how much capaciy remain o be ued. Find an augmening pah - pah p in G f along which flow can be puhed. puhe f uni of flow along p. Creae new flow f = f + f. Sop when here i no - pah in curren G f. Le S be he e of node reachable from in G f and T = V S. A concluion of FF algorihm, f = c(s, T) o f i opimal. 2
Reidual nework Gien flow f, he reidual nework G f coni of he edge along which we can (ill) puh more flow. The amoun ha can (ill) be puhed acro(u, ) i called he reidual capaciy c f (u, ). c f (u, ) = c(u, ) f(u, ). If here i flow from u o hen f(u, ) > 0 and c f (u, ) i he remaining capaciy on (u, ). If here i flow from o u hen f(u, ) < 0 and c f (u, ) = c(u, ) + f(, u) i he capaciy of (u, ) plu amoun of exiing flow ha can be puhed backward from u o. The Reidual nework G f i G f = (V, E f ) where E f = { (u, ) V V : c f (u, ) > 0 }
/6 0 / 2/2 9 7/7 9/20 2/ / 2 A flow / 2 2 9 2 9 7 I reidual nework
Lemma: Le f be a flow in G = (V, E) and G f i reidual nework. Le f be a flow in G f. Define f+f a (f+f )(u, ) = f(u, )+f (u, ). Then f + f i a flow in G wih alue f + f = f + f. Augmening pah p i a imple - pah in G f. The reidual capaciy of a.p. p i c f (p) = min{c f (u, ) : (u, ) on p}. Le p be an augmening pah in G f and define f p (u, ) = c f (p) if (u, ) i on p c f (p) if (, u) i on p 0 oherwie Lemma: If f i a flow and p an a.p.in G f hen: f p i a flow in G g wih f p = c f (p) > 0. f = f +f p i a flow in G wih f = f + f p > f.
/6 8/ 0 / 2/2 /9 / 2 7/7 /20 / 8 2 2 7 /6 2/ 0 / 2/2 9 / 2 7/7 9/20 / 2 2 9 2 9 7 An iniial flow f. I reidual nework G f and an augmening pah f in G f. The flow f + f and i reidual nework. 6
Opimaliy Theorem: (Max-Flow Min-Cu Theorem) Le f be a flow. Then he following hree condiion are equialen:. f i a maximum flow in G. 2. G f conain no augmening pah. f = C(S, T) for ome (S, T) cu. Proof: () (2): If G f conained an augmening pah p hen f + f p > f o f could no be maximal. (2) (): Le S = {u V : pah from o in G f }. T = V S. Then f(s, T) = f(s,v ) f(s,s) = f(s, V ) = f(, V )+f(s, V ) = f. Now noe ha u S, T, f(u, ) = c(u, ) ince oherwie c f (u, ) > 0 and S. Thu C(S, T) = f(s, T) = f. () (): We preiouly aw ha eery flow f mu aify f C(S, T) o if f = C(S, T), f mu be opimal. 7
The Ford-Fulkeron Mehod Sar wih flow f 0, ( u,, f(u, ) = 0) Conruc reidual nework G f. If G f conain no augmening pah, op (f i opimal by MFMC heorem). Oherwie.. Find an augmening pah ( pah) p in G f 2. Le f p be he flow in G f ha puhe c f (p) uni of flow along p.. Le f = f + f p be new flow in G. 8
6 2 9 20 0 7 /6 /2 /9 20 0 7 / 2 2 / 2 8 0 7 20 /6 /2 7/0 /9 7/7 7/20 / 2 0 2 / 8 7 7 /6 2/2 0 / /9 7/7 /20 / 2 8/ 2 / 8 2 2 7 /6 2/ 2/2 0 / 7/7 2 9 / 9/20 / 2 2 2 9 7 9 9
Running Time & Finiene The FF mehod i no a compleely defined algorihm ince i doen pecify how o chooe he augmening pah. In fac, if he capaciie are irraional, i i poible ha a bad way of chooing he a.p. will lead o a nonerminaing algorihm ha will neer op (i will keep on adding cheaper and cheaper augmening pah). See ecion 6. of he PS book for example. If he capaciie are all ineger hen each c p will be an ineger o he algorihm mu erminae afer f ep, where f i a max-flow. Mainaining he graph G and G f and he flow f uing adjacency li while uing DFS or BFS o find a - pah, he algorihm can hen be implemened o run in O( f E ) ime. Noe: Thi can be normalized o work if he capaciie are raional. 20
Sar wih flow f 0, O( E ) Conruc reidual nework G f. O( E ) If G f conain no augmening pah, op (f i opimal by MFMC heorem). Oherwie. Can be repeaed O( f ) ime.. Find an augmening pah p in G f O( E ) 2. Le f p be he flow in G f ha puhe c f (p) uni of flow along p.. Le f = f + f p be new flow in G. O( E ) 2
A pahological example in which each augmening pah only increae flow alue by uni.,000,000,000,000 u,000,000,000,000,000,000 999,999 u,000,000 999,999 999,999 999,999 u 999,999 999,999 999,999 999,998 u 999,999 999,998 999,998 999,998 u 999,998 999,998 22
The Edmond-Karp Algorihm Alway chooe an augmening pah of minimum-lengh in G f (where each edge ha uni lengh). Thi can be done in O(E) ime uing BFS. Theorem: The EK alg perform a mo O(V E) pah-augmenaion, o he E.K. alg run in O(V E 2 ) ime. Le δ f (u, ) denoe hore-pah diance from u o in G f. The proof of he Theorem i a conequence of he following wo lemma: Lemma: V {, }, δ f (, ) doe no decreae afer a flow augmenaion. Lemma: Edge (u, ) i criical on a.p. p if c f (u, ) = c f (p). Suppoe when running he E.K. algorihm ha (u, ) i criical for a.p. p in G f, and i laer criical again for anoher a.p. p in G f. Then δ f (, u) δ f (, u) + 2. 2
Applicaion: Max Biparie Maching A graph G = (V, E) i biparie if here exi pariion V = L R wih L R = and E L R. A Maching i a ube M E uch ha V a mo one edge in M i inciden upon. The ize of a maching i M, he number of edge in M. A Maximum Maching i maching M uch ha eery oher maching M aifie M M. Problem: Gien biparie graph G, find a maximum maching. 2
A biparie graph wih 2 maching L R L R 2
Our approach will be o wrie he Max Biparie Maching problem a a Max-Flow problem. Our flow nework will be G = (V, E ) where V = V {, } and E = {(, u) : u L} {(u, ) : u L, R and (u, ) E} {(, ) : R} We alo aign (u, ) E, c(u, ) =. Lemma: If f i an ineger alued flow in G hen here i a maching M of G wih f = M. Similarly, if M i a maching of G hen here i an ineger alued flow f wih f = M. Thi almo ell u ha Max-Flow ole our problem. The difficuly i ha i poible ha he max-flow migh no hae ineger alue (i i poible ha f migh be an ineger bu ome f(u, ) migh no be ineger). 26
A biparie graph and i aociaed flow nework. A maching and aociaed flow are illuraed L R L R 27
Theorem: Le G = (V, E ) be a flow nework in which c i inegral. Then he max-flow f found by he F.F. mehod ha he propery ha u,, f(u, ) i ineger alued. The proof i by inducion on he ep in he FF mehod. A each ep he curren flow f i ineger o he reidual capaciie are all ineger. Thi implie ha he a.p. found ha c f (p) inegral o he new flow f + f creaed i alo inegral. The heorem guaranee ha if G i he flow nework correponding o a biparie maching problem hen max flow alue f i he alue of a maximum maching. The flow found by he FF algorihm can be modified o yield he max maching. The FF algorihm run on hi pecial graph will ake O(V E) ime (why?). 28
Odd and End A faer implemenaion of he FF mehod ue he idea of blocking flow deeloped by Dinic. Thi approach find many augmening pah a once. A oally differen approach o he Max-Flow algorihm i he puh-relabel mehod (ee CLRS for deail). Thi can run in O( V ) ime a comapred o he O( V E 2 ) of FF. We will ee laer ha he max-flow problem can be wrien a a linear program. The FF mehod i eenial a pecial cae of he primal-dual algorihm for oling combinaorial LP. 29