Network Flow
Algorithm Design Divide and Dynamic Greedy Conquer Programming Formulate problem ? ? ? Design algorithm less work more work more work Prove correctness more work less work less work Analyze running time less work more work less work
Network Flow Greedy, Divide-and-Conquer, and Dynamic Programming were design techniques Network flow → a specific class of problems. Useful in many different applications! (matching, transportation, network design, etc.) Goal: design and analyze algorithms for max-flow problem, then apply to solve other problems
Soviet Rail Network, 1955 Reference: On the history of the transportation and maximum flow problems . Alexander Schrijver in Math Programming, 91: 3, 2002.
Flow Networks Flow network. Abstraction for material flowing through the edges. G = (V , E) = directed graph Two distinguished nodes: s = source, t = sink. c(e) = capacity of edge e. 5 2 9 10 15 15 10 4 t sink s source 3 5 8 6 10 15 4 6 10 15 capacity 4 7 30
Flows An s-t flow is a function f: E → R + that satisfies: Capacity condition: For each e ∈ E: � 0 ≤ f(e) ≤ c(e) Conservation condition: For each v ∈ V – {s, t}: � ∑ f(e) = ∑ f(e) e into v e out of v 0 5 2 9 0 0 0 4 10 15 15 10 flow = 4 4 0 0 0 t sink s source 3 5 8 6 10 0 4 15 4 0 0 6 10 15 4 4 7 30 0
Flows The value of a flow f is: v(f) = ∑ f(e) e out of s 0 value = 4 5 2 9 0 0 0 4 10 15 15 10 flow = 4 4 0 0 0 t sink s source 3 5 8 6 10 0 4 15 4 0 0 6 10 15 4 4 7 30 0
Flows The value of a flow f is: v(f) = ∑ f(e) e out of s 9 value = 24 5 2 9 0 9 1 0 10 15 15 10 flow = 10 4 4 6 6 t sink s source 3 5 8 6 10 0 9 15 4 10 1 6 10 15 0 4 7 30 10
Maximum Flow Problem Find s-t flow of maximum value. 9 value = 28 5 2 9 0 9 0 1 10 15 15 10 flow = 10 4 5 8 9 t sink s source 3 5 8 6 10 0 10 15 4 13 3 6 10 15 0 4 7 30 13
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. 1 0 0 20 10 s t 30 0 10 20 Flow value = 0 0 0 2
Towards a Max-Flow Algorithm Key idea: repeatedly choose paths and “augment” the amount of flow on those paths as much as possible until capacities are met
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. 1 × 20 0 0 20 10 × s t 30 0 20 10 20 × × Flow value = 0 20 0 0 20 2
Optimal Solution Flow value = 30 1 20 10 20 10 s t 10 30 10 20 10 20 2
Problem To fix the greedy algorithm, we need a way to track: (1) how much more flow can we send on any edge? (2) how much flow can we “undo” on each edge? 1 20 0 20 10 s t 20 30 10 20 0 20 2
Residual Graph Original edge: e = (u, v) ∈ E. u 17 v Flow f(e), capacity c(e). 6 Create two residual edges residual “Forward edge” capacity e = (u, v) with capacity c(e) - f(e) u v 11 “Backward edge” 6 e ’ = (v, u) with capacity f(e) Residual graph: G f = (V , E f ). E f = edges with positive residual capacity E f = {e : f(e) < c(e)} ∪ {e ’ : f(e) > 0}
Augmenting Path Use path P in G f to to update flow in G Augment(f, P) { / / edge on P with least residual capacity b = bottleneck(P) foreach e = (u,v) ∈ P { if e is a forward edge f(e) = f(e) + b / / forward edge: increase flow else let e’ = (v, u) f(e’) = f(e’) - b / / backward edge: decrease flow } return f } Example on board
Ford-Fulkerson Algorithm Repat: find an augmenting path, and augment! Ford-Fulkerson(G, s, t) { foreach e ∈ E f(e) = 0 // initially, no flow G f = copy of G // residual graph = original graph while (there exists an s-t path P in G f ) { f = Augment(f, P) // change the flow update G f // build a new residual graph } return f }
Next Time Termination and running time (easy) Correctness: Max-Flow Min-Cut Theorem
Recommend
More recommend