Project

stalagmite optimisation

The following outline summarizes how the genetic algorithm works:The algorithm begins by creating a random initial population.The algorithm then creates a sequence of new populations. At each step, the algorithm uses the individuals in the current generation to create the next population. To create the new population, the algorithm performs the following steps:

  1. Scores each member of the current population by computing its fitness value. These values are called the raw fitness scores.
  2. Scales the raw fitness scores to convert them into a more usable range of values. These scaled values are called expectation values.
  3. Selects members, called parents, based on their expectation.
  4. Some of the individuals in the current population that have lower fitness are chosen as elite. These elite individuals are passed to the next population.Produces children from the parents.
  5. Children are produced either by making random changes to a single parent—mutation—or by combining the vector entries of a pair of parents—crossover.
  6. Replaces the current population with the children to form the next generation.
  7. The algorithm stops when one of the stopping criteria is met.
% stalagmite function

function [f] = stalagmite(input_vector)


f1x = (sin((5.1*pi*input_vector(1))+0.5))^6;
f1y = (sin((5.1*pi*input_vector(2))+0.5))^6;

f2x = exp(-4*log(2)*((input_vector(1)-0.0667)^2)/0.64);
f2y = exp(-4*log(2)*((input_vector(2)-0.0667)^2)/0.64);

f = -f1x*f1y*f2x*f2y;

end






%Program to calculate the global maxima of a stalagmite function


clear all
close all
clc

%Defining our search space
x=linspace(0,0.7,180);
y=linspace(0,0.7,180);

%Increasing GA iterations 
options=optimoptions('ga');
options=optimoptions(options,'PopulationSize',180);

%creating a 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
  
%Plotting
surfc(xx,yy,f)
title('Stalagmite function')
xlabel('x values')
ylabel('y values')
zlabel('fitness function values')
shading interp

%Performing genetic algorithm for optimization
[inputs,fval]= ga(@stalagmite,2,[],[],[],[],[0;0],[1;1],[],[],options)

%Results
fprintf('The maximum value found was%g\\n', fval);
fprintf('Final x value was%g\\n', inputs(1));
fprintf('Final y value was%g\\n', inputs(2));


Result: The maximum value found was -1
        The value of x was 0.0668251
        The value of y was 0.06683
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.