=========================================================================== CSC 373H / L0501 Lecture Summary for Week 9 Fall 2006 =========================================================================== ----------------------- Network Flow Algorithms ----------------------- Definition: a "network" is a directed graph N=(V,E) with - a "source" s in V with no incoming edge, - a "target" t with no outgoing edge (sometimes called "sink"), - a nonnegative integer weight (the "capacity") for each edge. - Example picture. Networks can be used to represent, e.g., computer networks (capacity = bandwidth), electrical networks, etc. Network flow problem: assign flow f(e) for each edge e such that we have maximum flow in the network, subject to: - capacity constraint: 0 <= f(e) <= c(e) (flow does not exceed capacity); - conservation constraint: for each vertex v != s,t, flow into v = flow out of v (flow into v = sum_{e in E-(v)} f(e); flow out of v = ...E+..., where E-(v) = in-edges, E+(v) = out-edges). - Flow for network N = flow out of s = flow into t (by conservation). Augmenting paths: - First idea: path P = s -> ... -> t where f(e) < c(e) for each e. Define "residual capacity" delta_f(e) = c(e) - f(e), and residual capacity delta_f(P) = MIN (delta_f(e) for e in P). Augment path by adding delta_f(P) to all edge flows. - Problem: notion too narrow, can get stuck with sub-optimal solution. (Example.) - Second idea: allow "backward" edges on path and re-define residual capacity of e is c(e) - f(e) if e is a forward edge on the path; it's f(e) if e is a backward edge. - Augmenting path = s-t path where each edge has positive residual capacity (i.e., c(e)-f(e) > 0 for forward edges e, f(e) > 0 for backward edges e). (A backward edge with positive flow represents extra flow that can be reassigned to forward edges.) - Augmentation: add delta_f(P) (defined as before) to forward edges, subtract it from backward edges. - Example. Ford-Fulkerson algorithm: start with any flow f (e.g., f(e) = 0 for all e in E) while there is an augmenting path P augment f using P output f Cuts, getting maximum flow: - A "cut" is a partition of V into V_s, V_t (i.e., V = V_s U V_t and no vertex belongs to both V_s and V_t) such that s in V_s, t in V_t; . an edge (u,v) with u in V_s, v in V_t is a "forward" edge; . an edge (u,v) with u in V_t, v in V_s is a "backward" edge. - Example. - Lemma: For any cut X, flow for network |f| = flow across cut f(X), where f(X) = sum_{e forward} f(e) - sum_{e backward} f(e). - Lemma: For any cut X, f(X) <= capacity of cut c(X) (c(X) = sum of capacities of forward edges). - Corollary: For any flow f, any cut X, |f| <= c(X). Theorem (Ford-Fulkerson): |f| is maximum (and equal to c(X) for some cut) iff there is no augmenting path. Proof: (=>) augment (<=) Construct a cut X as follows: - s in V_s; - if (u,v) in E with u in V_s, v not in V_s, f(u,v) < c(u,v), then add v to V_s; - if (u,v) in E with v in V_s, u not in V_s, f(u,v) > 0, then add u to V_s. Let V_t = V \ V_s. Since there is no augmenting path, t in V_t. By definition of X, every edge crossing X has the property that f(e) = c(e) for forward edges and f(e) = 0 for backward edges. Hence, f(X) = |f| = c(X). Corollary (max-flow/min-cut theorem): For any network, the maximum flow equals the minimum cut capacity.