What is Dynamic Programming
Dynamic programming is a method of
solving complex problems by breaking
them down into sub-problems that can be
solved by working backwards from the last
stage.
Coined by Richard Bellman who described
dynamic programming as the way of
solving problems where you need to find
the best decisions one after another
Dynamic Programming
Dynamic programming is a simple method
of solving complex real world problems,
such as
Traveling salesman problem
Fibonacci sequence
Stagecoach problem
Knapsack problem
Numerous other applications exist
Steps to Dynamic Programming
Every problem is divided into stages
Each stage requires a decision
Decisions are made to determine the state of
the next stage
The solution procedure is to find an optimal
solution at each stage for every possible
state
This solution procedure often starts at the
last stage and works its way forward
Knapsack Problem
You are a mischievous child camping in the
woods. You would like to steal items from
other campers, but you can only carry so
much mass in your knapsack. You see seven
items worth stealing. Each
item has a certain mass and
monetary value. How do you
maximize your profit so you
can buy more video games
later?
Knapsack Problem
Value and mass of
each item is given
Maximize profit
Subject to mass
constraint of
knapsack: 15 kg
Being a smart kid,
you apply dynamic
programming
Smart Kids Write Equations
There are potentially 7 stages to this dynamic
programming problem.
When an item is placed in the knapsack, a decision,
F(m), is made to choose the next optimal item, i.
Start at the end of the problem, assuming that the
knapsack has an unknown mass, m.
Recurrence relation:
F(i,m) = max (F(i-1,m-mi) + fi, F(i-1, m))
Use recursion and iterate through the problem,
eventually coming up with the optimal solution.
Smart Kids Use MatLab
Now imagine you, the mischievous smart
thief kid, brought your laptop to the
camping trip. How would you solve the
equation? MATLAB!
Matlab Solution:
Profit: $21
Mass: 15kg
Not enough to buy a new video game
Sensitivity Analysis
Valuables are not very valuable when camping,
pick richer people to steal from.
Suddenly a valuable item of $15 that weighs
11kg is available, will the optimal solution
change?
Yes, the maximum profit becomes $23
Using MatLab, it is easy to change the variables
on the program for specific sensitivity analysis