Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lectures on Network Flows

Similar presentations


Presentation on theme: "Lectures on Network Flows"— Presentation transcript:

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

2 Lectures on Network Flows
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 Lectures on Network Flows
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 20 t s 10 u v 30

5 Lectures on Network Flows
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 v f(e) = ∑e out v f(e) there is a node t (target) with no outgoing edges Property: ∑e in t f(e) = ∑e out s f(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

6 20 t s 10 u v 30 Network: 20 t s 10 u v Flow:

7 Lectures on Network Flows
Useful definitions Given s-t flow f in G = (V,E) and any subset of nodes S f in(S) = ∑e in S f(e) f out(S) = ∑e out S f(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

8 Lectures on Network Flows
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: 20 10 Flow: 20 10 30 t s 10 t s 10 20 10 20 Lectures on Network Flows v v

9 Lectures on Network Flows
Residual graph Assume that we are given a flow f in graph 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 Network: u Residual Graph: 20 u Flow: 20 10 20 10 20 t s 30 t 20 10 t s s 20 10 20 10 20 v Lectures on Network Flows v v

10 Augmenting path & augmentation
Assume that we are given a flow f in graph G, and the 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: Network: u 10 20 u 20 10 10 10 20 10 t 20 s 30 t 10 10 20 t s 20 s v 10 10 20 20 Lectures on Network Flows v v

11 u 20 t s 10 v Residual Graph: u 20 t s v Flow: 20 t s 10 v New residual graph: u New flow: 20 t s 10 v u

12 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 Augment f through path P : Find minimum capacity on the path Go through the path and modify weights u Network: New flow: u New residual graph: u 20 10 10 10 20 20 30 t 10 20 10 10 20 t s s t s 10 10 10 20 20 20 v v v Lectures on Network Flows

13 Lectures on Network Flows
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 Network: New flow: u New residual graph: u 20 10 10 10 20 20 30 t 10 20 10 10 20 t s s t s 10 10 10 20 20 20 v v v Lectures on Network Flows

14 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

15 Lectures on Network Flows
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

16 Lectures on Network Flows
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 A c(e) = ∑e in B c(e) is the capacity of this cut Property: Minimum cut is equal to the maximum flow Example: c(A,B) = 50 u u A 20 10 20 10 B 30 t 30 t s s 10 20 10 20 v v Lectures on Network Flows

17 Lectures on Network Flows
Max Flow vs. Min Cut For any set A containing s we proceed in 3 steps: value(f) = ∑v in A ∑e out v f(e) - ∑v in A ∑e in v f(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 and f out(A) = 30 u u A 20 10 20 10/10 B 30 t 30/10 t s s 10 20 10/10 20 v v Lectures on Network Flows

18 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 that f is maximum u u 20 10 Residual graph: 20 10 30 t 10 20 t s s DFS 10 20 10 20 Lectures on Network Flows v Min-cut v

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

20 Lectures on Network Flows
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

21 Lectures on Network Flows
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

22 Lectures on Network Flows
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

23 Lectures on Network Flows
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 v f(e) = ∑e out v f(e) there is a node t (target) with no outgoing edges Property: ∑e in t f(e) = ∑e out s f(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

24 Lectures on Network Flows
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: 20 10 Flow: 20 10 30 t s 10 t s 10 20 10 20 Lectures on Network Flows v v

25 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 Augment f through path P : Find minimum capacity on the path Go through the path and modify weights u Network: New flow: u New residual graph: u 20 10 10 10 20 20 30 t 10 20 10 10 20 t s s t s 10 10 10 20 20 20 v v v Lectures on Network Flows

26 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 flow: u New residual graph: u Graph: 10 10 10 20 20 20 t 30 t 10 20 10 10 20 s s t s 10 10 10 20 20 20 v v v Lectures on Network Flows

27 Lectures on Network Flows
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 A c(e) = ∑e in B c(e) is a capacity of the cut Property: Minimum cut is equal to the maximum flow Example: c(A,B) = 50 u u A 20 10 20 10 B 30 t 30 t s s 10 20 10 20 v v Lectures on Network Flows

28 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

29 t s

30 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

31 Lectures on Network Flows
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

32 Lectures on Network Flows
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

33 Lectures on Network Flows
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

34 Lectures on Network Flows
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

35 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


Download ppt "Lectures on Network Flows"

Similar presentations


Ads by Google