0% found this document useful (0 votes)
27 views

Path Planning LAB: Dynamic Programming

The document discusses dynamic programming and how it can be used to find optimal solutions to problems that can be divided into stages. It defines the key concepts of dynamic programming including dividing problems into subproblems, storing solutions, and combining solutions. An example problem is solved using a MATLAB program to demonstrate dynamic programming.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Path Planning LAB: Dynamic Programming

The document discusses dynamic programming and how it can be used to find optimal solutions to problems that can be divided into stages. It defines the key concepts of dynamic programming including dividing problems into subproblems, storing solutions, and combining solutions. An example problem is solved using a MATLAB program to demonstrate dynamic programming.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

PATH PLANNING

LAB
Dynamic Programming

Submitted by:

Faizan Ali 140627


Hamza Naeem 140624
Submitted to:
Sir Umair Aziz
Lab 13:
Dynamic Programming
Objective:
The goal of dynamic programming is to find a combination of decisions that
optimizes a certain amount associated with a system.

Introduction:
Dynamic programming is a widely used mathematical technique for solving problems
that can be divided into stages and where decisions are required in each stage. dynamic
programming is a method for solving a complex problem by breaking it down into a
collection of simpler subproblems, solving each of those subproblems just once, and storing
their solutions. The next time the same subproblem occurs, instead of recomputing its
solution, one simply looks up the previously computed solution, thereby saving computation
time at the expense of (it is hoped) a modest expenditure in storage space. (Each of the
subproblem solutions is indexed in some way, typically based on the values of its input
parameters, so as to facilitate its lookup.
Dynamic programming algorithms are often used for optimization. A dynamic
programming algorithm will examine the previously solved sub-problems and will combine
their solutions to give the best solution for the given problem. In comparison, a greedy
algorithm treats the solution as some sequence of steps and picks the locally optimal choice at
each step. Using a greedy algorithm does not always guarantee an optimal solution, whereas a
dynamic programming algorithm does, because picking locally optimal choices may result in
a bad global solution

Divisions into Stages


 The problem is divided into smaller sub-problems each of them represented by a stage.
 The stages are defined in many different ways depending on the context of the problem.
 If the problem is about long-time development of a system, then the stages naturally
correspond to time periods.
 If the goal of the problem is to move some objects from one location to another on a
map, then partitioning the map into several geographical regions might be the natural
division into stages.
 Generally, if an accomplishment of a certain task can be considered as a multi-step
process, then each stage can be defined as a step in the process.

Flow Chart:
Decisions
 Making decisions at one stage transforms one state of the current stage into a state in
the next stage.
 In a geographical example, it could be a decision to go from one city to another.
 In resource allocation problems, it might be a decision to create or spend a certain
amount of a resource.

States
 Each stage has a number of states associated with it. Depending on what decisions are
made in one stage, the system might end up in different states in the next stage.
 If a geographical region corresponds to a stage then the states associated with it could
be some particular locations (cities, warehouses, etc.) in that region.
 In other situations, a state might correspond to amounts of certain resources, which
are essential for optimizing the system.

Exercise
Develop a MATLAB® program to solve the given problem using dynamic programming.
After the program is complete, make necessary changes in the code so that every input
required will be entered by the user.
Code:
%A=1;B=2;C=3;D=4;E=5;F=6;G=7;H=8;I=9;J=10;
clc;
clear all;
Links = [2 3 4;
5 6 7;
5 6 7;
5 6 7;
8 9 0;
8 9 0;
8 9 0;
10 0 0;
10 0 0];
Distances = [2 4 2;
7 4 8;
3 2 4;
4 1 5;
1 4 0;
6 3 0;
3 3 0;
3 0 0;
4 0 0];
stages = 5;
stage_indices = [1 0 0;
2 3 4;
5 6 7;
8 9 0;
10 0 0];
selectedNode = 1;
total_distance = 0;
List = [];
%Creating Nodes
for i = 0:stages-1
nodes_in_stage = stage_indices(stages-i,stage_indices(stages-i,:)>0);
[~,l_size] = size(nodes_in_stage);
nodeUnderCons = nodes_in_stage(selectedNode);
List = [List nodeUnderCons];
[x,y] = find(Links>nodeUnderCons-1 & Links<nodeUnderCons+1);
if (x>0 & y>0)
for k = 1:max(size(x))
if k==1
d = Distances(x(k),y(k));
else
d = [d Distances(x(k),y(k))];
end
end
else
selectedNode = 1;
d = 0;
end
[~,selectedNode] = min(d);
total_distance = total_distance + min(d);
end

List = sort(List);
disp("Path:")
disp(List);
disp("Total Distance:");
disp(total_distance);

Output:

Conclusion
We conclude that by using dynamic programming on given problem we find a
combination of decisions that optimizes a certain amount associated with a system. It takes a
decision and find the optimal path along with different path.

You might also like