Project

OPTIMISATION OF STALAGMITE FUNCTION AND TO FIND GLOBAL MAXIMA USING GENETIC ALGORITHM

AIM

To write a code in MATLAB to optimise the stalagmite function and find the global maxima of the function.

GENETIC ALGORITHM

A genetic algorithm is a search heuristic that is inspired by Charles Darwin’s theory of natural evolution. This algorithm reflects the process of natural selection where the fittest individuals are selected for reproduction in order to produce offspring of the next generation.


SYNTAX

  • x = ga(fun,nvars) finds a local unconstrained minimum, x, to the objective function, fun. nvars is the dimension (number of design variables) of fun.
  • x = ga(fun,nvars,A,b,Aeq,beq,lb,ub) defines a set of lower and upper bounds on the design variables, x, so that a solution is found in the rangelb ≤ x ≤ ub. (Set Aeq=[] and beq=[] if no linear equalities exist.)
  • x = ga(fun,nvars,A,b,[],[],lb,ub,nonlcon,IntCon) or x = ga(fun,nvars,A,b,[],[],lb,ub,nonlcon,IntCon,options) requires that the variables listed in IntCon take integer values.

PROGRAM

clear all 
close all
clc

%creating 1D array
x=linspace(0,0.6,150)
y=linspace(0,0.6,150)

%creating 2D array
[xx,yy]=meshgrid(x,y)
for i=1:length(xx)
    for j=1:length(yy)
        inputvector(1)=xx(i,j);
        inputvector(2)=yy(i,j);
        f(i,j)=stalagmite(inputvector);
    end
end
numcases=50;
%stastical behaviour
tic
for i=1:numcases;
[inputs,fopt(i)]=ga(@stalagmite,2);
xopt(i)=inputs(1);
yopt(i)=inputs(2);
end
study_time1 = toc;
%plotting unbounding conditions
figure(1);
subplot(2,1,1);
surfc(xx,yy,-f);
hold on;
shading interp;
plot3(xopt,yopt,-fopt,'Marker','o','Markersize',5,'Markerfacecolor','r');
subplot(2,1,2);
plot(-fopt);
xlabel('No of iterations');
ylabel('F maximum');
%plotting bounding conditions
tic;
    for i=1:numcases;
[inputs,fopt(i)]=ga(@stalagmite,2,[],[],[],[],[0;0],[1;1]);
xopt(i)=inputs(1);
yopt(i)=inputs(2);
    end
study_time2 = toc;
figure(2);
subplot(2,1,1) ;   
surfc(xx,yy,-f);
hold on;
shading interp;
plot3(xopt,yopt,-fopt,'Marker','o','Markersize',5,'Markerfacecolor','r');
subplot(2,1,2);
plot(-fopt);
xlabel('No of iterations');
ylabel('F maximum');

figure(3);
options=optimoptions('ga');
options = optimoptions(options,'populationsize',300);
tic
for i=1:numcases
[inputs,fopt(i)]=ga(@stalagmite,2,[],[],[],[],[0;0],[1;1],[],[],options);
xopt(i)=inputs(1);
yopt(i)=inputs(2);
end
study_time3 = toc;
figure(3);
    subplot(2,1,1);
surfc(xx,yy,-f);
hold on;
shading interp;
plot3(xopt,yopt,-fopt,'Marker','o','Markersize',5,'Markerfacecolor','r');
subplot(2,1,2);
plot(-fopt);
xlabel('No of iterations');
ylabel('F maximum');

FUNCTION

function f =stalagmite(inputvector)
f1x=(sin(5.1*pi*inputvector(1)+0.5))^6;
f1y=(sin(5.1*pi*inputvector(2)+0.5))^6;
f2x=exp(-4*log(2)*((inputvector(1)-0.0667)^2/0.64));
f2y=exp(-4*log(2)*((inputvector(2)-0.0667)^2/0.64));
f= -(f1x*f1y*f2x*f2y);
end

PLOTS

CASE 1 statistical behaviour without Bounding conditions

CASE 2 Statistical behaviour with Bounding conditions

CASE 3 By increasing GA iterations

CONCLUSION

Inorder to optimise the given stalagmite function to find global maxima by ga

  • we need to reduce the search space by using bounding copnditions which leds us to find the local maxima
  • inorder to find the global maxima we increase the 'populationsize' which specifies how many individuals there are in each generation. If we set Population size to be a vector of length greater than 1, the algorithm creates multiple subpopulations. Each entry of the vector specifies the size of a subpopulation.
  • ga is generally used to minimise the valves therefore we use (-sign) in our funtion f and fopt to find out the global maxima
  • Therefore the global maxima for the stalagmite function is 1 at (0.6683,0.6683)
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.