4/5/05Tucker, Sec Applied Combinatorics, 4rth Ed. Alan Tucker Section 4.3 Graph Models Prepared by Jo Ellis-Monaghan
4/5/05Tucker, Sec Real World Applications Of Network Flows Maximizing the flow of oil between two cities using a large pipeline network. Maximizing the number of telephone calls possible between two places. Calculating the maximum bandwidth of a computer network.
4/5/05Tucker, Sec k(e) represents the capacity of an edge e in the network. f(e) is how much is actually going along the edge (the flow). s(e) = k(e) – f(e) is the slack on the edge. If s(e) = 0, say e is saturated. In(x) = Set of edges directed into x. Out(x) = Set of edges directed out from x. Source, a = Initial starting vertex. Sink, z = Ending vertex. b a d c z e 8,8 5,5 4,3 4,0 5,5 3,2 4,1 7,6 7,4 8,6 Note: The edge labels are (k(e), f(e)), the capacity and flow on each edge.
4/5/05Tucker, Sec a-z Flow: an integer-valued function f defined on each edge e that satisfies the following conditions: a) b) c) b a d c z e 8,8 5,5 4,3 4,0 5,5 3,2 4,1 7,6 7,4 8,6
4/5/05Tucker, Sec Cut: Let denote the set of all edges with vertex This set is known as a cut. Note: denotes the complement of P. b a d c z e 8,8 5,5 4,3 4,0 5,5 3,2 4,1 7,6 7,4 8,6 Bold edges are in the cut. The grey edge is not in the cut since it goes from to P. The dashed line represents the cut. Say is an a-z cut if _________________________________________________
4/5/05Tucker, Sec _________________________________________________ The Capacity of a Cut: Just add up the capacities on the edges going from P to. b a d c z e 8,8 5,5 4,3 4,0 5,5 3,2 4,1 7,6 7,4 8,6 Here,
4/5/05Tucker, Sec An observation: Let P not contain a or z. Since then Note that if x and y are both in P, and there is an edge e from x to y, then f(e) appears on both sides of the equation, so we can cancel it. b a d c z e 8,8 5,5 4,3 4,0 5,5 3,2 4,1 7,6 7,4 8,6 P = {b,d,e}
4/5/05Tucker, Sec This leaves only flows on edges from a vertex in to a vertex in P on the left side of the equation, and only flows out of a vertex in P to a vertex in on the right side. Thus, ( ) For each vertex subset P not containing a or z, The flow into P equals the flow out of P. b a d c z e 8,8 5,5 4,3 4,0 5,5 3,2 4,1 7,6 7,4 8,6 (sum of green-to-blue flows = sum of blue-to-green flows)
4/5/05Tucker, Sec Theorem 1: For any a-z flow f, the flow out of a equals the flow into z. Proof: Let P be all vertices in N except a and z, so. The only flow into P from {a,z} must be from a, since condition (c) forbids flow from z. Similarly by condition (c), all flow out of P must go to z. Thus: _________________________________________________
4/5/05Tucker, Sec _________________________________________________ The Value of an a-z Flow: Just add up the flows on the edges going out of a, or equivalently, going into z. b a d c z e 8,8 5,5 4,3 4,0 5,5 3,2 4,1 7,6 7,4 8,6 Here, Note,
4/5/05Tucker, Sec Theorem 2: Intuitively, should equal the total flow from which is bounded by. For any a-z flow f and any a-z cut in a network N, _________________________________________________
4/5/05Tucker, Sec Expand the network N by adding a new vertex with an edge of immense capacity, and flow. Note that and z will be in for the resulting cut. Proof: z a’ e’ a P original Edges between P and
4/5/05Tucker, Sec Proof: Continued… Now apply condition ( ) from slide 8 to P in the new network.slide 8 It says that the flow into P, which is at least equals the flow out of P. Thus: z a’ e’ a
4/5/05Tucker, Sec Corollary 2a: For any a-z flow f and any a-z cut in a network N, if and only if: (i)For each edge (ii)For each edge Further, when, f is a maximal flow and is an a-z cut of minimal capacity. _________________________________________________
4/5/05Tucker, Sec Proof: Corollary 2a Recall: The first inequality is an equality—the flow from into P (in the expanded network) equals –if condition (i) holds; so that e’ is the only edge feeding into P, otherwise the flow into P is greater than. _________________________________________________
4/5/05Tucker, Sec The second inequality is an equality—the flow out of P equals –if condition (ii) holds; otherwise it is less. Thus if and only if conditions (i) and (ii) are both true. The last sentence in the corollary follows directly from Theorem 2 Proof: Corollary 2a, continued… _________________________________________________
4/5/05Tucker, Sec By Theorem 2, Thus if Then is as big as possible (say f is a maximum flow), and is as small as possible (say is an a-z cut of minimal capacity). Proof: Corollary 2a, continued… _________________________________________________
4/5/05Tucker, Sec Goal-- Find maximum flows in networks. Method I: Flow paths (Fast and easy, but not necessarily the best) b a d c z e 8,8 5,5 4,3 4,0 5,5 3,2 4,1 7,6 7,4 8,6 A flow path is just a path from a to z.
4/5/05Tucker, Sec Basic idea Find a flow path and push as much as possible along it. Find another flow path, using only unsaturated edges, and push as much as possible along it. And so on, until you can’t find any more flow paths along unsaturated edges.
4/5/05Tucker, Sec a bd c e z 5,3 6,3 3,3 1,0 6,0 5,0 3,0 Start with 0 flow on all edges. Find a flow path, L 1. Can push 3 units along it. Find another flow path, L 3. Can push 3 units along it. a bd c e z 5,0 6,0 3,0 1,0 6,0 5,0 3,0 a bd c e z 5,3+2 6,3 3,3 1,0 6,2 5,0 3,0 Find another flow path, L 2. Can push 2 units along it. Find another flow path, L 4. Can push 1 unit along it. Can’t do any more, so the flow is f = 3 L L L L 4 a bd c e z 5,3+2 6,3 3,3 1,0 6,2+3 6,2 5,3 3,3 a bd c e z 5,3+2 6,3+1 3,3 1,1 6,2+3 6,2 5,3+1 3,3
4/5/05Tucker, Sec Note--all of the edges have been saturated in the cut, where, and, so And hence by corollary 2a on slide 14, this flow is maximal.slide 14 How do we know…. That we are done? That this is the best possible flow? a bd c e z 5,3+2 6,3+1 3,3 1,1 6,2+3 6,2 5,3+1 3,3 = the sum of the flow out of a.
4/5/05Tucker, Sec Yes, but how would we find the cut in a large messy network? And what if we hadn’t noticed the last flow path and stopped too soon? Also note that we were essentially trying all possible paths from a to z, which isn’t feasible in a large network.
4/5/05Tucker, Sec Label vertex a: [__, ]. 2.Pick a labeled vertex p with label [v *, n], and consider the unlabeled vertices adjacent to it. a. Label a vertex on a incoming edge e by [p -, m], where m = min{n, f(e)} provided that f(e) > 0 b. Label a vertex on an outgoing edge e by [p +, m], where m = min{n, s(e)}, provided that s(e) > 0 If you can’t label any more vertices following the procedure in step 2, (if the edge flows and slacks are all zero), and z is unlabeled, then…. Let P be the set of labeled vertices, and is a saturated a-z cut, so is a minimal cut and f is a maximal flow with by Cor. 2aCor. 2a Augmenting Flow Algorithm
4/5/05Tucker, Sec If z has been labeled, go to step 4. Otherwise, go to step 2. 4.Find an a-z chain * backtracking the labels. Increase the flow in the forward edges from a to z (decrease the flow in the backward edges) m units, where m is the second label on z. 5.Remove all the vertex labels (but not the new edge labels!) and return to step 1. Continue doing this until you get stuck on step 2, which is when you are finished, having found a min cut/max flow. * A chain is just a path along the edges of the graph that doesn’t have to follow the directions of the arrows. Augmenting Flow Algorithm, cont…
4/5/05Tucker, Sec Tip… This algorithm assumes that the original flow is 0 on all the edges, and for a computer program this works just fine. However, if you are finding a max flow by hand, you can reduce the amount of work by starting with a ‘pretty good’ flow constructed from flow paths before implementing the algorithm. In fact, if your ‘pretty good’ flow is actually maximal, the algorithm will confirm this in the first run through (you will get stuck on step 2 before reaching z).
4/5/05Tucker, Sec ,0 7,0 5,0 4,0 12,0 3,0 5,0 4,0 7,0 9,0 Start with 0 flow…. Example a d c f be z K1K1 K2K2 K3K3 4K14K1 + 5K 2 + 4K 3 a c f e z 6,4 7,4 5,0 4,0 4,4 12,9 3,0 5,4 4,4 7,5 9,9 d b Use flow paths to get a ‘pretty good’ flow.
4/5/05Tucker, Sec Apply algorithm 6,4 7,4 5,0 4,0 4,4 12,9 3,0 5,4 4,4 7,5 9,9 a c f e z d b
4/5/05Tucker, Sec Getting… 6,4 7,4 5,0 4,0 4,4 12,9 3,0 5,4 4,4 7,5 9,9 a c f e z d b (_, ∞) (a +, 2) (c +,2) (f +,2) (b +, 2) (d -, 2) (a +, 2) Now backtrack from z to get an a-z chain
4/5/05Tucker, Sec Now augment along the chain from a to z by the amount of the label on z 6,4 7,4 5,0 4,0 4,4 12,9+2 3,0+2 5,4-2 4,4 7,5+2 9,9 a c f e z d b
4/5/05Tucker, Sec Now run the algorithm again on this new flow. 6,4 7,4 5,0 4,0 4,4 12,11 3,2 5,2 4,4 7,7 9,9 a c f e z d b
4/5/05Tucker, Sec ,4 7,4 5,0 4,0 4,4 12,11 3,2 5,2 4,4 7,7 9,9 a c f e z d b Getting… (_, ∞) (c +, 2) (c +,1) (f +,1) (b +, 2) (e +, 2) (a +, 2) Now backtrack from z to get an a-z chain
4/5/05Tucker, Sec ,4+1 7,4+1 5,0 4,0 4,0+1 4,4 12,11+1 3,2+1 5,2 4,4 7,7 9,9 a c f e z d b Now augment along the chain from a to z by the amount of the label on z
4/5/05Tucker, Sec ,5 7,5 5,0 4,0 4,1 4,4 12,12 3,3 5,2 4,4 7,7 9,9 a c f e z d b Now run the algorithm again on this new flow.
4/5/05Tucker, Sec ,5 7,5 5,0 4,0 4,1 4,4 12,12 3,3 5,2 4,4 7,7 9,9 a c f e z d b (_, ∞) (c +, 1) (b +, 1) (e +, 1) (a +, 1) The capacity of the cut is the size of the flow, here =16. Can’t label any more, so let P be the labeled vertices.
4/5/05Tucker, Sec Theorem 3 For any given a-z flow f, a finite number of applications of the augmenting flow algorithm yields a maximum flow. If P is the set of vertices labeled during the final application of the algorithm, then is a minimal a-z cut set.
4/5/05Tucker, Sec If f is the current flow and K is the augmenting a-z flow chain, we must show the new flow f + m K is a legal flow, where m is the label on z. Check that f + m K satisfies the flow conditions:flow conditions So yes, it is a valid flow. Proof of Theorem 3
4/5/05Tucker, Sec Each time we reach z in the algorithm, we augment the flow by a positive integer m, increasing the flow along some edges. But the capacities on the edges (and the number of edges) is finite, so eventually the algorithm must get stuck on step 2, failing to label z. Proof of Theorem 3 (cont.)
4/5/05Tucker, Sec Proof of Theorem 3 (cont.) Let P be the set of labeled vertices when z is not labeled. Clearly is an a-z cut since a is labeled and z is not.
4/5/05Tucker, Sec There is no edge with non-zero slack (i.e. where the flow on the edge doesn’t equal the capacity) from any labeled vertex p to any unlabeled vertex q or else q would have been labeled.labeled Thus, by Cor. 2a, is minimal and the flow is maximal.Cor. 2a Proof of Theorem 3 (cont.)
4/5/05Tucker, Sec b a d c z e 8,8 5,5 4,3 4,0 5,5 3,2 4,1 7,6 7,4 8,6 Class exercise—apply augmenting flow algorithm.