Professional Documents
Culture Documents
Decisions
Dynamic Programming
George Gross
Department of Electrical and Computer Engineering
University of Illinois at Urbana-Champaign
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 1
DYNAMIC PROGRAMMING
making problems
decision variable
dn
(decision)
sn stage n s n
state state
(input) (output)
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 4
RETURN FUNCTION
sn s n
stage n
state return
(input) function
rn ( s n , d n )
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 6
ROAD TRIP EXAMPLE
A poor student is traveling from NY to LA
To minimize costs, the student plans to sleep at
friends’ houses each night in cities along the trip
Based on past experience he can reach
Columbus, Nashville or Louisville after 1 day
Kansas City, Omaha or Dallas after 2 days
San Antonio or Denver after 3 days
LA after 4 days
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 7
ROAD TRIP EXAMPLE
680 610
2 Columbus 5 K. City 8 Denver
580
550 540 1030
790
790
900
NY 1 3 Nashville 760 6 Omaha 10 LA
700 790
770
510 1050 940 1390
660
4 Louisville 7 Dallas 9 S. Antonio
830 270
⎧ ⎫
⎪ ⎪
f 3 (6) = min ⎨(540 + 1,030),(940 + 1,390)⎬ = 1,570
⎪⎩ 1,570 2,330 ⎪⎭
⎧ ⎫
⎪ ⎪
f 3 (7) = min ⎨(790 + 1,030) ,(270 + 1,390)⎬ = 1,660
⎪⎩ 1,820 1,660 ⎪⎭
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 10
ROAD TRIP EXAMPLE CALCULATIONS
day 2 :
⎧ ⎫
⎪ ⎪
f 2 (2) = min ⎨(680 + 1,640) , (790 + 1,570) , (1,050 + 1,660) ⎬ = 2, 320
⎪⎩ 2,320 2,360 2,710 ⎪⎭
⎧ ⎫
⎪ ⎪
f 2 (3) = min ⎨(580 + 1,640) , (760 + 1,570) , ( 660 + 1,660 ) ⎬ = 2, 220
⎪⎩ 2,220 2,330 2,320 ⎪⎭
⎧ ⎫
⎪ ⎪
f 2 (4) = min ⎨(510 + 1,640) , (700 + 1,570) , ( 830 + 1,660 ) ⎬ = 2,150
⎪⎩ 2,150 2,270 2,490 ⎪⎭
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 11
ROAD TRIP EXAMPLE
day 1 :
⎧ ⎫
⎪ ⎪
f 1 (1) = min ⎨ (1,550 + 2, 320) , (900 + 2, 220) , (770 + 2,150) ⎬ = 2, 870
⎪⎩ *2,870* 3,120 2,920 ⎪⎭
The shortest path is 2,870 miles and corresponds
to the trajectory { (1, 2) , ( 2, 5 ) , ( 5, 8 ) , ( 8, 10 ) } ,
i.e., from NY, the student reaches Columbus on
the first day, Kansas City on the second day,
Denver the third day and then LA
Every other trajectory to LA leads to higher costs
and so is, by definition, suboptimal
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 12
PICK UP MATCHES GAME
There are 30 matches on a table and 2 players
be the winner?
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 13
WORKING BACKWARDS: PICK UP
MATCHES GAME
We solve this problem by reasoning in a back-
possible situations:
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 14
WORKING BACKWARDS: PICK UP
MATCHES GAME
1 ⇒ 4 left P 1 removes 3
P 2’s move
2 ⇒ 3 left P 1 removes 2
is to pick
3 ⇒ 2 left P 1 removes 1
We can reason similarly for the cases of 9, 13, 17,
21, 25, and 29 matches
Therefore, P 1 wins if P 1 picks 30 – 29 = 1 match
in the first move
In this manner, we can assure a win for any
number of matches in the game
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 15
OIL TRANSPORT TECHNOLOGY
We consider the development of a transport
network from the north slope of Alaska to one of 6
possible shipping points in the U.S
The network must meet the problem feasibility
requirements
7 pumping stations from a north slope ground
storage plant to a shipping port
use of only those paths that are physically
and environmentally feasible
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 16
OIL TRANSPORT TECHNOLOGY
intermediate
region
oil substations
storage final
destinations
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 17
OIL TRANSPORT TECHNOLOGY
Objective: determine a feasible pumping
example,
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 19
OIL TRANSPORT TECHNOLOGY
0 3 11 15 19 25 29 31 36
oil I-E II-E III-D IV-E V-C VI-D VII-C B
storage
but such a path is not unique and cannot be
guaranteed to be optimal
serial dynamic programming (DP ) : we need to
construct the problem solution by defining the
stages, states and decisions
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 20
DP SOLUTION
We define a stage to represent each pumping
stage
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 21
DP SOLUTION
We define a state s k to denote a final destination, a
destination
B 6 3 F 3
C 7 5 6 L 5
D 6 5 3 F 3
E 7 8 5 F 5
F 4 2 6 L 2
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 24
DP SOLUTION:
STAGE 2 REGION VI TO STAGE 1
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 25
STAGE 2 CALCULATION
costs of proceeding from the
state s2 to a state s1 in stage 1
⎛ ⎞
f *2 ( s 2 ) = min⎜ r 2 ( s 2 , d 2 ) + f *1 ( s 1 ) ⎟
⎜
d2 ⎝
⎟
⎠
a function of only s1
⇓
for a given d 2 , the state s1 is set
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 26
DP SOLUTION:
STAGE 3 REGION V TO STAGE 2
{ }
d3
s3 d *3 f *3 ( s3 )
R L F
A 14 16 R 14
B 14 17 15 R 14
C 10 5 13 R 10
D 9 12 9 R, F 9
E 12 15 L 12
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 27
DP SOLUTION:
STAGE 4 REGION IV TO STAGE 3
{ }}
d4
s4 d 4* f *4 ( s 4 )
R L F
B 17 18 23 R 17
C 15 22 16 R 15
D 18 17 16 F 16
E 16 21 L 16
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 28
DP SOLUTION:
STAGE 5 REGION III TO STAGE 4
f f*5 (5*s(5s)5 )== mi { +
min r55 55, d 5 5) + f 4 4((ss4 )4 )
**
}}
d5
s5 d *5 f *5 ( s 5 )
R L F
A 19 R 19
B 18 18 R,F 18
C 24 23 17 F 17
D 20 19 25 L 19
E 21 17 F 17
F 20 L 20
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 29
DP SOLUTION:
STAGE 6 REGION II TO STAGE 6
f f*6 (6*s( 6s)6 )== mi n r ( s{ , d ) +
min r66 66, d 6 )6 + f 5 5( (ss5 )5 )
f**
}}
d7
s7 d *7 f 7* ( s 7 )
R L F
A 27 32 R 27
B 26 33 26 R,F 26
C 34 25 27 L 25
D 25 27 33 R 25
E 27 35 30 R 27
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 31
THE OPTIMAL TRAJECTORY
For the last stage corresponding the oil storage
d8 A B C D E d 8* f *8 ( s 8 )
s8
f 8 (s 8 ) 33 30 32 33 30 B,E 30
f 8* ( s 8 ) = min{27 + 6, 26 + 4, 25 + 7, 25 + 8, 27 + 3 }
= 30
To find the optimal trajectory, we retrace forwards
II - B III - C IV - C VI - E
I-B
II - C III - B IV - B V-D VI - D VII - D
I-E
II - F III - E IV - E V-C
shipping
oil
storage point D
final destinations
3 3
6 3
9 6
oil substations
storage
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 35
OIL TRANSPORT PROBLEM
SOLUTION
For example, we may calculate the least cost
different than D
is not undertaken
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 36
OIL TRANSPORT: SENSITIVITY CASE
Consider the case where we got to stage VI but
the branch VI – D to VII – D cannot be built due to
some environmental constraint
We determine, then, the least-cost path from VI –
D to find the final destination D whose value is 9
instead of 6
2 7 final
VI - D VII - C destination
D
and so the sub optimal cost solution costs are 33
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 37
FACILITIES SELECTION PROBLEM
and considers:
3 location alternatives
building type
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 38
FACILITIES SELECTION PROBLEM
building size
B1 B2 B3 B4 none
site
R1 C1 R2 C2 R3 C3 R4 C4 R0 C0
elements
stage ↔ site
{
amount of funds available
state ↔
for construction
{
impact of a decision on the
transition function ↔
availablity of resources
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 43
DP SOLUTION APPROACH
We use backwards DP to solve the problem and
start with site I ↔ stage 1 , a purely arbitrary
choice, where this stage 1 represents the last
decision in the 3 – stage sequence and so is made
after the decision for the other two sites have
been taken
The amount of funds available is unknown since
the decision at sites II and III are already made,
and so
0 ≤ s 1 ≤ 21
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 44
DP SOLUTION APPROACH
There are no additional decisions to be made in
stage 0 and we define
s0 = 0 and f 0* ( s 0 ) = 0
s n −1 = s n − c n costs of decision d n
f n* ( s n ) = max { f n(s n ,d n ) + f *
n−1 }
( s n − 1 ) , n = 1,2,3
dn
with
s n −1 = s n − c n
and
revenues for
f n ( s n , d n ) = rn ( s n , d n ) = R n
decision d n
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 46
DP SOLUTION: STAGE 1 SITE I
f (s1 ) =
*
max {r 1 ( s 1 , d 1 )}
1
0 ≤ d1 ≤ 4 R1
s1 d1 0 1 2 3 4 d *
f 1* ( s1 )
1
f (s 2 ) =
*
max { r2 ( s 2 , d 2 ) + f ( s 1 ) } *
2
1
0 ≤ d2 ≤ 4 R2
where
s1 = s2 − c2
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 48
DP SOLUTION: STAGE 2 SITE II
s2 d2 0 1 2 3 4 d *2 f *2 ( s 2 )
21 ≥ s ≥ 13
2 1.40 2.02 2.18 2.36 3.20 4 3.20
12 1.40 2.02 2.18 2.36 2.60 4 2.60
11 1.40 2.02 2.18 2.36 2.60 4 2.60
10 1.40 2.02 2.18 1.76 2.45 4 2.45
9 1.40 2.02 1.58 1.61 2.30 4 2.30
8 1.40 2.02 1.58 1.61 1.80 1 2.02
7 1.40 2.02 1.43 1.46 1 2.02
6 1.40 1.42 1.28 0.96 3 1.46
5 1.40 1.42 0.78 1 1.42
4 0.80 1.27 1 1.27
3 0.80 1.12 1 1.12
2 0.65 0.62 0 0.65
1 0.50 0 0.50
0 0.00 0 0.00
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 49
SAMPLE CALCULATIONS
f *3 ( s 3 ) = max { r 3 ( s 3 , d 3 ) + f *2 ( s 2 ) }
d 3
R3
where
s2 = s3 − C 3
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 52
OPTIMAL SOLUTION
d3
s3 d 3* f *3 ( s3 )
0 1 2 3 4
21 3.20 3.91 4.40 4.20 4.45 4 4.45
1:
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 53
OPTIMAL SOLUTION
s 2 = s 3 − C 3 = 21 − 11 = 10
d *2 = 4 ↔ construct B 4 at site II
s 1 = s 2 − C 2 = 10 − 8 = 2
d = 2 ↔ construct B 2 at site I
*
1
C 1 = 5 and C 1 + C 2 + C 3 = 21
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 54
SENSITIVITY CASE
d3
s3 d 3* f *3 ( s3 )
0 1 2 3 4
d *2 = 4 ↔ construct B 4 at site II
s 1 = s 2 − C 2 = 11 − 8 = 3
d 1* = 3 ↔ construct B 3 at site I
C 1 = 3 and C 1 + C 2 + C 3 = 15
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 56
OPTIMAL CUTTING STOCK PROBLEM
construct a 4 – stage DP
d4 d3 d2 d1
r4 r3 r2 r1
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 58
DP SOLUTION APPROACH
produce in stage n :
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 59
DP SOLUTION APPROACH
⎡ F0 ⎤ F0
dn = ⎢ ⎥ , the largest integer in
⎢⎣ L n ⎥⎦ Ln
where
L n = length of order n ( ft )
remaining at stage n
s n − 1 = s n − d n Ln n = 2,3,4
s 0 = s 1 − d 1 L1
and s0 should be as close as possible to 0
Clearly,
⎡ s1 ⎤
d1 = ⎢ ⎥
⎢⎣ L1 ⎥⎦
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 61
DP SOLUTION APPROACH
The recursion relation is
f *n ( s n ) = max { rn ( s n , d n ) + f *
n−1 (s n−1 ) }
⎡s ⎤
0 ≤ dn ≤ ⎢ n⎥
⎢ Ln ⎥
⎣ ⎦
where
s n −1 = s n − d n Ln
and
f *0 ( s 0 ) = 0
f n ( s n , d n ) = rnd n + f *
n −1 ( s n − d n L n ), n = 1,2,3,4
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 62
DP SOLUTION APPROACH
pick
stage n 1 2 3 4
length of
2.5 4 3 2
order ( ft )
⎡ 13 ⎤
d1 ≤ ⎢ ⎥ = 5
⎣ 2.5 ⎦
s1
d *
1
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 64
DP SOLUTION: STAGE 2
f *2 ( s 2 ) = max
0 ≤ d2 ≤ 3
{ 5.25 d 2 + f *1 ( s 2 − 4 d 2 ) }
⎡ 13 ⎤
d2 ≤ ⎢ ⎥ = 3
⎣4⎦
s2
f *2 ( s 2 )
d *2
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 65
DP SOLUTION: STAGE 3
f *3 ( s 3 ) = max
0 ≤ d3 ≤ 4
{ 4.40 d 3 + f *2 ( s 3 − 3 d 3 ) }
⎡ 13 ⎤
d3 ≤ ⎢ ⎥ = 4
⎣3⎦
s2
f *3 ( s 3 )
d *3
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 66
DP SOLUTION: STAGE 4
f *4 ( s 4 ) = max
0 ≤ d4 ≤ 6
{ 2.5 d 4 + f *3 ( s 4 − 2 d 4 ) }
⎡ 13 ⎤
d4 ≤ ⎢ ⎥ = 6
⎣2⎦
d4 0 1 2 3 4 5 6 d *4 f *4 ( s 4 )
⎡ 11 ⎤
d 4′ ≤ ⎢ ⎥ = 5
⎣2⎦
d 4′ 0 1 2 3 4 5 d *
4′
f 4*′ ( s4 )
d 4*′ = 1 ↔ 1 roll of 2 ft
d 3*′ = 3 ↔ 3 rolls of 3 ft
d 2*′ = 0 ↔ no rolls of 4 ft
demand 40 20 30 40 30 20
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 74
INVENTORY CONTROL PROBLEM
lot size 10 20 30 40 50
discount
4 5 10 20 25
%
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 75
INVENTORY CONTROL PROBLEM
There are additional ordering costs: each order
incurs fixed costs of $ 2 and $ 8 for shipping,
handling and insurance
The storage limitations of the retailer require that
no more than 40 units be in inventory at the end of
the month and the storage charges are 0.2 $/unit;
there is 0 inventory at the beginning and at the
end of the period under consideration
Underlying assumption: demand occurs at a
constant rate throughout each month
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 76
DP SOLUTION APPROACH
stage
6 5 4 3 2 1
n
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 77
DP SOLUTION APPROACH
d6 d5 d4 d3 d2 d1
r6 r5 r4 r3 r2 r1
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 78
DP SOLUTION APPROACH
The state variable in stage n is defined as the
amount of entering inventory given that there
are n additional months remaining – the present
month n plus the months n – 1 , n – 2 , ... , 1
The decision variable d n in stage n is the amount
of units ordered to satisfy the demands D i in the n
remaining months, i = 1, 2, ... , n
The transition function is defined by
s n -1 = s n + d n − D n n = 1, 2, ... , 6
s0 = 0 s6 = 0 demand in month n
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 79
DP SOLUTION APPROACH
The return function in the stage n is given by
r 1 ( s 1 , d 1 ) = φ ( d n ) + hn ( s n + d n − D n )
ordering 0.2( sn + dn − Dn )
costs storage costs
with
dn = 10, 20, 30, 40 or 50
φ ( dn ) = 10 + 4[1 − ρ ( d n ) ] d n
fixed discount
costs factor
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 80
DP SOLUTION APPROACH
dn 0 10 20 30 40 50
d
n
{
f *n ( s n ) = min φ (d n ) + h n ⎡⎣ s n + d n − D n ⎤⎦ + f *
n−1 ( s n −1 ) }
n = 1, ... ,6
s 0 = 0 and so f *0 ( s 0 ) = 0
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 81
DP SOLUTION: STAGE 1
s0 = 0 ⎫⎪
⎬ ⇒ s 1 = 20 , 10 or 0 ⇒ d 1 = 0 , 10 or 20
*
D 1 = 20 ⎪⎭
f ( s 1 ) = m in φ (d 1 ) + 0
*
1 { } = φ (d *
1 )
d1
s1 20 10 0
*
d 1
0 10 20
f *1 ( s 1 ) 0 48 86
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 82
DP SOLUTION: STAGE 2
s 1 = s 2 + d 2 − 30 since D 2 = 30
f *2 ( s 2 ) = min { φ (d 2 ) + 0.2 ⎡⎣ s 2 + d 2 − 30 ⎤⎦ + f *1 ( s 1 ) }
d2
d2
d *2 f *2 ( s2 )
s2 0 10 20 30 40 50
0 204 188 164 50 164
10 172 168 142 40 142
20 134 136 122 122 30 122
30 86 98 90 0 86
40 50 52 0 50
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 83
DP SOLUTION: STAGE 3
s 2 = s 3 + d 3 − 40 since D 3 = 40
{
f *3 ( s 3 ) = min φ (d 3 ) + 0.2 ⎡⎣ s 3 + d 3 − 40 ⎤⎦ + f *2 ( s 2 )
d 3
}
d3
s3 d *3 f *3 ( s 3 )
0 10 20 30 40 50
0 302 304 40 302
10 282 282 286 30, 40 282
20 250 262 264 252 20 250
30 212 230 244 230 218 10 218
40 164 192 212 210 196 0 164
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 84
DP SOLUTION: STAGE 4
s 3 = s 4 + d 4 − 30 since D 4 = 30
*
4
d 4
{ ⎡ ⎤
f ( s 4 ) = min φ (d 4 ) + 0.2 ⎣ s 4 + d 4 − 30 ⎦ + f 3 ( s 3 )
*
}
d4
s4 d *4 f *4 ( s 4 )
0 10 20 30 40 50
0 420 422 414 50 414
10 388 402 392 384 50 384
20 350 370 372 362 332 50 332
30 302 332 340 342 210 0 302
40 284 302 310 290 0 284
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 85
DP SOLUTION: STAGE 5
s 4 = s 5 + d 5 − 20 since D 5 = 20
{
f *5 ( s 5 ) = min φ (d 5 ) + 0.2 ⎡⎣ s 5 + d 5 − 20 ⎤⎦ + f *5 ( s 5 )
d 5
}
d5
d 5* f *5 ( s5 )
s5 0 10 20 30 40 50
0 500 504 474 468 50 468
10 462 472 454 446 452 40 446
20 414 434 422 426 430 0 414
30 386 384 394 410 10 384
40 336 356 378 0 336
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 86
DP SOLUTION: STAGE 6
D 6 = 40 and s 6 = 0
s 5 = s 6 + d 6 − 40 = d 6 − 40
*
6
d 6
{ ⎡ ⎤
f ( s 6 ) = m in φ (d 6 ) + 0.2 ⎣ s 6 + d 6 − 40 ⎦ + f 5 ( s 5 )
*
}
d6 0 10 20 30 40 50 d *
6
f 6* ( s6 )
d *6 = 40 ⇒ d *5 = 50 ⇒ d *4 = 0 ⇒ d *3 = 40 ⇒ d *2 = 50 ⇒ d *1 = 0
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 87
OPTIMAL SOLUTION
d *6 = 40 which implies to s 5 = 0 and costs 606
d 1* = 0 with costs 0
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 88
OPTIMAL SOLUTION
d = 40
*
6 d = 50
*
5
d =0
*
4 d 3* = 40 d 2* = 50 d 1* = 0
optimal trajectory is
s0 = 0 s 1 = 20 s2 = 0 s3 = 0 s 4 = 30 s5 = 0
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 94
DP SOLUTION APPROACH
We use backwards DP to solve the problem
r5 r4 r3 r2 r1
d5 d4 d3 d2 d1
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 95
DP SOLUTION METHOD
For stage n , the state s n is the amount of capital
s1
d1
where
r 1 = (1 + I A ) d 1 + (1 + I B ) ( s 1 − d 1 ) + i 1 Ad 1 + i 1 B( s 1 − d 1 )
( )
= I A + i 1 A − I B − i 1 B d 1 + (1 + I B + i 1 B ) s 1
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 99
DP SOLUTION: STAGE 1
r 1 = earnings in stage 1 (returns realized at
the end of 5 years)
⎧⎪ d 1 ( I A + i 1 A − I B − i 1 B ) + ⎫⎪
f 1 ( s 1 ) = max { r 1 } = max ⎨
*
⎬
d1 d1 ⎪ ⎩ s 1 (1 + I B + i 1 B ) ⎭⎪
= max
d1
{d 1 ( − 0.005) + s 1 (1.07) } maximum
optimal return in
decision d * = 0 with f 1* ( s 1 ) = 1.07 s 1 stage 1
1
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 100
DP SOLUTION: STAGE 2
r 2 = returns realized at the end of 5 years due to
= d 2 (1 + I A )2 + ( s 2 − d 2 )(1 + I B )2
⎡ 2 2
⎤
= d 2 ⎣ (1 + I A ) − (1 + I B ) ⎦ + s 2 (1 + I B ) 2
s 1 = s 2 i 1 B + d 2 ( i 1 A − i 1 B ) + 1,000
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 101
DP SOLUTION: STAGE 2
We select d 2* to maximize
f 2* ( s 2 ) = max
d2
{ r 2 + f *1 ( s 1 ) }
= max
d2
{ d 2 (1.042 − 1.032 ) + s 2 (1.03)2 + f *1 ( s 1 ) }
⎧ d 2 ( .0207) + 1.0609 s 2 + ⎫
= max ⎨ ⎬
0 ≤ d 2 ≤ s2 ⎩1.07[ .04 s 2 + d 2 ( − .015) + 1,000]⎭
= m ax
d2
{d 2 (.0046) + 1.1037 s 2 + 1070 }
d = s2
*
2 with f ( s 2 ) = 1.108 s 2 + 1070
*
2
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 102
DP SOLUTION: STAGE 3
the decision d 3
= d 3 (1 + I A )3 + ( s 3 − d 3 )(1 + I B )3
= d 3 ⎡⎣(1 + I A )3 − (1 + I B )3 ⎤⎦ + s 3 (1 + I B )3
s 2 = s 3 i 3 B + d 3 ( i 3 A − i 3 B ) + 1,000
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 103
DP SOLUTION: STAGE 3
We select d 3* to maximize
f *3 ( s 3 ) = max
d3
{ r 3 + f *2 ( s 2 ) }
⎧ d 3 (1.043 − 1.033 ) + s 3 (1.03)3 + ⎫
= max ⎨ ⎬
d3 ⎩1.108 s 2 + 1,070 ⎭
= max
0 ≤ d 3 ≤ s3
{ 2,178 + 1.1481s 3 + .0018d 3 }
d 3* = s 3 with f 3* ( s 3 ) = 1.15 s 3 + 2,178
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 104
DP SOLUTION: STAGE 4
= d 4 (1 + I A )4 + ( s 4 − d 4 )(1 + I B )4
= d 4 ⎡⎣(1 + I A )4 − (1 + I B )4 ⎤⎦ + s 4 (1 + I B )4
s 3 = s 4 i 4 B + d 4 ( i 4 A − i 4 B ) + 1,000
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 105
DP SOLUTION: STAGE 4
We select d 4* to maximize
f *4 ( s 4 ) = max
d4
{ r4 + f *3 ( s 3 ) }
= max
d4
{ d 4 (1.044 − 1.034 ) + s 4 (1.03)4 + 1.15 s 3 + 2,178 }
= max
0 ≤ d4 ≤s
{ 3328 + 1.1772 s 4 + .0156d 4 }
4
= d 5 (1 + I A )5 + ( s 5 − d 5 )(1 + I B )5
s 4 = s 5 i 5 B + d 5 ( i 5 A − i 5 B ) + 1,000
= 10,000 i 5 B + d 5 ( i 5 A − i 5 B ) + 1,000
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 107
DP SOLUTION: STAGE 5
We select d *5 to maximize
⎧ ⎫
⎪ ⎪
f 5 ( s 5 ) = max ⎨10,000(1.03) + d 5 (1.04 − 1.03 ) + f 4 ( s 4 ) ⎬
* 5 5 5 *
0 ≤ d 5 ≤ s 4 ⎪
⎪
⎩ 11,593 0.0574 ⎭
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 108
DP SOLUTION: STAGE 5
⎧ (.0574 − 0.048) ⎫
= m ax ⎨16,830 + d 5 ⎬
0 ≤ d 5 ≤ s5 ⎩ 0.097 ⎭
= 16,830 + 0.097(10,000)
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 109
OPTIMAL SOLUTION
optimal return at end of 5 years is 16,927 using the
following strategy
beginning investment in
of year fund A fund B
1 10,000 0
2 STD returns + 1,000 0
3 STD returns + 1,000 0
4 STD returns + 1,000 0
5 0 STD returns + 1,000
© 2006 – 2009 George Gross, University of Illinois at Urbana-Champaign, All Rights Reserved. 110