main program
close all
clear all
clc
%defining th workspace.
x=linspace(0,0.6,150);
y=linspace(0,0.6,150);
numcase=50;
F=get_stalagmite_func(x,y);
% Creating a 2 dimensional array
[xx , yy]=meshgrid(x,y);
% Evaluating stalgamite function
for i=1:lenght(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
figure(1)
surfc(xx,yy,-F)
shading interp
[inputs, fval]=ga(@stalagmite,2);
% Case study 1
tic
for i=1:numcase
[inputs,fopt(i)]=ga(@stalagmite,2);
xopt(i)=inputs(1);
yopt(i)=inputs(2);
end
study_time1=toc;
%Plotting
figure(2)
subplot(2,1,1)
hold on
surf(x,y,-F)
shading interp
plot3(xopt,yopt,fopt,'marker','o','markersixe',3,'markerfacecolor','r')
title('bounded input')
subplot(2,1,2)
plot(fopt)
xlabel('iteration')
ylabel('F maximum')
%case_study2 giving the lower and upper bound conditions
tic
for i=1:numcase
[inputs,fopt(i)]=ga(@stalagmite,2,[],[],[],[],[0;0],[1;1]);
xopt(i)=inputs(1);
yopt(i)=inputs(2);
end
study_time2=toc;
%plotting
figure(3)
subplot(2,1,1)
hold on
surfc(x,y,F)
shadinginterp
ploy3(xopt,yopt,fopt,'maker','o','markersize',3,'markerfacecolor','r')
title('bounded inputs')
subplot(2,1,2)
plot(fopt)
xlabel('iteration')
ylabel('F maximum')
% study-3 Increasing the ga Iteration
options=optimoptions('ga');
options=optimoptions(options,'populationsize',170);
tic
for i=1:numcase
[inputs,fopt(i)]=ga(@stalagmite,2,[],[],[],[],[0;0],[1,1],[],[],options);
xopt(i)=inputs(1);
yopt(i)=inputs(2);
end
study_time3=toc;
%plotting
figure(4)
subplot(2,1,1)
hold on
surfc(x,y,F)
shading interp
plot3(xopt,yopt,fopt,'marker','o','markersize',3,'markerfacecolor','r')
title('bounded inputs')
subplot(2,1,2)
plot(fopt)
xlabel('iteration')
ylabel('F maximum')
% program of function
function [F]= stalagmite_func(input_vector)
x=input_vector(1);
y=input_vector(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.667).^2)./0.64));
f2y=exp(-4*(log(2))*(((y-0.667).^2)./0.64));
f=-(f1x*f1y*f2x*f2y);
F=1/(1+f);
end