04 - Dynamic Programming
04 - Dynamic Programming
Dynamic Programming
Learning Objectives
When you complete this chapter you should be able to
understand:
• Understand the concept of dynamic programming
• Know characteristics of dynamic programming
• Know applications of dynamic programming
2
Dynamic programming – The concept
• Complex problems are sometimes solved quickly if approached in a
sequential manner.
– Decisions made in a stage will affect the decisions at the subsequent stages
but are independent to each other.
• For the tth stage the stage transformation and the benefit functions are
– St+1 = g(Xt, St)
– NBt = h(Xt, St)
• Objective of this multistage problem is to find the optimum values of all
decision variables X1, X2,…, XT such that the individual net benefits of each
stage that is expressed by some objective function, f(NBt) and the total net
benefit which is expressed by f(NB1, NB2,…, NBT) should be maximized.
Dynamic programming – The concept
• Therefore, dynamic programming can be applied to this multistage
problem if the objective function is separable and monotonic.
“An optimal policy (or a set of decisions) has the property that
whatever the initial state and initial decision are, the remaining
decisions must constitute an optimal policy with regard to the
state resulting from the first decision.”
How to solve a DPP?
• Recursive equations are used to solve a DPP in sequence.
– Recursive equations are used to structure a multistage decision
problem as a sequential process.
– Each recursive equation represents a stage at which a decision is
required.
– A series of equations are successively solved, each equation
depending on the output values of the previous equations.
• Recursive equations for a multistage decision process can be formulated in
• a backward manner, and
• a forward manner
• Backward recursion - A problem is solved by writing equation first for the
final stage and then proceeding backwards to the first stage.
• Forward recursion - The problem is solved by starting from stage 1 and
proceeding towards the last stage.
How to solve a DPP? – Backward Recursion
S3 = S2-X2
S2 = S1-X1
How to solve a DPP? – Forward Recursion
S1 = S2-X2
S2 = S3-X3
How to solve a DPP?
To explain the concept of backward and forward recursion
approach, take the following Water Allocation Problem
• Consider a canal supplying water for three different Fields
for crop production.
• Maximum capacity of the canal is Q units of water
• Amount of water allocated to each field as Xi
How to solve a DPP?
x1 x2 x3 Q
0 xi Q for i 1, 2, 3
x1 x2 x3 Q
i 1
x , x , x 0
1 2 3
How to solve a DPP?
A. Backward Recursion:
How to solve a DPP?
A. Backward Recursion:
f1 (Q) Max NB1 x1
0 x1 Q S1
Max NB2 x2 Max NB3 x3
S1 Q
0 x2 Q x1 S 2
0 S 2 Q 0 x3 S 2 x2 S3
0 S 3 Q
• Thus,
f 2* ( S 2 ) Max NB x f
0 x2 S 2
2 2
*
3
( S 2 x2 )
0 S 2 Q
How to solve a DPP?
f 1* ( S1 ) f 1* (Q) Max NB1 x1 f 2* ( S1 x1 )
0 x1 Q
S1 Q
Note:
Once the value of f3(S3) is calculated the value of f2(S2) can be
determined from which f1(Q) can be determined.
How to solve a DPP?
A. Forward Recursion:
How to solve a DPP?
A. Forward Recursion:
• Let the function fi(Si)be the total benefit from crops 1 to i
for a given input of Si which is allocated to those crops.
• Considering the first stage,
f 1* ( S1 ) Max NB1 x1
0 x1 S1
0 S1 Q
• But S1=S2-x2
• Considering the first two crops, for an available quantity of
S2 , f2(S2) can be written as:
f 2* ( S 2 ) Max
0 x2 S 2
NB x f
2 2 1
*
( S 2 x2 )
0 S 2 Q
How to solve a DPP?
• But S2=S3-x3
• Considering the whole system, f3(S3) can be expressed as:
f 3* ( S3 ) Max NB3 x3 f 2* ( S3 x3 )
0 x3 S3
S 3 Q
Numerical Example 1 . Resource Allocation Problem
Numerical Example 1 . Resource Allocation Problem
f 2* ( S 2 ) Max NB x f
0 x2 S 2
2 2
*
3
( S 2 x2 )
0 S 2 Q
Numerical Example 1 . Resource Allocation Problem
Numerical Example 1 . Resource Allocation Problem
f 1* (Q) Max NB1 x1 f 2* ( S1 x1 )
0 x1 Q
S1 Q
Numerical Example 1 . Resource Allocation Problem
Check :
NB1 ( x1 ) 5 x1 0.5 x12 5 1 0.5 12 4.5
NB2 ( x2 ) 8 x2 1.5 x22 8 1 1.5 12 6.5
NB3 ( x3 ) 7 x3 x32 7 2 2 2 10
3
Max NBi 4.5 6.5 10 21
i 1
Numerical Example 1 . Resource Allocation Problem
NB2 x2
f ( S 2 ) Max *
*
0 x2 S 2 f ( S x )
2
0 S 2 Q 1 2 2
Numerical Example 1 . Resource Allocation Problem
f 3* ( S3 ) Max NB3 x3 f 2* ( S3 x3 )
0 x3 S3
with S3 4
S 3 Q
Numerical Example 1 . Resource Allocation Problem
Example 2. Short Route Problem
Consider A traveler wishes to minimize the length of a journey
from town A to J.
E B 7 2 9
C 3 4 7 7 C, D
D 4 3 7
F B 4 2 6
C 2 4 6 4 D
D 1 3 4
G B 6 2 8
C 4 4 8 8 B,C,D
D 5 3 8
Example 2. Short Route Problem
Stage 3:
S3 : Node in stage 3
x3 : node from which S3 is reached
d(x3,S3) : distance between nodes x3 and S3
f3(S3) : Minimum distance from source node A to node S3
: min[d(x3,S3)+ f *2(x3)]
Example 2. Short Route Problem
H E 1 7 8
F 6 4 10 8 E
G 3 8 11
I E 4 7 11
F 3 4 7 7 F
G 3 8 11
Example 2. Short Route Problem
Stage 4:
S4 : Node in stage 4
x4 : node from which S4 is reached
d(x4,S4) : distance between nodes x4 and S4
f4(S4) : Minimum distance from source node A to node S4
: min[d(x4,S4)+ f *3(x4)]
J H 3 8 11
I 4 7 11 11 H,I
Example 2. Short Route Problem
The optimal route is traced back:
B E
A C F J
D G
45
Home Take Assignment 6
1. A total of 6units of water is to be allocated optimally to three users. The
allocation is made in discrete steps of one unit ranging from 0 to 6. With the
three users denoted as user 1, user 2 and user 3 respectively. The returns
obtained from the users for a given allocation are given in the following table.
Find allocations to the three users so that the total return is maximized.
Amount of water allocated Return from