Genetic Algorithm of stalagmite in matlab
AIM:
Write a code in MATLAB to optimise the stalagmite function and find the global maxima of the function.
OBJECTIVE:
Plot graphs for all 3 studies and for F maximum vs no. of iterations. Title and axes labels are a must, legends could be shown if necessary.
Clearly expalin the concept of genetic algorithm in your own words and also explain the syntax for ga in MATLAB in your report.
STALAGMITE:
A stalagmite is an upward-growing mound of mineral deposits that have precipitated from water dripping onto the floor of a cave. Most stalagmites have rounded or flattened tips.

GENETIC ALGORITHM:
It is the search based optimisation technique and it is based on the principle of natural selection. Optimisation is used to get the better output from the set of inputs. Search base means there is n number of solutions in problem ,it gives best solution to the problem.In search space, there is n number of solutions is called individuals. GA is used mate the randam individuals values and bring the child value to get the better solution for the problem. Selecting of random individuals by best fitness values because to get the better output.
SYNTAX OF GA IN MATLAB:
x = ga(fun,nvars)
x = ga(fun,nvars,A,b)
x = ga(fun,nvars,A,b,Aeq,beq)
x = ga(fun,nvars,A,b,Aeq,beq,lb,ub)
x = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon)
x = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon,options)
x = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon,intcon)
x = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon,intcon,options)

STALAGMITE FORMULA:

CODE:
clear all
close all
clc
x=linspace(0,0.6,150);
y=linspace(0,0.6,150);cases=50;
[xx,yy]=meshgrid(x,y);
for i=1:length(xx)
for j=1:length(yy)
a(1)=xx(i,j);
a(2)=yy(i,j);
f(i,j)=stalagmite(a);
end
end
figure(1)
surf(xx,yy,f)
xlabel('x axis')
ylabel('y axis')
zlabel('z axis')
shading interp
[input,fval]=ga(@stalagmite,2)
tic
for k=1:cases
[output1,fout1(k)]=ga(@stalagmite,2);
xopt(k)=output1(1);
yopt(k)=output1(2);
end
timezones=toc
figure(2)
subplot(2,1,1)
hold on
surf(xx,yy,f)
shading interp
plot3(xopt,yopt,fout1,'Marker','o','markersize',5,'MarkerFaceColor','r');
title('without bound')
subplot(2,1,2)
plot(fout1)
xlabel('iteration')
ylabel('maximum value')
tic
for l=1:cases
[output2,fout2(l)]=ga(@stalagmite,2,[],[],[],[],[0;0],[0.6;0.6])
xopt1(l)=output2(1);
yopt1(l)=output2(2);
end
timezones1=toc
figure(3)
subplot(2,1,1)
hold on
surf(xx,yy,f)
shading interp
plot3(xopt1,yopt1,fout2,'Marker','o','markersize',5,'MarkerFaceColor','r');
title('with bound')
subplot(2,1,2)
plot(fout2)
xlabel('iteration')
ylabel('maximum value')
options=optimoptions('ga')
options=optimoptions(options,'PopulationSize',200)
tic
for m=1:cases
[output3,fout3(m)]=ga(@stalagmite,2,[],[],[],[],[0;0],[0.6;0.6],[],[],options)
xopt2(m)=output3(1);
yopt2(m)=output3(2);
end
timezones2=toc
figure(4)
subplot(2,1,1)
hold on
surf(xx,yy,f)
shading interp
plot3(xopt2,yopt2,fout3,'Marker','o','markersize',5,'MarkerFaceColor','r');
title('with bound and population size')
subplot(2,1,2)
plot(fout3)
xlabel('iteration')
ylabel('maximum value')
FUNCION CODE:
function nandhu=stalagmite(a)
x1=a(1);
y1=a(2);
f1=[sin((5.1*pi*x1)+0.5)].^6;
f2=[sin((5.1*pi*y1)+0.5)].^6;
f3=exp((-4*log(2)*(x1-0.0667).^2)/0.64);
f4=exp((-4*log(2)*(y1-0.0667).^2)/0.64);
nandhu=-(f1*f2*f3*f4);
end
OUTPUT:[STALAGMITE]

OUTPUT:[CASE1-WITHOUT BOUND]

OUTPUT:[CASE2-WITH BOUND]

OUTPUT:[CASE3-WITH BOUND AND POPULATION]

EXPLANATION:
-First , we creating the x and y for 150 values using linespace and we are going to mesh the x , y to get xx, yy. Passing the xx and yy in staligmite function using for loop to get different values.
-After finding the xx, yy and f , We are going to surf the xx,yy and f.
-But we didn't know the maximum value of the surf. so ,we are going to the concept of the genetic algorithm.
-Using ga default in matlab, we can find the minimum value of the problem.so , we are using the different cases.
-In the first case, we are giving the iteration 50 times for ga without the bound. so, we can get the 50 values.
This method is not getting the best output for the problem.
-In the second case, we are giving the iteration and bound values. so , we can get the maximum values with in the surf. This method also not getting the best output for the problem.
-In the third case, we are giving the iteration and bound values and population size 200. so , we can get the maximum value in this method.
ERRORS AND OVERCOME:

CONCLUTION:
Finally , We created the code in MATLAB to optimise the stalagmite function and the global maxima of the function. We conclude that case 3 is the best way to find the global maxima.