Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI 256 Data Structures and Algorithm Analysis Lecture 18 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.

Similar presentations


Presentation on theme: "CSCI 256 Data Structures and Algorithm Analysis Lecture 18 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some."— Presentation transcript:

1 CSCI 256 Data Structures and Algorithm Analysis Lecture 18 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some by Iker Gondra

2 Network Flow Soviet Rail Network, 1955 Reference: On the history of the transportation and maximum flow problems. Alexander Schrijver in Math Programming, 91: 3, 2002.

3 Maximum Flow and Minimum Cut Max flow and min cut –Two very rich algorithmic problems –Cornerstone problems in combinatorial optimization –Beautiful mathematical duality Nontrivial applications / reductions –Data mining –Project selection –Airline scheduling –Bipartite matching –Baseball elimination –Image segmentation –Network connectivity –Network reliability –Distributed computing –Security of statistical data –Network intrusion detection –Multi-camera scene reconstruction –Many many more...

4 Flow Network Flow network –Abstraction for material flowing through the edges –G = (V, E) = directed graph, no parallel edges –Two distinguished nodes: s = source, t = sink –c(e) = capacity of edge e s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 15 4 4 capacity source sink

5 Flows Def: An s-t flow is a function that satisfies –For each e  E: (capacity) –For each v  V – {s, t}: (conservation) Def: The value of a flow f is: The maximum-flow problem –Given a flow network, a natural goal is to arrange the traffic so as to make as efficient use as possible of the available capacity –Thus basic algorithmic problem is: given a flow network, find a flow of maximum possible value

6 Flow Example a s d b cf e g h i t 20 5 55 5 5 10 20 5 5 5 5 10 30

7 How to solve the Max-Flow Problem?? There is no known algorithm for the Maximum- Flow problem that can be viewed as belonging to the DP paradigm What about greedy approaches?? Let us look at a simple example

8 Simple Flow Example u st v 20 30 10

9 Towards a Max Flow Algorithm Greedy algorithm –Start with f(e) = 0 for all edges e  E –Find an s-t path P where each edge has f(e) < c(e) –Augment flow along path P –Repeat until you get stuck s 1 2 t 10 00 00 0 20 30 Flow value = 0

10 Towards a Max Flow Algorithm Greedy algorithm –Start with f(e) = 0 for all edge e  E –Find an s-t path P where each edge has f(e) < c(e) –Augment flow along path P –Repeat until you get stuck s 1 2 t 20 Flow value = 20 10 20 30 00 00 0 X X X 20

11 Towards a Max Flow Algorithm Greedy algorithm –Start with f(e) = 0 for all edge e  E –Find an s-t path P where each edge has f(e) < c(e) –Augment flow along path P –Repeat until you get stuck local optimality  global optimality greedy = 20 s 1 2 t 2010 20 30 200 0 opt = 30 s 1 2 t 2010 20 30 2010 20

12 Towards a Max Flow Algorithm The way we are going to increase the flow is by finding augmenting paths (i.e., s-t paths that increase the flow) The other way that we can increase the flow is by reversing the direction of flow Push forward on edges with leftover capacity and push backward on edges that are already carrying flow to divert it in a different direction To search for forward-backward capacity for a flow network G and a flow f on G define the notion of residual graph G f

13 Residual Graph G f has original nodes of G = (V,E), and but we redefine the set of edges and their capacities Original edge: e = (u, v)  E Given: flow f(e), capacity c(e) G f - Forward edge –(u,v)  E, where c(e) > f(e) G f - Backward edge –"Undo" flowsent – e R = (v, u) if f(e) > 0 - G f - Capacity: –For e: it is c(e)-f(e) –For e R : it is f(e) Residual graph: G f = (V, E f ) –E f = {e : f(e) 0} uv 17 6 capacity flow uv 11 residual capacity 6

14 Residual Graph –Any edge e such that f(e) 0) is called a backward edge – Consider our example graph with path s,1,2,t, and flows e(s,1) = 20, e(1,2) = 20 and e(2,t) = 20 and the other edges have 0 flow.

15 Below, the flow function f is indicated by blue. Build Residual Graph G f - do in class (see text fig 7.4 (b) ) s 1 2 t 2010 20 30 200 0

16 To push flow from s to t in G f Call capacities in G f “residual capacities” Let P be a simple s-t path in G f Bottleneck (P,f) = the minimal residual capacity of any edge in P, with respect to f; denote it by b b units of flow can be added (to each edge) along the path P The following operation augment(f,P) yields a new flow f’ in G:

17 Augmenting Paths in a Residual Graph augment(f,P) Let b = bottleneck(P,f) For each edge (u,v) in P If e=(u,v) is a forward edge then increase f(e) in G by b Else (u,v) is a backward edge; let e = (v,u) decrease f(e) in G by b EndIf EndFor Return(f)

18 example The algorithm augment(f,P) results in a new flow f’ in G, obtained by increasing and decreasing the flow on edge values of P Start with f(e) = 0 everywhere. Then G f = G. Consider first (simple) path P: s,1, t. Let f’=augment (P,f); and find G f’ Then in our example with a new path simple P, the path s,2,1,t in G f’, find f’’= augment(f’,P) and find G f’’

19 Max-Flow Ford Fulkerson Algorithm Initially f(e) = 0 for all e in G While there is an s-t path in G f Find P a simple s-t path in G f f’=augment(P,f) Update the residual graph G f to be G f’ Let f’ be f and G f’ be G f EndWhile Return f


Download ppt "CSCI 256 Data Structures and Algorithm Analysis Lecture 18 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some."

Similar presentations


Ads by Google