Challenge

Week 4.1 - Genetic Algorithm

 close all
 clear all
 clc
 % defining the search space
 x = linspace(0,0.6,150);
 y = linspace(0,0.6,150);
 % to create 2d mesh
%   [xx,yy] = meshgrid(x,y);
%  % assigning valus to inputs
  for i = 1:length(x)% takes values until length of xx
      for j = 1:length(y)% takes values until length of xx
          inputs(1) = x(i);
          inputs(2) = y(j);
          f(i,j) = stalagmite(inputs);
      end
  end
 num_case = 50; % creating a variable and assigning the number to which iterations performed
%  f = get_stalagmite(x,y);
 tic % Starts the timer
 % Studt case-1
 for z = 1:num_case % takes values until length of num_cases
         [inputs,fopt(z)]  = ga(@stalagmite,2);% solve stalagmite function using GA and assigning to variables
         xopt(z) = inputs(1);
         yopt(z) = inputs(2);
 end
 Time_study1 = toc % Gives time taken to perform the case

 figure(1)
 subplot(2,1,1) % creates sub-plot in the figure 
 hold on
 surfc(x,y,-f) % Creates a surface
 shading interp % varies the color in each line segment and face by interpolating the colormap index or true color value across the line or face.
 plot3(xopt,yopt,-fopt,'marker','o','markersize',5,'markerfacecolor','r')% plot3 command used to plot in 3 axis
 % marker is used to create a visible points on the plot
 title('unbounded inputs') 
 xlabel('x-axis')
 ylabel('y-axis')
 zlabel('z-axis')
 subplot(2,1,2)
 plot(-fopt)
 xlabel('iterations')
 ylabel('Function maximum')

% Study Case-2 Defining upper and lower bounds
tic
 for z = 1:num_case
         [inputs,fopt(z)] = ga(@stalagmite,2,[],[],[],[],[0;0],[0.4;0.4]);
         %defines a set of lower and upper bounds on the design variables
         xopt(z) = inputs(1);
         yopt(z) = inputs(2);
 end
 Time_study2 = toc

 figure(2)
 subplot(2,1,1)
 hold on
 surfc(x,y,-f)
 shading interp
 plot3(xopt,yopt,-fopt,'marker','o','markersize',5,'markerfacecolor','r')
 title('Bounded inputs')
 xlabel('x-axis')
 ylabel('y-axis')
 zlabel('z-axis')
 subplot(2,1,2)
 plot(-fopt)
 xlabel('iterations')
 ylabel('Function maximum')
 clc
 % Study Case-3 Increasing iterations
 options = optimoptions('ga');% returns a set of default options for the SolverName solver.
 options = optimoptions(options,'PopulationSize',270);%Defining population size
 
 tic
 for z = 1:num_case
         [inputs,fopt(z)]  = ga(@stalagmite, 2,[],[],[],[],[0;0],[0.4;0.4],[],[],options);
         % takes the values of options and solves ga in required population
         xopt(z) = inputs(1);
         yopt(z) = inputs(2);
 end
 Time_study3 = toc;

 figure(3)
 subplot(2,1,1)
 hold on
 surfc(x,y,-f)
 shading interp
 plot3(xopt,yopt,-fopt,'marker','o','markersize',5,'markerfacecolor','r')
 title('Increased population')
 xlabel('x-axis')
 ylabel('y-axis')
 zlabel('z-axis')
 subplot(2,1,2)
 plot(-fopt)
 xlabel('iterations')
 ylabel('Function maximum')
 % The Global Maximum at the position
%  display(inputs)


function [f]=stalagmite(V)
x = V(1);
y = V(2);

f1x=(sin((5.1*pi*x)+0.5))^6;
f1y=(sin((5.1*pi*y)+0.5))^6;
f2x=exp(-4*log(2)*(((x-0.0667)^2)/0.64));
f2y=exp(-4*log(2)*(((y-0.0667)^2)/0.64));

f=-(f1x*f1y*f2x*f2y);

OPTIMAZATION :

Area of study how do minimize or maximize particular function depends on multiple input parameters.

STALAGMITE:

Mathematical model to show the local minima and universal maxima.It is the 3D function.

GENATIC ALGORITHM:

It is proposed by charles darwin based on evalution theory. It is imbuild function.

We are using three cases here,

case 1

It is unbounded study

we are not setting any limits

we are not setting any ranges

we could not come conclusion by this

case 2

It is bounded study

We set some certain limits or boundaries according to the some studies.

this condition focussed on specific area that we set

case 3

it is bounded with some extra data

it increase the choices

according to the number of choices the output will be more accurate.

The syntex of above three cases are exist in program.kindly refer them.

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.