Docsity

Wayne Winston, .... Edition, 2003 - 18 deterministic dynamic programming, Manuais, Projetos, Pesquisas de Engenharia de Produção

Toggle sidebar
bg1
Match PuzzleEXAMPLE 1
MilkEXAMPLE 2
†
This section covers topics that may be omitted with no loss of continuity.
Deterministic Dynamic Programming
Dynamic programming is a technique that can be used to solve many optimization problems.
In most applications, dynamic programming obtains solutions by working backward from the
end of a problem toward the beginning, thus breaking up a large, unwieldy problem into a
series of smaller, more tractable problems.
We introduce the idea of working backward by solving two well-known puzzles and then
show how dynamic programming can be used to solve network, inventory, and resource-
allocation problems. We close the chapter by showing how to use spreadsheets to solve
dynamic programming problems.
18.1 Two Puzzles
†
In this section, we show how working backward can make a seemingly difficult problem
almost trivial to solve.
Suppose there are 30 matches on a table. I begin by picking up 1, 2, or 3 matches. Then
my opponent must pick up 1, 2, or 3 matches. We continue in this fashion until the last
match is picked up. The player who picks up the last match is the loser. How can I (the
first player) be sure of winning the game?
Solution If I can ensure that it will be my opponent’s turn when 1 match remains, I will certainly win.
Working backward one step, if I can ensure that it will be my opponent’s turn when 5 matches
remain, I will win. The reason for this is that no matter what he does when 5 matches re-
main, I can make sure that when he has his next turn, only 1 match will remain. For exam-
ple, suppose it is my opponent’s turn when 5 matches remain. If my opponent picks up 2
matches, I will pick up 2 matches, leaving him with 1 match and sure defeat. Similarly, if I
can force my opponent to play when 5, 9, 13, 17, 21, 25, or 29 matches remain, I am sure
of victory. Thus, I cannot lose if I pick up 30 29 1 match on my first turn. Then I sim-
ply make sure that my opponent will always be left with 29, 25, 21, 17, 13, 9, or 5 matches
on his turn. Notice that we have solved this puzzle by working backward from the end of the
problem toward the beginning. Try solving this problem without working backward!
I have a 9-oz cup and a 4-oz cup. My mother has ordered me to bring home exactly 6 oz
of milk. How can I accomplish this goal?
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38

Pré-visualização parcial do texto

Baixe Wayne Winston, .... Edition, 2003 - 18 deterministic dynamic programming e outras Manuais, Projetos, Pesquisas em PDF para Engenharia de Produção, somente na Docsity!

E X A M P L E 1 Match Puzzle

E X A M P L E 2 Milk

†This section covers topics that may be omitted with no loss of continuity.

Deterministic Dynamic Programming

Dynamic programming is a technique that can be used to solve many optimization problems. In most applications, dynamic programming obtains solutions by working backward from the end of a problem toward the beginning, thus breaking up a large, unwieldy problem into a series of smaller, more tractable problems. We introduce the idea of working backward by solving two well-known puzzles and then show how dynamic programming can be used to solve network, inventory, and resource- allocation problems. We close the chapter by showing how to use spreadsheets to solve dynamic programming problems.

18.1 Two Puzzles

In this section, we show how working backward can make a seemingly difficult problem almost trivial to solve.

Suppose there are 30 matches on a table. I begin by picking up 1, 2, or 3 matches. Then my opponent must pick up 1, 2, or 3 matches. We continue in this fashion until the last match is picked up. The player who picks up the last match is the loser. How can I (the first player) be sure of winning the game? Solution If I can ensure that it will be my opponent’s turn when 1 match remains, I will certainly win. Working backward one step, if I can ensure that it will be my opponent’s turn when 5 matches remain, I will win. The reason for this is that no matter what he does when 5 matches re- main, I can make sure that when he has his next turn, only 1 match will remain. For exam- ple, suppose it is my opponent’s turn when 5 matches remain. If my opponent picks up 2 matches, I will pick up 2 matches, leaving him with 1 match and sure defeat. Similarly, if I can force my opponent to play when 5, 9, 13, 17, 21, 25, or 29 matches remain, I am sure of victory. Thus, I cannot lose if I pick up 30  29  1 match on my first turn. Then I sim- ply make sure that my opponent will always be left with 29, 25, 21, 17, 13, 9, or 5 matches on his turn. Notice that we have solved this puzzle by working backward from the end of the problem toward the beginning. Try solving this problem without working backward!

I have a 9-oz cup and a 4-oz cup. My mother has ordered me to bring home exactly 6 oz of milk. How can I accomplish this goal?

962 C H A P T E R 1 8 Deterministic Dynamic Programming

Solution By starting near the end of the problem, I cleverly realize that the problem can easily be solved if I can somehow get 1 oz of milk into the 4-oz cup. Then I can fill the 9-oz cup and empty 3 oz from the 9-oz cup into the partially filled 4-oz cup. At this point, I will be left with 6 oz of milk. After I have this flash of insight, the solution to the problem may easily be described as in Table 1 (the initial situation is written last, and the final sit- uation is written first).

