Professional Documents
Culture Documents
1-WK 07 - Lect 19 - 20 - UC-II
1-WK 07 - Lect 19 - 20 - UC-II
1-WK 07 - Lect 19 - 20 - UC-II
Unit commitment - II
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 2
Dynamic Programming
Dynamic Programming is mainly an optimization over plain recursion.
Wherever we see a recursive solution that has repeated calls for same inputs,
we can optimize it using Dynamic Programming.
The idea is to simply store the results of sub-problems, so that we do not have
to re-compute them when needed later.
This simple optimization reduces time complexities from exponential to
polynomial.
if we write simple recursive solution for Fibonacci Numbers, we get exponential
time complexity
if we optimize it by storing solutions of subproblems, time complexity reduces
to linear.
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 3
Fibonacci Numbers
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 4
Fibonacci Numbers
Fibonacci Tree
fib(5)
/ \
fib(4) fib(3)
/ \ / \
fib(3) fib(2) fib(2) fib(1)
/ \ / \ / \
fib(2) fib(1) fib(1) fib(0) fib(1) fib(0)
/ \
fib(1) fib(0)
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 5
Recursion
Recursion: the process which comes into existence when a function calls a
copy of itself to work on a smaller problem.
Any function which calls itself is called recursive function, and such
function calls are called recursive calls.
Example: recursion may be applied to sorting, searching, and traversal
problems.
Why do we need recursion?
Recursion can solve all those problems which can be solved by for loop. But
it is difficult or quite impossible to solve some problems by for loop. Some
dynamic problems can be solved easily by recursion instead of for loop. For
a hard problem you do not have to think much solving by recursion instead
of for loop.
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 6
Recursion
Difference Between Recursion and Iteration.
Recursion and iteration both repeatedly executes the set of instructions.
Recursion is when a statement in a function calls itself repeatedly.
The iteration is when a loop repeatedly executes until the controlling condition becomes
false.
What is recursion vs do while?
The concept of Recursion and Iteration is to execute a set of instructions
repeatedly.
The difference between them is that
recursion is simply a method call in which the method being called is the same as the one
making the call
while iteration is when a loop is repeatedly executed until a certain condition is met.
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 7
Properties of Dynamic Programming (DP) Problem
Dynamic Programming (DP):
Algorithmic paradigm
solves complex problem by breaking it into sub-problems
stores the results of sub-problems to avoid computing the same results again.
Two main properties of Dynamic Programming Problem
Overlapping Sub-problems
Optimal Substructure
Overlapping Sub-problems
DP combines solutions to sub-problems.
solutions of same sub-problems are needed again and again.
computed solutions to sub-problems are stored so that these don’t have to be
recomputed.
Binary Search doesn’t have common sub-problems.
Fibonacci Numbers, there are many sub-problems which are solved again and again.
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 8
Properties of DP Problem
Optical Substructure
A given problem has Optimal Substructure Property if optimal solution of the given
problem can be obtained by using optimal solutions of its sub-problems.
If a node x lies in the shortest path from a source node u to destination node v then the
shortest path from u to v is combination of shortest path from u to x and shortest path from
x to v.
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 9
Tabulation vs Memorization
There are following two different ways to store the values so that the values
of a sub-problem can be reused
Tabulation: Bottom Up
I will study the theory of Dynamic Programming from optimization books, then I will
practice some problems on classic DP and hence I will master Dynamic
Example:
Let a state for our DP problem be dp[x] with dp[0] as base state and dp[n] as our
destination state.
So, we need to find the value of destination state i.e dp[n]. If we start our transition from
our base state i.e dp[0] and follow our state transition relation to reach our destination state
dp[n], we call it Bottom Up approach as it is quite clear that we started our transition from
the bottom base state and reached the top most desired state.
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 10
Tabulation vs Memorization
Memorization: Top Down
To Master Dynamic Programming, I would have to practice Dynamic problems and to
practice problems – Firstly, I would have to study some theory of Dynamic Programming
from books of optimization.
Example
instead of starting from the base state that i.e, dp[0] we ask our answer from the states that can
reach the destination state dp[n] following the state transition relation, then it is the top-down
fashion of DP.
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 11
Tabulation vs Memorization
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 12
Recursion
Why recursion is used in C?
Recursion in C Programming.
The process of calling a function by itself is called recursion and the function which calls
itself is called recursive function.
Recursion is used to solve various mathematical problems by dividing it into smaller
problems. This method of solving a problem is called Divide and Conquer.
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 13
Dynamic Programming --- Application
Dynamic programming (DP)
problem is divided into stages.
Each stage has a number of states associated with it. Number of states may be either
finite or infinite.
problem is solved stage-by-stage using a recursive relationship.
Let
N = number of stages
n = label for current stage, (n = 1, 2, …., N)
sn = current state of stage n.
xn = decision variable at stage n
xn* = optimal value of xn for given sn
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 14
Dynamic Programming --- Application
fn(sn,xn) = contribution of stages n, n+1, ……, N to the objective function,
if system starts in state sn, and, immediate decision variable is xn
fn*(sn) = optimal value of fn (sn , xn)
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 15
Dynamic Programming --- Application
Where cn(xn) = contribution of xn to objective function at stage n.
fn+1*(xn) = optimal value of objective function at next stage n+1, if decision
variable is xn at current stage n.
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 16
Dynamic Programming --- Application
Objective function, stages and states for every problem in DP methodology
is problem specific.
The formulation of DP problems requires
careful review of the data to decide about stages ,
consequent states in the data
Formulation of relation among states
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 17
DP- Problem – 1: 10 - City Problem
Consider a 10-city problem with city 1 as starting city, and, city 10 as terminal
city.
Find shortest path between starting and terminal cities along with the shortest
route information. Travel times are provided over arcs in Figure 1.
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 18
DP- Problem – 1: 10 - City Problem
The network diagram in Figure shows that a traveler starting his journey
from city 1 will have to make decision about his next move prior to start his
journey, since he has three alternate routes to follow.
Either he will go to city 2 or city 3 or city 4. Suppose he decides to go to city
3.
At city 3, he will have three choice; i.e., either go to city 5 or go to city 6 or
go to city 7. Suppose he decides to go to city 6.
Once he is in city 6, he will have again two choices; either go to city 8 or go
to city 9.
Dynamic programming technique requires that we should divide our route
decision into four stages as shown below in Figure 2.
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 19
DP- Problem – 1: 10 - City Problem
Figure 2
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 20
DP- Problem – 1: 10 - City Problem
Since dynamic programming (DP) methodology uses recursive relationship to
find an optimal solution to given problem, we will start from stage 4.
At stage 4, what are possible ways to reach our destination (city 10)?
As we can see, city 10 can be reached either from city 8 or from city 9; hence,
there are two possible alternatives to begin our journey at stage 4. These are city
8 or city 10. Mathematically, we can express it as follows;
s4 = 8 , 9.
The above expression implies that variable state at stage 4 (s4) will contain
information about cities from where traveler may start his journey, and, these
values are city 8 and city 9 at this stage.
Let, tsn,xn = travel time at stage n for state sn if decision variable is xn. Then,
recursive equation for last stage (n = 4) will be;
fn(sn , xn) = t sn , xn
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 21
DP- Problem – 1: 10 - City Problem
The objective function values and corresponding decision variables for stage 4
are presented in Table 1 below.
x4
s f 4 * ( s) x 4*
10
8 7 7 10
10
9 6 6
Table 1
The entries in the Table 1 are straight forward. From city 8 to city 10, travel time
is 10, and destination city is 10. The same interpretations are valid for s=9. Let’s
go one stage backward to stage 3.
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 22
DP- Problem – 1: 10 - City Problem
At stage 3, recursive relationship will be;
f3(s3 , x3) = t s , x3 + f4*(x3)
What will be the values of state at stage 3?
From travel network diagram (Figure 1); cities 5, 6 and 7 constitute stage 3. Hence
s3 = 5, 6, 7.
What are destination cities from the cities of stage 3?
Again from travel network diagram (Figure 2), city 8 and city 9 are two
destination cities from stage 3 cities. Decisions are to be made about best travel
plan at stage 3.
Table 2 contains the details of best travel plan using recursive relationship.
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 23
DP- Problem – 1: 10 - City Problem
Table 2
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 24
DP- Problem – 1: 10 - City Problem
Stage 2 ( n = 2). At stage 2, recursive relationship will be
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 25
DP- Problem – 1: 10 - City Problem
Table 3
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 26
DP- Problem – 1: 10 - City Problem
Stage 1 ( n=1). At stage 1, recursive relationship will be;
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 27
DP- Problem – 1: 10 - City Problem
Optimal path from city 1 to city 10:
Going from stage 1 to stage 4 in forward direction reveals the following optimal solution.
Cities : 1 – 3 – 5 -- 8 – 10
Table 2
Table 1
Table 3
Table 4
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 28
DP- Problem – 2: Production Planning
A manufacturing organization is deciding a production plan for a particular item. The item can
be produced with following cost schedule
A total of six units of the item must be produced at the end of March.
Using Dynamic Programming technique,
make a production plan.
Solution
Let
• x1, x2 and x3 be number of units to be produced in the
months of January, February and March, respectively
• c1(x1), c2(x2) and c3(x3) be the corresponding costs of
production during months of January, February and
March for producing x1, x2 and x3 units of the item.
• n1, n2 and n3 be the stages corresponding to months of
January, February and March, respectively.
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 29
DP- Problem – 2: Production Planning
Let s1, s2 and s3 denote the variable state corresponding to the months of
January, February and March, respectively.
How to interpret state in this problem?
Beginning from stage 3
what will be the value of state variable s3?
How many alternatives to produce are there in the
month of March?
Since, there are five alternatives in March regarding
quantity to be produced; s3 = 0, 1, 2, 3, 4.
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 30
DP- Problem – 2: Production Planning
At stage 3, the only factor affecting objective function is the cost of producing s3
units.
Hence, objective function will be f3(s3,x3)= c3(x3) at stage 3.
Table 1 contains value of the objective function for all values of s3, and,
corresponding value of decision variable x3.
Table 1
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 31
DP- Problem – 2: Production Planning
Stage 2 (n=2):
Remember, a total of six units are to be delivered at the end of March (n=3).
At every stage, we can produce a maximum of four units of the item.
At stage 3, we had five alternatives and five values of x3 ( x3 = 0, 1, 2, 3, 4).
Going back from March (stage 3) to February (stage 2), how many possibilities exist at
stage 2 for variable s2?
Since 6 units of the item must be delivered at the end of stage 3 (month of March), the
number of units produced either in February and March should not exceed 6. This
condition is best illustrated by the following constraint; x2 + x3 <= 6;
This constraint means that the number of units to be produced at stage 2 (x2) depends on
x3. If x3 is 3; x2 may be 0, 1, 2 or 3. Similarly, if x3 is 4, x2 may be 0, 1 or 2. So the state
variable s2 at stage 2 may have values; s2 = 0, 1, 2, 3, 4, 5, 6.
To meet the constraint; x2 + x3 <= 6; we explore all possible combinations of x2 and x3 in
Table 2
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 32
DP- Problem – 2: Production Planning
Table 2
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 33
DP- Problem – 2: Production Planning
Combination tree approach is very useful to enumerate the recursive relationship
for given combination of x2 and x3 for specific value of state variable.
there are two combinations of x2 and x3 when s2 = 1. The objective function is
enumerated and shown in Figure for this value of s2.
Figure 1
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 34
DP- Problem – 2: Production Planning
there are three combinations of x2 and x3 when s2 = 2.
The objective function value is 10, 15 and 11 when decision variable x2 is 2, 1 and
0 respectively; given corresponding x3 values were 0, 1 and 2 at subsequent stage
(n=3) as shown in Figure 1
Figure 2
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 35
DP- Problem – 2: Production Planning
The same arguments may be cited for s2 = 3 and 4. The enumerations are shown
in Figures 3 and 4 respectively.
Figure 3
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 36
DP- Problem – 2: Production Planning
Figure 4
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 37
DP- Problem – 2: Production Planning
When state variable s2 = 5, the feasible combinations of x2 and x3 are shown in
Figure 5. Note that x2 = 0 is not feasible when s2=5.
Figure 5
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 38
DP- Problem – 2: Production Planning
The feasible combinations of x2 and x3 are shown in Figure 6 when s2 =6.
Again note that x2 = 0 or x2= 1 are not feasible values for s2=6.
Figure 6
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 39
DP- Problem – 2: Production Planning
At the end of stage 2, the total cost values of the objective function enumerated
in Figures 1 to 6 are entered in Table 3.
Minimum value of f*(s2) and corresponding value of x2* are shown on right side
columns for each value of s2
Table 3
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 40
DP- Problem – 2: Production Planning
From stage 2 (month of February) to stage 1 (month of January), the demand
constraint is updated as follows to reflect production requirement
x1 + x2 + x3 = 6
Total number of units of the item produced during three months must be equal
to six.
Hence, there is only one possible value of state variable at stage 1; i.e., s1 = 6 (The
number of units produced either in January or in February or in March must be
exactly equal to requirement of 6 units).
The expression of the objective function for stage 1 will be;
f1(6,x1) = c1(x1) + f2*(6-x1), where x1 = 0, 1, 2, 3, 4.
The combination tree for n=1, s1=6 is shown in Figure 7. The tree provides all
feasible combinations of stage 1 decision variable x1, and, stage 2 decision
variable x2.
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 41
DP- Problem – 2: Production Planning
Figure 7
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 42
DP- Problem – 2: Production Planning
The values of objective function at stage 1 with s1 = 6, and, possible values of
decision variable x1:( 0≤ x1 ≤4) are contained in Table 4 below.
Transferring values from combination tree of Figure7 in the Table 4, the optimal
solution value; f1*(6) = 20, and optimal value of decision variable, x1*=3.
Table 4
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 43
DP- Problem – 2: Production Planning
Optimal Solution:
Optimal cost; f1*(6) = 20
x1* = 3;
s2= 6 – x1* = 3, go to Table 3 (stage 2)
x2* = 3 for s2 = 3
s3 = 3 – x2* = 0, go to Table 2 (stage 1)
x3* = 0 for s3 = 0.
Hence, x1*=x2* = 3, x3* = 0.
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 44
DP- Problem – 3: 13 - City Problem
Select time of travel of all stages and find travel root of shortest time from city 1
to 14.
2 5
9 12
1 3 6 14
10
4 7 13
11
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 45
Thank You
3/31/2020 WK: 07 Lect 19-20 --- Unit Commitment–II : By Dr. T. N. Malik Slide No. 46