Dynamic Programming Overview and Concepts
Dynamic Programming Overview and Concepts
Generalities
Dynamic Programming (DP) is an optimization method that can be applied to
different problems, some of which have already been addressed through programming
linear or graphical method.
Depending on the nature of the parameters of the mathematical model of the problem, it
distinguish the:
SOME APPLICATIONS
Problem Solution
PD
Combinatorial Solution
PD
Optimization
What is the best solution?
Example: What is the route with the shortest distance to get from the origin city to the destination city?
Session 7 – Dynamic Programming
These son
scenarios that the
Player A must
avoid in order to
to win.
Session 7 - Dynamic Programming
The winning strategy of Player A consists of leaving the following on the table
quantities of matchsticks for Player B's turn.
If player A gets to start the game, meaning it is his turn first, he is going to
pick up a matchstick.
30 - 1 = 29
Therefore, we have the first number corresponding to the winning strategy.
Later try to leave on the table the amounts of matches indicated and that
It would be the winning strategy.
Principle of:
Let's dive deeper into the characteristics, into the foundations of this method:
1. Properties of PD problems
2. Basic concepts of PD
3. Solution procedure
4. Summary
Session 7 – Dynamic Programming
1 Optimal substructure
Fibonacci series
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, …
n = 1, 2, 3, 4, 5, 6, 7, ...
therefore we can collect these observations in the following way:
Fibonacci function 2 initial conditions Recursion formula
Stages
States Model
Mathematician
Decision variables of the Problem
Recurrence function
Principle of optimality
Stages
They are the period of time, the place, the phase or the situation in which it occurs.
a change due to a decision.
Solo puede tomarse una decisión en cada etapa, es decir para pasar a la
next stage.
To have a graphic idea of what is happening:
This is the concept of stages, and it is here where at each stage we will propose the
subproblem and then the combination of the solutions of the subproblems, the idea
divide and conquer.
Session 7 – Dynamic Programming
They show the current situation of the system when it is in the stage.
n=1
1
n=2
2
n=3
3
…
EVOLUTION OF THE SYSTEM
n=1
1
n=2
2
n=3
3 …
EVOLUTION OF THE SYSTEM
We have each stage with its status and then for the stage changes they make
It is necessary to make decisions; at each stage, a decision variable will intervene.
what is going to allow the change of lid and condition.
Session 7 - Dynamic Programming
Recurrence function
Describe the behavior of the system based on the states and variables.
decision.
Each stagetits own associated recurrence function a que v ade p eunder the
states and the decision variables of each stage. ( , )
Let's see how PD problems are solved, one can start from the beginning.
until the end or from the end to the beginning, that is forward or backward, by
In general, it will always go backward (from the end to the beginning).
Considering the above, the recurrence function is associated with each stage.
n=1
1
n=2
2
n=3
3 …
It will only cover or depend on stage 3. 3 ( 3 , 3 )
Well, it will depend on the current situation, on the state we are in.
considering and the state that has already been considered. 2 ( ,
2 2 )
Well, it will depend on the current situation, of the
state that we are considering and of the state 1 ( 1 , 1)
which was already considered in 2 and 3, since it will go
encompassing everything that is being obtained up to the
momento.
Session 7 - Dynamic Programming
Optimality principle (Richard Bellman)
With the concepts seen, Stage, State, Decision Variables, and recurrence function,
are part of the mathematical model. The principle of optimality attributed to Richard
Bellman is what provides sustenance, it is the essence of the DP theory.
1 Inretreat
The terminal conditions are fixed and the computation of the values
Numerical analysis is carried out from the final stage to the initial stage.
2 Inadvance
The initial conditions are fixed and the computation of the values
Numerical analysis is carried out from the initial stage to the final stage.
C
L
N
Session 7 - Dynamic Programming
Example – PD (Shortest Path)
On the second day, it is expected to reach one of the following three cities: Omaha (Nebraska), Kansas
City (Kansas) or Dallas (Texas)
On the third day, it is expected to arrive at one of the following two cities: Denver (Colorado) or San Antonio.
(Texas)
On the last day or fourth day, we would connect with the Angels (California), which would be our destination city.
C
D O
L
K
N
S D
Session 7 - Dynamic Programming
Example - PD (Shortest Path)
DAY 1 DAY 2 DAY 3 DAY 4
Stage 1 Stage 2 Stage 3 Stage 4
In which cities should one spend the night each day so that the distance traveled between NY and LA
minimum sea?
Although we can solve this problem through a network model, today we are going to solve it by means of
PD.
Sesión 7 – Programación Dinámica
Example – PD (Shortest Path)
Resolution of the problem - In retrogression
That is to say, it starts from stage 4 (Los Angeles)
9
State 8
Saint
Denver Antonio
Denver
8 1030
The ( Length
) of the shortest path from the city to Los
Angels in the stage, this function gathers the optimum, it is
Angels
say the shortest length, this function accumulates
10
distances, in this particular stage 4, we have
San 1390 the following options:
Antonio
9 (48 )=1030
(49 )=1390
We must establish the elements that
establish the mathematical model of PD:
Session 7 - Dynamic Programming
Example – PD (Shortest Path)
Resolution of the problem - In reverse
5 6 7 KC From
+ (48 )=610+1030=1640
DAY 3 KC O D KC 58
(35 ) =mim {1640,2180 }=1640
5
Stage 3 KC SA
59 + (49 )=790+1390=2180
Kansas City
610
5
790 O Of
Denver + ( 84 )=540+1030=1570
O 68
8
6
(36 )=mim {1570,2330 }=1570
540 O SA
Omaha 69 + ( 94 )=940+1390=2330
6
940
San Yes Of
790 Antonio
D 78 + (48 )=790+1030=1820
9
7
(37 ) =mim {1820,1660 }=1660
Yes SA
Dallas 270
7 79 + (49 )=270+1390=1660
Note that we have already calculated the optimal solutions for this stage if we wake up in Kansas City, Omaha, or Dallas.
Session 7 - Dynamic Programming
Example - DP (Shortest Path)
Resolution of the problem - In reverse
C KC C O C Yes
C KC
=mim680+
2 3 4
(22
) { ( ) ,790+ ( ) 1050+ ( ) }
DAY 2 C C O
C N L 2
Stage 2 (22 )=mim {680+ ,790+1000+ }
C Yes
Colombus
2
790
680 Kansas City
5
(22 )=mim {2320,2360,2710 }
=2320
N KC N O N Yes
1050 N KC
N
{
(23 ) =mim580+ ( ) ,760+ ( ) ,600+ ( )}
N O
580 3
(23 ) =mim {580+ {"value":760}+600+ }
Nashville Omaha N Yes
3 760 6 (23 ) =mim {2220,2330,2260 }=2220
600
L KC L O L Yes
L KC
510
L L O
(24 )
=mim510+
{ ( ) ,700+ ( ) ,830+ ( )}
700 4
Louisville Dallas (24 )=mim {510+ A time, 700+0.3+ }
4 830 7 L Yes
(24 )=mim {2150,2270,2490 }=2150
So if we are in stage 2, if we start in any of the three cities (C, N, and L), the best or optimal thing is
to head towards Kansas City
Session 7 - Dynamic Programming
Example – PD (Shortest Path)
Problem resolution - In regression
Stage 1
Columbus
2
500
NY C
New York
900
Nashville NY
(11
) =mim550+
{ ( ) ,900+ ( ) 770+ ( ) }
NY N
1 3 1 (11 )=mim {550+915,900+ ,1050+ }
770
NY L (11 )=mim {2870,3120,2970 }
=2870
Louisville
4
So we have already found the optimal solutions by stage, now we are going to combine these solutions, which will give us the
optimal route.
Session 7 – Dynamic Programming
Example - PD (Shortest Path)
Optimal route 12 + ( ) =550+ =2870
(1 )=mim
1 13 +
14 +
=900+
( )
( ) =770+
=3120
=2920
NY C
C KC
2 5
25 + ( )
=680+ =2320
Of ( 2 )=mim
2 26 + ( )
=790+ =2360 C KC
NY
1
N
3
O
6
8 LA
10
27 + ( )
=1050+ =2710
SA
L Yes
9
( 5 ) =mim
58+ ( )
=610+ =1640 KC Of
=790+ =2180
3
4 7
59 + ( )
( 8 )=1030
4 Of LA
These are the nodes or the cities that we need to connect in our optimal route.
Session 7 - Dynamic Programming
Example - PD (Shortest Path)
550
z = 2870 Miles
1030 680 C
D O
L
610 K
N
S D
CONCLUSIONES