P R O B L E M S

Group A

1 Suppose there are 40 matches on a table. I begin by picking up 1, 2, 3, or 4 matches. Then my opponent must pick up 1, 2, 3, or 4 matches. We continue until the last match is picked up. The player who picks up the last match is the loser. Can I be sure of victory? If so, how? 2 Three players have played three rounds of a gambling game. Each round has one loser and two winners. The losing player must pay each winner the amount of money that the winning player had at the beginning of the round. At the end of the three rounds each player has $10. You are told that each player has won one round. By working backward, determine the original stakes of the three players. [ Note: If the answer turns out to be (for example) 5, 15, 10, don’t worry about which player had which stake; we can’t really tell which player ends up with how much, but we can determine the numerical values of the original stakes.]

Group B 3 We have 21 coins and are told that one is heavier than any of the other coins. How many weighings on a balance will it take to find the heaviest coin? ( Hint: If the heaviest coin is in a group of three coins, we can find it in one weighing. Then work backward to two weighings, and so on.) 4 Given a 7-oz cup and a 3-oz cup, explain how we can return from a well with 5 oz of water.

18.2 A Network Problem

Many applications of dynamic programming reduce to finding the shortest (or longest) path that joins two points in a given network. The following example illustrates how dynamic programming (working backward) can be used to find the shortest path in a network.

T A B L E 1 Moves in the Cup-and-Milk Problem No. of Ounces No. of Ounces in 9-oz Cup in 4-oz Cup 6 0 6 4 9 1 0 1 1 0 1 4 5 0 5 4 9 0 0 0

964 C H A P T E R 1 8 Deterministic Dynamic Programming

