MEIO/UPC-UB : NETWORK FLOWS Network Flows UPCOPENCOURSEWARE number 34414 Topic 10: Generalized Flows F.-Javier Heredia This work is licensed under the Creative Commons AttributionNonCommercial-NoDerivs 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. • Definitions. • Applications. • Properties and optimality conditions. • Generalized Network Simplex Algorithm. • Source material: – R.K. Ahuja, Th.L. Magnanti, J. Orlin “Network Flows”, chap. 15. – J. Orlin “Network Optimization” http://ocw.mit.edu/courses/sloanschool-of-management/15-082j-network-optimization-fall-2010/ F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 2 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS Generalized Flows • Suppose one unit of flow is sent in (i,j). We relax the assumption that one unit arrives at node j. • If 1 unit is sent from i, µij units arrive at j: i µij = 7 j µij is called the multiplier of (i,j) F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 3 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS Overview of Generalized Flows xij = amount of flow sent in (i,j) µij = multiplier of (i,j) b(i) = supply at node i cij = unit cost of flow in (i,j) uij = upper bound on flow in (i,j) Minimize subject to ∑ ∑ c xij ( i , j )∈ A ij j:( i , j )∈ A xij − ∑ j:( j ,i )∈A µ ji x= b( i ) ∀ i ∈ N ji 0 ≤ xij ≤ uij ∀ (i , j ) ∈ A F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 4 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS LP Formulation of Generalized Flows i µij = 1.05 4/1/03 i coal j (i,j) represents a 1 year investment in an equity 4/1/04 µij = .4 j electricity (i,j) represents a conversion of coal into electricity F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 5 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS Conversions of physical entities i job µij = 3 j machine It takes 3 hours to make one unit of job i on machine j. xij = units of product i made on machine j µij = number of hours to make product i on machine j d(i) = number of units of product i that need to be made. d(j) = total time available on machine j. F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 6 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS Machine Scheduling • Suppose that 1 incremental unit is sent from node 1, that flow is conserved in 2, 3, and 4, arrives at node 5. 1 1 µ12 = 3 2 3 µ23 = .5 3 µ34 = 4 1.5 4 µ45 = 1 6 5 6 • For a directed path P from i to j, if one unit of flow is sent from i, then the amount arriving at j is: µ ( P ) = ∏ ( i , j )∈P µ ij F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 7 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS Flows Along Directed Paths • Suppose that 1 incremental unit is sent from node 1, that flow is conserved in 2, 3, and 4, arrives at node 5. µ12 = 4 1 1 1 2 4 µ23 = 2 -2 3 µ34 = 6 2 2 • Let P be a path from i to j. P = Forward arcs of P P = Backward arcs of P µ45 = 4 4 -3 12 5 3 Flow reduction • If one unit of flow is sent from i, then the amount arriving at j is: µ ( P ) = ∏ ( i , j )∈P µ ij / ∏ ( i , j )∈P µ ij F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 8 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS Flows Along Non-directed Paths • Suppose 1 unit is sent 2 4 1 4 1 -2 1 3 W 1.5 -1.5 3 around W starting and ending at node 1. 2 2 6 2 5 4 -3 2 µ (W ) = ∏ ( i , j )∈W µ ij / ∏ ( i , j )∈W µ ij µ(W) = 1.5 4 12 • If µ(W) ≠ 1, then the amount of flow arriving at node 1 is different than the amount leaving node 1. • If µ (W) = 1, W is called a breakeven cycle. F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 9 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS Flows Along Cycles 2 4 1 4 • Suppose θ units are 2 s send around W starting and ending at node s. 3 • The net amount W 1.5 6 2 3 5 4 2 4 12 arriving at node 1 is: θ[µ(W)- 1 ]. • To create a “supply” of “a” units at node s, send θ =a/[µ(W)- 1 ] units of flow. F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 10 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS Flows Along Cycles Minimize s. t.: ∑ ∑ c xij ( i , j )∈ A ij j:( i , j )∈ A xij − ∑ j:( i , j )∈A µ ji x ji = b( i ) i ∈ N 0 ≤ xij ≤ uij ∀ ( i , j ) ∈ A. • The equality constraints have full row rank, which is n. • A basis consists of n columns that are linearly independent. • Equivalently, a basis has n columns such that no subset of these columns is dependent. F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 11 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS On the LP for Generalized Flows r W • An augmented tree T is a connected subset of k nodes and k arcs for some k i.e. T it is a spanning tree plus an extra arc. • It usually has a root. • T is called good if the cycle is non-breakeven. F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 12 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS Augmented Trees 1 4 12 5 7 W1 10 9 11 6 2 W2 3 8 • An augmented forest is a collection of node disjoint augmented trees including all nodes. • The augmented forest is good if each cycle is nonbreakeven. F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 13 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS Augmented Forests 1 4 12 5 7 W1 10 9 11 6 2 W2 3 8 • Def.: (F, L, U) is an augmented forest structure − F are the arcs in the augmented forest. − L are the arcs at their lower bound: xij = 0 for (i,j)∈ L − U are the arcs at their upper bound: xij = uij for (i,j)∈ U • Th. (good augmented forests and basis): A set B of arcs defines a basis of the generalized network flow problem if and only if B is a good augmented forest proof: AMO, pag. 582-583 F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 14 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS Augmented Forest Structure • Let π(i) be the node potential for node i. π c • The reduced cost of arc (i,j) is: ij =cij − π ( i ) + µijπ ( j ) i µij j F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 15 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS Node Potentials and Reduced Costs Th. (Generalized Flow Sufficient Optimality Conditions) A flow x* is an optimal solution of the generalized network flow problem if it is feasible and for some vector π of node potentials, the pair (x*, π) satisfies the following optimality conditions: (a) If 0 < xij* < uij , then cijπ = 0 = (b) If xij* 0, then cijπ ≥ 0 = (c) If xij* uij , then cijπ ≤ 0 proof: AMO pag.: 576-577 F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 16 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS Optimality Conditions (1/2) Property (Augmented Forest Structure Optimality Conditions) A feasible augmented forest structure (F, L, U) with the associated flow x* is an optimal augmented forest structure if for some vector π of node potentials, the pair (x*, π) satisfies the following optimality conditions. (a) For all ( i , j ) ∈ F , cijπ = 0 (b) For all ( i , j ) ∈ L, cijπ ≥ 0 (c) For all ( i , j ) ∈ U , cijπ ≤ 0 F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 17 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS Optimality Conditions (2/2) algorithm generalized network simplex begin determine the initial feasible augmented forest structure (F, L, U); let x be the flow and π be the node potentials; while some nonbasic arc violates its optimality condition do begin select an entering arc (k,l) violating its opt. condition; add arc (k,l) to the forest and determine the leaving arc; perform a forest update, and update x and π; end; end; F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 18 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS Generalized Network Simplex 1. Find an initial feasible augmented forest structure (F, L, U). (This is often an artificial solution, see AMO, pag 584). 2. Compute node potentials π reduced costs cπij . 3. Find feasible flow x. 4. Simplex leaving arc rule. F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 19 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS The generalized simplex algorithm 1 Compute node potentials $3,2 1. Set the potential of the root node to θ. We will determine θ later. 2. Determine the node potentials of all other nodes so that tree arcs have a reduced cost of 0. cij uij 7 $1,4 $0,2 $2, 4 10 8 4 $1,3 3. Determine θ so that the extra arc also has a reduced cost of 0. $1,1 12 F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 20 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS Computing Node Potentials for an Augmented Forest Structure 0 cijπ = cij − π ( i ) + µ ijπ ( j ) = θ 1 π c17 =c17 − π (1) + µ17π (7) =0 3 - θ + 2 π(7) = 0 π(7) = (θ - 3)/2 $3,2 (θ-3)/2 7 $1,4 $0,2 $2, 4 10 8 4 $1,3 $1,1 12 F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 21 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS Computing Node Potentials θ 1 0 cijπ = cij − π ( i ) + µ ijπ ( j ) = $3,2 π c7,10 =c7,10 − π (7) + µ 7,10π (10) =0 0 - (θ - 3)/2 + 2 π(10) = 0 π(10) = (θ - 3)/4 (θ-3)/2 7 $1,4 $0,2 $2, 4 (θ-3)/4 10 8 4 $1,3 $1,1 12 F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 22 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS Computing Node Potentials θ 1 0 cijπ = cij − π ( i ) + µ ijπ ( j ) = $3,2 π c8,7 =c8,7 − π (8) + µ 8,7π (7) =0 1 - π(8) + 4(θ - 3)/2 = 0 π(8) = 2θ - 5 (θ-3)/2 7 $1,4 $0,2 $2, 4 (θ-3)/4 10 8 2θ-5 4 $1,3 $1,1 12 F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 23 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS Computing Node Potentials θ 1 0 cijπ = cij − π ( i ) + µ ijπ ( j ) = $3,2 π c7,4 =c7,4 − π (7) + µ 7,4π (4) =0 2 - (θ - 3)/2 + 4 π(4) = 0 π(4) = (θ - 7)/8 (θ-3)/2 7 $1,4 $0,2 $2, 4 (θ-3)/4 10 8 2θ-5 4 (θ-7)/8 $1,3 $1,1 12 F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 24 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS Computing Node Potentials θ 1 0 cijπ = cij − π ( i ) + µ ijπ ( j ) = $3,2 π c4,12 =c4,12 − π (4) + µ 4,12π (12) =0 1 - (θ - 7)/8 + π(12) = 0 π(12) = (θ - 15)/8 (θ-3)/2 7 $1,4 $0,2 $2, 4 (θ-3)/4 10 8 2θ-5 4 $1,3 (θ-7)/8 $1,1 (θ-15)/8 12 F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 25 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS Computing Node Potentials θ 1 0 cijπ = cij − π ( i ) + µ ijπ ( j ) = $3,2 π c4,10 =c4,10 − π (4) + µ 4,10π (10) =0 1 - (θ - 7)/8 + 3(θ - 3)/4 = 0 8 - θ + 7 + 6θ - 18 = 0 θ = 3/5 (θ-3)/2 7 $2, 4 (θ-3)/4 10 • This equation has a feasible solution whenever the cycle is non-breakeven (exercise 15.20). $1,4 $0,2 8 2θ-5 4 $1,3 (θ-7)/8 $1,1 (θ-15)/8 12 • To compute the node potentials for a basis structure (F, L, U), compute the node potentials for each connected component of F. F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 26 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS NEXT: Look at the extra arc and compute θ • Compute reduced costs in the usual way. 3/5 1 $3,7 $3,2 -6/5 7 $1,4 $0,2 cijπ = cij − π ( i ) + µ ijπ ( j ) $2, 4 π c10,1 =c10,1 − π (10) + µ10,1π (1) -3/5 10 4 $1,3 -4/5 $1,1 π c10,1 =+ 3 3 / 5 + 7(3 / 5) = 39 / 5 8 -19/5 -9/5 12 F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 27 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS The reduced costs • The node numbers are 1 1 supplies/demands. The arc numbers are the multipliers. 2 0 7 • To compute the arc flows, set the flow in the extra arc to θ and then compute the tree arcs in the usual way as a function of θ. 4 2 -11 10 4 3 4 -1 12 F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ -6 1 8 1 GF- 28 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS The Arc Flows • Set the flow in the extra 1 1 arc to θ. 2 • Compute the flow in 0 7 (4,12) x4,12 = 1 4 2 -11 10 4 3, 3 θ 4 -6 1, 1 1 8 1 -1 12 F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 29 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS The supply of node 12 is -1 • Compute the flow in (8,7) 1 1 2 x8,7 = 1 0 7 4,1 2 -11 10 4 3, θ 4 -6 1, 1 1 8 1 -1 12 F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 30 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS The supply of node 8 is 1 • Compute the flow in (7,10) 1 1 2 2 x7,10 + 3 x4,10 = 11 (11 - 3θ)/2 0 7 4,1 2 x7,10 = (11 - 3θ)/2 -11 10 4 3, θ 4 -6 1, 1 1 8 1 -1 12 F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 31 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS The supply of node 10 is -11 • Compute the flow in (1,7) 1 1 2 1 2, x1,7 = 1 (11 - 3θ)/2 0 7 4,1 2 -11 10 4 3, θ 4 -6 1, 1 1 8 1 -1 12 F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 32 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS The supply of node 1 is 1 • Compute the flow in (7,4) 1 1 2 1 2, - 4x7,4 + x4,12 + x4,10 = -6 (11 - 3θ)/2 x7,4 = (6 + 1 + θ )/4 = (7 + θ )/4 0 7 4,1 2 -11 10 4 3, θ 4 8 1 -6 (7 + θ)/4 1 1, 1 -1 12 F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 33 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS The supply of node 4 is -6 1 1 2 1 2, (11 - 3θ)/2 x7,10 + x7,4 - 4x8,7 – 2 x1,7 = 0 0 7 4,1 2 (11 - 3θ)/2 + (7 + θ)/4 – 4 – 2 = 0 -11 10 (22 - 6θ) + (7 + θ) – 24 = 0 4 3, θ 4 θ=1 8 1 -6 1 1 (7 + θ)/4 1, -1 12 F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 34 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS The supply of node 7 determines θ θ=1 1 1 2 1 2, 4 • But how do we know that there will be a solution for θ? We next present an alternative approach that shows that there is a solution to the system of equations. 0 7 4,1 2 -11 10 4 3, 1 4 -6 1 1 2 1, -1 12 F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ 8 1 GF- 35 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS The basic flows 1 1 • Choose a node of the 2 cycle. Say node 7. 0 7 • Satisfy supply/demand constraints using tree arcs but ignoring node 7. 2 -11 10 4 4 4 • Satisfy flow in node 7 by sending flow around the cycle. -6 1 8 1 -1 12 F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 36 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS An alternative approach 1 1 x4,12 = 1 2, 2 1 x8,7 = 1 2 5.5 2, x7,10 = 5.5 0 7 4 1 4, 4 -11 10 4 x1,7 = 1 -6 1 1, 1 8 1 -1 12 F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 37 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS An alternative approach 1 1 x4,12 – 4 x7,4 = - 6 2 1 2, 1 – 4 x7,4 = - 6 0 7 2 5.5 2, 4 1 4, x7,4 = 1.75 4, 1,75 4 • Now send flow around -11 10 the cycle 7-4-10-7 to cancel the excess flow of -1.25 units at node 7. 3 4 -6 1 1, 1 8 1 -1 12 • Since the cycle is not breakeven, this is possible. Thus there is a feasible solution to this set of equations. F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 38 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS An alternative approach • Send one unit out of 7 and 6 satisfy conservation of flow at nodes 4 and 10: µ(W) = 4*3/2 = 6 1 • Currently, there is a deficit of 1.25 units at node 7. So, we need to send another 1.25 units to node 7. • Sending 7 e(7)=-1.25 2 10 (5/4) /[µ(W)- 1 ] = 1/4 3 12 units around the cycle balances node 7 (⇒θ=1). F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ 4 4 4 GF- 39 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS Sending flow around the cycle • In computing flows, we assumed that all non- basic flows are 0. If U ≠ ∅, then we first compute the flows of arcs in U, and adjust the supplies and demands (or excess and deficits) accordingly, and then compute flows in arcs in F. F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 40 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS What happens if U ≠ ∅ ? • Suppose (i,j) enters the basis. Let y be the flow obtained in F + (i,j) by setting yij = 1, and determining flows in F so that there is conservation of flow everywhere. • Let x* be the basic feasible flow for (F, L, U). • Choose λ maximal so that x* + λy satisfies upper and lower bound constraints. Pivot out an arc (r, s) that has hit its upper or lower bound for this choice of λ. • Time to determine leaving arc is O(n). F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 41 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS Finding the leaving arc • Suppose x* = (2, 1, 3, 1, 0, 0, 5) • Suppose y = (1, 2, -1, 0, 1, 0, 0) • Suppose u = (4, 4, 4, 3, 6, 2, 5) 0 0 0 0 0 0 0 ≤ 2 1 3 1 0 0 5 + λ 1 2 -1 0 1 0 0 ≤ 4 4 4 3 6 2 5 λ≤2 λ ≤ 1.5 λ≤3 λ≤6 • So, we pick λ = 1.5. and variable 2 drops out of the basis. • Exercise. F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 42 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS A quick illustration of choosing λ • The bases for generalized flow problems are good augmenting forests assuming that the graph is – connected and – has a non-breakeven cycle • Complexity: – Theoretical: the number of iterations cannot be polinomial bounded (neither pseudopolinomial) – Practical: O(nm) (2 or 3 times slower than the network simplex) F.-Javier Heredia http://gnom.upc.edu/heredia J. Orlin http://jorlin.scripts.mit.edu/ GF- 43 Generalized Flows MEIO/UPC-UB : NETWORK FLOWS Summary