CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 23
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.
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...
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 t capacity source sink
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
Flow Example u st v
Flow Example a s d b cf e g h i t
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 Flow value = 0
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 = X X X 20
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 opt = 30 s 1 2 t
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
Residual Graph Original edge: e = (u, v) E –Flow f(e), capacity c(e) Residual edge –"Undo" flow sent –e = (u, v) and e R = (v, u) –Residual capacity: Residual graph: G f = (V, E f ) –Residual edges with positive residual capacity –E f = {e : f(e) 0} uv 17 6 capacity flow uv 11 residual capacity 6
Build Residual Graph s 1 2 t
Augmenting Path Lemma Let P be a path from s to t with minimum capacity b in the residual graph b units of flow can be added along the path P in the flow graph
Augmenting Path Algorithm Augment(f, c, P) { b bottleneck(P) foreach e P { if (e E) f(e) f(e) + b else f(e R ) f(e) - b } return f } forward edge backward edge
Ford-Fulkerson Max-Flow Algorithm Ford-Fulkerson(G, s, t, c) { foreach e E f(e) 0 G f residual graph while (there exists augmenting path P) { f Augment(f, c, P) update G f } return f }
Ford-Fulkerson Example s t G: Flow value = 0 0 flow capacity
Ford-Fulkerson Example s t G: s t G f : X X X 0 Flow value = 0 capacity residual capacity flow
Ford-Fulkerson Example s t G: s t G f : X X X 2 X Flow value = 8
0 Ford-Fulkerson Example s t G: s t 4 2 G f : X X X 8 X Flow value = 10
Ford-Fulkerson Example s t G: s t 1 6 G f : X X X 0 X Flow value = 16
Ford-Fulkerson Example s t G: s t 6 2 G f : X X X 9 X X 3 Flow value = 18
Ford-Fulkerson Example s t G: s t G f : Flow value = 19