Challenge

Week 4.1 - Genetic Algorithm

A GENETRIC ALGORITHM

A GENETRIC ALGORITHM IS A METHOD TO SLOVE THE BOTH CONSTRAINED AND UNCONSTRAINED

OPTIMIZATION PROBLEM BASED ON A NATURAL SELECTION PROCESS THAT MIMICS BIOLOGICAL EVOLUTION .AND ALSOIS SEACH HEURISTIC THAT IS INSPIRED BY THE CHARLES DARWIN'S THEORY OF NATURAL EVOLUTION

In genetic algorithm id done in three step are considered in genetic algorith

they are,

(1)selection

(2)crossover

(3)mutation

slection

The ideal of selection phase is to select the fittness individual and let them pass their genes to the next generation.

Two pairs of individuals(parents) are selected basond on their fitness scores individual with high fitness have more chance to be selected for reproduction

crossover

cross over is the most significant phase in a genetic algorithm .for each pair of parents tobe mated, acrossover point is chosen atrandom from with in the genes

mutation

In a certain new oofspring formed some of theirgenes can be subjected to a mutation with a low random probability .this implies that some of the bits in the spring can be flipped

syntax;

x=ga(fun,nvars)

x=ga(fun.nvars) find a local un constrained minimum,x,to the object functionfun.nvars is the number of design variables of the function , fun .

stopping criteria

  • Generation

The algorithm stop when the number of generation reaches the value of generation

  • Time limit

The algorithm stop after running for an amount of time in second is equal to the time limit

  • Fitnes limit

the algorithm stop when the value of fitness function for the best piont in the current population is less than the equal to fitness limit

clear all
close all
clc


%inputs
x=linspace(0,0.6,100)
y=linspace(0,0.6,100)
num_cases=40;

%for 2d mesh
[xx yy]=meshgrid(x,y)

%evaluating the stalagmite function
for i=1:length(xx);
    
    for j=1:length(yy);

        input_vector(1) = xx(i,j);

        input_vector(2) = yy(i,j);

        f(i,j)=stalagmite(input_vector);
    end
end

tic
%study 1-satistical behavior
for i=1:num_cases
    [inputs,fopt(i)]=ga(@stalagmite,2);
    xopt(i)=inputs(1);
    yopt(i)=inputs(2);
end
study1_time=toc



%plotting
figure(1);
subplot(2,1,1);
hold on
surfc(xx,yy,f);
shading interp
plot3(xopt,yopt,fopt,'o')
subplot(2,1,2)
plot(fopt)
xlabel('iteration');
ylabel('function minimum');

tic
%study2 
for i=1:num_cases
    [inputs,fopt(i)]=ga(@stalagmite,2,[],[],[],[],[0;0],[1;1]);
    
    xopt(i)=inputs(1);
    yopt(i)=inputs(2);
end
study2_time=toc

%studing 3 increasing ga iteration

options=optimoptions('ga')
options=optimoptions(options,'populationsize',170);



%plotting
figure(2)
subplot(2,1,1);
hold on
surfc(xx,yy,f);
shading interp;
plot3(xopt,yopt,fopt,'o');
title('bounded  input');
subplot(2,1,2);
plot(fopt)
xlabel('iteration');
ylabel('function minimum');


%study3
for i=1:num_cases
    [inputs,fopt(i)]=ga(@stalagmite,2,[],[],[],[],[0;0],[1;1],[],[],options);
    
    xopt(i)=inputs(1);
    yopt(i)=inputs(2);
end
study3_time=toc



%plotting
figure(3)
subplot(2,1,1);
hold on
surfc(xx,yy,f);
shading interp;
plot3(xopt,yopt,fopt,'o');
title('bounded  input');
subplot(2,1,2);
plot(fopt)
xlabel('iteration');
ylabel('function minimum');

------------------------------------------------------------------


function [f]=stalagmite(input_vector)
x=input_vector(1);

y=input_vector(2);

f1=(sin(5.1*pi*x+0.5))^6;

f2=(sin(5.1*pi*y+0.5))^6;

f3=exp(-4*log(2)*((x-0.0667)^2/0.64));

f4=exp(-4*log(2)*((y-0.0667)^2/0.64));


f=-(f1*f2*f3*f4);
end


figure (1)

in this digram the basic digram for the global maxima. by using the code and generated the global maxima

figure(2)

to determining the minimum point of the global minima with genetic algorithm

in this figure we analysis the so much point is consider of the requiment of the point in this stage (1)

figure (3)

in figure(3) we analysis the less point the in showed in the figure

when we compare with figure (2) the point are reduced with reqirment of the spot of stage (2)

with genenitic algorithm

figure(4)

in the final stage the point are reduced when we comapre with stage 1 and 2

this is the final genetric algorithm because the point are are less than three

so that the final output for ga global minimum og stage (3)

result

  • *The code as be upload fot the global maxima and stalagmite fuction are completed
  • *And then the genetric algorith and syntax is completed
  • *The graph for three studies of gobal minima are plotted and attached
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.