Chapter 5 Page 1 Network Flow Programming Methods The focus of this chapter is on the development of algorithms for solving network flow problems. We begin with a discussion of the most prominent special cases, including the transportation problem, the shortest path problem, the maximum flow problem and their variants, and conclude with a presentation of the primal simplex algorithm for the pure minimum cost flow problem. Although virtually all of the special cases are instances of the minimum cost flow problem, a great deal can be learned by studying them separately. The individual algorithms provide insight into different ways of solving problems, and have the benefit of being extremely efficient. In addition, many applications of the minimum cost flow problem embody features of the special cases. From a modeling perspective, it is helpful to know how these features can be incorporated in broader formulations. 5.1 Transportation Problem The transportation problem is concerned with finding an optimal distribution plan for a single commodity. A given supply of the commodity is available at a number of sources, there is a specified demand for the commodity at each of a number of destinations, and the transportation cost between each source-destination pair is known. In the simplest case, the unit transportation cost is constant. The problem is to find the optimal distribution plan for shipments from sources to destinations that minimizes the total transportation cost. Matrix Model The traditional way to describe a transportation problem is with a matrix or tableau as in Fig. 1. The m sources at which the commodity is available are identified by name at the left side of the matrix, and the n destinations to which the commodity is to be shipped are arrayed along the top. The quantities available at the sources are shown as numbers at the right of the matrix with si the supply at source i. The quantities required by the destinations are shown as numbers along the bottom with the demand dj required at destination j. The numbers in the body of the matrix are the unit costs of shipping from sources to destinations with cij the cost from source i to destination j. If it is not possible to ship between a given source and destination, a large cost of M is entered in the appropriate cell. A requirement of most solution algorithms is that total supply equal total demand; i.e., Σ i si = Σ j dj. This is known as the feasibility property. All instances of the traditional transportation problem can be modified so that this requirement is satisfied by simply adding either a dummy source if demand exceeds supply, or a dummy destination if supply exceeds demand. 2 Network Flow Programming Methods Sources Demands s1 s2 : sm d1 c11 c21 : cm1 d1 Destinations d2 … … c12 … c22 : … cm2 … d2 dn c1n c2n : cmn dn Supplies s1 s2 : sm Figure 1. Matrix model of the transportation problem A solution to this model is an assignment of flows to the cells of the matrix. In general, we call x ij the flow in the cell representing shipments from source s i to destination dj. For a feasible solution, the sum of the flows across a row of the matrix must equal the supply at the associated source, and the sum of the flows down a column of the matrix must equal the demand at the associated destination. A numerical example is given in Fig. 2a. The optimal solution is displayed in Fig. 2b. a. Transportation model b. d1 d2 d3 Supply s1 9 12 10 15 s1 s2 8 15 12 15 s2 s3 13 17 19 15 s3 20 15 Demand 10 Received Optimal solution d1 d2 d3 0 5 10 10 0 5 0 15 0 10 20 15 Shipped 15 15 15 Figure 2. Instance of transportation problem in matrix format The transportation problem is a linear program so it can be solved using the simplex method described in earlier chapters. Because of its special structure, however, the simplex method can be considerably simplified. In the following, we assume that total supply equals total demand. Example Throughout this section we use the example presented in Fig. 3 in matrix or tableau format. The example has three sources and five destinations. The supplies at the sources are shown in the right column of the table, and the demands at the destinations are shown along the bottom. Simplex Method for the Transportation Problem D1 S1 15 S2 13 D2 D3 15 5 11 11 15 9 6 Demand 12 5 Supply 10 11 8 D5 16 15 0 S3 D4 3 15 11 15 7 8 0 15 10 5 5 10 10 15 Figure 3. Example problem A cell is identified for each supply-demand combination, and the unit cost of shipping is the boxed number in the upper left corner of the cell. The bold number in the lower right is the flow assigned to the cell. Because the total supply equals the total demand, the flows in each row sum to the supply at the corresponding source. The flows in each column sum to the demand at the corresponding destination. The flows shown in Fig. 3 are feasible but not optimal. The goal of this section is to describe an algorithm to find the optimal flow, that is, the flow that minimizes total cost. Theory Primal Linear Programming Model Let x ij be the flow from source i to destination j. The transportation problem has a linear programming model. Minimize the total shipping cost: m Minimize Z = n ∑ ∑c x i =1 j =1 ij ij subject to (i) the supply at each source must be used: n ∑x ij = si for i = 1,...,m. PS(i) j =1 (ii) the demand at each destination must be met: m ∑x ij = dj for j = 1, ...,n. PD(i) i =1 (iii) nonnegativity: x ij ≥ 0 for i = 1,...,m and j = 1,...,n. Although we have an equality constraint for every source and destination, one of the equality constraints of the model is redundant. 4 Network Flow Programming Methods This can be seen by separately adding the m supply constraints and the n demand constraints and observing from the feasibility property that the two sums are equal. Thus the m+ n equations are linearly dependent. As we will see, the transportation algorithm exploits this redundancy. Basic Solutions The primal problem has n + m constraints with one redundant constraint. A basic solution for this problem is determined by a selection of n + m - 1 independent variables. The basic variables assume values to satisfy the supplies and demands, while the nonbasic variables are zero. For the example problem, m = 3 and n = 5, so the number of basic variables is 7. Figure 3 shows a basic solution. The flows in the seven basic cells, identified with bold-faced numbers, uniquely satisfy the supplies and demands. The fact that some of the basic flows are zero indicates that this basic solution is degenerate. Cells are said to be dependent and do not form a basis if one can trace a closed path through the cells in the tableau. The path consists of a series of horizontal and vertical moves turning only at the selected cells. Figure 4 depicts a selection of dependent cells and the closed path that connects them. D1 S1 D2 15 D3 15 S2 13 11 S3 8 12 16 n → ↑ 15 n Demand 5 D4 10 D5 11 → ← n 11 ↑ n 15 → Supply 11 → n 15 9 6 15 7 8 ↓ ↓ ↓ ← → ← 5 ← n 10 15 Figure 4. Dependent cells A basis is any collection of n + m – 1 cells that does not include a dependent subset. The basic solution is the assignment of flows to the basic cells that satisfies the supply and demand constraints. The solution is feasible if all the flows are nonnegative. From the theory of linear programming we know that there is an optimal solution that is a basic feasible solution. Dual Linear Programming Model The dual of the primal linear programming model has a dual variable for each constraint of the primal. Let ui be the dual variable corresponding to the constraint PS(i). Let v j be the dual variable corresponding to the constraint PD(j). Then using the procedures of Section 4.4, the dual problem is constructed as below. Simplex Method for the Transportation Problem m Maximize y 0 = ∑ n siui + i =1 subject to ui + v j ≤ cij 5 ∑ djv j . j =1 for i = 1,...,m , j = 1,...,n. D(i, j) The values of ui and v j are unrestricted in sign for all i and j. Conditions for Optimality From duality theory we know that a complementary pair of primal and dual feasible solutions are optimal to their respective problems. To simplify our discussion, define the slack variable for the general dual constraint to be w ij , where w ij = cij – ui – v j. (1) The complementary slackness property states that for every basic primal variable the corresponding dual constraint must be satisfied as an equality; i.e., ui + v j = cij or w ij = 0 for every basic variable x ij (2) Because of the redundant primal constraint, one of the dual variables can be arbitrarily set to zero. The others can be determined with Eq. (2). By construction we assure that the primal solution is feasible. If all the dual constraints are satisfied for the dual solution, both the primal and dual solutions are optimal. The condition for dual feasibility is as follows: ui + v j ≤ cij or w ij ≥ 0 for all nonbasic cells (3) This result is the foundation for the solution algorithm described below. In numerical examples, we use the graphical construction of Fig. 5 to show the dual variables and the corresponding dual slack variables. The dual variables ui are shown along the right margin and the variables v j are shown along the bottom. The dual slacks are shown in the nonbasic cells in the upper right corner. These values are zero for the basic cells and are not shown. D1 S1 15 S2 13 S3 8 1 16 D4 –3 11 D5 -4 11 Supply -5 10 11 12 5 7 D3 15 5 2 Deman d vj D2 9 -2 6 -6 15 11 11 4 15 7 0 15 10 7 8 15 15 0 5 ui 8 5 5 7 0 10 10 8 Figure 5. Dual variables shown on the matrix 15 6 Network Flow Programming Methods The tableau is constructed for any basic solution by arbitrarily assigning zero to one of the ui or v j variables. In the examples, we always assign the zero value to the row or column with the most basic cells. This simplifies the process of determining the other dual values. Given the basic cells, it is a simple matter to compute the values of the remaining n + m – 1 dual variables. This is done by solving the n + m – 1 simultaneous equations given by Eq. (2) using back substitution. Note that there is no requirement that ui or v j be nonnegative. Once the dual variables are determined, the values of w ij for the nonbasic cells are computed using Eq. (1). Figure 5 shows the complete tableau that we use for transportation problems. Given the basic cells, there is a unique assignment of flows to satisfy the supplies and demands. Once one of the dual variables is assigned arbitrarily to zero, the others are uniquely determined. The value of w ij is, in fact, the marginal benefit of allowing x ij to enter the basis. Evidently the basis picked for Fig. 5 is not optimal because some of the w ij are negative. The value of w 25 = -6 indicates that the objective value will be reduced by 6 for every unit increase in x 25. The primal simplex algorithm proceeds by allowing x 25 to enter the basis as described presently. The Simplex Algorithm Step 1.Construct the initial tableau. Prepare the initial tableau showing problem parameters. Start with some selection of independent basic cells for which the primal solution is feasible. Determine the unique values of the basic variables (cell flows) for this basis and place them in the cells. Step 2.Compute the dual variables for the current basis and check for optimality. a. Assign the value of zero for the dual variable of the row or column with the most basic cells. Determine the values of the others so that the complementary slackness condition (w ij = 0 for basic cells) is satisfied. Place these values at the boundaries of the tableau. b. For each nonbasic cell compute the dual slack variable w ij and place it in the body of the cell. c. If all the values of w ij are nonnegative, stop with the optimal solution; otherwise go to Step 3. Step 3.Change the basis a. (Find the cell to enter the basis) Select the entering cell as the one with the most negative value of w ij . b. (Find the cell to leave the basis). Construct the cycle that starts with the entering cell, passes through only basic cells, and Simplex Method for the Transportation Problem 7 returns to the entering cell. Show the cycle in the tableau as a sequence of alternating vertical and horizontal lines connecting pairs of cells on the cycle. Mark the entering cell with a plus (+). Mark the first basic cell on the cycle with a minus (–). Alternately mark each basic cell on the cycle with (+) or (–) until the entering cell is reached. Find the basic cell marked with a minus having the smallest value of flow. This is the cell that is to leave the basis. If there is a tie, select any one of the tied cells arbitrarily. Let δ be the value of the basic variable for the leaving cell. c. (Change the basic solution). For every cycle cell marked with a plus, increase the basic variable by δ. For every cycle cell marked with a minus, decrease the basic variable by δ. Remove the leaving cell from the basis. Add the entering cell to the basis with flow equal to δ. d. Return to Step 2. Solution to the Example Problem We illustrate how the algorithm works with the example problem starting from the basic solution shown in Fig. 5. A step of the algorithm is completely described with a tableau similar to that shown in Fig. 6. The basic cells are identified by the cells with the flow indicated in the lower right. The dual slack variables are computed for the nonbasic cells and shown in the upper right. A cell with a negative w ij is selected to enter the basis as indicated by a + sign. We find the unique cycle formed by this cell and some of the cells of the current basis. The small arrows indicate the cells on the cycle. The signs with the arrows indicate the direction in which the basic flows will change. Note that the signs alternate in the cells of the cycle. Figure 6 shows these steps for the first iteration of the algorithm. D1 S1 S2 S3 D2 15 13 8 D3 15 5 2 1 16 vj 11 12 5 7 –3 11 D5 -4 11 Supply -5 10 15 0 5 →− 9 11 -2 6 8 -6 ↓+ 15 11 10 7 ui 15 ↑+ Demand D4 7 0 15 8 5 5 7 4 15 ←− 0 10 10 15 8 Figure 6. First iteration for example; x 25 enters the basis and x 35 leaves with δ = 10 The cells that have negative signs determine the maximum flow change in the cycle and hence the variable to leave the basis. In the example, cells (2, 3) and (3, 5) experience a decrease in flow. The 8 Network Flow Programming Methods minimum flow in these two cells determines the flow change, δ = 10. The basis change will have cell (2, 5) entering the basis and cell (3, 5) leaving. Figure 7 shows the tableau of the second iteration. D1 S1 15 S2 13 S3 D2 D3 15 5 2 8 1 16 →− 11 ↑+ 12 –3 10 15 0 5 ←− 5 11 vj -4 11 -2 6 15 Supply 1 ui 4 15 7 10 15 10 11 11 ↓+ 9 D5 0 5 11 ↑+ Demand D4 10 6 8 ←− 5 5 11 15 –4 15 10 6 Figure 7. Second iteration for example; x 14 enters the basis and x 23 leaves with δ = 5 The second iteration selects cell (1, 4) to enter the basis. The cycle formed is shown by the arrows, with the direction of flow change indicated by the signs of the cycle cells. The minimum flow in the cells containing negative signs is the value of the flow change, δ = 5. Both cells (2, 3) and (3, 4) have this value, and we select (2, 3) arbitrarily. Because of the tie for the leaving variable, the flow x 34 will be zero in the next tableau, a degenerate solution. The remaining iterations are shown in Figs. 8 – 10. All the values of w ij are nonnegative in the final figure, indicating that the optimum has been found. D1 S1 15 →− S2 S3 D2 13 8 D3 15 5 2 -3 16 1 15 4 5 11 12 5 1 11 ↑+ 5 Demand vj 15 D4 15 15 11 5 2 7 15 15 10 11 ↓+ 9 D5 ←− 11 Supply 1 ui 0 15 6 8 0 5 –4 10 2 15 –4 15 10 10 Figure 8. Third iteration; x 31 enters the basis and x 34 leaves with δ = 0 Simplex Method for the Transportation Problem D1 S1 D2 15 15 →− S2 5 2 13 S3 8 5 11 5 4 12 ↑+ 15 16 ↓+ 15 -2 11 1 9 5 2 3 15 15 18 D5 11 7 10 15 D4 11 ←− 0 5 Demand vj D3 9 Supply ui 1 0 15 6 –4 10 5 8 15 –7 15 5 11 10 10 Figure 9. Fourth iteration; x 13 enters the basis and x 11 leaves with δ = 5 D1 S1 15 D2 2 D3 15 16 5 S2 13 S3 8 4 11 12 15 5 2 vj 11 9 5 2 6 7 1 8 Supply 10 15 0 15 –4 10 3 15 –5 15 15 16 ui 1 10 5 13 D5 11 5 3 11 5 Demand D4 5 11 10 10 Figure 10. Optimal solution Finding an Initial Basic Feasible Solution Algorithm The simplex algorithm starts from any feasible basic solution. When first encountering a problem, though, some procedure must be used to find this solution. A general algorithm follows based on the process of crossing out rows and columns until all the supply is exhausted and all the demand is met. Once again, we assume that the feasibility property holds. Initialization Step Draw a tableau showing all problem parameters. None of the rows or columns is crossed out. Iterative Step According to some criterion, select a cell that has not been crossed out. Let that cell be basic. Assign a value to the basic variable for the cell that will use up either the remaining supply in the row or the remaining demand in the column (i.e., pick the smaller of the two). Reduce the remaining supply for the row and the remaining demand for the column by the amount assigned. Cross out the row or column whose supply or demand goes to zero. If both go to zero, cross out only one. 10 Network Flow Programming Methods Stopping Rule If only one row or column remains, let all the cells not yet crossed out be basic and assign them all the remaining supply or demand. Stop with a basic solution defined by the selected cells. If more than one row and more than one column remain, go to iterative step. There are alternative possibilities for the selection rule in the iterative step. They differ with respect to the work required to carry them out and the quality of the initial solution they generate. Generally, methods requiring greater effort will yield better solutions. For hand calculations the effort may be justified. For computer implementations it is often true that the simpler methods are more effective because the iterative step of the transportation simplex algorithm is so efficient. Several alternatives are described below. Northwest Corner Rule The upper left-hand corner of the tableau is called the northwest corner. The rule is to select the uncrossed cell closest to the northwest corner. This is the simplest rule to apply. The initial solution used in the example, as seen in Figs. 5 and 6, was obtained by the northwest corner rule. Vogel's Method This method looks ahead one step and constructs a penalty for not being able to assign a flow to the remaining cells in a row or column whose cost is smallest, but instead having to pick the cell with the second smallest cost. In economic terms, the idea is to determine the opportunity cost associated with each possible assignment and then pick the cell with the greatest opportunity cost. To begin, compute for each uncrossed row the difference between the smallest cost in the row and the second smallest cost. Do the same for uncrossed columns. Select the row or column with the greatest of the differences. The rule is to choose the uncrossed cell in the selected row or column with the smallest cost. When done by hand, Vogel's method is usually performed directly on the tableau. The selection of basic variables in each iteration is accompanied by the crossing out of a row or column and the recomputation of differences as well as supplies and demands. The tableau becomes so messy, however, that we suggest using the format shown in Table 1 together with the transportation matrix. Each row of the table lists the row and column differences, the basic variable assigned, the adjustment of demands and supplies, and the row or column crossed out. Vogel's method on the example problem yields the optimal solution shown in Fig. 10 without additional iterations. Simplex Method for the Transportation Problem 11 Table 1. Format for Vogel computations Iteration no. 1 Row differences 1 2 3 0 3 1 2 0 3 3 0 4 5 6 7 1 5 Column differences 2 3 4 1 4 2 5 2 x 31 = 5 1 –– 1 4 2 2 x 33 = 10 3 –– –– 4 1 2 5 x 25 = 10 4 2 –– –– 4 1 2 –– x 14 = 5 1 4 –– –– 4 1 –– –– x 22 = 5 Only row 1 remains Only row 1 remains Basic variable x 12 = 5 x 13 = 5 Action d1 = 0, s3 = 10 Cross out column 1 d3 = 5, s3 = 0 Cross out row 3 d5 = 0, s2 = 5 Cross out column 5 d4 = 0, s1 = 10 Cross out column 4 d2 = 5, s2 = 0 Cross out row 2 d2 = 0, s1 = 5 d3 = 0, s1 = 0 Russell's Method This method makes use of the reduced costs associated with cells not yet assigned. At each iteration, compute for the uncrossed rows and columns ui = value of the largest uncrossed cost in row i. v j = value of the largest uncrossed cost in column j For each uncrossed cell compute w ij = cij – ui – v j. The rule is to choose the uncrossed cell with the largest negative value of w ij . Illustrating Russell's method for the example problem we obtain the results in Table 2. As can be seen, the basic feasible solution identified by this method is also optimal. 12 Network Flow Programming Methods Table 2. Computations for Russell’s method Iteration no. Rows (ui) Basic variable Columns (v j) 1 1 16 2 15 3 12 1 15 2 15 3 16 4 11 5 11 x 25 = 10 2 16 15 12 15 15 16 11 –– x 22 = 5 3 16 –– 12 15 15 16 11 –– x 31 = 5 4 16 –– 12 –– 15 16 11 –– x 33 = 10 5 6 7 Only row 1 remains Only row 1 remains Only row 1 remains x 12 = 5 x 13 = 5 x 14 = 5 Action d5 = 0, s2 = 5 Cross out column 5 d2 = 5, s2 = 0 Cross out row 2 d1 = 0, s3 = 10 Cross out column 1 d3 = 5, s3 = 0 Cross out row 3 d2 = 0, s1 = 10 d3 = 0, s1 = 5 d4 = 0, s1 = 0