Professional Documents
Culture Documents
8th Semester Path Lab 6
8th Semester Path Lab 6
LAB NO.6
GROUP MEMBERS:
(2019)
LAB SUPERVISOR
Objective:
To move from starting point to the endpoint on permissible while avoiding
collisions with obstacles and minimizing total distance travelled, time taken or
energy consumed
Stochastic Methods:
It are based on laws of probability for sampling of random events and have
the advantage that they can handle large problems.
Genetic Algorithms (GA):
It is applicable to both static and dynamic environments. In static
environment all coordinates (MR, obstacles, goal) are input into the onboard
computer system of MR while in dynamic environment sensors need to be used.
Flow Chart:
Formulas:
𝐹𝑖𝑡𝑛𝑒�(𝑖𝑃𝑎𝑡ℎ)=1.0/𝐷𝑖�𝑡𝑎𝑛𝑐𝑒𝐼𝑛𝑃𝑎𝑡ℎ(𝑖𝑃𝑎𝑡ℎ)
CHROMOSOME_LENGTH=(NOBS+2)*NBITS
Code
clc;
clear all;
x = [1 1 3 3 5 6 6 8 10 10 10 11 13 12 14 14];
y = [7 11 14 1 8 11 4 4 1 7 11 14 12 2 3 8];
z = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16];
links = [1 2 4 5 0;
2 3 1 0 0;
3 2 6 12 0;
4 1 7 9 0;
5 1 7 6 0;
6 3 5 11 0;
7 4 5 8 0;
8 7 10 14 0;
9 4 14 0 0;
10 8 11 16 0;
11 6 10 12 0;
12 3 11 13 0;
13 12 16 0 0;
14 8 9 15 16;
15 14 16 0 0;
16 10 13 14 15];
populationSize = 500;
itterations = 500;
%list Size Decalration
Gen = zeros(populationSize,9);
nextGen = zeros(populationSize,9);
fitList = zeros(populationSize,1);
%Generation Production
for g = 1:populationSize
%disp(Path);
distance = 0;
flag = 0;
%Calculating Distance
for i = 2:9
distance = distance + ((x(Path(i))-x(Path(i-1)))^2 + (y(Path(i))-y(Path(i-
1)))^2)^0.5;
if ~ismember(Path(i-1),links(Path(i),:))
flag = flag + 1;
end
end
%Calculating Fitness
fitness = 1/(distance+(flag*100));
%Starting itterations
for itteration = 1:itterations
clc;
disp(["Itterations: " , itteration]);
nextGen = Gen;
%Selecting Mother
while max(pdf) == val
[~,index] = max(pdf);
pdf(index) = 0;
end
[val,index] = max(pdf);
motherIndex = index;
mother = nextGen(motherIndex,:);
disp("Mother is:");
disp(mother);
%Selecting Third Best
while max(pdf) == val
[~,index] = max(pdf);
pdf(index) = 0;
end
[~,index] = max(pdf);
thirdbestIndex = index;
thirdbest = nextGen(thirdbestIndex,:);
disp("Third fittest:");
disp(thirdbest);
%Parensts Selected
%Calculating Distance
for i = 2:9
distance = distance + ((x(Gen(g,i))-x(Gen(g,i-1)))^2 + (y(Gen(g,i))-
y(Gen(g,i-1)))^2)^0.5;
if ~ismember(Gen(g,i-1),links(Gen(g,i),:))
flag = flag + 1;
end
end
%Calculating Fitness
fitness = 1/(distance+(flag*100));
%UpdatingFitList
fitList(g,:) = fitness;
end
Gen = [Gen pdf];
nextGen = sortrows(Gen,10);
nextGen = nextGen(:,1:9);
Gen = nextGen;
disp("=====================");
%disp("New Generation is:");
%disp(nextGen);
%Calculating Fitness and distances of new Generation
Gen = nextGen;
for g = 1:populationSize
distance = 0;
flag = 0;
%Calculating Distance
for i = 2:9
distance = distance + ((x(Gen(g,i))-x(Gen(g,i-1)))^2 + (y(Gen(g,i))-
y(Gen(g,i-1)))^2)^0.5;
if ~ismember(Gen(g,i-1),links(Gen(g,i),:))
flag = flag + 1;
end
end
%Calculating Fitness
fitness = 1/(distance+(flag*100));
%UpdatingFitList
fitList(g,:) = fitness;
end
%Generating Probability
pdf = fitList ./ sum(sum(fitList));
%Generating Cummulative Probability
Sum = 0;
cuProb = pdf;
for cubit = 1:populationSize
Sum = Sum + pdf(i);
cuProb(cubit) = Sum;
end
end
Output:
Conclusion: