540 likes | 625 Views
CSE 780: Design and Analysis of Algorithms. Lecture 17: Max Flow Definitions. Flow network. Directed graph G = (V, E) with non-negative edge weights c : E -> R c (u, v): capacity of an edge (u, v) E c ( u,v ) = 0 if ( u,v ) E If then s : source of the network
E N D
CSE 780: Design and Analysis of Algorithms Lecture 17: Max Flow Definitions CSE 2331/5331
Flow network • Directed graph G = (V, E) with non-negative edge weights c : E -> R • c (u, v):capacity of an edge (u, v) E • c (u,v) = 0 if (u,v) E • If then • s: source of the network • t: sink of the network We can still handle it if this is not satisfied. CSE 2331/5331
Flow • Aflow is a function f:V V Rs.t., • Capacity constraint: • For all u, v V, 0 ≤f(u,v) ≤ c(u,v) • Flow conservation constraint: • For all u V - {s,t}, That is, flow in = flow out. CSE 2331/5331
Value of Flow • Given a flow f, the value of f is • : i.e., total flow out of the source CSE 2331/5331
Value of Flow • Lemma: • That is, total flow out of source s = total flow in sink t. CSE 2331/5331
Max Flow Problem • Max flow problem: • Given a flow network G, find over all flows f in G. Max flow has value 23. CSE 2331/5331
Max Flow Problem • Given a flow network G, compute the max flow in G. CSE 2331/5331
Example Are we done? CSE 2331/5331
Example Max flow value: 23. CSE 2331/5331
Second Example CSE 2331/5331
Second Example Are we done ? CSE 2331/5331
Second Example We have another augmenting path! CSE 2331/5331
Max Flow for Second Example Max flow value = 14. How do we know it is not possible to further improve? CSE 2331/5331
Residual Network • Given a flow f in the network • Residual network is another directed graph defined on the same nodes with capacity on edges defined as: • For an edge , its residual capacity is: • consists of all edges with non-zero residual capacity CSE 2331/5331
Residual Capacity • Residual capacity is always positive, which follows from : • capacity constraints of the flow , and • in input network , edges and cannot both exists. CSE 2331/5331
Example CSE 2331/5331
Augmenting Path • Any directed path from source to sink in the residual network is called an augmenting path. CSE 2331/5331
Augmenting-Path Lemma: • Given an augmenting path , let be the smallest residual capacity along the path. Then there is a new flow with value as defined below: Intuitively, think of a flow on the path with value , CSE 2331/5331
Example New flow CSE 2331/5331
More Examples • What is the residual network? • What are some augmenting paths? CSE 2331/5331
More Examples • What is the residual network? • What are some augmenting paths? Can we further improve this flow? CSE 2331/5331
Max-Flow-Residual Theorem • Max-Flow-Residual Theorem • A flow f is a max-flow if and only if its residual network admits no augmenting path. • Proof: • One direction easy: If f is max flow, then there is no augmenting path in the residual network. • The other direction will be handled later. Suggests an algorithm to compute Max-flow. CSE 2331/5331
Is this flow Max-flow? New flow CSE 2331/5331
Ford-Fulkerson Max Flow Alg. CSE 2331/5331
Ford-Fulkerson Alg. (More detailed) CSE 2331/5331
Example CSE 2331/5331
Time Complexity Analysis of Ford-Fulkerson Max Flow Algorithm. CSE 2331/5331
Special Case • Consider only the case where all capacities are integers! • Integer-Flow Lemma: If all capacities of the flow network are integers, then FFMaxFlow() algorithm increases the flow by a positive integer at each iteration. CSE 2331/5331
Time Complexity for Integers Case • Time Complexity: • Let be the number of edges in an input flow network and let be the max-flow. If all capacities are integers, then FFMaxFlow() algorithm runs in time. • Note: • Time complexity depends on the output size. CSE 2331/5331
x 1000 1000 1 t s 1000 1000 y Remark • Performance depending on the augmenting paths we choose. • There is one strategy that makes sure we choose good augmenting path (Edmonds-Karp Algorithm), but we will not cover it in this class. CSE 2331/5331
Multi-sources and multi-sinks flow networks CSE 2331/5331
Sources: • Sinks: • Value of a flow f: CSE 2331/5331
Multi-Source/Sink Max Flow Problem • Given a flow network with multiple sources and sinks, find the flow with maximum value. • Reduce to single source/sink max-flow problem! • By adding an extra super-source and super-sink. CSE 2331/5331
Example CSE 2331/5331
Multi-Source/Sink Max-Flow CSE 2331/5331
Max-Flow Min-Cut CSE 2331/5331
Cuts • A cutof a flow network G = (V, E) • is a partition of V into S and , such that and • The capacity of cut (S, T) is Capacity = 25 Capacity = 36 Capacity = 28 CSE 2331/5331
Min-Cut • A minimum-cut is a cut whose capacity is minimum over all cuts Min-cut: Capacity = 23 CSE 2331/5331
Net Flow • The net flow across cut (S, T) is • That is, flow from S to T minus flow from T to S. Net flow = 19 Net flow = 19 CSE 2331/5331
Net Flow Property I • Net-Flow Lemma Given a flow in a network the net-flow is the same for any cut , and . • Proof intuition: • Intuitively, due to flow conservation property. CSE 2331/5331
Net Flow Property II • Cut Lemma: Given a flow in a network for any cut , the net flow is at most the cut capacity. That is, for any cut . • Proof: • Follows from definitions. • Corollary: Given a flow network let be the max flow of . Then, for any cut . CSE 2331/5331
Example • Recall max-flow has value 14. • What is the min-cut of this network? CSE 2331/5331
Another Example • Recall the max-flow has value 11 • What is the min-cut? CSE 2331/5331
In general, how to compute Min-cut? CSE 2331/5331
Max-Flow Min-Cut Theorem • Max-Flow Min-Cut Theorem: For any flow network the value of max-flow of = capacity of min-cut of . • Max-Flow Min-Cut Theorem Version-2: For any flow network the following three statements are equivalent: (1) is max-flow of (2) There is no augmenting path in residual network (3) for some cut of . CSE 2331/5331
Proof Sketch • : easy. Discussed before. • : Assume has no augmenting path. • Set reachable from in • Set . (So vertices in T not reachable from s.) • Since there is no edge in from any to • Total flow from S to T = • Total flow from T to S = 0 • Hence net-flow =. • : follow from Cut-Lemma and its Corollary. CSE 2331/5331
Computing Min-Cut • But proof of , once we compute the max-flow, we can compute a min-cut from it. Max flow CSE 2331/5331
Bipartite Matching CSE 2331/5331
Matching in Bipartite Graph • Bipartite graph: • Graph G = (V, E) , where V = L R, and no edge in E crosses (L, R). • A matching in bipartite graph is • A subset of edges M from E, where at most one edge from M is incident on any v V. • Maximum matching in bipartite graph • A matching with largest cardinality CSE 2331/5331