MEIO/UPC-UB : NETWORK FLOWS Network Flows UPCOPENCOURSEWARE number 34414 Topic 6: Minimum Cost Network Flow Problems 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. (Chap. 9,10 & 11 Ahuja,Magnanti,Orlin) • Pseudo-polynomial algorithms (AMO, Chap. 9) • Polynomial algorithms (AMO, Chap. 10) • Simplex algorithm (AMO, Chap. 11) F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 2 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS 6.- Minimum Cost Network Flow Problems • Definitions and assumptions. • Applications. • Optimality Conditions: – Negative Cycle Optimality Conditions. – Reduced Cost Optimality Conditions. – Complementary Slackness Optimality Conditions. • Minimum Cost Flow Duality. • Algorithms: (assignments) – Cycle-canceling and negative cycle O.C. – Successive shortest-path and Reduced cost O.C. – Out-of-kilter algorithm and Complementary Slackness O.C. • The dual-primal network flow algorithm (assignment). • Relaxation methods. • Summary. F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 3 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS MCNF: Basic algorithms (Chap. 9 AMO) • Given the network G=(N,A) with costs c, capacities u and supplies/demands b, the Minimum Cost Network Flow Problem (MCNFP) is defined as: min s.a.: z= ∑cx (i, j)∈A ∑ { j:( i , j )∈A} xij − ∑ ij ij = x ji b(i ) ∀i ∈ N (1a) (1b) { j:( j ,i )∈A} 0 ≤ xij ≤ uij ∀(i, j ) ∈ A F.-Javier Heredia http://gnom.upc.edu/heredia (1c) MCNFP- 4 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Minimum Cost Network Flow Problem (MCNFP) 1. All data (cost, supply, demand and capacity) are integral (needed for some proofs, and some running time analysis). 2. The network is directed. 3. The supplies/demands at the nodes satisfy the condition Σi∈N b(i) = 0 and the minimum cost flow problem has a feasible solution. 4. The network G contains an uncapacitated directed path between every pair of nodes • If necessary artificial uncapacitated arcs (1,j) and (j,1) ∀j∈N will be added with infinity costs. 5. All arc costs cij are nonnegative. F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 5 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS MCNFP: Assumptions • To create a feasible solution, add a dummy node d. • Add an arc from d 3 2 -4 4 3 5 2 -5 1 1 to each demand node, each with a large cost M, and large capacity. 3 6 d • Add an arc to d from each supply node, each with a large cost M, and a large capacity. • In an optimal solution, arcs with large cost will have a flow of 0. F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 6 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Artificial Solutions • Residual capacity rij : cij , uij i xij j cij , rij = uij - xij xij j i xji -cij , rij = xji • Residual network G(x) : nodes N and arcs (i,j) replaced with arcs (i,j) and (j,i) with positive residual capacity rij F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 7 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Residual network • Def: Augmenting Cycle W in G w.r.t. x : any cycle W (not necessarily oriented) s.t. “x+f(W)” feasible. – Prop.: W augmenting cycle in G w.r.t. x ⇔ W directed cycle in G(x) • Th. (Augmenting Cycle Theorem.): Let x and x0 be any two feasible Proof: AMO, page. 83 Interpretation: -4 i xij bi ( cij , uij ) j bj 2 2 5 1 4 1 3 2 x0 x 3 i 2 3 1 4 3 3 4 3 5 c(x0) + c( f(W) ) = 35 – 6 = c(x) -6 1 4 3 3 rij j G(x0) F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 8 Minimum Cost Network Flow Problems solutions of a network flow problem. Then x equals x0 plus the flow of at most m directed cycles in G(x0). Furthermore, the cost of x equals the cost of x0 plus the cost of flow on these augmenting cycles. (2,3) MEIO/UPC-UB : NETWORK FLOWS Augmenting Cycle Theorem • Ta (Negative Cycle Optimality Cond.): A feasible solution x* is an optimal solution of the minimum cost flow problem if and only if satisfies the negative cycle optimality conditions: namely, the residual network G(x*) contains no negative cost (directed) cycle. Proof: ⇒ : a pos. flow along any neg.cycle of G(x) always improve the o.f.: if x* optimal, G(x*) cannot contain a neg. cycle. ⇐ : Assume x* feasible and G(x*) without neg. cycle. Then, by the Augmenting Cycle Th., for any feasible flow x≠x* holds c(x) =c( x* ) + c( f(W) ) ≥ c( x* ) and thus, x* is optimal F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 9 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Negative cycle optimality conditions • Potentials nodes: • Reduced costs: π ( i ) ∀i ∈ N cijπ =cij − π (i ) + π ( j ) ∀(i, j ) ∈ A – Red. cost in the red. Net. G(x): • cπji = −cijπ ∀(i, j ) ∈ G ( x ) Properties: a) For any directed path P from node k to node l, π = c ∑ (i , j )∈P ij ∑ b) For any directed cycle W, • c − π ( k ) + π (l ) ( i , j )∈P ij ∑ π c = ∑ ( i , j )∈W cij ij ( i , j )∈W Consequences of properties (a) and (b): i. (a) ⇒ P is the shortest path w.r.t. c ⇔ P is the shortest path w.r.t. cπ ii. (b) ⇒ W is a neg. cycle w.r.t. c ⇔ W is a neg. cycle w.r.t. cπ F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 10 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Reduced cost optimality conditions (1/2) • Th. (Reduced Cost Optimality Cond.): A feasible solution x* is an optimal solution of the minimum cost flow problem if and only if some set of node potencials π satisfy the following reduced cost optimality conditions: Proof: cijπ ≥ 0 ∀(i, j ) ∈ G ( x*) (1) – We will see the equivalence with the Neg. Cycle. Opt. Cond (NCOC). – RCOC ⇒ NCOC: – x* optimal w.r.t. The RCOC ⇒ Prop. (b) ⇒ cπ ∑ ∑= ( i , j )∈W ij ∑ ( i , j )∈W ( i , j )∈W cijπ ≥ 0 ∀ directed cycle W ∈ G ( x*) cij ≥ 0 ⇒ G(x*) contains no negative cycle. RCOC ⇐ NCOC: x* NCOC ⇒ G(x*) contains no negative cycles. Let d(·) be the shortest path labels of the label correcting algorithm from node 1 over G(x*) and let π = -d. Then, by the convergence theorem of the label-correcting alg. (1) holds true. Remark: relation between the RCOC over G(x*) and the simplex optimality conditions for saturated arcs xij = uij F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 11 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Reduced cost optimality conditions (2/2) • Th. (Complementary Slackness Optimality Conditions): A feasible solution x* is an optimal solution of the minimum cost flow problems if and only if for some set of node potentials π, the reduced costs and flow values satisfy the following complementary slackness optimality conditions for every arc ( i , j ) ∈ A: If cijπ > 0 If 0 < xij < uij If cijπ < 0 0 , then xij* = 0 , then cijπ = , then xij* = uij Proof: AMO, pag. 310 (quite technical!!) • Relation with the optimality condition of the simplex algorithm F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 12 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Complementary Slackness Opt. Cond. Complementary Slackness optimality conditions (CSOC) If cijπ > 0 If 0 < xij < uij If cijπ < 0 , then xij* = 0 , then cijπ = 0 , then xij* = uij Kilter Diagram for arc (i, j) Francesc López Ramos y Fernándo Saráchaga Gutierrez F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 13 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS CSOC & Kilter Diagram Complementary Slackness optimality conditions (CSOC) (i, j ) (i, j ) B − D − E (i, j ) A−C ≡ ( xij , cijπ ) → in − kilter → out − of − kilter In-Kilter and Out-kilter arc Diagram Francesc López Ramos y Fernándo Saráchaga Gutierrez F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 14 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS In-Kilter / Out-kilter • Definition, – The k(i, j) is a magnitude of the change in x(i, j) required to make the arc (i, j) an in-kilter arc while keeping C(i, j, π) fixed. • Consequently, – If (i, j) is in-kilter then k(i, j) = 0. – We can measure how far we are from the optimal solution as follows: K= ∑ k (i, j ) ( i , j )∈ A – The smaller the value of K, the closer we are from the optimal solution. Francesc López Ramos y Fernándo Saráchaga Gutierrez F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 15 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Kilter Number (k(i, j)) k(i, j) has a close relation with CSOC as follows: 1) if cijπ > 0 then kij = xij 2) if cijπ < 0 then kij = uij − xij cijπ = 0 & xij > uij then kij = xij − uij cijπ = 0 & xij < 0 then kij = − xij 3) 3.1) if 3.2) if In order to use k(i, j) in the OFKA and thus, in the G(x), it is redefined as follows: 0 kij = rij if if cijπ ≥ 0 ∀(i, j ) ∈ G ( x) π cij < 0 Francesc López Ramos y Fernándo Saráchaga Gutierrez F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 16 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Computation of k(i, j)’s x(i, j) = -2 , c(i, j, π) > 0 → k(i , j) = |-2| = 2 x(i, j) = 3 , c(i, j, π) > 0 → cij k(i , j) = |3| = 3 1 1 x(i, j) = 6 , c(i, j, π) = 0 → x(i, j) = -2 , c(i, j, π) = 0 → k(i , j) = -(-2) = 2 k(i , j) = 6 - 4 = 2 3.2 3.1 xij uij = 4 2 2 x(i, j) = -2 , c(i, j, π) < 0 → x(i, j) = 2 , c(i, j, π) < 0 → k(i , j) = |4 - (-2)| = 6 k(i , j) = |4 - 2| = 2 Francesc López Ramos y Fernándo Saráchaga Gutierrez F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 17 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Cases MEIO/UPC-UB : NETWORK FLOWS Relation with G(x) G G(x) i xij = 0 rij = uij G xij = 0, cij(π) ≥ 0 j cij(π) ≥ 0 rij rij = uij - xij j cij(π) ≥ 0 0 < xij < uij i (x factible) j 0 < xij < uij, cij(π)= - cji(π) ≥0 ⇒ cij(π) = 0 rji = xij xij = uij i rji = uji j xij = uij, cij(π) = - cji(π) ≤ 0 cji(π) ≥ 0 Francesc López Ramos y Fernándo Saráchaga Gutierrez F.-Javier Heredia http://gnom.upc.edu/heredia 18 MCNFP- 18 Minimum Cost Network Flow Problems i algorithm out-of-kilter; begin π: = 0; establish a feasible flow x in the network; define the residual network G(x) and compute the kilter numbers of arcs; while the network contains an out-of-kilter arc do begin select an out-of-kilter arc (p, q) in G(x); define the length of each arc (i, j) in G(x) as max {0, C(i, j, π)}; let d(·) denote the shortest path distances from node q to all other nodes in G(x) – {(q, p)} and let P denote a shortest path from node q to node p; update π´(i) : = π(i) – d(i) for all i є N; if C(p, q, π´) < 0 then begin W : = P U {(p, q)}; delta : = min { r(i, j) : (i, j) є W }; augment delta units of flow along W; update x, G(x) and the reduced costs; end; end; end; Francesc López Ramos y Fernándo Saráchaga Gutierrez F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 19 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Out-of-kilter algorithm • Def. (Dual Minimum Cost Flow Problem) : max = w(π , α ) ∑ b(i )π (i ) − ∑ uijαij i∈N ( i , j )∈A s.t.: π (i ) − π ( j ) − αij ≤ cij ∀(i, j ) ∈ A αij ≥ 0 ∀(i, j ) ∈ A π ( j ) unrestricted ∀j ∈ N (1a) (1b) (1c) (1d) – It is easy to verify that this is the dual of the standard form of the MCNFP (exercise). F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 20 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Minimum Cost Flow Duality • Th. (Weak Duality Theorem): Let z(x) denote the objective function of some feasible solution x of the minimum cost flow problem and let w(π,α) denote the objective function value of some feasible solution (π,α) of its dual. Then w(π,α) ≤ z(x). • Th. (Strong Duality Theorem): Any minimum cost flow problem with optimal solution x* has a dual minimum cost flow problem with optimal solution π satisfying the property that z(x*)=w(π). • Th. (Rel. Duality - Comp. Slack. O.C.): If x* is an optimal solution of the minimum cost flow problem, and π is an optimal solution of the dual minimum cost flow problem, the pair (x*, π) satisfies the complementary slackness optimality conditions. F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 21 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Minimum Cost Flow Duality • Def. Lagrangian relaxed problem LR(π): = w(π ) min ∑ cij xij + ∑ π (i ) b(i ) − ∑ xij + ∑ x ji 0 ≤ xij ≤ uij ∀(i, j ) ∈ A i∈N { j:( i , j )∈A} { j:( j ,i )∈A} x (i , j )∈A • Alternative expressions of LR(π): = w(π ) min ∑ cij xij + ∑ π (i )e(i ) 0 ≤ xij ≤ uij ∀(i, j ) ∈ A i∈N x (i , j )∈A π = w(π ) min ∑ cij xij + ∑ π (i )b(i ) 0 ≤ xij ≤ uij ∀(i, j ) ∈ A i∈N x (i , j )∈A (1) (2) • Solution of problem LR(π): trivial, from formulation (2). xij* 0 if cijπ > 0 Property 1: If a pseudoflow x of the minimum cost flow problem satisfies the reduced cost if cijπ < 0 uij optimality conditions for some π, then x is an π 0 any x ∈ 0, uij if cij = optimal solution of LR(π) F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 22 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Relaxation Algorithm (1) • Lemma: a) For any node potentials π, w(π) ≤ z* b) For some choice of node potentials π*, w(π*) = z* Proof: a) If x* opt. sol. of the MCNFP ⇒ ∀π, x* feasible for LR(π) and w(π) ≤ z*. b) Let π*, x* satisfy the RCOC ⇒ By Prop. 1 : x* is the opt. solution of LR(π*) ⇒ w(π*) = z*. • Rationale of the Relaxation algorithm: – Maintains a pair (π, x), x a pseudoflow, s.t. satisfy the RCOC – It modifies π to π’ and x to x’ so that x’ is an optimal solution of LR(π’) and w(π’) > w(π). – Keeping π unchanged, it modifies x to x’ so that x’ is also an optimal solution of LR(π) and the excess of at least one node decreases F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 23 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Relaxation Algorithm (2) At some stage of the algorithm: • S: nodes of a tree T rooted at node s s.t. – Every node s∈S : e(s) ≥0. – Every arc (i,j)∈T : cπij =0 • S=N-S ; (S,S) onward arcs of cut [S, S] in G(x) ; (S,S) backward arcs of cut [S, S] in G(x). = e( S ) = e(i ) ; r (π , S ) ∑ i∈S 3 S 8 s 1 ∑ ( i , j )∈( S , S ) cijπ =0 (0,2 ) -1 2 0 rij 5 (0,3 ) 6 4 3 (2,4 ) 5 7 4 (cπij , rij ) -2 8 (3,2 ) e(i) i S 0 e(j) j F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 24 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Relaxation Algorithm (3) 3 S 8 s 1 (0,2 ) -1 2 5 (0,3 ) 0 6 4 3 (2,4 ) 5 7 -2 4 8 (3,2 ) e(i) i (cπij , rij ) S 0 e(j) j • Case 1: if e(S) > r(π,S) then increase w(π) – Modify x saturating all (i,j) ∈ (S,S) s.t. cπij =0 (w(π) invariant, due to (2)) – The change in x reduces e(S) : e(S) ← e(S)- r(π,S) ≥ 0. F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 25 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Relaxation Algorithm (4) MEIO/UPC-UB : NETWORK FLOWS Relaxation Algorithm (5) S 8 s 1 (0,2 ) 1 2 -3 5 (0,3 ) 6 7 3 (2,4 ) 5 7 -2 4 8 (3,2 ) e(i) i (cπij , rij ) S 0 e(j) j • Case 1: if e(S) > r(π,S) then increase w(π) – – – – Modify x saturating all (i,j) ∈ (S,S) s.t. cπij =0 (w(π) invariant, due to (2)) The change in x reduces e(S) : e(S) ← e(S)- r(π,S) ≥ 0. At this point cπij > 0 ∀(i,j)∈(S,S): α:=min{ cπij | (i,j) ∈ (S,S) } > 0 (*) Increase π(i) : π’(i) := π(i) + α ∀i∈S w(π) exp. (1) : w(π’) := w(π) + [e(S)-r(π,S)] α > w(π) F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 26 Minimum Cost Network Flow Problems 1 MEIO/UPC-UB : NETWORK FLOWS Relaxation Algorithm (6) 1 S 8 s 1 (2,2 ) 1 2 -3 5 (2,3 ) 6 7 3 (0,4 ) 5 7 -2 4 8 (1,2 ) e(i) i (cπij , rij ) S 0 e(j) j Modify x saturating all (i,j) ∈ (S,S) s.t. cπij =0 (w(π) invariant, due to (2)) The change in x reduces e(S) : e(S) ← e(S)- r(π,S) ≥ 0. At this point cπij > 0 ∀(i,j)∈(S,S): α:=min{ cπij | (i,j) ∈ (S,S) } > 0 (*) Increase π(i) : π’(i) := π(i) + α ∀i∈S w(π) exp. (1) : w(π’) := w(π) + [e(S)-r(π,S)] α > w(π) – The RCOC is conserved: cπij := cπij - α ≥ 0 ∀(i,j) ∈(S,S) due to (*) (and the rest of cπij cannot be < 0) – – – – F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 27 Minimum Cost Network Flow Problems • Case 1: if e(S) > r(π,S) then increase w(π) • Case 2: if e(S) ≤ r(π,S): – r(π,S) ≥ e(S) > 0 ⇒ ∃(i,j)∈(S,S) s.t. cπij = 0 – If e(j) ≥ 0 then: S:=S+{ j } – If e(j) < 0 then : augmenting flow δ trough P(s→j) e(S) decreases. w(π) invariant (cπij =0 ∀(i,j) ∈P(s →j) F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 28 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Relaxation Algorithm (7) Relaxation algorithm: given a MCNFP in standard form. begin procedure adjust-potential; x:= 0 and π:= 0; begin while the network contains a node s for every arc (i,j)∈(S,S) with cπij =0 do send rij units with e(s)>0 do of flow on the arc (i,j); begin compute α := min{cπij : (i,j)∈(S,S) and rij > 0}; S := {s}; for every node j∈S do π(j) := π(j) + α; if e(S) > r(π,S) then adjust-potencial end; else repeat select an arc (i,j)∈(S,S) in the residual network with cπij =0; if e(j) ≥ 0 then set pred(j):= i and add node j to S; procedure adjust-flow; until e(j) < 0 or e(S) > r(π,S); if e(S) > r(π,S) then adjust-potential begin identify directed P(s→j) from pred(); else adjust-flow; δ:=min[ e(s) , -e(j) , min{rij : (i,j) ∈P}]; endif augment δ along P; end; update imbalances and residual capac.; end; where: e( S ) end; = e(i ) ; r (π , S ) ∑ i∈S ∑ ( i , j )∈( S , S ) π =0 cij rij F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 29 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Relaxation algorithm (8) • Convergence: The relaxation algorithm terminates with an optimal flow x*. Proof: i. The rel. Alg. terminates with e(s)=0 ∀s∈N ⇒ x* is a feasible flow. ii. The pair (π*,x*) satisfies the RCOC. • Finite convergence: the relaxation algorithm terminates in a finite number of iterations (for problems with integral data). • Worst case analysis: O(m2nCU2) (worst than cyclecancelling, succ. shortest path and primal-dual) F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 30 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Relaxation algorithm - convergence 25 1 (4,10) (5,25) 2 3 b(i) i 4 0 (2,25) (cij ,uij ) 5 -25 j b(j) F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 31 Minimum Cost Network Flow Problems 0 (1,20) MEIO/UPC-UB : NETWORK FLOWS Relaxation algorithm – example F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 32 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Relaxation algorithm – example (cont.) The algorithms studied so far are pseudopolynomial-time algorithms, that is, its worst-case complexity is bounded by a polynomial of n, m, C and U. Algorithm Worst-case complexity Cycle cancelling O( nm2CU ) Succ. shortest path O(n3U ) ← O( nU∙S(n,m,nC)) Primal-dual O(mn3∙min{U,C}) ← O( min{nU, nC}∙{S(n,m,nC)+M(n,m,U)} ) Out-of-kilter O(mn2U ) ← O( mU∙S(n,m,nC)) Relaxation O(m2nCU2) S(n,m,nC): running time of the shortest path alg. with cij ≥ 0 (O(n2) for Dijkstra). M(n,m,U): running time of a max-flow alg. (O(mn2) for the SAPA) Instead, polynomial-time algorithms have a worst-case complexity that is bounded by a polynomial of n, m, logC and logU. F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 33 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Summary of pseudopolynomial-time MCNF algorithms • Capacity Scaling algorithm. • Cost Scaling Algorithm (assignment) • Double Scaling Algorithm (assignment) F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 34 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Polynomial MCNFP algorithms • This algorithm is an enhancement of the successive shortest path algorithm. • It ensures that in each augmentation, sufficiently large flow (at least Δ) is sent from an excess node to a deficit node. • Δ-residual network G(x, Δ): subgraf of G(x) consisting on those arcs whose residual capacity is at least Δ. • The algorithm selects a node k with excess at least Δ, selects a node l with deficit at least Δ, identifies a shortest path in G(x) from node k to node l with residual capacity at least Δ, and augments flow along this path. • The algorithm terminates when there is no imbalanced node. • Source: J. Orlin “Network Optimization” http://ocw.mit.edu/courses/sloan-schoolof-management/15-082j-network-optimization-fall-2010/ F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 35 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS The Capacity Scaling Algorithm algorithm capacity scaling; begin x: = 0 and π : = 0; Δ: = 2 log U; while Δ ≥ 1do begin {Δ-scaling phases} for every arc (i, j) in the residual network G(x) do; if rij ≥ Δ and cijπ < 0 then send rij units of flow along (i, j), update x and the imbalances e(i) and e(j); end for; S(Δ) : = {i ∈ N : e(i) ≥ Δ}; T(Δ) : = {i ∈ N : e(i) ≤ -Δ}; while S(Δ) ≠ Ф and T(Δ) ≠ Ф (and a path P from k to l over G(x,Δ)⇐ Ass.4) do Select a node k ∈ S(Δ) and a node l ∈ T(Δ); Determine a shortest path distance d(.) from node k to all other nodes in the Δ-residual network G(x,Δ) with respect to the reduced costs cijπ; Let P denote a shortest path from node k to node l in G(x, Δ); Update π := π – d and cijπ := cijπ + d(i) - d(j); Augment Δ units of flow along the path P; Update x, S(Δ), T(Δ), and G(x, Δ); end while; Δ : = Δ/2; end {Δ-scaling phases}; end while; end; F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 36 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS The Capacity Scaling Algorithm (contd.) 0 0 4 2 4 7 5 2 0 1 1 6 3 0 2 5 0 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 37 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS The Original Costs and Node Potentials 5 10 2 -2 4 30 25 23 20 20 1 20 3 -7 25 5 -19 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 38 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS The Original Capacities and Supplies/Demands 5 10 2 -2 We send flow from nodes with excess ≥ ∆ to nodes with deficit ≥ ∆. 4 30 25 23 20 20 1 20 3 -7 25 5 We ignore arcs with capacity ≤ ∆. -19 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 39 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Set ∆ = 16. This begins the ∆-scaling phase. 7 shortest path distance 8 4 2 4 7 0 5 2 1 1 6 3 6 2 The shortest path tree is marked in bold and blue. 5 8 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 40 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Select a supply node and find the shortest paths MEIO/UPC-UB : NETWORK FLOWS Update the Node Potentials and the Reduced Costs -7 43 4 7 5 6 0 0 0 2 1 1 0 6 3 -6 2 0 To update a node potential, substract the shortest path distance. 5 -8 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 41 Minimum Cost Network Flow Problems 2 -8 5 10 2 -2 Send flow from node 1 to node 5. 4 30 25 23 20 1 20 3 -7 25 20 How much flow should be sent? 5 -19 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 42 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Send Flow Along a Shortest Path in G(x, 16) 5 10 2 -2 19 units of flow were sent from node 1 to node 5. 4 30 23 4 25 20 1 20 19 1 19 3 5 6 -7 -19 0 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 43 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Update the Residual Network 5 10 2 -2 4 30 25 4 20 1 e(j) ≤ -∆ for some j. 20 19 1 The ∆-scaling phase continues when e(i) ≥ ∆ for some i. There is a path from i to j. 19 3 5 6 -7 0 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 44 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS This ends the 16-scaling phase. 5 10 2 -2 4 30 25 4 20 1 e(j) ≤ -∆ for some j. 20 19 1 The ∆-scaling phase continues when e(i) ≥ ∆ for some i. There is a path from i to j. 19 3 5 6 -7 0 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 45 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS This begins and ends the 8-scaling phase. 5 10 2 -2 4 30 25 4 20 1 20 19 1 19 3 What would we do if there were arcs with capacity at least 4 and negative reduced cost? 5 6 -7 0 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 46 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS This begins 4-scaling phase. -7 3 2 4 0 0 0 -8 6 1 1 0 0 0 3 5 The shortest path tree is marked in bold and blue. 0 -6 -8 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 47 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Select a “large excess” node and find shortest paths. MEIO/UPC-UB : NETWORK FLOWS Update the Node Potentials and the Reduced Costs 0 2 1 0 0 4 2 0 1 To update a node potential, subtract the shortest path distance. 4 -4 0 3 5 0 -6 -10 -8 -12 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 48 Minimum Cost Network Flow Problems -7 -11 -8 5 10 2 -2 4 30 25 4 20 1 20 How much flow should be sent? 19 1 19 3 Send flow from node 1 to node 7 5 6 -7 0 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 49 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Send Flow Along a Shortest Path in G(x, 4). 5 6 -2 2 4 4 26 0 4 4 units of flow were sent from node 1 to node 3 25 4 20 1 16 19 4 1 15 3 -7 -3 5 10 0 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 50 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Update the Residual Network 5 6 -2 2 4 4 26 0 There is no node j with e(j) ≤ -4. 25 4 20 1 16 19 4 1 15 3 5 10 -3 0 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 51 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS This ends the 4-scaling phase. 5 6 -2 2 There is no node j with e(j) ≤ -4. 4 4 26 0 25 4 20 1 16 19 4 1 15 3 5 10 -3 What would we do if there were arcs with capacity at least 4 and negative reduced cost? 0 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 52 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Begin the 2-scaling phase 5 6 -2 2 4 Send flow from node 2 to node 4 4 26 0 25 4 20 1 16 19 4 1 15 3 5 How much flow should be sent? 10 -3 0 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 53 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Send flow along a shortest path 3 5 4 0 -2 2 4 2 units of flow were sent from node 2 to node 4 6 26 0 25 4 20 1 16 19 4 1 15 3 5 10 -3 0 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 54 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Update the Residual Network 3 0 4 2 4 Send flow from node 2 to node 3 6 26 0 25 4 20 1 16 19 4 1 15 3 5 How much flow should be sent? 10 -3 0 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 55 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Send Flow Along a Shortest Path 0 3 0 1 2 4 3 units of flow were sent from node 2 to node 3 9 26 0 25 4 20 1 13 19 7 1 12 3 5 13 -3 0 0 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 56 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Update the Residual Network 0 0 1 2 4 Are we optimal? 9 26 0 25 4 20 1 13 19 7 1 12 3 5 13 0 0 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 57 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS This ends the 2-scaling phase. 0 0 1 2 4 9 26 0 25 4 20 1 13 19 7 1 Saturate any arc whose capacity is at least 1 and with negative reduced cost. 12 3 reduced cost 0 is negative 5 13 0 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 58 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Begin the 1-scaling phase. 0 0 1 2 4 Send flow from node 3 to node 1. 9 26 -1 25 4 20 1 13 20 7 12 3 Note: Node 1 is now a node with deficit 5 13 1 0 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 59 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Update the Residual Network 0 0 2 2 4 1 unit of flow was sent from node 3 to node 1. 8 27 0 25 3 20 1 ∆:= ∆/2 = ½ →END 14 20 6 13 3 5 Is this flow optimal? 12 0 0 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 60 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Update the Residual Network MEIO/UPC-UB : NETWORK FLOWS The Final Optimal Flow 5 10,8 2 -2 4 30,3 23 20 20,6 1 20,20 3 -7 25,13 5 -19 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 61 Minimum Cost Network Flow Problems 25 -7 0 2 4 1 0 0 -11 2 0 1 Flow is at lower bound. -4 Flow is at upper bound 3 -10 0 5 -12 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 62 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS The Final Optimal Node Potentials and the Reduced Costs • • Convergence: as in the successive shortest-path algorithm. Running time: – A Δ-scaling phase performs at most 2(n+m)=O(m) augmentations: In the Δ-scaling phase the sum of excesses is bounded by 2(n+m)Δ (see text). Each augmentation reduces the excess by at least Δ units. – Each augmentation solves a shortest path problem, S(n,m,nC) – At most log U Δ-scaling phases. – In the overall: O(m log U S(n,m,nC)) • Theorem: the capacity scaling algorithm solves the minimum cost flow problems in O( m log U S(n,m,nC) ). – Successive shortest-path alg.: O( n U S(n,m,nC) ) (pseudo-polynomial) . n m U m*logU n*U n*U/m*logU 1000 2000 1,0E+01 6,64E+03 1,00E+04 1,51E+00 1000 2000 1,0E+02 1,33E+04 1,00E+05 7,53E+00 1000 2000 1,0E+03 1,99E+04 1,00E+06 5,02E+01 1000 2000 1,0E+04 2,66E+04 1,00E+07 3,76E+02 1000 2000 1,0E+05 3,32E+04 1,00E+08 3,01E+03 1000 2000 1,0E+06 3,99E+04 1,00E+09 2,51E+04 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 63 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS The Capacity Scaling Algorithm (contd.) • Standard form. • Spanning Tree Structure. • Simplex specialization: – – – – – – – Computing the basic feasible solution. Reduced cost calculation. Leaving variable selection. Base change . Simplex Algorithm for Network Flows. Example. Exercises. F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 64 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS MCNF: Network Simplex Algorithm. (Cap. 11 AMO) • Mathematic formulation: min s.a. : z= ∑c x (i,j)∈ A ∑ xij − { j:( i , j )∈A} ij ij (1.1a) Balance equations ∑ x ji = bi ∀i ∈ N (1.1b) { j:( j ,i )∈A} xij ≥ 0 ∀(i, j ) ∈ A (1.1c) n – Assuming that the network is balanced: ∑b = 0 i =1 • Matrix notation: i c′x (1.2a) min s.a. : N x = b (1.2b) x ≥ 0 (1.2c) F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 65 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Standard form of the Minimum Cost Flow Problem • Ta : “Each spanning tree T of G define a base of the minimum cost flow problem. Conversely, each base of the minimum cost flow problem define a spanning tree of G.” (1, 2) (3,1) (3,5) ( 2, 4) 1 3 2 5 4 1 2 B= 3 4 5 (3,1) (3,5) (1, 2) ( 2, 4) 3 1 −1 0 0 5 1 −1 0 0 0 1 1 0 B=2 4 0 0 0 −1 1 0 0 −1 0 +1 +1 0 0 0 −1 0 0 0 0 −1 +1 0 0 0 −1 −1 0 +1 0 • Ta: “The rows and columns of the B matrix linked to a spanning tree T it can be rearranged so that B is triangular” Procedure: – Nodes are arranged in crossbar order : 3-5-2-4-1 – The arcs are arranged visiting the nodes according to the crossbar order. Each node is associated with the only arc that relates it with its predecessor: (3,1), (3,5), (1,2), (2,4) F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 66 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Spanning tree and bases. • 15 1 i 4 5 5 6 7 5 10 -15 15 1 5 10 -20 2 4 5 5 xij j bj 3 0 -20 2 5 5 5 bi 3 0 15 10 6 7 10 -15 Procedure: 1. Select a leaf node. 2. Assign flow to its associated arc. 3. Modify the predecessor contribution. 4. Eliminate the node and the arc treated. xB T = [10,5,5,5,10,15] (second crossbar order) F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 67 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Feasible basic solution calculation. • Reduced cost: rij = cij - πT Nij = cij - πi + πj , ∀(i,j)∈A – Any constant k it can be summed to the Lagrange multipliers πi without change the value of rij : rij = cij - πi + πj = cij – (πi+k) + (πj+k) – This implies that we can fix arbitrarily the value of the Lagrange multiplier in a node: π1 = 0 – The rest of the Lagrange multipliers can be calculated using the reduced cost expression of the basic arcs: rij = cij - πi + πj = 0 , ∀(i,j)∈T F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 68 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Reduce cost computation (I) πi i 1 5 2 -5 cij j πj 4 6 -7 2 5 -3 1 7 • 0 3 3 -2 1 -2 4 -1 Procedure: 1. Assign the value π1 = 0 to the source node. 2. Visit the following node according to the cross bar order. 3. Compute the Lagrange multiplier based on: cij - πi + πj = 0 4. Go to step 2. πT = [ -5, -3, -7, -2, -2, -1] (Cross bar order) F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 69 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Langrange multipliers computation (II) • No bàsic arc (k,l) introduction to base with flow θ : xB(θ ) = B-1b - B-1 Nklθ = xB - yklθ = xB + ∆xB(θ ) 1 i (xBij , –yij ) 2 j (2,-1) (4,0) 6 5 (3,-1) • The vector ykl is defined by the (3,0) (1,+1) 3 (0,+1) 7 4 θ =+1 fundamental cycle associated to (k,l): – If (k,l) = (7,4) i θ =+1: ∆xB(+1 ) = - ykl = [0,-1,0,-1,+1,+1]T • θ is increase until the flow of a basic arc is cancelled. – In the example, the arc (5,2) would leave and (7,4) would enter to the base with a value of 2 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 70 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Leaving variable selection • Pivotation between the outgoing arc (5,2) and the entering arc (7,4): 1 1 2 2 5 6 7 3 3 4 4 7 • The values of xB are updated, π and r from the new spanning tree 5 6 F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 71 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Base change Begin A initial feasible tree T is defined; While there are no basic arcs (i,j)∉ T with rij < 0 Do The Lagrange multipliers π are defined and the flow x associated to T; An entering arc (k,l) is selected with rkl < 0; The arc (k,l) is added to the tree and the outgoing arc (p,q); The tree T is updated; End while End F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 72 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Simplex algorithm for network flows MEIO/UPC-UB : NETWORK FLOWS Example i 0 2 9 1 cij 5 bj j -2 4 2 5 3 0 4 • Solve the problem of network 6 -5 flows associated to the following network. 5 -2 (Solution) F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 73 Minimum Cost Network Flow Problems bi 1. Formulate a network flow feasible problem of minimum cost with 6 nodes and 9 arcs. 2. Find a initial spanning tree feasible. 3. Solve the problem from the spanning tree found in the last section with the simplex algorithm for network flows. 4. Find the optimal solution with the Giden support. F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 74 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Exercise bi i 0 2 9 1 j -2 4 5 2 i πi xij j πj • Solve the network flows 5 3 0 rij bj cij 6 -5 5 -2 4 • Begin: 1 0 9 -3 2 -3 2 7 -5 3 -5 5 4 -8 0 4 2 -2 problem associated to the network. 6 -11 – Initial feasible tree: T={(1,2),(2,3),(2,5),(2,4),(4,6)} – xB=[9,0,2,7,5]T – π = [0,-3,-5,-5,-8,-11]T • 1st iteration: – A\ T={(1,3),(3,5),(5,4),(5,6)} r = [ -3, 4, 2, -2]T⇒ (1,3) entering arc – (2,3) outgoing arc F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 75 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Example (I) 1 0 -2 3 0 9 rij 1 -5 5 -2 3 4 -8 2 -2 0 j πj 2 -3 7 2 3 1 3 1 -5 5 5 -9 6 i πi xij • 2nd iteration: 6 -11 0 9 • 2 -3 2 7 2 4 -8 2 – Feasible tree: T={(1,3),(1,2),(2,5),(2,4),(4,6)} – xB=[0,9,2,7,5]T (invariant for all arcs ∉ fundamental cycles) – π = [0,-2,-3,-5,-8,-11]T(invariant from node 2) – A\ T={(2,3),(3,5),(5,4),(5,6)} r = [ 3, 1, 2, -2]T⇒ (5,6) entering arc (4,6) outgoing arc. 3rd iteration: – Feasible tree: T={(1,3),(1,2),(2,5),(5,6),(2,4)} – xB=[0,9,7,5,2]T – π = [0,-2,-3,-5,-9,-8]T – A\ T={(2,3),(3,5),(5,4),(4,6)} r = [ 3, 1, 2, 2]T>0 ⇒ optimum F.-Javier Heredia http://gnom.upc.edu/heredia MCNFP- 76 Minimum Cost Network Flow Problems MEIO/UPC-UB : NETWORK FLOWS Example (II)