280 likes | 441 Views
Maximum Flow. Haidong Xue (Haydon ) 10/28/2013. What is a flow network?. A no- selfloop , weak connected directed graph (V, E) Among vertices in V T here is one and only one source vertex There is one and only one sink vertex For each vertex v, there is a path
E N D
Maximum Flow HaidongXue (Haydon) 10/28/2013
What is a flow network? • A no-selfloop, weak connected directed graph (V, E) • Among vertices in V • There is one and only one source vertex • There is one and only one sink vertex • For each vertex v, there is a path • No antiparallel edges in E • if • A Capacity is defined on each edge: V E
What is a flow network? • A flow on a flow network • i.e. does not exceed (capasity constraint) • (flow conservation) Note: In some definition of flow networks, negative flows are allowed; in these slides, we keep consistent with the textbook
Red: flow Green: capacity What is a flow network? • Are they flow networks with valid flows? 17/12 12/12 12/12 20/20 15/20 15/20 11/16 11/16 11/16 1/4 1/4 6/4 7/7 7/7 4/9 4/9 4/9 Not connected Violate the capacity constraint 4/4 4/4 13/13 8/13 10/13 11/14 11/14 12/12 15/20 11/16 1/4 7/7 4/9 4/4 8/13 11/14 Multiple Sinks Violate the flow conservation rule
Red: flow Green: capacity What is a flow network? • Are they flow networks with valid flows? 0/7 12/12 12/12 12/12 15/20 15/20 15/20 11/16 11/16 11/16 s t 1/4 1/4 1/4 7/7 7/7 7/7 0/10 4/9 4/9 4/9 have a self-loop have an antiparallel edge 4/4 4/4 4/4 8/13 8/13 8/13 11/14 11/14 11/14 1 source; 1 sink; no self-loop; no antiparallel edge; no flow exceed capacity; for all non-source non-sink vertices, total flow is 0. Page 710 Fig 26.1(b)
What if the real problem has antiparallel edges or multiple sinks or sources? v1 v1 10 V’ 4 Why do we disallow antiparallel edges? 10 4 10 Add an intermediate vertex to eliminate antiparallel edges v2 v2 s1 10 3 12 s2 t1 5 15 6 8 t s3 t2 s 20 14 13 7 s4 t3 11 18 2 s5 Add a super-source and a super sink
What is the max-flow problem? 12/12 15/20 11/16 s t 1/4 7/7 4/9 The flow of a flow network, : the net output of the source i.e., - 4/4 8/13 11/14 In the above example, = 11+8=19
What is the max-flow problem? Given a flow network, there could be more than one valid flows: = 17 The maximum-flow problem: Given a flow network, find a valid flow that has the maximum 12/12 10/12 12/12 19/20 15/20 15/20 9/16 12/16 11/16 s s s t t t 1/4 1/4 4 7/7 7/7 7/7 9 4/9 2/9 = 19 4/4 2/4 4/4 11/13 8/13 8/13 11/14 9/14 11/14 = 23 (it is a max-flow)
Find a maximum flow • Input: a flow network • Output: a flow net work with max-flow 12/12 12 19/20 20 16 12/16 s s t t 4 4 7 7/7 9 9 4 4/4 13 11/13 14 11/14
Find a maximum flow- residual networks • What are the possible modifications can be made on an edge that does not break the capacity constraint? 8/12 4/20 4/16 s t 4/4 7 4/9 4/4 4/13 4/14 Increase it at most by 10 = c-f=14-4; Decrease it at most by 4=f. To represent a possible modifications, residual networks are introduced
Find a maximum flow - residual networks A flow network with a valid flow 12/12 15/20 11/16 s t 1/4 7/7 4/9 4/4 8/13 A residual network of where 11/14 5 15 12 5 11 3 s t 5 1 4 7 8 4 11 5 3
Find a maximum flow – augmenting paths 12/12 15/20 11/16 s t 1/4 7/7 4/9 An augmenting path is a simple path from s to t in the residual network 4/4 8/13 11/14 5 15 12 5 15 12 5 11 3 s t 5 5 1 4 7 11 3 s t 5 8 1 4 7 8 4 11 5 4 11 5 3 3
Find a maximum flow – augmenting paths An augmenting path is a simple path from s to t in the residual network 5 15 12 4/ 5 11 3 s t 5 1 7 4/ 4 8 4 11 4/ 5 Guaranteed by Corollary 26.3 , modifying according to this flow on does not break the flow conservation rule 3 The residual capacity of an augmenting path: The flow defined by
Find a maximum flow – augmenting paths 5 15 12 12/12 15/20 4/ 5 11/16 11 3 s t 5 1 7 4/ 4 8 s t 1/4 7/7 4/9 4 11 4/ 5 3 Modifyaccording to 4/4 8/13 11/14 12/12 11/16 19/20 s t 1/4 7/7 0/9 4/4 12/13 11/14
Find a maximum flow • Corollary 26.3 guarantees that: • is a valid flow in • Theorem 26.6 (Max-flow min-cut theorem) further tells that: • If there is no augmenting path in , in is a maximum flow Do you have any idea to develop an algorithm to find a max-flow?
Find a maximum flow – the basic Ford-Fulkerson algorithm FORD-FULKERSON() for each ; whilethere exist pathfrom toin for each in p if+ else Initialize to 0 Repeatedly find a , and apply the modification until there is no augmenting path Is it correct? What is the time complexity?
Find a maximum flow – Analysis of F-F • Is it correct in general? • No! • A counter example: http://en.wikipedia.org/wiki/Ford%E2%80%93Fulkerson_algorithm#Non-terminating_example • Is it correct with integer capacities? • Yes. • To find a, if using DFS or BFS that is O(|V|+|E|)=O(|E|) • At most, need to it times • Time complexity:
Find a maximum flow – Edmonds-Karp algorithm EDMONDS-KARP() for each ; while there exist a BFS pathfrom toin for each in p if+ else
Find a maximum flow – Analysis of E-K • Theorem 26.8 • The total number of flow augmentations performed by the algorithm is O(|V||E|) • Time complexity
Find a maximum flow – Example 12 20 16 s t 4 7 9 12 12 12 4 13 20 20 20 16 16 16 14 s s s t t t 4 4 4 7 7 7 9 9 9 12/ 12 12/ 8 12/ 4 4 4 4 13 13 13 12 12 s t 4 7 14 14 14 9 4 13 14 12 12/ 8 12/ 4 12/ 12 12 s t 4 7 9 4 4 4 4/ 9 4/ 10 4/
Find a maximum flow – Example 12 12/ 12/ 8 12/ 4 12/ 12/ 12 12 s t 4 7 9 4 4 12 12 4 4/ 4/ 9 4/ 20 20 10 4/ 16 16 s s t t 4 4 7 7 9 9 12 19/ 1 4 4 4 12 13 13 19 s t 4 7 7/ 9 14 14 11 11 4 2 11/ 11/ 3 A max-flow cannot be reached by
Maximum bipartite matching • A problem can be converted to the max-flow problem • Bipartite Graph • A undirected graph (V, E) • , • All edges in E go betweenand • Every vertex in V has at least one incident edge
Maximum bipartite matching L L L R R R
Maximum bipartite matching A matching , L L L R R R The maximum bipartite matching problem: find a M with the maximum
Maximum bipartite matching Convert it to a max-flow problem L R L R s t Set each edge with a capacity of 1 By Lemma 26.9,
Summary • Max-flow problem • Flow network • The flow of • The residual network • A augmenting path of • , • Ford-Fulkerson, Edmonds-Karps • Maximum bipartite Matching • Bipartite graph • Matching • Convert a bipartite graph to a flow net work
FYI • Your next assignment has already been posted • Chaoyang’s will be holding extended office hours on Wednesdays from 12:00pm-4:00pm • ACM has an event tomorrow Room 460, University Center Distributed Content Delivery Systems with Real Time Route Optimization Free knowledge, pizza, soda, donut, and a door price
Pop Quiz Write down your official name clearly on the right-top corner in the form: Last Name, First Name. (e.g. Xue, Haidong)