Supp 05
Supp 05
Algorithms for
Network Models
DESTINATIONS Supply
D1 D2 D3 D4
S1 50 75 30 45 12
Sources S2 65 80 40 60 17
S3 40 70 50 55 11
Demand 10 10 10 10
CD-283
CD-284 SUPPLEMENT CD5 Algorithms for Network Models
D1 D2 D3 D4 Supply
50 75 30 45
S1 12
S2 65 80 40 60 17
S3 40 70 50 55 11
Demand 10 10 10 10 Unit
Shipment will Shipping
be placed here Cost FIGURE CD5.1
The Transportation Tableau
1. Select the remaining variable in the upper left (northwest) corner and note the
supply remaining in the row, s, and the demand remaining in the column, d.
2. Allocate the minimum of s or d to this variable. If this minimum is s, eliminate all
variables in its row from future consideration and reduce the demand in its
column by s; if the minimum is d, eliminate all variables in the column from
future consideration and reduce the supply in its row by d.
REPEAT THESE STEPS UNTIL ALL SUPPLIES HAVE BEEN ALLOCATED.
I The Transportation Problem—The Transportation Algorithm CD-285
For this problem, the sequence of steps for the Northwest Corner starting proce-
dure is as follows:
Remaining Remaining
Supply in Demand in
Northwest the Row the Column
Corner (s) (d) Allocate Modifications
After the fourth step, only row 3 is left with a remaining supply of 11. Since the re-
maining demand is now 1 for column 3 and 10 for column 4, the allocations X33
1, and X34 10 are made. These results are given by the transportation tableau in
Figure CD5.2. While the northwest corner procedure is quick and easy to imple-
ment, unfortunately, it ignores costs altogether and frequently results in a starting
solution that is not very close to the optimal solution.
D1 D2 D3 D4 Supply
S1 50 75 30 45
12
10 2
S2 65 80 40 60 17
8 9
S3 40 70 50 55 11
1 10
Demand 10 10 10 10
FIGURE CD5.2
Northwest Corner Starting Solution
For this problem, the sequence of steps for the least cost starting procedure is
as follows:
Remaining Remaining
Supply in Demand in
Least Cost the Row the Column
Cell (s) (d) Allocate Modifications
1. X13 12 10 X13 10 Eliminate column 3;
Cost 30 reduce row 1 supply to
12 10 2
2. X31 11 10 X31 10 Eliminate column 1;
Cost 40 reduce row 3 supply to
11 10 1
3. X14 2 10 X14 2 Eliminate row 1; reduce
Cost 45 column 4 demand to
10 2 8
4. X34 1 8 X34 1 Eliminate row 3; reduce
Cost 55 column 4 demand to
817
Since only row 2 is left with a remaining supply of 17 and the remaining demand
for the only remaining columns is now 10 for column 2 and 7 for column 4, the
final allocations are X22 10 and X24 7. This results in the transportation
tableau shown in Figure CD5.3.
D1 D2 D3 D4 Supply
S1 50 75 30 45
12
10 2
S2 65 80 40 60 17
10 7
S3 40 70 50 55 11
10 1
Demand 10 10 10 10
FIGURE CD5.3
Least Cost Starting Solution
The major problem with the least cost approach is that, after initially allocat-
ing to one or two low-cost routes, the last few allocations may be to very high-cost
routes; that is, the method does not take into account relative costs. Note, for ex-
ample, that, in least cost allocation for our sample problem, X22 10; that is, 10
units are shipped to the most costly cell (with a unit cost of $80).
Vogel’s Approximation Method (VAM)
Vogel’s Approximation Method (VAM) introduces the concept of relative costs into
the starting method. It requires more start-up calculations, but, once a starting so-
lution is reached using this method, the optimal solution is typically attained more
quickly than in the previous two methods. The VAM method proceeds as follows:
Applying the Vogel Approximation Method to the above problem results in the
following iterations:
Since row 2 has the largest penalty, as many items as possible are allocated to the
cell with the lowest cost of 40 (column 3). Since the supply in row 2 is 17 and the
demand in column 3 is 10, X23 is set equal to 10, reducing the supply for row 2 to
17 10 7, and eliminating column 3 from future consideration.
The largest of these and the three remaining column penalties is the 15 for row
3. One then allocates as much supply as possible to the least cost remaining in
row 3; that is, to X31 (unit cost 40). Since the remaining supply in row 3 is 11
and the remaining demand in column 1 is 10, X31 is set equal to 10, reducing
the supply for row 3 to 11 10 1, and eliminating column 1 from future
consideration.
The maximum of these and the two remaining column penalties (5 for column 2
and 10 for column 4) is the 30 for row 1. Now one allocates as much as possible to
the least cost remaining in row 1—that is, X14 (unit cost 45). Since the remaining
supply in row 1 is 12 and the remaining demand column 4 is 10, X14 is set equal to
10, reducing the supply for row 1 to 12 10 2, and eliminating column 4.
Now since there is only one column left, column 2, with a remaining demand
of 10, and the remaining supplies at rows 1, 2, and 3 are 2, 7, and 1, respectively,
set X12 2, X22 7, X23 1. The resulting basic feasible solution is shown in Fig-
ure CD5.4.
D1 D2 D3 D4 Supply
S1 50 75 30 45
12
2 10
S2 65 80 40 60 17
7 10
S3 40 70 50 55 11
10 1
Demand 10 10 10 10
1. Find the current Cij–Zij values for each nonbasic variable and select the one
with the most negative Cij–Zij value as the entering variable; if all Cij–Zij
values are nonnegative, the current solution is optimal.
2. Determine which basic variable reaches 0 first when the entering variable is
increased.
3. Determine a new basic solution and repeat the steps.
To illustrate how the transportation simplex method performs these steps suppose
the tableau generated by the VAM starting procedure in Figure CD5.4 is used as
the starting tableau.
1. If Ui is the dual variable associated with the i-th supply constraint, and
Vj is the dual variable associated with the j-th demand constraint, then
for shipments from node i to node j, one can find the corresponding
Zij value by Zij Ui Vj. Thus the Cij–Zij value for variable Xij is
found by
From Figure CD5.4 the basic variables are in cells X12, X14, X22, X23, X31, and X32.
By setting U1 0, the remaining Ui’s and Vj’s are determined as follows:
I The Transportation Problem—The Transportation Algorithm CD-289
The Cij–Zij values for the nonbasic variable cells are then calculated as follows:
X11 C11 U1 V1 50 0 45 5
X13 C13 U1 V3 30 0 35 5
X21 C21 U2 V1 65 5 45 15
X24 C24 U2 V4 60 5 45 10
X33 C33 U3 V3 50 (5) 35 20
X34 C34 U3 V4 55 (5) 45 15
The most negative Cij–Zij value is 5, which is associated with the nonbasic vari-
able, X13; thus X13 is selected as the entering variable.
D1
D2 D3 D4 Supply
5075 30 45
S1 12
2 10
S2 65 80 40 60 17
7 10
S3 40 70 50 55 11 FIGURE CD5.5
10 1 Determining the Cycle of the
Demand 10 10 10 10
Entering Variable with the
Basic Variables
Now if one unit is added to X13, a unit must be subracted from X23 (leaving 9),
added to X22 (giving 8), and subtracted from X12 (leaving 1). This will save $5. If
two units are added to X13, two must be subtracted from X23 (leaving 8), added to
X22 (giving 9), and subtracted from X12 (leaving 0). This will save 2($5) $10.
CD-290 SUPPLEMENT CD5 Algorithms for Network Models
Since X12 has now reached 0, no further reduction is possible for this variable;
2 is the most that presently can be allocated to X13. Note that this is the minimum
amount on the cycle where a subtraction is to be made.
D1 D2 D3 D4 Supply
50 75 30 45
S1 12
2 10
S2 65 80 40 60 17
9 8
S3 40 70 50 55 11
10 1 FIGURE CD5.6
Demand 10 10 10 10
The Transportation Tableau
for Iteration 2
Continuing with the next iteration of the algorithm on the tableau shown in
Figure CD5.6, after Step 1 setting U1 0, the other Ui’s and Vj’s are determined
as follows.
X11 C11 U1 V1 50 0 40 10
X12 C12 U1 V2 75 0 70 5
X21 C21 U2 V1 65 10 40 15
X24 C24 U2 V4 60 10 45 5
X33 C33 U3 V3 50 0 30 20
X34 C34 U3 V4 55 0 45 10
Since all the Cij–Zij values are now nonnegative, the solution shown in Figure
CD5.6 is optimal. This solution is summarized as follows:
Unit Transportation
From To Amount Cost Cost
S1 D3 2 $30 $ 60
S1 D4 10 $45 $ 450
S2 D2 9 $80 $ 720
S2 D3 8 $40 $ 320
S3 D1 10 $40 $ 400
S3 D2 1 $70 $ 70
Total $2020
II T h e C a p a c i t a t e d T r a n s s h i p m e n t P r o b l e m —
The Out-of-Kilter Algorithm
Another streamlined form of the simplex method, the out-of-kilter algorithm,
can be used to solve a network problem with sources, destinations, intermediate
nodes, unit shipping costs, and maximum capacities between nodes. Shipments
may or may not be allowed between supply nodes or between demand nodes.1 In
the most general case, the one illustrated here, such shipments are possible.
1
The most general form of this problem allows for lower bounds on the arcs other than 0. For
simplicity, assume that all arcs have a minimum capacity of 0.
CD-292 SUPPLEMENT CD5 Algorithms for Network Models
The concepts behind this algorithm follow those of the transportation prob-
lem. Once a basic feasible solution has been found, the Cij–Zij values for the flow
along each nonbasic shipping route that is not currently being used are calculated
to see if increasing flow along the arc will reduce the overall total cost. Increasing
the flow along an arc with a negative Cij–Zij value reduces the total cost.
The new wrinkle in this problem is that arcs with flows at their upper bound
are also considered nonbasic. The Cij–Zij values for these arcs are also calculated to
see if a reduction in the flow on these arcs can possibly save money. Decreasing the
flow along an arc with a positive Cij–Zij value reduces the total cost.
If increasing the flow along an arc that is not being used or reducing the flow
along an arc used to capacity results in cost savings, the system is said to be out of
kilter. The out-of-kilter algorithm uses a simple technique for calculating the
Cij–Zij values for nonbasic arcs. Once those values are calculated, if it is deter-
mined that a modification to the flow will improve the objective function value,
the algorithm provides a way to make this change quite easily. The Cij–Zij values
for the new solution are then recalculated and the process is repeated.
The out-of-kilter method assumes that the total supply at the supply nodes
equals the total demand at the demand nodes. If not, a dummy supply node with
zero-cost arcs from the dummy node to all demand nodes, or a dummy demand
node with zero-cost arcs from all supply nodes to the dummy node is created to
balance the problem.
As stated above, there are two types of nonbasic variables in a capacitated trans-
shipment problem: (1) those at their lower bound (0); and (2) those at their upper
bound (M). Variables that are at neither their lower bound nor their upper bound
are the basic variables. There are n 1 basic variables (where n is the total number
of nodes).2 The arcs corresponding to these basic variables form a spanning tree in
the network. The following are the steps of the out-of-kilter algorithm:
Iterative Steps:
1. Calculate the value of the dual variables:
(1) Set U1 0
(2) Solve for the other Uis by Cij Ui Uj 0 for basic variable arcs. (The flow
is FROM node i TO node j.)
2. Calculate the Cij–Zij values for the nonbasic arcs:
Cij Zij Cij Ui Uj
3. For nonbasic variables at their lower bound (0), variables with negative Cij–Zij
values are out of kilter: Determine the variable with the most negative Cij–Zij value.
For nonbasic variables at their upper bound (Mij), variables with positive Cij–Zij
values are out of kilter: Determine the variable with the most positive Cij–Zij value.
Of these two, select the one with the larger absolute Cij–Zij value as the
entering variable. If this largest value is 0, STOP; the current flow is optimal.
4. The arc for this variable forms a cycle in the network with a set of other basic
variables. If the entering variable is at its lower bound, increase the flow on the
arc; if it is at its upper bound, decrease the flow on the arc. In either case, the
flow along the other arcs in the cycle must be adjusted to maintain a feasible
flow. Adjust the flow until some arc reaches either 0 or its upper bound (Mij).
This is the new nonbasic variable.
GO TO STEP 1.
2
If the number of variables that are at neither their upper nor lower bound is less than n 1, the
problem is degenerate and any arc at its lower bound or any arc at its upper bound can be made basic
as long as the arc does not form a cycle with any of the other basic variables.
II The Capacitated Transshipment Problem—The Out-of-Kilter Algorithm CD-293
This approach illusrated for the capacitated transshipment problem shown in Fig-
ure CD5.7.
S110 $20
1 5 D512
$1 6
0
12 $7
$11
$5
8
7
3
$12
8
$6
$7
7
5
$15 $15
S215 2 4 6 D613
10 17
FIGURE CD5.7
Unit Cost Capacity Capacitated Transshipment Problem
INITIALIZATION STEP
The initial basic feasible flow was found by trial and error:
Lower Bound Upper Bound
Basic Nonbasic Nonbasic
Variables Flow Variables Flow Variables Flow
X13 9 X12 0 X15 6
X21 5 X56 0 X24 10
X34 3 X65 0
X35 6
X46 13
The basic variable tree for this solution is highlighted in Figure CD5.8; the flows
are shown in the circles below the arcs.
$20 6
S110 1 5 D512
$1 6
0 9
12 6
$5
$7
3
$11
7
3 8
5
$12 3
8
$7
5
$6
7
$15 10 $15 13
S215 2 4 6 D613
10 17
Flow
Nonbasic variables at their lower bound (0) FIGURE CD5.8
Nonbasic variables at their upper bound (Mij) Transshipment Problem:
Basic variables with flows between 0 and Mij A First Basic Feasible Solution
ITERATION 1
Step 1: Determine the U i ’s
Set U1 to 0. Then,
Basic
Variable Cij–Zij 0 Substitute Implies
X12 C12 U1 U2 5 0 6 11 No
X56 C56 U5 U6 11 (17) (37) 9 Yes
X65 C65 U6 U5 7 (37) (17) 27 No
Since X56 is the variable that is most out of kilter ( 9 3) it becomes the
entering variable.
3 8
X56 can increase by 7
$12 3
$15 13
4 6 D613
FIGURE CD5.9 17
Cycle Formed by X56 and X46 can decrease by 13
Current Basic Variables to its lower bound of 0
The calculations for the maximum amount of change in these four variables
before reaching the bounds shown in Figure CD5.9 are as follows:
X56 0 7 707
X35 6 8 862
Variables Current Lower Maximum
Decreased Value Bound Decrease
X34 3 0 30 3
X46 13 0 13 0 13
II The Capacitated Transshipment Problem—The Out-of-Kilter Algorithm CD-295
$20 6
S110 1 5 D512
$1 6
0 9
12 8
$5
$7
$11
7 2
3 8
$12 1
8
FIGURE CD5.10
$7
5
$6
7
Augmenting Flow by 2 on X56,
$15 10 $15 11 X35, X34, and X45 Gives the
S215 2 4 6 D613
10 17 Next Iteration
ITERATION 2
Basic
Variable Opportunity Cost 0 Substitute Implies
X12 C12 U1 U2 5 0 6 11 No
X65 C65 U6 U5 7 (37) (26) 18 No
Since no arcs are out of kilter, the network in Figure CD5.10 is optimal. The opti-
mal solution is:
Unit Transportation
From To Amount Cost Cost
III T h e A s s i g n m e n t P r o b l e m —
The Hungarian Algorithm
The Hungarian algorithm for solving the assignment problem of a least cost
assignment of m workers to m jobs is based on the observation that a number
can be added to or subtracted from every number in a row or a column of an as-
signment cost matrix without affecting the optimal solution. A number sub-
tracted from all numbers in a row or column is considered a minimum amount
each worker will charge or that each job will cost; the resulting numbers can
then be thought of as a premium above this fixed amount. Similarly, adding a
number to a row or column can be regarded as an increase in the fixed price
that each worker will charge or that each job will cost. This process of adding
or subtracting a number from all numbers in a row or column is known as ma-
trix reduction.
The idea behind the Hungarian algorithm is to reduce the matrix so that only
nonnegative costs exist and at least one 0 remains in each row and column; then an
attempt is made to complete the assignment using only the 0 costs. If this is unsuc-
cessful, a systematic matrix reduction procedure is applied that creates a new ma-
trix of costs, in which an entry that previously had a positive cost is reduced to 0.
Then another attempt is made to find a complete 0 cost assignment. The process
is repeated until an assignment of only 0 entries is found.
The following description of the Hungarian algorithm assumes that:
Initialization
1. For each row, subtract the minimum number from all numbers in that row.
2. In the resulting matrix, subtract the minimum number in each column from all
numbers in the column.
Iterative Steps
1. Make as many 0 cost assignments as possible. If all workers are assigned, STOP;
this is the minimum cost assignment. Otherwise draw the minimum number of
horizontal and vertical lines necessary to cover all 0’s in the matrix. (A method
for making the maximum number of 0 cost assignments and drawing the
minimum number of lines to cover all 0’s follows.)
2. Find the smallest value not covered by the lines; this number is the reduction value.
3. Subtract the reduction value from all numbers not covered by any lines. Add the
reduction value to any number covered by both a horizontal and vertical line.
GO TO STEP 1.
For small problems, one can usually determine the maximum number of zero-
cost assignments by observation. For larger problems, the following procedure can
be used:
1. For each row, if only one 0 remains in the row, make that assignment and
eliminate the row and column from consideration in the steps below.
2. For each column, if only one 0 remains, make that assignment and eliminate that
row and column from consideration.
3. Repeat steps 1 and 2 until no more assignments can be made. (If 0’s remain, this
means that there are at least two 0’s in each remaining row and column. Make
an arbitrary assignment to one of these 0’s and repeat steps 1 and 2.)
Again, for small problems, the minimum number of lines required to cover all
the 0’s can usually be determined by observation. The following procedure, based
on network flow arguments, can be used for larger problems:
Figure CD5.11 shows the sequence of matrix reductions required to solve the
Ballston Electronics problem introduced in Chapter 4 of the text. In the third,
fourth, and fifth matrices, a box is placed around each 0 cost assignment. A “•” is
used to mark the rows and columns required to draw the minimum covering set of
lines using the procedures outlined above. The minimum uncovered value is circled.
CD-298 SUPPLEMENT CD5 Algorithms for Network Models
A B C D E
1 10 4 6 10 12
2 11 7 7 9 14
3 13 8 12 14 15
4 14 16 13 17 17
5 17 11 17 20 19
Row Subtraction
A B C D E
1 6 0 2 6 8
2 4 0 0 2 7
3 5 0 4 6 7
4 1 3 0 4 4
5 6 0 6 9 8
Column Subtraction
A B C D E
1 5 0 2 4 4
Minimum Uncovered
2 3 0 0 0 3
Number
3 4 0 4 4 3
4 0 3 0 2 0
5 5 0 6 7 4
A B C D E
1 3 0 0 2 2
2 3 2 0 0 3
3 2 0 2 2 1 Minimum Uncovered
4 0 5 0 2 0 Number
5 3 0 4 5 2
A B C D E
1 3 1 0 2 2
2 3 3 0 0 3
3 1 0 1 1 0
4 0 6 0 2 0
5 2 0 3 4 1
Optimal Solution
1–C 6
2–D 9
3–E 15
4–A 14 FIGURE CD5.11
5–B 11 Solution for the Ballston
65 Electronics Assignment
Problem
IV A Traveling Salesman Algorithm CD-299
J1 J2 J3 J4
W1 67 58 90 55
W2 58 88 89 56
W3 74 99 80 22
DUMMY 0 0 0 0
The lost opportunity matrix given below is derived by subtracting each num-
ber in the J1 column from 74, each number in the J2 column from 99, each number
in the J3 column from 90, and each number in the J4 from 56.
J1 J2 J3 J4
W1 7 41 0 1
W2 16 11 1 0
W3 0 0 10 34
DUMMY 74 99 90 56
The Hungarian algorithm can now be applied to this lost opportunity matrix
to determine the maximum profit set of assignments.
An initial upper bound for the optimal objective function value, U, can be found
by calculating the cost of any tour. Initially, U is set to the objective function value of
the tour 1–2–3– . . . –n–1. The branches consist of problems that have been revised
by assigning a high cost (M) to one of the arcs on a subtour (thus making that sub-
tour infeasible). Then the assignment algorithm is applied to the revised problem.
Once the solution is found, its objective function value is compared to the cur-
rent upper bound, U. If it is not less than U, it is fathomed (eliminated from con-
sideration). If it is less than U and the solution is a tour, we reset U to the total
cost of the tour. If it is not a tour, additional branching from this problem must be
done. The branch and bound process is repeated until all the branches have been
fathomed.
The branch and bound steps are summarized below. (Remember that “fath-
oming” means ceasing further consideration of the branch.)
Initialization Step
Solve the problem as an assignment problem. If the optimal solution is a tour, the
minimum distance has been found. It the optimal solution is not a tour, make this
solution the first active branch of the branch and bound tree and set U the
objective function value of the tour 1–2–3–4–5 . . . –n.
Branch and Bound Steps
1. Choose an unfathomed branch. Consider the subtour consisting of the minimum
number of arcs (say, there are k arcs on this subtour). Create k branches from
this node, each corresponding to an assignment problem that assigns a very
large value M to one of the arcs of the subtour, making the subtour infeasible.
For each branch, re-solve the assignment problem, giving an objective function
value Z. (If there are no unfathomed branches, STOP; the optimal solution is the
one that gives the value of U.)
2. For each of these branches:
If Then
The problem is infeasible • Fathom the branch
ZU • Fathom the branch
The solution is a tour and Z U • Fathom the branch
• Reset U Z
• Fathom all branches with Z U
The solution is not a tour and Z U • This is a new active subproblem.
GO TO STEP 1
1 M 63 22 20 18 10
2 60 M 56 40 54 58
3 28 54 M 20 21 15
4 40 39 37 M 24 41
5 30 40 26 20 M 18
6 30 56 24 40 26 M
IV A Traveling Salesman Algorithm CD-301
Initialization
When this problem is solved as an assignment problem, the solution consists of
two subtours: (1–6–5–3–1) and (2–4–2), giving Z 164. Since a tour was not
found, the value of the tour (1–2–3–4–5–6–1) is calculated ( 63 56 20 24
18 30 221) and used as our first upper bound: U 221.
Iteration 1 U 221
The subtour with the smallest number of arcs is (2–4–2). Now create two new
branches, one blocking the route from 2–4 (by changing the entry for arc (2,4) in
the assignment matrix to M), the other blocking the route from 4–2 (by chang-
ing the entry for arc (4,2) in the assignment matrix to M.) Re-solve each as an as-
signment problem.
Bl
oc
k2
k4
oc
–2
Bl
174 166
Tour Subtours
1–6–3–5–4–2–1 1–6–3–1
2–4–5–2
Fathom–Tour
Reset U to 174
since 174 221
Iteration 2 U 174
Because the number of arcs on each subtour created by blocking the route from
4–2 is the same, arbitrarily choose the subtour (2–4–5–2) to branch on. Three new
subproblems are created, which in addition to blocking the route from 4–2, block
the routes from 2–4, 4–5, and 5–2, respectively. Re-solving each of these as an as-
signment problem gives the following:
CD-302 SUPPLEMENT CD5 Algorithms for Network Models
These results are summarized by the tree in Figure CD5.13. Since all branches are
now fathomed, the optimal solution is the tour (1–6–3–5–4–2–1) giving Z 174.
164
Subtours U174 (1-6-3-5-4-2-1)
1–6–5–3–1
2–4–2
–4
Bl
oc
k2
k4
oc
–2
Bl
174 166
Tour Subtours
1–6–3–5–4–2–1 1–6–3–1
2–4–5–2
Bl
–4
oc
k2
k5
oc
–2
Bl
Replace the temporary label at the adjacent node by D only if the current label at
the adjacent node is greater than D. If the label is replaced, record the assigned
node that generated the label (shown next to the label valve).
GO TO STEP 1.
The shortest path is determined by retracing the path of assigned nodes from
the terminal node back to the start node. The Dijkstra algorithm will now be illus-
trated using the network shown in Figure CD5.14.
8
2 5
15
2
18 6
1 4 7
7
10
17
9
4
FIGURE CD5.14
Shortest Path: Find the
Minimum Distance from 3
18
6
Node 1 to Node 7
INITIALIZATION
All nodes have temporary labels of (not shown), except for node 1 which has a
temporary label of 0.
ITERATION 1
According to Figure CD5.14:
Minimum Temporary Label (Made Permanent): 0 at Node 1
Temporary Nodes Adjacent to Node 1: Nodes 2 and 3
2 0 18 18 Yes—18 (1)
3 0 10 10 Yes—10 (1)
18 (1)
8
2 5
15
2
6
Permanent 18
Label
0 1 4 7
5
10
17
9
4
18
3 6
Temporary 10 (1) Previous
Label Node
Minimum
Distance
Found Thus Far
ITERATION 2
According to Figure CD5.15a:
2 10 7 17 18 Yes—17 (3)
4 10 4 14 Yes—14 (3)
6 10 18 28 Yes—28 (3)
17 (3)
18 (1)
8
2 5
15
2
18
0 1 4 7
7
10
14 (3)
17
9
4
18
3 6
10 (1) 28 (3)
ITERATION 3
According to Figure CD5.15b:
Minimum Temporary Label (Made Permanent): 14 at Node 4
Temporary Nodes Adjacent to Node 4: Nodes 2, 5, and 6
15
2
6
18
0 1 4 7
7
5
10
14 (3)
17
9
4
FIGURE CD5.15c 18
3 6
Shortest Path Solution:
Iteration 3 10 (1) 28 (3)
ITERATION 4
According to Figure CD5.15c:
Minimum Temporary Label (Made Permanent): 16 at Node 2
Temporary Nodes Adjacent to Node 2: Node 5
5 16 8 24 29 Yes—24 (2)
16 (4)
17 (3) 24 (2)
18 (1) 29 (4)
8
2 5
15
2
18
0 1 4 7
7
10
14 (3)
17
9
4
FIGURE CD5.15d 18
3 6
Shortest Path Solution:
Iteration 4 10 (1) 28 (3)
CD-306 SUPPLEMENT CD5 Algorithms for Network Models
ITERATION 5
According to Figure CD5.15d:
Minimum Temporary Label (Made Permanent): 24 at Node 5
Temporary Nodes Adjacent to Node 5: Nodes 6 and 7
6 24 5 29 28 No
7 24 6 30 Yes—30 (5)
16 (4)
17 (3) 24 (2)
18 (1) 29 (4)
8
2 5
15
2
6
18
0 1 4 7 30 (5)
7
5
10
14 (3)
17
9
4
FIGURE CD5.15e 3
18
6
Shortest Path Solution:
Iteration 5 10 (1) 28 (3)
ITERATION 6
According to Figure CD5.15e:
Minimum Temporary Label (Made Permanent): 28 at Node 6
Temporary Nodes Adjacent to Node 6: Node 7
7 28 9 37 30 No
16 (4)
17 (3) 24 (2)
18 (1) 29 (4)
8
2 5
15
2
18
0 1 4 7 30 (5)
7
10
14 (3)
17
9
4
FIGURE CD5.15f 3
18
6
Shortest Path Solution:
Iteration 6 10 (1) 28 (3)
VI The Minimal Spanning Tree Problem—The Greedy Algorithm CD-307
ITERATION 7
According to Figure CD5.15f:
16 (4)
17 (3) 24 (2)
18 (1) 29 (4)
8
2 5
15
2
6
18
0 1 4 7 30 (5)
5
10
14 (3)
17
9
4
FIGURE CD5.15g 18
3 6
Shortest Path Solution:
Iteration 7 10 (1) 28 (3)
Since all nodes have now been assigned a permanent label, the algorithm
terminates. The shortest distance from node 1 to node 7 is 30. Retracing the
path from node 7, observe that node 7 was reached from node 5; node 5 was
reached from node 2; node 2 was reached from node 4; node 4 was reached
from node 3; and node 3 was reached from node 1. Thus the shortest path is
1–3–4–2–5–7. The shortest distances and paths from node 1 to all other nodes
in the network are as follows:
To Distance Path
Node 2 16 1–3–4–2
Node 3 10 1–3
Node 4 14 1–3–4
Node 5 24 1–3–4–2–5
Node 6 28 1–3–6
Node 7 30 1–3–4–2–5–7
VI T h e M i n i m a l S p a n n i n g T r e e
Problem—The Greedy Algorithm
The objective of a minimal spanning tree model is to find the tree that intercon-
nects all the nodes in a network at minimum total distance. The Greedy algo-
rithm is an easy, efficient way to find this minimal spanning tree. The idea behind
the Greedy algorithm is that one is, in fact, “greedy.” The process starts by select-
ing the minimum arc out of a particular node (this can be node 1 or any node in
the network) and then continue to build a tree by adding the lowest cost arcs that
do not form cycles. The approach is formally stated as follows:
CD-308 SUPPLEMENT CD5 Algorithms for Network Models
Initialization Step
Select the minimum arc out of node 1 to start the tree.
Iterative Step
Add to the current tree the connecting arc of minimum distance that does not form a
cycle. If all nodes are connected, STOP; the minimal spanning tree has been found.
Repeat the above iterative step until all nodes have been connected.
If there are n nodes, the tree consists of n 1 arcs.
In Figure CD5.16, we show in thick blue the minimal spanning tree for the same
network as the one we used to illustrate the shortest path problem. It was gener-
ated by the following iterations.
8
2 5
15
6
18 2
1 4 7
7
5
10 17
4
9
FIGURE CD5.16
Minimum Spanning 18
3 6
Tree Solution
INITIALIZATION
Choose the minimum arc out of node 1—arc (1, 3)—distance 10.
0 (1, 3) 10 Yes 10
1 (3, 4) 4 Yes 14
2 (2, 4) 2 Yes 16
3 (2, 3) 7 No—Cycle
(2, 5) 8 Yes 24
4 (5, 6) 5 Yes 29
5 (5, 7) 6 Yes 35
Thus the minimum spanning tree has a total distance of 35 and consists of arcs
(1, 3), (3, 4), (2, 4), (2, 5), (5, 6), and (5, 7).
VII T h e M a x i m a l F l o w P r o b l e m — T h e
Maximal Flow Algorithm
In a maximal flow problem, the objective is to find the maximum volume of
flow from a source node to a terminal sink node in a capacitated network. Al-
though it is a special case of the capacitated transshipment problem and can be
VII The Maximal Flow Problem—The Maximal Flow Algorithm CD-309
solved by the simplex method or the out-of-kilter algorithm, the following max-
imal flow algorithm is easy to implement and avoids the necessity of keeping
track of basic variables. In it, one determines if there is any path from the
source to the sink that can carry flow. If there is, the flow is augmented as much
as possible along this path, and the residual capacities of the arcs used on the
path are reduced accordingly.
The only complication is that we might find that “if only we hadn’t already
committed to some flow along this arc, we could find an alternative path that
could give a larger flow.” Thus, when a residual arc capacity is reduced in one
direction along an arc, the residual capacity is increased in the other direction on
the arc (known as its backwards capacity) to account for a possible future “change
of mind.” As a result, the algorithm might determine an optimal solution in
which five units are shipped from node i to node j and 3 units are shipped back
from node j to node i. Of course, this means that only 5 3 2 are shipped
from node i to node j.
A formal statement of the maximal flow algorithm is as follows:
Note that choosing which path to use in the network in Step 1 is purely arbi-
trary. Often, however, it is not easy to determine if any path of positive flow exists
from the source node to the sink node. One way to find such a path is to assign a
“distance” of “1” to all arcs with positive residual capacities and to the other
arcs. Then a shortest path algorithm can be used to find the minimum distance
from the source node to the terminal node; if this distance is less than , a path
with positive flow has been found. In the following example, however, we simply
select the paths arbitrarily.
In the network shown in Figure CD5.17 the numbers next to each node rep-
resent the residual capacity on the arc from the node to the adjacent node.
3 3
0 2 5
2
7
2
6
2
3
1 6
3 2
0
0
3
2 2 7
0
6
1
2
ITERATION 1
Select the path 1–2–5–7. The capacity on arc (1, 2) is 6; on arc (2, 5) is 3; and on
arc (5, 7) is 7. Since the minimum of these is 3, the flow along this path is in-
creased by 3, as shown in Figure CD5.18a. For iteration 2, the residual capacities
along the arcs (1, 2), (2, 5), and (5, 7) are reduced by 3 to 3, 0, and 4, respectively,
and the residual backwards capacities on arcs (2, 1), (5, 2), and (7, 5) are increased
by 3 to 3, 6, and 3, respectively.
Path: 1–2–5–7
Residual Capacities
1–2 6 Augment flow by 3
2–5 3 Reduce forward capacities by 3
5–7 7 Increase backwards capacities by 3
3
3 3
0 2 5
2
7
2
3
3
6
2 3
1 6
3 2
0
0
3
2 2 7
0
6
1
FIGURE CD5.18a
2
0 2
Maximal Flow Solution: 4 2
Iteration 1
ITERATION 2
From Figure CD5.18b, observe that no additional flow is possible along arc (2, 5).
Thus a new path with positive residual capacities from node 1 to node 7 must be
found. Here the path 1–2–3–6–7 is selected. The residual capacity on arc (1, 2) is
3; on arc (2, 3) is 2; on arc (3, 6) is 2; and on arc (6, 7) is 2. Since the minimum of
these is 2, we increase the flow along this path by 2. For iteration 3, decrease the
residual capacities along the arcs (1, 2), (2, 3), (3, 6), and (6, 7) by 2 to 1, 0, 0, and
0, respectively. The residual backwards capacities on arcs (2, 1), (3, 2), (6, 3), and
(7, 6) are increased by 2 to 5, 4, 4, and 2, respectively.
Path: 1–2–3–6–7
Residual Capacities
1–2 3 Augment flow by 2
2–3 2 Reduce forward capacities by 2
3–6 2 Increase backwards capacities by 2
3–6 2
Augmented Flow 3
0 6
2 3 2 5
2
4
2
Current Flow 3
2
3
3
3
2
1 6
3 2
2
3
2 0
3
2 2 7
0
6
1
FIGURE CD5.18b
2
0 2
Maximal Flow Solution: 4 2
Iteration 2
VII The Maximal Flow Problem—The Maximal Flow Algorithm CD-311
ITERATION 3
In Figure CD5.18c, observe that no additional flow is possible along arcs (2, 3) or
(2, 5), since no further flow is possible along arc (1, 2). Thus a path from node 1 to
node 7 with positive residual capacities using arc (1, 4) must be found. Here the
path 1–4–7 is selected. The residual capacity on arc (1, 4) is 6, and on arc (4, 7) is
2. Since the minimum of these is 2, the flow along this path is increased by 2. For
iteration 4, the residual capacities along the arcs (1, 4) and (4, 7) are decreased by
2 to 4 and 0, respectively, and the residual backwards capacities on arcs (4, 1) and
(7, 4) are increased by 2 to 2 and 2, respectively.
Path: 1–4–7
Residual Capacities
1–4 6 Augment flow by 2
4–7 2 Reduce forward capacities by 2
Increase backwards capacities by 2
0 3 6
5 2 5
2
4
0
5
2
3
1
4 3
1 6
3 0
2
3
2 2 2
3
4 0 7
0
6
1
FIGURE CD5.18c 2
2
0 2
Maximal Flow Solution: 4
2
Iteration 3
ITERATION 4
In Figure CD5.18d, observe that no additional flow is possible along arc (4, 7);
thus a new path with positive residual capacities from node 1 to node 7 must be
found using arc (1, 4). Here the path 1–4–3–5–7 is selected. The residual capacity
on arc (1, 4) is 4; on arc (4, 3) is 2; on arc (3, 5) is 3; and on arc (5, 7) is 4. Since the
minimum of these is 2, the flow along this path is increased by 2. For iteration 5,
the residual capacities along the arcs (1, 4), (4, 3), (3, 5), and (5, 7) are decreased
by 2 to 2, 0, 1, and 2, respectively, the residual backwards capacities on arcs (4, 1),
(3, 4), (5, 3), and (7, 5) are increased by 2 to 4, 5, 4, and 5, respectively.
Path: 1–4–3–5–7
Residual Capacities
1–4 4 Augment flow by 2
4–3 2 Reduce forward capacities by 2
3–5 3 Increase backwards capacities by 2
5–7 4
0 3 6
5 2 5
2
4
0
5 2
2
2 3
1
3
4
1 4
2 3 0
2
3
2 2 2
3
4 0 7
2
6
1
2 2
FIGURE CD5.18d 2 2 2
Maximal Flow Solution: 4 0
Iteration 4
CD-312 SUPPLEMENT CD5 Algorithms for Network Models
ITERATION 5
In Figure CD5.18e, observe that because no additional flow is possible along arcs
(4, 3) and (4, 7), any additional flow from arc (1, 4) must flow along arc (4, 6). A
path with positive residual capacities from node 1 to node 7 using this arc is
1–4–6–3–5–7. The residual capacity on arc (1, 4) is 2; on arc (4, 6) is 2; on arc (6, 3)
is 4; on arc (3, 5) is 1; and on arc (5, 7) is 2. Since the minimum of these is 1, the
flow along this path is increased by 1. The residual capacities along the arcs (1, 4),
(4, 6), (6, 3), (3, 5), and (5, 7) are decreased by 1 to 1, 1, 3, 0, and 1, respectively,
and increase the residual backwards capacities on arcs (4, 1), (6, 4), (3, 6), (5, 3),
and (7, 5) are increased by 2 to 5, 2, 1, 5, and 6, respectively.
Path: 1–4–6–3–5–7
Residual Capacities
1–4 2
4–6 2
6–3 4 Augment flow by 1
3–5 1 Reduce forward capacities by 1
5–7 2 Increase backwards capacities by 1
0 3 6
5 2 5
4
2
0
5 1 1
2
2 5
1
1
4
1 2 1
1 3 0
2
5
4 2 2
5
4 0 7
2
6
1
2 0
1
FIGURE CD5.18e 4 2 2
Maximal Flow Solution: 4
0
Iteration 5
ITERATION 6
As seen in Figure CD5.18f, no more flow is possible because there is no residual
capacity left on the cut consisting of arcs (2, 5), (3, 5), (6, 7), and (4, 7). This is a
minimal cut for the network. Note also that, at iteration 2, there is a flow of 2 from
node 3 to node 6, while at iteration 5, there is a flow of 1 from node 6 to node 3.
This means that the maximum flow has a net flow of 2 1 1 from node 3 to
node 6.
0 3 6
5 2 5
5
1
0
5
2
3 6
1
0
4
1 1
3 1
1
6
5 2
5
3 0 2 7
2
6
2
2
FIGURE CD5.18f 1
Maximal Flow Solution: 2 Minimum
0
5 1 Cut
Final Network, No Additional 0
4
Flow Possible
VII The Maximal Flow Problem—The Maximal Flow Algorithm CD-313
Thus, for this problem, a maximum flow of 10 from node 1 to node 7 is at-
tained as follows:
From To Flow
1 2 5
1 4 5
2 3 2
2 5 3
3 5 3
3 6 1
4 3 2
4 6 1
4 7 2
5 7 6
6 7 2