Forward Backward Recursion
Forward Backward Recursion
Although the forward procedure appears more logical DP literature invariably uses backward
recursion. The reason for this preference is that, in general, backward recursion may be more
efficient computationally.
Question 1: Use dynamic programming to find the maximum value of the product
y 1 , y 2 , y 3 ,… … y a, when y 1 + y 2 + y 1+ … …+ y n=Q
Solution:
This is the optimal sub-division problem in which the given quantity Q is to be divided into n
parts in such a way that their product is maximized. The problem can be written as
Maximize ∏sjel yl
Subject to ∑iE=1 y i=Q
y i ≥0 , i=1 , 2 ,3 , … … … , n .
f i ( xi ) ¿ max { y j }
y 2=x i
f i ( x i ) ¿ max { y 1 ⋅f i−1 ( x i− y i ) }
∥i xi
¿ ¿
f 1 ( x 1 )=x 1
for i=2
f 2 ( x 2 )= max { y 2 ⋅ f 1 ( x 2− y 2) }
min cic 2
1
y 2 (−1)+ ( x 2− y 2 )=0
x2
⇒ y 2=
2
∴ f 2 ( x 2 )=
x2
2
x 2−
x2
2 ( )
2
x2
¿
4
( )
2
x2
¿
2
As x 2= y 1 + y 2
y 1=x 2− y 2
x2 x2
y 1=x 2− =
2 2
x
Or y 1= y 2= 2
2
For i=3
f 3 ( x 3 )= max { y 3 f 2 ( x 3− y 3 ) }
← ∈ LB L 4
{ }
2
( x3 − y 3 )
¿ max y 3 ,
an 4
x22
[ since f 2 ( x 2 )= ]
2
¿
2
Differentiating y 3 ( x 5− y 5 ) with respect to y 3 and equating to zero, we get
( x 5− y 3 ) (−2 y 3 + x 3− y 3 )=0
x1
∴ Either y 3=x 3 or, y 1=
3
x3
∴ Solution y 3= satisfies the sufficiency condition for a maximum.
2
( )
2
x3
x 3−
( )
3 3
x1 3 x3 x3
∴ f 3 ( x 3 )= = =
3 4 27 3
x 1= y 1 + y 2 + y 3
x
¿ y1 + y2 + 1
3
2 x1
∴ y 1+ y 2 =
3
As
x1
Further as y 1= y 2 , we have y 1= y 2= y 3= .
3
Similarly, it can be derived that for i=4
x4
y 1= y 2= y 1= y 4=
4
( )
4
x4
And f 4 ( y 4 ) =
4
xe
y 1= y 2= y 3 =… … …= y v =
n
( )
n
xn
And f n ( y n) =
n
But x a= y 1 + y 2 + y 3 +… …+ y s=Q
( )
n
Q Q
∴ f w (Q)= and y 1= y 2= y 1=¿ .= y n= .
n n
∂ f 2 ( x2)
=x 2−2u 2=0
∂ u2
x2
or u2= .
2
( )
2
x2 x2 x2
∴ f 2 ( x 2 )= x− = .
2 2 2 4
Now
{ } { }
2
x22 ( x 3−u3 )
f 3 ( x 3 ) =max u 3− =max u3
4 4
[
∂ ( u3 x 3+u 3−2 u3 x 3 )
]
2 3 2
=0
∂ u1 4
or x 25 +3 u23−4 u3 x 5=0
or x 23−3 u3 x3 +3 u23 −n3 x3 =0
or x 3 ( x 1−3 u3 ) −u3 ( x 3−3 u3 )=0
or ( x 1−u1 ) ( x 3−3 u3 ) =0.
∴ Either u3=x 5 mhich is trivial since, x 5=u1 +u2 +u3 ;
x 10
or u3= 3 = −∵ : x 3=x 1 +α 2+ α 4=10 ∣
3 3
10 20 x
∴ x 2=10− = ,|x x2= x3 −x1|and u2= 2 = 10
3 3 2 3
10
Hence w 1= [ ∵ u1 m x 2−a2 mu 1 ]
3
10
∴ u1=u2 =u1=
3
1,000
The maximum product u1 ⋅u2 ⋅u 3= .
27
x 3= y 1+ y 2+ y 3 ,
x 2=x 3− y 3= y 1+ y 2 ,
x 1=x 2− y 2= y 1 .
f 5 ( x 1 )=max { y 21 +f 2 ( x 2 ) }
h
f 2 ( x 2 )=max { y 22 + f 1 ( x 1 ) } and
n
f 1 ( x1 ) =max { y 1 }= y 1
2 2
2
Since x 1=x 2− y 2 and f 1 ( x 1 )= y1
∴ f 2 ( x 2 )=max { y 22 + ( x 2− y 2 )2 } .
x2
2 y 2 +2 ( x 2− y 2 ) (−1)=0
x2
⇒ y 2= .
2
( )( )
2 2 2
x2 x2 x2
∴ f 2 ( x 2 )= + x 2− =
2 2 2
Now f 5 ( x 5 ) =max y { y 3 + f 2 ( x 2 ) }
2
1
2
x2
Since x 2=x 5− y 3 and f 2 ( x 2 )=
2
{ }
2
2 ( x 1− y 3 )
∴ f 3 ( x 1 )=max y + 3
n 2
{ }
2
(x −y )
Differentiating y + 1 3 w.r. t. y 3 and equating to zero, we get,
2
5
2
x3
y3 ¿
3
( )
2
x3
x 3−
( )
2 2
x3 3 x3
∴ f 3( x1) ¿ + =
3 2 3
Since x 3= y 1 + y 2 + y 3 ≥ 15
for maximization of f 3 ( x 3 ) , y 1+ y 2+ y 3=15
∴ f 5 ( x 1 )=¿ ¿
x3
and y 5= =5
3
x 2 x 3− y 3 15−5
y 2= = = =5
2 2 2
y1 =x2 − y 2=10−5=5
Question 4: solve the following Linear programming problem by the dynamic programming
technique:
Maximize Z=8 y 1+ 7 y 2
Subject to 2 y 1+ y 2 ≤ 8
5 y 1 +2 y 2 ≤ 15
and y 1 , y 2 ≥ 0
Solution:
There are two variables, and bence it is a two stage problem Since there are two resources, the
state of the system is described by two variables.
Let the state at stage j be ( B1 , , B 2 ) and the objective fumction is f 1 ( B1 , , B2 j ).
Starting with stage 2 , i.e. j=2
max
f 2 ( B12 , B22 )=0 ≤ y 2 ≤ B 12 [ C 2 y 2 ]
0 ≤ y 2 ≤ B22
max
¿ 0≤ y 2 ≤ B12 [ 7 y 2 ]
0 ≤ y 2 ≤ B21
¿
[ (
∴ f 1 ( 8 ,15)= max 8 y 1+7 min 8−2 y 1 ,
0 ≤ y 1 ≤3
15−5 y 1
2 )]
15−5 y 1
Minimum of ( 8−2 y 1 ) and for 0 ≤ y 1 ≤ 3 is obtained for y 1=3
2
15−5 y 1
When 8−2 y1 =2 and =0
2
¿
∴ y 1=3
¿
f 1 (8 , 15)=[8 ×3+7 × 0]=24
(
y ¿2=min B12 ,
B32
2 )
[ B 21−5 y 1
¿ min B11 −2 y 1 ,
2 ]
¿ min 8−6 , [
15−15
2
=0 ]
Hence the optimal solution is y 1=3 , y 2=0 and Z max =24 .