CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows.

Slides:



Advertisements
Similar presentations
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
Advertisements

1 Review of some graph algorithms Graph G(V,E) (Chapter 22) –Directed, undirected –Representation Adjacency-list, adjacency-matrix Breadth-first search.
Introduction To Algorithms CS 445 Discussion Session 8 Instructor: Dr Alon Efrat TA : Pooja Vaswani 04/04/2005.
MAXIMUM FLOW Max-Flow Min-Cut Theorem (Ford Fukerson’s Algorithm)
The Maximum Network Flow Problem. CSE Network Flows.
Advanced Algorithm Design and Analysis (Lecture 8) SW5 fall 2004 Simonas Šaltenis E1-215b
Chapter 26 of CLSR Maximum Network Flow by me Dr. M. Sakalli Ch26 of CSLR and many other sources. Marmara Univ. Picture taken from without permission.
1 The Max Flow Problem. 2 Flow networks Flow networks are the problem instances of the max flow problem. A flow network is given by 1) a directed graph.
1 Efficient implementation of Dinic’s algorithm for maximum flow.
CS138A Network Flows Peter Schröder. CS138A Flow Networks Definitions a flow network G=(V,E) is a directed graph in which each edge (u,v)
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2001 Lecture 4 Tuesday, 2/19/02 Graph Algorithms: Part 2 Network.
1 Maximum flow problems. 2 - Introduction of: network, max-flow problem capacity, flow - Ford-Fulkerson method pseudo code, residual networks, augmenting.
1 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method Maximum bipartite matching.
1 Optimization Spring 2007 (Third Quarter). 2 Some practical remarks Homepage: Exam: Written, 3 hours. There.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lecture 4 Tuesday, 10/2/01 Graph Algorithms: Part 2 Network.
Yangjun Chen 1 Network Flow What is a network? Flow network and flows Ford-Fulkerson method - Residual networks - Augmenting paths - Cuts of flow networks.
Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching.
Flows sourcesink s t Flows sourcesink edge-weights = capacities.
1 Efficient implementation of Dinic’s algorithm for maximum flow.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2006 Lecture 5 Wednesday, 10/4/06 Graph Algorithms: Part 2.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2004 Lecture 5 Wednesday, 10/6/04 Graph Algorithms: Part 2.
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
Maximum Flow Maximum Flow Problem The Ford-Fulkerson method
Flow Networks Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut.
Maximum Flow Chapter 26.
Yangjun Chen 1 Network Flow What is a network? Flow network and flows Ford-Fulkerson method - Residual networks - Augmenting paths - Cuts of flow networks.
Single Source Shortest-Path: The General Case (with negative edges) Bellman-Ford algorithm. Iteratively relax all edges |V|-1 times Running time? O(VE).
CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Finding Max Flow.
10. Lecture WS 2006/07Bioinformatics III1 V10: Network Flows V10 follows closely chapter 12.1 in on „Flows and Cuts in Networks and Chapter 12.2 on “Solving.
Maximum Flow. p2. Maximum Flow A flow network G=(V, E) is a DIRECTED graph where each has a nonnegative capacity u.
Max Flow – Min Cut Problem. Directed Graph Applications Shortest Path Problem (Shortest path from one point to another) Max Flow problems (Maximum material.
Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices.
1 CS612 Algorithms for Electronic Design Automation CS 612 – Lecture 8 Lecture 8 Network Flow Based Modeling Mustafa Ozdal Computer Engineering Department,
Flow Networks Ching-Chen Huang Hsi-Yue Hsiao. CONTENTS Network flows on directed acyclic graphs Ford-fulkerson Algorithms -Residual networks.
CSCI 256 Data Structures and Algorithm Analysis Lecture 20 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
Theory of Computing Lecture 12 MAS 714 Hartmut Klauck.
Iterative Improvement for Domain-Specific Problems Lecturer: Jing Liu Homepage:
A directed graph G consists of a set V of vertices and a set E of arcs where each arc in E is associated with an ordered pair of vertices from V. V={0,
Maximum Flow Problem Definitions and notations The Ford-Fulkerson method.
Instructor Neelima Gupta Edited by Divya Gaur(39, MCS '09) Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09)
The Maximum Network Flow Problem
TU/e Algorithms (2IL15) – Lecture 8 1 MAXIMUM FLOW (part II)
Network Flow What is a network? Flow network and flows
Maximum Flow Chapter 26.
The Maximum Network Flow Problem
Maximum Flow Chapter 26.
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Graph Algorithms Minimum Spanning Tree (Chap 23)
CS4234 Optimiz(s)ation Algorithms
Algorithms and Networks Hans Bodlaender
Network flow problem [Adapted from M.Chandy].
Richard Anderson Lecture 23 Network Flow
Lecture 22 Network Flow, Part 2
Algorithms and Networks
Network Flows and Matching (Supplementary)
Flow Networks Topics Flow Networks Residual networks
Richard Anderson Lecture 23 Network Flow
Richard Anderson Lecture 23 Network Flow
Richard Anderson Lecture 21 Network Flow
Network Flows and Matching (Supplementary)
Flow Networks General Characteristics Applications
Flow Networks and Bipartite Matching
Algorithms (2IL15) – Lecture 7
Lecture 21 Network Flow, Part 1
Richard Anderson Lecture 22 Network Flow
Lecture 21 Network Flow, Part 1
Lecture 22 Network Flow, Part 2
Richard Anderson Lecture 22 Network Flow
Advanced Graph Homer Lee 2013/10/31.
Presentation transcript:

CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows

CS 473Lecture ?2 FLOW NETWORKS & FLOWS A flow network: a directed graph G = ( V, E ) –Two distinguished vertices : a source s and a sink t –Each edge has a nonegative capacity c(u,v)  0 (if (u,v)  E then c(u,v) = 0) –for convenience :  v  V – { s,t }, s v t, i.e., every vertex v lies on some path from s to t.

CS 473Lecture ?3 A positive flow p on G: a fn p:VxV  R  0 satisfying –capacity constraint: 0  p(u,v)  c(u,v),  u,v  V i.e., flow from one vertex to another cannot exceed the capacity note : p(u,v) > 0  (u,v)  E with c(u,v) > 0 –flow conservation: Kirschoff’s current law total positive flow leaving a vertex = total positive flow entering the vertex  u  V- { s,t } FLOW NETWORKS & FLOWS

CS 473Lecture ?4 FLOW NETWORKS & FLOWS value of a positive flow: a sample flow network G and a positive flow p on G: p/c for every edge s v1v1 v3v3 v2v2 v4v4 t 2/2 1/3 2/3 0/1 1/2 2/3 1/3 2/3 note: flow  capacity at every edge note: flow conservation holds at every vertex (except s and t) 1/1

CS 473Lecture ?5 FLOW NETWORKS & FLOWS s v1v1 v3v3 v2v2 v4v4 t 2/2 1/3 2/3 0/1 1/2 2/3 1/3 2/3 1/1

CS 473Lecture ?6 FLOW NETWORKS & FLOWS cancellation : can say positive flow either goes from u to v or from v to u, but not both –if not true, can transform by cancellation to be true –e.g.,  3 units of net positive flow from u to v –  can be obtained by canceling 2 units of flow in each direction capacity constraint still satisfied : flows only decrease flow conservation still satisfied : flow-in & flow-out both reduced by the same amount vu 5/6 2/4 vu 3/6 0/4

CS 473Lecture ?7 NET FLOW VERSUS POSITIVE FLOW DEFINITIONS positive flow is more intuitive net flow brings mathematical simplification: half as many summations to write A net flow f on G: a fn f:VxV  R satisfying –capacity constraint:  u,v  V f(u,v)  c(u,v) –skew symmetry:  u,v  V f(u,v)= - f(v,u) thus, f(u,u)= - f(u,u)  f(u,u)=0  net flow from a vertex to itself is 0 –flow conservation:  u  V- {s,t}, total net flow into a vertex is 0 Nonzero net flow from u to v  (u,v)  E, or (v,u)  E, or both. value of a net flow : |f|= net flow out of the source

CS 473Lecture ?8 NET FLOW VERSUS POSITIVE FLOW DEFINITIONS equivalence of net flow and positive flow definitions: define net flow in terms of positive flow: –f(u,v)= p(u,v) - p(v,u) Given definition of p, this def. of f satisfies (1) capacity constraint, (2) skew symmetry, and (3) flow constraint.

CS 473Lecture ?9 NET FLOW VERSUS POSITIVE FLOW DEFINITIONS define positive flow in terms of net flow: f(u,v), if f(u,v) > 0 0, if f(u,v)  0 Given definition of f, this def. of p satisfies (1) capacity constraint, (2) flow constraint. p(u,v)=

CS 473Lecture ?10 NET FLOW VERSUS POSITIVE FLOW DEFINITIONS proof of (2)  flow conservation in net flow model means that –  positive net flow leaving a vertex = positive net flow entering the vertex split summation because of skew symmetry

CS 473Lecture ?11 FLOW NETWORKS & MAXIMUM FLOW PROBLEM maximum flow problem : given a flow network G with source s and sink t –find a flow of maximum value from s to t flow network with multiple sources and sinks : –a flow network G with m sources {s 1, s 2,..., s m }= S m and n sinks {t 1, t 2,..., t n }= T n –Max flow problem : find a flow of max value from m sources to n sinks –Can reduce to an ordinary max-flow problem witha single source & a single sink

CS 473Lecture ?12 FLOW NETWORKS & MAXIMUM FLOW PROBLEM add a supersource s and a supersink t such that –Add a directed edge (s,s i ) with capacity c(s,s i )=  for i=1,2,...,m –Add a directed edge (t,t i ) with capacity c(t,t i )=  for i=1,2,...,n –i.e., V = V  {s,t}; E = E  {(s,s i ) with c(s,s i )=  :  s i }  {(t,t i ) with c(t,t i )=  :  t i }

CS 473Lecture ?13 s1s1 10 FLOW NETWORKS & MAXIMUM FLOW PROBLEM s2s2 s3s3 s4s4 v1v1 v1v1 v1v1 t1t1 t1t1 Example: A flow network with multiple sources and sinks s1s1 10 s1s1 s1s1 s1s1 v1v1 v1v1 v1v1 t1t1 t1t t s      

CS 473Lecture ?14 NET FLOW VERSUS POSITIVE FLOW DEFINITIONS Claim : any flow in a multiple-source multiple-sink flow network G = (v, t) –Corresponds to a flow of identical value in G = ( v, t ) Proof : define f for G interms of G

CS 473Lecture ?15 IMPLICIT SUMMATION NOTATION where X,Y  V functions over sets imply summation; because will write lots of summations. Example: value of a flow f = Example: flow conservation :

CS 473Lecture ?16 IMPLICIT SUMMATION NOTATION L1 : let G=(V,E) be a flow network, and let f be a flow on G, then: (a) For X  V; f(X,X) = 0 –Because each f(u,v) canceled by f(v,u)= – f(u,v) due to skew symmetry. (b) for X,Y  V; f(X,Y) = – f(Y,X) –Generalization of f(X,X)=0, same reasoning (c) for X,Y,Z  V, with X  Y=  –f(X  Y,Z) = f(X,Z)+f(Y,Z) & f(Z,X  Y) = f(Z,X)+f(Z,Y) –Split summation into sum of two summations, one over X, one over Y

CS 473Lecture ?17 IMPLICIT SUMMATION NOTATION XX Y f(x,y) f(X,X) = 0 f(y,x) X Y Z f(x,z) f(y,z) XYXY f(X,Y) = – f(Y,X) f(X  Y,Z) = f(X,Z) + f(Y,Z)

CS 473Lecture ?18 IMPLICIT SUMMATION NOTATION (d) For any X  V – {s,t}; f(X,V) = 0  f(V,X) = – f(X,V) = 0 due to flow conservation L2: |f| = f(V,t)

CS 473Lecture ?19 CUTS OF FLOW NETWORKS & UPPER BOUND ON MAX FLOW def: A cut (S, T) of a flow network is a partition of V into S and T = V-S such that s  S and t  T –Similar to the cut definition given for MST –Differences: G is a directed graph here & we insist that s  S and t  T def: f(S, T) is the net flow across the cut (S, T) of G for a flow f on G –Add all edges S  T and negative of all edges T  S due to skew symmetry def: c(S, T) is the capacity across the cut (S, T) of G –not like flow because no skew symmetry; just add edges S  T (no neg. values)

CS 473Lecture ?20 (S 1, T 1 ) = ({s, a, b}, {c, d, t}) f(S 1, T 1 ) = f(a, c) + f(b, c) + f(b, d) = 12 + (-4) + 11 = 19 c(S 1, T 1 ) = c(a, c) + c(b, d) = = 26 (S 2, T 2 ) = ({s, a}, {b, c, d, t}) f(S 2, T 2 ) = f(s, b) + f(a, b) + f(a, c) = 8 + (-1) + 12 = 19 c(S 2, T 2 ) = c(s, b) + c(a, b) + c(a, c) = = 35 ac 15/20 11/16 11/14 12/12 bd s t 4/4 4/9 8/13 T1T1 Example: 0/10 1/4 7/7 S1S1 T1T1 S2S2 T2T2 CUTS OF FLOW NETWORKS & UPPER BOUND ON MAX FLOW

CS 473Lecture ?21 WHY WE NEED NEGATIVE FLOWS Reasons behind negative flow across a cut : S f(S,T) = f(a,c) – f(c,b) + f(b,d) = 5 – = 10 = |f| no neg. Flow across the cut ac ?/5 ?/10 bd s t ?/5 T S a c 5/5 5/10 bd s t 0/5 5/5 T

CS 473Lecture ?22 WHY WE NEED NEGATIVE FLOWS Exploit capacity c(c,b) = 5 to induce negative flow across (S,T) –i.e., sacrifice negative flow of 5 for a better utilization of c(a,c) = 10 & c(b,d) = 10 S ac 5/5 10/10 bd s t 5/5 T f '(S,T) = f(a,c) – f(c,b) + f(b,d) = (5+5) – (5) + (5+5) = 10 – 5 – 10 = 15 = | f |

CS 473Lecture ?23 CUTS OF FLOW NETWORKS & UPPER BOUND ON MAX FLOW L3: For any flow f on G, the net flow across any cut (S, T) of G = |f| –f(S, T) = f(S, V-S) = f(S, V) – f(S, S) by L1(c) = f(S, V) + 0 = f(S, V)by L1(a) = f(s  (S – s), V) = f(s, V) + f(S – s, V) by L1(c) = f(s, V) + 0 = f(s, V) = |f| by L1(d) since S-s  V – {s, t}

CS 473Lecture ?24 CUTS OF FLOW NETWORKS & UPPER BOUND ON MAX FLOW C1: the value of any flow f in G is bounded above by the capacity of any cut of G –Let (S, T) be any cut of G –|f| = f(S, T) =

CS 473Lecture ?25 RESIDUAL NETWORKS intuitively: the residual network G f of a flow network G with a flow f –Consists of edges that can admit more flow def: given a flow network G = (V, E) with a flow f –residual capacity of (u, v): c f (u, v) = c(u, v) – f(u, v) c f (u, v): additional flow we can push from u to v without exceeding c(u, v) –residual network of G induced by f is the graph G f = (V, E f ) with Strictly positive residual capacities: E f = {(u, v)  V x V: c f (u, v) > 0}

CS 473Lecture ?26 RESIDUAL NETWORKS recall: if both (u, v)  E and (v, u)  E then –Transform such that either f(u, v) = 0 or f(v, u) = 0 by cancellation examples: (1) both (u, v)  E and (v, u)  E c f (u, v) = c (u, v) – f (u, v) = 5 – 3 = 2 > 0 c f (v, u) = c (v, u) – f (v, u) = 1 – (–3) = 4 > 0 uv 3/5 0/1 uv 2 4

CS 473Lecture ?27 RESIDUAL NETWORKS (2) (u, v)  E but (v, u)  E and f(u, v) ≥ 0: (v, u) becomes an edge of E f |E f | ≤ 2|E|, since (u,v)  E f only if at least one of (u,v) and (v,u) is in E note: c f (u, v) + c f (v, u) = c(u, v) + c(v, u) uv 5/5 uv 5 c f (u, v) = 5 – 5 = 0 ≤ 0 × c f (v, u) = 0 – (– 5) = 5 > 0 √ uv 3/5 uv 2 3 c f (u, v) = 5 – 3 = 2 > 0 √ c f (v, u) = 0 – (– 3) = 3 > 0 √

CS 473Lecture ?28 FLOW SUMS def: let f 1 and f 2 be flows on G flow sum f 1 +f 2 : VxV  R  ( f 1 +f 2 )(u,v) = f 1 (u,v)+f 2 (u,v) L4: flow sum f 1 + f 2 satisfies (2) skew symmetry & (3) flow conservation –(2) ( f 1 + f 2 )(u, v) = f 1 (u, v) + f 2 (u, v) = – f 1 (v, u) – f 2 (v, u) = – (f 1 (v, u) + f 2 (v, u)) = – ( f 1 + f 2 )(u, v) –(3) note: flow sum may violate (1) capacity constraint –f 1 (u,v), f 2 (u,v) ≤ c(u,v) may not mean that f 1 (u,v)+f 2 (u,v) ≤ c(u,v)

CS 473Lecture ?29 FLOW SUMS How a flow on G f relates to a flow on the original network G? L5: let f be a flow on G and let f ' be a flow on G f then, flow sum f+f ' is a flow on G with value | f+f '| = | f |+| f '| –First verify that f+f ' is a flow on G ie, show that f+f ' satisfies (1) capacity constraint, (2) skew symmetry, (3) flow constraint note that f ' is also a flow on G –so, by L4, f+f ' already satisfies (2) and (3) on G thus it remains to show that f+f ' satisfies (1) on G –(f+f ')(u, v) = f(u, v)+f '(u, v) ≤ f(u, v)+c f (u, v) = f(u, v)+(c(u, v) – f(u, v)) = c(u, v)

CS 473Lecture ?30 FLOW SUMS Second show that | f + f '| = | f |+| f '| –|f+f '| = = = | f |+| f '|

CS 473Lecture ?31 AUGMENTING PATHS For a flow f on G –augmenting path p is a simple path from s to t in G f c f (p): residual capacity of a path p = –i.e., c f (p) = max. amount of the flow we can ship along edges of p on G f

CS 473Lecture ?32 AUGMENTING PATHS L6: let f be a flow on G, and let p be an augmenting path in G f. Let f p be a flow on G f with value | f p | = c f (p) > 0 defined as c f (p) if (u,v)  p in G f f p (u,v) = 0 otherwise then, f’ = f+f p is a flow on G with value | f’ | = | f | + | f p | > | f |

CS 473Lecture ?33 AUGMENTING PATHS example: a single path p on G –can easily say that it is not all of G since flow is not conserved on p –define flow f p on G f with c f (p) = min{2, 4, 5, 2, 2, 2} = 2 st 3/52/65/52/32/4 p on G with f: st p on G f : st 2/22/4 2/5 2/2 f p on G f :

CS 473Lecture ?34 AUGMENTING PATHS example (cont.): a single path p on G –flow on p in G that results from augmenting along path p: st 3/52/65/52/32/4 p on G with f: st 5/54/63/50/34/4 f + f p on p of G: st 2/22/4 2/5 2/2 f p on G f :

CS 473Lecture ?35 MAX-FLOW MIN-CUT THEOREM Thm (max-flow min-cut): the following are equivalent for a flow f on G –(1) f is a maximum flow –(2) G f contains no augmenting paths –(3) | f | = c(S, T) for some cut (S, T) of G

CS 473Lecture ?36 MAX-FLOW MIN-CUT THEOREM proof (1)  (2): f is a max flow on G –for contradiction, assume that G contains an augmenting path p with c f (p) > 0 –then, by L6 flow sum f + f p is a flow on G f with value > | f |, contradiction

CS 473Lecture ?37 MAX-FLOW MIN-CUT THEOREM proof (2)  (3): G f contains no augmenting path, i.e., G f contains no path from s to t –define S = s  {u:  a path from s to u in G f } –define T = V – S –(S, T) is a cut: s  S & t  S  t  T because  no path from s to t in G f

CS 473Lecture ?38 MAX-FLOW MIN-CUT THEOREM proof (2)  (3) (cont.): –for each u  S and v  T, we have f(u, v) = c(u, v) Otherwise c f (u,v) = c(u,v) – f(u,v) > 0  v  S, contradiction uv uv s SV-S u v …. so, by L3, | f | = f(S, T) =c(S,T)

CS 473Lecture ?39 MAX-FLOW MIN-CUT THEOREM proof (3)  (1): | f | = c(S,T) for some cut (S,T) of G –already proved by C1 that | f | ≤ c(S, T) for all cuts (S, T) –so, | f | = c(S, T) implies that f is a max flow