DynamicProgramming_Ch18
DynamicProgramming_Ch18
*Wayne L. Winston, Operations Research, Duxbury Press, 4th Edition. ISBN: 978-0534380588
1
Description
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 the
problem toward the beginning, thus breaking up a large,
unwieldy problem into a series of smaller, more tractable
problems
2
Match Puzzle Example
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?
3
Match Puzzle Example
If I can ensure that it will be 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.
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 1 match on my first turn.
4
Milk Example:
• I have a 9-oz cup and a 4-oz cup. My mother has
ordered me to bring home exactly 6oz of milk.
How can I accomplish this goal?
By starting near the end of the problem,
I realize that the problem will be solved
if I can get 1 oz of milk into the 4-oz
cup.
Then I can fill the 9-0z cup and empty 3
oz from the 9oz cup into the partially
filled 4-oz cup.
At this point, I will be left with 6 oz of
milk.
At Table 1 the initial ituation is written
last and the final situation is written
first.
A Network Problem
Many applications of dynamic programming reduce to
finding the shortest (or longest) path that joins two
points in a given network.
For larger networks dynamic programming is much more
efficient for determining a shortest path than the explicit
enumeration of all paths.
6
Shortest Path Problem
Joe Cougar lives in New York City, but he plans to drive to
Los Angeles to seek fame and fortune. Joe’s funds are
limited, so he has decided to spend each night on his trip
at a friend’s house. Joe has friends in Columbus,
Nashville, Louisville, Kansas City, Omaha, Dallas, San
Antonio, and Denver. Joe knows that after one day’s
drive he can reach Columbus, Nashville, or Louisville.
After two days of driving, he can reach Kansas City,
Omaha, or Dallas. After three days of driving, he can
reach San Antonio or Denver. Finally, after four days of
driving, he can reach Los Angeles. To minimize the
number of miles traveled, where should Joe spend each
night of the trip? The actual road mileages between
cities are given in Figure 1 (next slide). 7
Shortest Path Problem
8
Shortest Path Problem
We define to be the road mileage between city and city .
For example, is the road mileage between Nashville and
Kansas City.
We let be the length of the shortest path from city to Los
Angeles, given that city is a stage city.
– The length of the shortest path (sp) from NYC to LA is given by .
Stage 4 Computations
the length of sp from Denver to LA
the length of sp from San Ant. to LA
9
Shortest Path Problem
Stage 3 Computations
We now work backward one stage (to stage 3 cities) and find the
shortest path to LA from each stage 3 city.
For example, to determine , we note that the shortest path from city 5
to LA must be one of the following:
– Path 1 Go from city 5 to city 8 and then take the shortest path from city 8 to
city 10.
– Path 2 Go from city 5 to city 9 and then take the shortest path from city 9 to
city 10.
The length of path 1 may be written as , and
the length of path 2 may be written as .
Hence, the shortest distance from city 5 to city 10 may be written as
10
Shortest Path Problem
Stage 3 Computations
Similarly, we find
We find
11
Shortest Path Problem
Stage 2 Computations
Given our knowledge of , , and , it is now easy to work
backward one more stage and compute , , and .
Let’s first find the shortest path (and it length) from city 2
to city 10.
12
Shortest Path Problem
Stage 2 Computations
13
Shortest Path Problem
Stage 1 Computations
We can now use our knowledge of , , and to work backward
one more stage to find .
15
Characteristics of Dynamic Programming Applications
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.
Characteristic 5
– If the states for the problem have been classified into on of T
stages, there must be a recursion that related the cost (or
reward earned) during stages to the cost (or reward earned)
from stages .
– In shortest path example, our recursion could have been
written as
16
An Inventory Problem
Dynamic programming can be used to solve an inventory
problem with the following characteristics:
1. Time is broken up into periods, the present period being period 1,
the next period 2, and the final period T. At the beginning of period
1, the demand during each period is known.
2. At the beginning of each period, the firm must determine how
many units should be produced. Production capacity during each
period is limited.
3. Each period’s demand must be met on time from inventory or
current production. During any period in which production takes
place, a fixed cost of production as well as a variable per-unit cost
is incurred.
4. The firm has limited storage capacity. This is reflected by a limit on
end-of-period inventory. A per-unit holding cost is incurred on each
period’s ending inventory.
5. The firms goal is to minimize the total cost of meeting on time the
17
An Inventory Problem
In this model, the firm’s inventory position is reviewed at
the end (or beginning) of each period, and then the
production decision is made.
Such a model is called a periodic review model.
This model is in contrast to the continuous review model
in which the firm knows its inventory position at all times
and may place an order or begin production at any time.
18
Inventory Problem
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
produced.
At the end of each month, a holding cost of 50¢ per unit on hand is
incurred. Capacity 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.
Assume that 0 units are on hand at the beginning of the first month.
The company wants to determine a production schedule that will
meet all demands on time and will minimize the sum of production
and holding costs during the four months. 19
Inventory Problem
We must first define to be the minimum cost of meeting
demands for months if units are on hand at the beginning of
month t.
– minimum cost of the problem
We define to be the cost of producing units during a period.
– then
– and for , .
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 determining , , , , and
We define to be a production level during month that
minimizes the total cost during months if units are on hand
at the beginning of month .
20
Inventory Problem- Month 4 Computations
21
Inventory Problem - Month 3 Computations
22
Inventory Problem - Month 2 Computations
23
Inventory Problem- Month 1 Computations
24
Inventory Problem
Determination of the Optimal Production Schedule
Let’s determine a production schedule that minimizes the total
cost of meeting the demand for all four months on time.
Since our initial inventory is 0 units, the minimum cost for the
four months will be . To attain , we must produce unit during
month 1.
Then the inventory at the beginning of month 2 will be . Thus,
in month 2, we should produce units.
Then at the beginning of month 3, our beginning inventory will
be . Hence, during month 3, we need to produce units.
Then month 4 will begin with units on hand. Thus, units should
be produced during month 4.
In summary, the optimal production schedule incurs a total cost
of $20 and produces 1 unit during month 1, 5 units during
25
18.6 Formulating Dynamic Programming Recursions
IE318: Applications in OR 29
Dynamic Lot-Size Models
IE318: Applications in OR 30
A Dynamic Lot-Size Problem
We now determine an optimal production schedule for a
five-period dynamic lot-size model with , , , , , , , and .
We assume that the initial inventory level is zero.
The solution to this example will be discussed but before
starting with the solution we need to provide the
recursion relation (next slide).
IE318: Applications in OR 31
A Dynamic Lot-Size Problem
Using dynamic programming we can develop a recursion relation
to determine an optimal production policy.
We know that the initial inventory level is zero.
Define as the minimum cost incurred during periods , given that
at the beginning of period , the inventory level is zero. Then must
satisfy
IE318: Applications in OR 34
A Dynamic Lot-Size Problem
Stage 3 Computations
IE318: Applications in OR 35
A Dynamic Lot-Size Problem
Stage 2 Computations
IE318: Applications in OR 36
A Dynamic Lot-Size Problem
Stage 1 Computations
IE318: Applications in OR 39
Generalized Resource Allocation Problem
To solve this problem by dynamic programming, define
to be the maximum benefit that can be obtained from
activities if unites of the resource may be allocated to
activities .
We may generalize the recursions to this situation by
writing
IE318: Applications in OR 40
Knapsack Problem
Suppose a 10-lb knapsack is to be filled with the items
listed in Table 9. To maximize total benefit, how should
the knapsack be filled?
IE318: Applications in OR 41
Knapsack Problem
We have , , , , ,
Define to be the maximum benefit that can be earned from a
pound knapsack that is filled with items of Type .
Stage 3 Computations
IE318: Applications in OR 42
Knapsack Problem
Stage 2 Computations
IE318: Applications in OR 43
Knapsack Problem
Stage 2 Computations (continued)
IE318: Applications in OR 44
Knapsack Problem
Stage 2 Computations (continued)
IE318: Applications in OR 45
Knapsack Problem
Stage 1 Computations
IE318: Applications in OR 46