1 / 31

Lectures on Network Flows

Lectures on Network Flows. COMP 523: Advanced Algorithmic Techniques Lecturer: Dariusz Kowalski. Overview. Previous lectures: Dynamic programming Weighted interval scheduling Sequence alignment These lectures: Network flows Applications: largest matching in bipartite graphs. Network.

loc
Download Presentation

Lectures on Network Flows

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lectures on Network Flows COMP 523: Advanced Algorithmic Techniques Lecturer: Dariusz Kowalski Lectures on Network Flows

  2. Overview Previous lectures: • Dynamic programming • Weighted interval scheduling • Sequence alignment These lectures: • Network flows • Applications: largest matching in bipartite graphs Lectures on Network Flows

  3. Network A directed graph G = (V,E) such that • each directed edge e has its nonnegative capacity denoted by ce • there is a node s (source) with no incoming edges • there is a node t (target) with no outgoing edges u 20 10 u,v - internal nodes 30 t s 10 20 v Lectures on Network Flows

  4. Flow s-t flow in G = (V,E) is a function f from E to R+ • capacity condition: for each e, 0  f(e) ce • conservation condition: for each internal node v, ∑e in vf(e) =∑e out vf(e) • there is a node t (target) with no outgoing edges Property: ∑e in tf(e) =∑e out sf(e) u u Network: 20 10 Flow: 20 10 30 t 10 t s s 10 20 10 20 Lectures on Network Flows v v

  5. Useful definitions Given s-t flow f in G = (V,E) and any subset of nodes S • f in(S) = ∑e in Sf(e) • f out(S) = ∑e out Sf(e) Property: f in(t) = f out(s) Example: f in(u,v) = f out(u,v) = 30 u u Network: 20 10 Flow: 20 10 30 t s 10 t s 10 20 10 20 Lectures on Network Flows v v

  6. Problem(s) • What is the maximum value of f in(t) (flow) for a given graph G = (V,E) ? • How to compute it efficiently? Assumption: capacities are positive integers. Example: f in(t) = f out(s) = 30 u u Network: Flow: 20 10 20 10 30 t s 10 t s 10 20 10 20 Lectures on Network Flows v v

  7. Residual graph Assume that we are given a flow f ingraph G. Residual graph Gf • The same nodes, internal and s,t • For each edge e in E with ce > f(e) we put weight ce - f(e) (residual capacity) • For each edge e = (u,v) in E we put weight f(e) to the backward edge (v,u) (residual capacity) u u Residual Graph: Network: u 20 0 Flow: 20 10 20 10 20 t s 30 t 20 10 t s s 0 20 20 10 10 20 v Lectures on Network Flows v v

  8. Augmenting path & augmentation Assume that we are given a flow f ingraph G, andthe corresponding residual graph Gf • Find a new flow in residual graph - through a path with no repeating nodes, and value equal to the minimum capacity on the path (augmenting path) • Update residual graph along the path New residual graph: u New flow: u Network: 10 20 u 20 10 10 10 20 10 20 t s 30 t 10 10 20 t s 20 s 10 v 10 20 20 Lectures on Network Flows v v

  9. Ford-Fulkerson Algorithm • Initialize f(e) = 0 for all e • While there is s-t path P in residual graph • Augment f through path P and get new f and new residual graph Augmentf through path P: • Find minimum capacity on the path • Go through the path and modify weights u New residual graph: Network: u u New flow: 20 10 10 10 20 20 30 t 10 20 10 10 20 t s t s s 10 10 10 20 20 20 v v v Lectures on Network Flows

  10. Analysis Correctness: maximum flow - proof later termination - each time the flow is an integer and advances by at least 1 (assumption about integer capacities) Time: O(mC) • at most C iterations, where C is the value of the maximum flow, m is the number of edges • each iteration takes O(m+n) steps - use DFS to find path P u New residual graph: u u Network: New flow: 20 10 10 10 20 20 30 t 10 20 10 10 20 t s t s s 10 10 10 20 20 20 v v v Lectures on Network Flows

  11. Reminder: Depth-First Search (DFS) Given a directed graph G = (V,E) of diameter D and the root node Goal: find a directed rooted spanning tree such that each edge in graph G corresponds to the ancestor relation in the tree Recursive idea of the algorithm: Repeat until no neighbor of the root is free • Select a free out-neighbor v of the root and add the edge from root to v to partial DFS • Recursively find a DFS’ in graph G restricted to free nodes and node v as the root’ and add it to partial DFS root’ root root’’ Lectures on Network Flows

  12. Implementing DFS Structures: • Adjacency list • List (stack) S • Array Discovered[1…n] Algorithm: • Set S= {root} • Consider the top element v in S • For each out-neighbor w of node v, if w is not Discovered then put w into the stack S and start the next iteration for w as the top element • Otherwise remove v from the stack, add edge (z,v) to partial DFS, where z is the current top element, and start the next iteration for z as the top element Remark: after considering the out-neighbor of node v we remove this neighbor from adjacency list to avoid considering it many times! root’ root root’’ Lectures on Network Flows

  13. Flows vs. Cuts (A,B) - cut in graph G: • A,B is a partition of nodes, s in A, t in B c(A,B)= ∑e out Ac(e) = ∑e in Bc(e) is the capacity of this cut Property: Minimum cut is equal to the maximum flow Example: c(A,B)= 50 u u A B 20 10 20 10 30 t 30 t s s 10 20 10 20 v v Lectures on Network Flows

  14. Max Flow vs. Min Cut For any setAcontaining s we proceed in 3 steps: • value(f)= ∑v in A ∑e out vf(e) - ∑v in A ∑e in vf(e) • value(f)= f out(A) - f in(A) • c(A,B)  f out(A) - f in(A) = value(f) Conclusion: Min-cut  value(f) Example:c(A,B)= 50 andf out(A) = 30 u u A B 20 10 20 10/10 30 t 30/10 t s s 10 20 10/10 20 v v Lectures on Network Flows

  15. FF-algorithm gives Max-flow Suppose FF-algorithm stopped with flow f : • Directed DFS tree rooted in s does not contain t • It means that cut-capacity between nodes in DFS and the remaining ones is 0 in residual graph • It follows that each edge in this cut has been reversed by augmenting flow, which means that c(DFS,DFS’) = value(f) • Using Min-cut  value(f) we get thatfis maximum u u 20 10 20 10 Residual graph: 30 t 10 20 t s s DFS 10 20 10 20 Lectures on Network Flows v Min-cut v

  16. Conclusions Network flow algorithms: • Ford-Fulkerson algorithm in time O(mC) • Correspondence between max-flows and min-cuts Lectures on Network Flows

  17. Exercises READING: • Chapter 7, Sections 7.1, 7.2, and 7.3 EXERCISES: • Modify FF-algorithm to work in time O(m2 log C) • Find an augmentation scheme to guarantee time O(mn) in FF-algorithm independently from integer C Lectures on Network Flows

  18. Overview Previous lecture: • Network flows • Ford-Fulkerson algorithm • Max-flows versus Min-cuts This lecture: • Rational and real capacities in network • Applications: largest matching in bipartite graphs • Application to disjoint paths problem Lectures on Network Flows

  19. Network Given a directed graph G = (V,E) such that • each directed edge e has its nonnegative capacity denoted by ce • there is a node s (source) with no incoming edges • there is a node t (target) with no outgoing edges u 20 10 u,v - internal nodes 30 t s 10 20 v Lectures on Network Flows

  20. Flow s-t flow in G = (V,E) is a function f from E to R+ • capacity condition: for each e, 0  f(e) ce • conservation condition: for each internal node v, ∑e in vf(e) =∑e out vf(e) • there is a node t (target) with no outgoing edges Property: ∑e in tf(e) =∑e out sf(e) u u Network: 20 10 Flow: 20 10 30 t 10 t s s 10 20 10 20 Lectures on Network Flows v v

  21. Problem What is a maximum value f in(t) = f out(s) (flow) for a given graph G = (V,E) ? How to compute it efficiently? Assumption: capacities are positive integers. Example: f in(t) = f out(s) = 30 u u Network: Flow: 20 10 20 10 30 t s 10 t s 10 20 10 20 Lectures on Network Flows v v

  22. Ford-Fulkerson Algorithm • Initialize f(e) = 0 for all e • While there is s-t path P in residual graph • Augment f through path P and get new f and new residual graph Augmentf through path P: • Find minimum capacity on the path • Go through the path and modify weights u New residual graph: Network: u u New flow: 20 10 10 10 20 20 30 t 10 20 10 10 20 t s t s s 10 10 10 20 20 20 v v v Lectures on Network Flows

  23. Non-integer capacities • Rational capacities - rescale them to integers by multiplying by the common multiply • Real capacities - difficult to handle: • Min-cut = Max-flow • FF-algorithm may work very slowly u New residual graph: u u New flow: Graph: 10 10 10 20 20 20 t 30 t 10 20 10 10 20 s t s s 10 10 10 20 20 20 v v v Lectures on Network Flows

  24. Flows vs. Cuts (A,B) - cut in graph G: • A,B is a partition of nodes, s in A, t in B c(A,B)= ∑e out Ac(e) = ∑e in Bc(e) is a capacity of the cut Property: Minimum cut is equal to the maximum flow Example: c(A,B)= 50 u u A B 20 10 20 10 30 t 30 t s s 10 20 10 20 v v Lectures on Network Flows

  25. Applications - largest matching Input: bipartite graph G=(V,W,E) Goal: largest set of non-incident edges (with different ends) Solution using flow algorithms: • Lets direct edges from V to W, introduce s connected to all nodes in V, t connected from all nodes in W • Capacities are 1 for all edges • Max-flow is the largest matching t s Lectures on Network Flows

  26. Applications - disjoint paths Input: network graph G=(V,E) Goal: largest set of edge-disjoint paths from s to t Solution: Using flow algorithms, where each edge has capacity 1 t s Lectures on Network Flows

  27. Disjoint paths cont. Suppose that k is the largest number of edge-disjoint paths from s to t. • It is also a flow: • capacity condition is clear since we push flow with value 1 through each path, and • conservation is satisfied since if a path comes into a node it also goes out Conclusion: the largest number of edge-disjoint paths from s to t is not bigger than Max-flow t s Lectures on Network Flows

  28. Disjoint paths cont. Suppose that x is the value of Max-flow produced by FF-algorithm. How to construct x edge-disjoint paths from s to t ? By induction on the number of edges in the flow. For 0 edges trivial (nothing to do, no even a path) Assume j edges in the flow. Take one of them (s,v) and continue going using edges in the flow: • We go to t - done, since we have path, remove it from the graph and continue by induction • We make a cycle - reduce the flow along the cycle to zero, and the obtained is a flow having the same value but smaller number of edges - next continue by induction t s Lectures on Network Flows

  29. Complexity Time of FF-algorithm: O(mn) ( since C = O(n) ) Time of extracting paths: each edge is considered once while extracting one path, hence total time O(mn) Total time: O(mn) Additional memory: O(m+n) for keeping paths t s Lectures on Network Flows

  30. Conclusions Network flow algorithms: • Rational capacities are easy to deal with • Real capacities are difficult to compute - although we can alternatively check Min-cut • Application to the largest matching problem in time O(mn) (n = C since capacities are 1) • Application to the edge-disjoint paths problem in time O(mn) (n = C since capacities are 1) Lectures on Network Flows

  31. Textbook and Exercises READING: • Chapter 7, Sections 7.5, 7.6 and 7.7 EXERCISES: • Find a network with real capacities for which FF-algorithm works very slowly • Prove formally that FF-algorithm gives the largest matching in the last application • Design the algorithm for finding the largest number of edge-disjoint paths from s to t in undirected network • Design the algorithm for finding the largest number of node-disjoint paths from s to t in both directed and undirected networks Lectures on Network Flows

More Related