f 3 (5)  min (^) {

c 58  f 4 (8)  610  1,030  1,640* c 59  f 4 (9)  790  1,390  2, [the * indicates the choice of arc that attains the f 3 (5)]. Thus, we have shown that the shortest path from city 5 to city 10 is the path 5–8–10. Note that to obtain this result, we made use of our knowledge of f 4 (8) and f 4 (9). Similarly, to find f 3 (6), we note that the shortest path to Los Angeles from city 6 must begin by going to city 8 or to city 9. This leads us to the following equation:

f 3 (6)  min (^) {

c 68  f 4 (8)  540  1,030  1,570* c 69  f 4 (9)  940  1,390  2, Thus, f 3 (6)  1,570, and the shortest path from city 6 to city 10 is the path 6–8–10. To find f 3 (7), we note that

f 3 (7)  min (^) {

c 78  f 4 (8)  790  1,030  1, c 79  f 4 (9)  270  1,390  1,660* Therefore, f 3 (7)  1,660, and the shortest path from city 7 to city 10 is the path 7–9–10.

Stage 2 Computations Given our knowledge of f 3 (5), f 3 (6), and f 3 (7), it is now easy to work backward one more stage and compute f 2 (2), f 2 (3), and f 2 (4) and thus the shortest paths to Los Angeles from city 2, city 3, and city 4. To illustrate how this is done, we find the shortest path (and its length) from city 2 to city 10. The shortest path from city 2 to city 10 must begin by go- ing from city 2 to city 5, city 6, or city 7. Once this shortest path gets to city 5, city 6, or city 7, then it must follow a shortest path from that city to Los Angeles. This reasoning shows that the shortest path from city 2 to city 10 must be one of the following: Path 1 Go from city 2 to city 5. Then follow a shortest path from city 5 to city 10. A path of this type has a total length of c 25  f 3 (5).

Los Angeles 10

Denver 8

San Antonio 9

Kansas City 5

Columbus 2

550

680

(^580 )

790

1,050^790

(^790 )

900 760

660

510

700

830

270

(^940) 1,

770

Stage 1 Stage 5

Stage 2 Stage 3

Stage 4

1,

Omaha 6

Nashville 3

Dallas 7

Louisville 4

New York 1

F I G U R E 1 Joe’s Trip Across the United States

Path 2 Go from city 2 to city 6. Then follow a shortest path from city 6 to city 10. A path of this type has a total length of c 26  f 3 (6).

Path 3 Go from city 2 to city 7. Then follow a shortest path from city 7 to city 10. This path has a total length of c 27  f 3 (7). We may now conclude that

c 25  f 3 (5)  680  1,640  2,320* f 2 (2)  min 

c 26  f 3 (6)  790  1,570  2, c 27  f 3 (7)  1,050  1,660  2,

Thus, f 2 (2)  2,320, and the shortest path from city 2 to city 10 is to go from city 2 to city 5 and then follow the shortest path from city 5 to city 10 (5–8–10). Similarly, c 35  f 3 (5)  580  1,640  2,220* f 2 (3)  min 

c 36  f 3 (6)  760  1,570  2, c 37  f 3 (7)  660  1,660  2,

Thus, f 2 (3)  2,220, and the shortest path from city 3 to city 10 consists of arc 3–5 and the shortest path from city 5 to city 10 (5–8–10). In similar fashion, c 45  f 3 (5)  510  1,640  2,150* f 2 (4)  min 

c 46  f 3 (6)  700  1,570  2, c 47  f 3 (7)  830  1,660  2,

Thus, f 2 (4)  2,150, and the shortest path from city 4 to city 10 consists of arc 4–5 and the shortest path from city 5 to city 10 (5–8–10).

Stage 1 Computations

We can now use our knowledge of f 2 (2), f 2 (3), and f 2 (4) to work backward one more stage to find f 1 (1) and the shortest path from city 1 to city 10. Note that the shortest path from city 1 to city 10 must begin by going to city 2, city 3, or city 4. This means that the short- est path from city 1 to city 10 must be one of the following:

Path 1 Go from city 1 to city 2 and then follow a shortest path from city 2 to city 10. The length of such a path is c 12  f 2 (2).

Path 2 Go from city 1 to city 3 and then follow a shortest path from city 3 to city 10. The length of such a path is c 13  f 2 (3).

Path 3 Go from city 1 to city 4 and then follow a shortest path from city 4 to city 10. The length of such a path is c 14  f 2 (4). It now follows that

c 12  f 2 (2)  550  2,320  2,870* f 1 (1)  min 

c 13  f 2 (3)  900  2,220  3, c 14  f 2 (4)  770  2,150  2,

Determination of the Optimal Path

Thus, f 1 (1)  2,870, and the shortest path from city 1 to city 10 goes from city 1 to city 2 and then follows the shortest path from city 2 to city 10. Checking back to the f 2 (2) cal- culations, we see that the shortest path from city 2 to city 10 is 2–5–8–10. Translating the numerical labels into real cities, we see that the shortest path from New York to Los An-

1 8. 2 A Network Problem 965

1 8. 2 A Network Problem 967

the shortest path from node 1 to node 27. Because explicit enumeration requires 15, additions, we see that dynamic programming requires only 0.007 times as many additions as explicit enumeration. For larger networks, the computational savings effected by dy- namic programming are even more dramatic. Besides additions, determination of the shortest path in a network requires compar- isons between the lengths of paths. If explicit enumeration is used, then 5 5  1  3, comparisons must be made (that is, compare the length of the first two paths, then com- pare the length of the third path with the shortest of the first two paths, and so on). If dy- namic programming is used, then for t  2, 3, 4, 5, determination of each ft ( i ) requires 5  1  4 comparisons. Then to compute f 1 (1), 5  1  4 comparisons are required. Thus, to find the shortest path from node 1 to node 27, dynamic programming requires a total of 20(5  1)  4  84 comparisons. Again, dynamic programming comes out far superior to explicit enumeration.

Characteristics of Dynamic Programming Applications

We close this section with a discussion of the characteristics of Example 3 that are com- mon to most applications of dynamic programming.

Characteristic 1

The problem can be divided into stages with a decision required at each stage. In Exam- ple 3, stage t consisted of those cities where Joe could be at the beginning of day t of his trip. As we will see, in many dynamic programming problems, the stage is the amount of time that has elapsed since the beginning of the problem. We note that in some situations, decisions are not required at every stage (see Section 18.5).

Characteristic 2

Each stage has a number of states associated with it. By a state, we mean the informa- tion that is needed at any stage to make an optimal decision. In Example 3, the state at stage t is simply the city where Joe is at the beginning of day t. For example, in stage 3, the possible states are Kansas City, Omaha, and Dallas. Note that to make the correct de- cision at any stage, Joe doesn’t need to know how he got to his current location. For ex- ample, if Joe is in Kansas City, then his remaining decisions don’t depend on how he goes to Kansas City; his future decisions just depend on the fact that he is now in Kansas City.

Characteristic 3

The decision chosen at any stage describes how the state at the current stage is trans- formed into the state at the next stage. In Example 3, Joe’s decision at any stage is sim- ply the next city to visit. This determines the state at the next stage in an obvious fash- ion. In many problems, however, a decision does not determine the next stage’s state with certainty; instead, the current decision only determines the probability distribution of the state at the next stage.

Characteristic 4

Given the current state, the optimal decision for each of the remaining stages must not depend on previously reached states or previously chosen decisions. This idea is known as the principle of optimality. In the context of Example 3, the principle of optimality

968 C H A P T E R 1 8 Deterministic Dynamic Programming

reduces to the following: Suppose the shortest path (call it R ) from city 1 to city 10 is known to pass through city i. Then the portion of R that goes from city i to city 10 must be a shortest path from city i to city 10. If this were not the case, then we could create a path from city 1 to city 10 that was shorter than R by appending a shortest path from city i to city 10 to the portion of R leading from city 1 to city i. This would create a path from city 1 to city 10 that is shorter than R , thereby contradicting the fact that R is a shortest path from city 1 to city 10. For example, if the shortest path from city 1 to city 10 is known to pass through city 2, then the shortest path from city 1 to city 10 must include a shortest path from city 2 to city 10 (2–5–8–10). This follows because any path from city 1 to city 10 that passes through city 2 and does not contain a shortest path from city 2 to city 10 will have a length of c 12  [something bigger than f 2 (2)]. Of course, such a path cannot be a shortest path from city 1 to city 10.

Characteristic 5 If the states for the problem have been classified into one of T stages, there must be a re- cursion that relates the cost or reward earned during stages t, t  1,... , T to the cost or reward earned from stages t  1, t  2,... , T. In essence, the recursion formalizes the working-backward procedure. In Example 3, our recursion could have been written as ft ( i )  min j

{ cij  ft  1 ( j )}

where j must be a stage t  1 city and f 5 (10)  0. We can now describe how to make optimal decisions. Let’s assume that the initial state during stage 1 is i 1. To use the recursion, we begin by finding the optimal decision for each state associated with the last stage. Then we use the recursion described in charac- teristic 5 to determine fT  1 () (along with the optimal decision) for every stage T  1 state. Then we use the recursion to determine fT  2 () (along with the optimal decision) for every stage T  2 state. We continue in this fashion until we have computed f 1 ( i 1 ) and the optimal decision when we are in stage 1 and state i 1. Then our optimal decision in stage 1 is chosen from the set of decisions attaining f 1 ( i 1 ). Choosing this decision at stage 1 will lead us to some stage 2 state (call it state i 2 ) at stage 2. Then at stage 2, we choose any decision attaining f 2 ( i 2 ). We continue in this fashion until a decision has been chosen for each stage. In the rest of this chapter, we discuss many applications of dynamic programming. The presentation will seem easier if the reader attempts to determine how each problem fits into the network context introduced in Example 3. In the next section, we begin by study- ing how dynamic programming can be used to solve inventory problems.

P R O B L E M S

Group A

1 Find the shortest path from node 1 to node 10 in the network shown in Figure 3. Also, find the shortest path from node 3 to node 10. 2 A sales representative lives in Bloomington and must be in Indianapolis next Thursday. On each of the days Monday, Tuesday, and Wednesday, he can sell his wares in Indianapolis, Bloomington, or Chicago. From past experience, he believes that he can earn $12 from spending a day in Indianapolis, $ from spending a day in Bloomington, and $17 from spending a day in Chicago. Where should he spend the first three days

2 2

7 4 6 3 4 4 5

3 3 3

3

1 3 6 1

4 2

4 3

1 3 10

4

5

6

8

9

7

F I G U R E 3

970 C H A P T E R 1 8 Deterministic Dynamic Programming

A company knows that the demand for its product during each of the next four months will be as follows: month 1, 1 unit; month 2, 3 units; month 3, 2 units; month 4, 4 units. At the beginning of each month, the company must determine how many units should be produced during the current month. During a month in which any units are produced, a setup cost of $3 is incurred. In addition, there is a variable cost of $1 for every unit pro- duced. At the end of each month, a holding cost of 50¢ per unit on hand is incurred. Ca- pacity limitations allow a maximum of 5 units to be produced during each month. The size of the company’s warehouse restricts the ending inventory for each month to 4 units at most. The company wants to determine a production schedule that will meet all de- mands on time and will minimize the sum of production and holding costs during the four months. Assume that 0 units are on hand at the beginning of the first month.

Solution Recall from Section 3.10 that we can ensure that all demands are met on time by re- stricting each month’s ending inventory to be nonnegative. To use dynamic programming to solve this problem, we need to identify the appropriate state, stage, and decision. The stage should be defined so that when one stage remains, the problem will be trivial to solve. If we are at the beginning of month 4, then the firm would meet demand at mini- mum cost by simply producing just enough units to ensure that (month 4 production)  (month 3 ending inventory)  (month 4 demand). Thus, when one month remains, the firm’s problem is easy to solve. Hence, we let time represent the stage. In most dynamic programming problems, the stage has something to do with time. At each stage (or month), the company must decide how many units to produce. To make this decision, the company need only know the inventory level at the beginning of the current month (or the end of the previous month). Therefore, we let the state at any stage be the beginning inventory level. Before writing a recursive relation that can be used to “build up” the optimal produc- tion schedule, we must define ft ( i ) to be the minimum cost of meeting demands for months t , t  1,... , 4 if i units are on hand at the beginning of month t. We define c ( x ) to be the cost of producing x units during a period. Then c (0)  0, and for x  0, c ( x )  3  x. Because of the limited storage capacity and the fact that all demand must be met on time, the possible states during each period are 0, 1, 2, 3, and 4. Thus, we begin by determin- ing f 4 (0), f 4 (1), f 4 (2), f 4 (3), and f 4 (4). Then we use this information to determine f 3 (0), f 3 (1), f 3 (2), f 3 (3), and f 3 (4). Then we determine f 2 (0), f 2 (1), f 2 (2), f 2 (3), and f 2 (4). Finally, we determine f 1 (0). Then we determine an optimal production level for each month. We define xt ( i ) to be a production level during month t that minimizes the total cost during months t , t  1,... , 4 if i units are on hand at the beginning of month t. We now begin to work backward.

Month 4 Computations During month 4, the firm will produce just enough units to ensure that the month 4 de- mand of 4 units is met. This yields f 4 (0)  cost of producing 4  0 units  c (4)  3  4  $7 and x 4 (0)  4  0  4 f 4 (1)  cost of producing 4  1 units  c (3)  3  3  $6 and x 4 (1)  4  1  3 f 4 (2)  cost of producing 4  2 units  c (2)  3  2  $5 and x 4 (2)  4  2  2 f 4 (3)  cost of producing 4  3 units  c (1)  3  1  $4 and x 4 (3)  4  3  1 f 4 (4)  cost of producing 4  4 units  c (0)  $0 and x 4 (4)  4  4  0

E X A M P L E 4 Inventory

1 8. 3 An Inventory Problem 971

Month 3 Computations

How can we now determine f 3 (i) for i  0, 1, 2, 3, 4? The cost f 3 ( i ) is the minimum cost incurred during months 3 and 4 if the inventory at the beginning of month 3 is i. For each possible production level x during month 3, the total cost during months 3 and 4 is

(^12 )( i  x  2)  c ( x )  f 4 ( i  x  2) (1)

This follows because if x units are produced during month 3, the ending inventory for month 3 will be i  x  2. Then the month 3 holding cost will be (^12 )( i  x  2), and the month 3 production cost will be c ( x ). Then we enter month 4 with i  x  2 units on hand. Since we proceed optimally from this point onward (remember the principle of op- timality), the cost for month 4 will be f 4 ( i  x  2). We want to choose the month 3 pro- duction level to minimize (1), so we write

f 3 ( i )  min x {(^12 )( i  x  2)  c ( x )  f 4 ( i  x  2)} (2)

In (2), x must be a member of {0, 1, 2, 3, 4, 5}, and x must satisfy 4  i  x  2  0. This reflects the fact that the current month’s demand must be met ( i  x  2  0), and ending inventory cannot exceed the capacity of 4( i  x  2 4). Recall that x 3 ( i ) is any value of x attaining f 3 ( i ). The computations for f 3 (0), f 3 (1), f 3 (2), f 3 (3), and f 3 (4) are given in Table 3.

Month 2 Computations

We can now determine f 2 ( i ), the minimum cost incurred during months 2, 3, and 4 given that at the beginning of month 2, the on-hand inventory is i units. Suppose that month 2 production  x. Because month 2 demand is 3 units, a holding cost of (^12 )( i  x  3) is

T A B L E 3 Computations for f 3 (i)

Total Cost f 3 ( i ) i x ( ^12  )( i  x  2)  c ( x ) f 4 ( i  x  2) Months 3, 4 x 3 ( i )

0 2 0  5  5 7 5  7  12* f 3 (0)  12 0 3 ^12 ^  6  ^123 ^6 ^123 ^  6  ^225 ^ x 3 (0)  2 0 4 1  7  8 5 8  5  13 0 5 ^32 ^  8  ^129 ^4 ^129 ^  4  ^227  1 1 0  4  4 7 4  7  11 f 3 (1)  10 1 2 ^12 ^  5  ^121 ^6 ^121 ^  6  ^223 ^ x 3 (1)  5 1 3 1  6  7 5 7  5  12 1 4 ^32 ^  7  ^127 ^4 ^127 ^  4  ^225  1 5 2  8  10 0 10  0  10* 2 0 0  0  0 7 0  7  7* f 3 (2)  7 2 1 ^12 ^  4  ^92 ^6 ^92 ^  6  ^221 ^ x 3 (2)  0 2 2 1  5  6 5 6  5  11 2 3 ^32 ^  6  ^125 ^4 ^125 ^  4  ^223  2 4 2  7  9 0 9  0  9 3 0 ^12 ^  0  ^12 ^6 ^12 ^  6  ^123 * f 3 (3)  ^123  3 1 1  4  5 5 5  5  10 x 3 (3)  0 3 2 ^32 ^  5  ^123 ^4 ^123 ^  4  ^221  3 3 2  6  8 0 8  0  8 4 0 1  0  1 5 1  5  6* f 3 (4)  6 4 1 ^32 ^  4  ^121 ^4 ^121 ^  4  ^129 ^ x 3 (4)  0 4 2 2  5  7 0 7  0  7

1 8. 3 An Inventory Problem 973

unit during month 1. Then the inventory at the beginning of month 2 will be 0  1  1  0. Thus, in month 2, we should produce x 2 (0)  5 units. Then at the beginning of month 3, our beginning inventory will be 0  5  3  2. Hence, during month 3, we need to produce x 3 (2)  0 units. Then month 4 will begin with 2  2  0  0 units on hand. Thus, x 4 (0)  4 units should be produced during month 4. In summary, the opti- mal production schedule incurs a total cost of $20 and produces 1 unit during month 1, 5 units during month 2, 0 units during month 3, and 4 units during month 4.

Note that finding the solution to Example 4 is equivalent to finding the shortest route join- ing the node (1, 0) to the node (5, 0) in Figure 5. Each node in Figure 5 corresponds to a state, and each column of nodes corresponds to all the possible states associated with a given stage. For example, if we are at node (2, 3), then we are at the beginning of month 2, and the inventory at the beginning of month 2 is 3 units. Each arc in the network rep- resents the way in which a decision (how much to produce during the current month) transforms the current state into next month’s state. For example, the arc joining nodes (1,

  1. and (2, 2) (call it arc 1) corresponds to producing 3 units during month 1. To see this, note that if 3 units are produced during month 1, then we begin month 2 with 0  3  1  2 units. The length of each arc is simply the sum of production and inventory costs during the current period, given the current state and the decision associated with the cho- sen arc. For example, the cost associated with arc 1 would be 6  (^12 )2  7. Note that some nodes in adjacent stages are not joined by an arc. For example, node (2, 4) is not joined to node (3, 0). The reason for this is that if we begin month 2 with 4 units, then at the beginning of month 3, we will have at least 4  3  1 unit on hand. Also note that we have drawn arcs joining all month 4 states to the node (5, 0), since having a positive inventory at the end of month 4 would clearly be suboptimal.

T A B L E 5 Computations for f 1 (i )

f 1 ( i ) i x ( ^12  )( i  x  1)  c ( x ) f 2 ( i  x  1) Total Cost x 1 ( i )

0 1 0  4  4 16 4  16  20* f 1 (0)  20 0 2 ^12 ^  5  ^121 ^15 ^121 ^  15  ^421 ^ x 1 (0)  1 0 3 1  6  7 14 7  14  21 0 4 ^32 ^  7  ^127 ^12 ^127 ^  12  ^421  0 5 2  8  10 ^221 ^10  ^221 ^  ^421  1 0 0  0  0 16 0  16  16* f 1 (1)  16 1 1 ^12 ^  4  ^92 ^15 ^92 ^  15  ^329 ^ x 1 (1)  0 1 2 1  5  6 14 20 1 3 ^32 ^  6  ^125 ^12 ^125 ^  12  ^329  1 4 2  7  9 ^221 ^9  ^221 ^  ^329  2 0 ^12 ^  0  ^12 ^15 ^12 ^  15  ^321 * f 1 (2)  ^321  2 1 1  4  5 14 5  14  19 x 1 (2)  0 2 2 ^32 ^  5  ^123 ^12 ^123 ^  12  ^327  2 3 2  6  8 ^221 ^8  ^221 ^  ^327  3 0 1  0  1 14 1  14  15* f 1 (3)  15 3 1 ^32 ^  4  ^121 ^12 ^121 ^  12  ^325 ^ x 1 (3)  0 3 2 2  5  7 ^221 ^7  ^221 ^  ^325  4 0 ^32 ^  0  ^32 ^12 ^32 ^  12  ^227 * f 1 (4)  ^227  4 1 2  4  6 ^221 ^6  ^221 ^  ^323 ^ x 1 (4)  0

974 C H A P T E R 1 8 Deterministic Dynamic Programming

Returning to Example 4, the minimum-cost production schedule corresponds to the shortest path joining (1, 0) and (5, 0). As we have already seen, this would be the path corresponding to production levels of 1, 5, 0, and 4. In Figure 5, this would correspond to the path beginning at (1, 0), then going to (2, 0  1  1)  (2, 0), then to (3, 0  5  3)  (3, 2), then to (4, 2  0  2)  (4, 0), and finally to (5, 0  4  4)  (5, 0). Thus, our optimal production schedule corresponds to the path (1, 0)–(2, 0)–(3, 2)–(4, 0)–(5, 0) in Figure 5.

P R O B L E M S

Group A

1, 0

1, 1

1, 2

1, 3

1, 4 Month 1 Month 2 Month 3 Month 4

Month 5

2, 0

2, 1

2, 2

2, 3

2, 4

3, 0

3, 1

3, 2

3, 3

3, 4

4, 0

4, 1

4, 2 5, 0

4, 3

4, 4

F I G U R E 5 Network Representation of Inventory Example

1 In Example 4, determine the optimal production schedule if the initial inventory is 3 units. 2 An electronics firm has a contract to deliver the following number of radios during the next three months; month 1, 200 radios; month 2, 300 radios; month 3, 300 radios. For each radio produced during months 1 and 2, a $10 variable cost is incurred; for each radio produced during month 3, a $12 variable cost is incurred. The inventory cost is $1.50 for each radio in stock at the end of a month. The cost of setting up for production during a month is $250.

Radios made during a month may be used to meet demand for that month or any future month. Assume that production during each month must be a multiple of 100. Given that the initial inventory level is 0 units, use dynamic programming to determine an optimal production schedule. 3 In Figure 5, determine the production level and cost associated with each of the following arcs: a (2, 3)–(3, 1) b (4, 2)–(5, 0)

18.4 Resource-Allocation Problems

Resource-allocation problems, in which limited resources must be allocated among sev- eral activities, are often solved by dynamic programming. Recall that we have solved such problems by linear programming (for instance, the Giapetto problem). To use linear pro- gramming to do resource allocation, three assumptions must be made: Assumption 1 The amount of a resource assigned to an activity may be any nonnegative number.

976 C H A P T E R 1 8 Deterministic Dynamic Programming

terminate our computations by computing f 1 (6). Then we retrace our steps and determine the amount that should be allocated to each investment (just as we retraced our steps to determine the optimal production level for each month in Example 4).

Stage 3 Computations We first determine f 3 (0), f 3 (1),... , f 3 (6). We see that f 3 ( d 3 ) is attained by investing all available money ( d 3 ) in investment 3. Thus, f 3 (0)  0 x 3 (0)  0 f 3 (1)  9 x 3 (1)  1 f 3 (2)  13 x 3 (2)  2 f 3 (3)  17 x 3 (3)  3 f 3 (4)  21 x 3 (4)  4 f 3 (5)  25 x 3 (5)  5 f 3 (6)  29 x 3 (6)  6

T A B L E 6 Computations for f 2 (0), f 2 (1),... , f 2 (6) NPV from f 2 ( d 2 ) d 2 x 2 r 2 ( x 2 ) f 3 ( d 2  x 2 ) Investments 2, 3 x 2 ( d 2 ) 0 0 0 0 0* f 2 (0)  0 x 2 (0)  0 1 0 0 9 9* f 2 (1)  10 1 1 10 0 10* x 2 (1)  1 2 0 0 13 13* f 2 (2)  19 2 1 10 9 19* x 2 (2)  1 2 2 13 0 13* 3 0 0 17 17* f 2 (3)  23 3 1 10 13 23* x 2 (3)  1 3 2 13 9 22* 3 3 16 0 16* 4 0 0 21 21* f 2 (4)  27 4 1 10 17 27* x 2 (4)  1 4 2 13 13 26* 4 3 16 9 25* 4 4 19 0 19* 5 0 0 25 25* f 2 (5)  31 5 1 10 21 31* x 2 (5)  1 5 2 13 17 30* 5 3 16 13 29* 5 4 19 9 28* 5 5 22 0 22* 6 0 0 29 29* f 2 (6)  35 6 1 10 25 35* x 2 (6)  1 6 2 13 21 34* 6 3 16 17 33* 6 4 19 13 32* 6 5 22 9 31* 6 6 25 0 25*

1 8. 4 Resource-Allocation Problems 977

Stage 2 Computations

To determine f 2 (0), f 2 (1),... , f 2 (6), we look at all possible amounts that can be placed in investment 2. To find f 2 ( d 2 ), let x 2 be the amount invested in investment 2. Then an NPV of r 2 ( x 2 ) will be obtained from investment 2, and an NPV of f 3 ( d 2  x 2 ) will be obtained from investment 3 (remember the principle of optimality). Since x 2 should be chosen to maximize the net present value earned from investments 2 and 3, we write

f 2 ( d 2 )  max x 2 { r 2 ( x 2 )  f 3 ( d 2  x 2 )} (5)

where x 2 must be a member of {0, 1,... , d 2 }. The computations for f 2 (0), f 2 (1),... , f 2 (6) and x 2 (0), x 2 (1),... , x 2 (6) are given in Table 6.

Stage 1 Computations

Following (5), we write

f 1 (6)  max x 1 { r 1 ( x 1 )  f 2 (6  x 1 )}

where x 1 must be a member of {0, 1, 2, 3, 4, 5, 6}. The computations for f 1 (6) are given in Table 7.

Determination of Optimal Resource Allocation

Since x 1 (6)  4, Finco invests $4,000 in investment 1. This leaves 6,000  4,000  $2,000 for investments 2 and 3. Hence, Finco should invest x 2 (2)  $1,000 in investment

  1. Then $1,000 is left for investment 3, so Finco chooses to invest x 3 (1)  $1,000 in in- vestment 3. Therefore, Finco can attain a maximum net present value of f 1 (6)  $49, by investing $4,000 in investment 1, $1,000 in investment 2, and $1,000 in investment 3.

Network Representation of Resource Example

As with the inventory example of Section 18.3, Finco’s problem has a network represen- tation, equivalent to finding the longest route from (1, 6) to (4, 0) in Figure 6. In the fig- ure, the node ( t , d ) represents the situation in which d thousand dollars is available for in- vestments t , t  1,... , 3. The arc joining the nodes ( t , d ) and ( t  1, d  x ) has a length rt ( x ) corresponding to the net present value obtained by investing x thousand dollars in investment t. For example, the arc joining nodes (2, 4) and (3, 1) has a length r 2 (3)  $16,000, corresponding to the $16,000 net present value that can be obtained by invest-

T A B L E 7 Computations for f 1 (6)

NPV from f 1 (6) d 1 x 1 r 1 ( x 1 ) f 2 (6  x 1 ) Investments 1–3 x 1 (6)

6 0 0 35 35 f 1 (6)  49 6 1 9 31 40 x 1 (6)  4 6 2 16 27 43 6 3 23 23 46 6 4 30 19 49* 6 5 37 10 47 6 6 44 0 44

1 8. 4 Resource-Allocation Problems 979

have been determined. To wind things up, we now calculate f 1 ( w ) and x 1 ( w ). Then we im- plement activity 1 at a level x 1 ( w ). At this point, we have w  g 1 [ x 1 ( w )] units of the re- source available for activities 2, 3,... , T. Then activity 2 should be implemented at a level of x 2 { w  g 1 [ x 1 ( w )]}. We continue in this fashion until we have determined the level at which all activities should be implemented.

Solution of Knapsack Problems by Dynamic Programming

We illustrate the use of (7) by solving a simple knapsack problem (see Section 9.5). Then we develop an alternative recursion that can be used to solve knapsack problems.

Suppose a 10-lb knapsack is to be filled with the items listed in Table 9. To maximize to- tal benefit, how should the knapsack be filled? Solution We have r 1 ( x 1 )  11 x 1 , r 2 ( x 2 )  7 x 2 , r 3 ( x 3 )  12 x 3 , g 1 ( x 1 )  4 x 1 , g 2 ( x 2 )  3 x 2 , and g 3 ( x 3 )  5 x 3. Define ft ( d ) to be the maximum benefit that can be earned from a d -pound knap- sack that is filled with items of Type t , t  1,... , 3.

Stage 3 Computations Now (7) yields f 3 ( d )  max x 3 {12 x 3 }

E X A M P L E 6 Knapsack

T A B L E 8 Examples of a Generalized Resource Allocation Problem Interpretation Interpretation of Interpretation of r (^) t ( x (^) t ) gt ( x (^) t ) of w Benefit from placing xt Weight of x (^) t type t items Maximum weight that type t items in a knapsack knapsack can hold Grade obtained in course t Number of hours per week x (^) t Total number of study hours if we study course t for x (^) t spent studying course t available each week hours per week Sales of a product in Cost of assigning x (^) t sales Total sales force budget region t if x (^) t sales reps are reps to region t assigned to region t Number of fire alarms per Cost per week of maintaining Total weekly budget for week responded to within x (^) t fire engines in precinct t maintaining fire engines one minute if precinct t is assigned x (^) t engines

T A B L E 9 Weights and Benefits for Knapsack Item Weight (lb) Benefit 1 4 11 2 3 7 3 5 12

980 C H A P T E R 1 8 Deterministic Dynamic Programming

where 5 x 3 d and x 3 is a nonnegative integer. This yields f 3 (10)  24 f 3 (5)  f 3 (6)  f 3 (7)  f 3 (8)  f 3 (9)  12 f 3 (0)  f 3 (1)  f 3 (2)  f 3 (3)  f 3 (4)  0 x 3 (10)  2 x 3 (9)  x 3 (8)  x 3 (7)  x 3 (6)  x 3 (5)  1 x 3 (0)  x 3 (1)  x 3 (2)  x 3 (3)  x 3 (4)  0

Stage 2 Computations Now (7) yields f 2 ( d )  max x 2 {7 x 2  f 3 ( d  3 x 2 )} where x 2 must be a nonnegative integer satisfying 3 x 2 d. We now obtain 7(0)  f 3 (10)  24* x 2  0

f 2 (10)  max

7(1)  f 3 (7)  19 * x 2  1 7(2)  f 3 (4)  14 * x 2  2 7(3)  f 3 (1)  21 * x 2  3 Thus, f 2 (10)  24 and x 2 (10)  0. 7(0)  f 3 (9)  12 * x 2  0

f 2 (9)  max

7(1)  f 3 (6)  19 * x 2  1 7(2)  f 3 (3)  14 * x 2  2 7(3)  f 3 (0)  21* x 2  3 Thus, f 2 (9)  21 and x 2 (9)  3. 7(0)  f 3 (8)  12 * x 2  0 f 2 (8)  max

7(1)  f 3 (5)  19* x 2  1 7(2)  f 3 (2)  14 * x 2  2 Thus, f 2 (8)  19 and x 2 (8)  1. 7(0)  f 3 (7)  12 * x 2  0 f 2 (7)  max

7(1)  f 3 (4)  7 * x 2  1 7(2)  f 3 (1)  14* x 2  2 Thus, f 2 (7)  14 and x 2 (7)  2. 7(0)  f 3 (6)  12 * x 2  0 f 2 (6)  max

7(1)  f 3 (3)  7 * x 2  1 7(2)  f 3 (0)  14* x 2  2 Thus, f 2 (6)  14 and x 2 (6)  2.

f 2 (5)  max (^) 

7(0)  f 3 (5)  12* x 2  0 7(1)  f 3 (2)  7 * x 2  1 Thus, f 2 (5)  12 and x 2 (5)  0.

f 2 (4)  max (^) 

7(0)  f 3 (4)  0 * x 2  0 7(1)  f 3 (1)  7* x 2  1