Project

optimisation of stalagmite function to get maximum value

A genetic algorithm (GA) is a method for solving both constrained and unconstrained optimization problems based on a natural selection process that mimics biological evolution. The algorithm repeatedly modifies a population of individual solutions. At each step, the genetic algorithm randomly selects individuals from the current population and uses them as parents to produce the children for the next generation. Over successive generations, the population \"evolves\" toward an optimal solution.You can apply the genetic algorithm to solve problems that are not well suited for standard optimization algorithms, including problems in which the objective function is discontinuous, nondifferentiable, stochastic, or highly nonlinear[1]

clc
close all
clear all



%inputs

x=linspace(0,0.6,150);
y=linspace(0,0.6,150);
[xx yy]=meshgrid(x,y);

num_cases=100;   %creating no of iterations

%creating negative stalagmite function

for i=1:length(xx)
    for j=1:length(yy)
        input_vector(1)=xx(i,j);
        input_vector(2)=yy(i,j);
        S(i,j)=stalagmite(input_vector);
    end
end


%setting population size

options=optimoptions(\'ga\');
options=optimoptions(options,\'populationSize\',470);

%finding out minimum value for iterations=numcases

tic
for j=1:num_cases
  [inputs,fopt(j)]=ga(@stalagmite,2,[],[],[],[],[0;0],[1,1],[],[],options);
  x_opt(j)= inputs(1);
  y_opt(j)=inputs(2);
  
end
study_time=toc
figure(1)
subplot(2,1,1)
hold on
surfc(x,y,S);
shading interp;
xlabel(\'x\');
ylabel(\'y\');
plot3(x_opt,y_opt,fopt,\'marker\',\'o\',\'markersize\',5)
subplot(2,1,2)
plot(fopt)
xlabel(\'iteration\')
ylabel(\'fmin\')
maxvalue=1 % from figure as minimum value of -f is -1 so max value of f is 1

function code

function [ fxy ] = stalagmite(u)

x = u(1);

y = u(2);

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

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

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

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

 fxy= -(fx * gx * fy * gy); 

end

for 200 iterations 270 population size

for 200 iterations 370 population size

for 100 iterations 470 population size

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.