clear all
close all
clc
%Defining search space
x= linspace(0,0.6,150);
y= linspace(0,0.6,150);
%Creating a 2D mesh
[xx yy] = meshgrid(x,y);
%Evaluation of 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
% Number of iterations
num_cases = 50;
%Optimization of Stalagmite function for Global Maxima
% Study 1- Statistical Behaviour
tic
thestate = rng
for i=1:num_cases
[inputs1, fval1(i)] = ga(@stalagmite, 2);
xopt1(i) = inputs1(1);
yopt1(i) = inputs1(2);
end
rng(thestate);
study1_time = toc
figure(1)
subplot(2, 1, 1)
hold on
surfc(xx, yy, -F)
xlabel('X-value')
ylabel('Y-value')
shading interp
% to plot the markers on the optimum function value points
plot3(xopt1, yopt1, -fval1, 'Marker','o','MarkerSize',5,'MarkerFaceColor','r')
title('Study 1: Unbounded Inputs')
subplot(2, 1, 2)
plot(-fval1)
xlabel('Iterations')
ylabel('Function Maxima')
tic
%study 2- statistical behaviour with bounded inputs
tic
thestate=rng;
for i=1:num_cases
[inputs2, fval2(i)] = ga(@stalagmite,2, [], [], [], [], [0.6; 0.6]);
xopt2(i) = inputs2(1);
yopt2(i) = inputs2(2);
end
rng(thestate);
figure(2)
subplot(2, 1, 1)
hold on
surfc(xx, yy, -F)
xlabel('X-value')
ylabel('Y-value')
shading interp
% to plot the markers on the optimum function value points
plot3(xopt2, yopt2, -fval2, 'Marker','o','MarkerSize',5,'MarkerFaceColor','r')
title('Study 2: Unbounded Inputs')
subplot(2, 1, 2)
plot(-fval2)
xlabel('Iterations')
ylabel('Function Maxima')
study2_time = toc
% study 3- Increasing population size
options = optimoptions('ga','PopulationSize',180)
tic
thestate = rng;
for i= 1:num_cases
[inputs3, fval3(i)] = ga(@stalagmite, 2, [], [], [], [], [0;0], [0.6;0.6], [], [], options);
xopt3(i) = inputs3(1);
yopt3(i) = inputs3(2);
end
rng(thestate);
figure(3)
subplot(2, 1, 1)
hold on
surfc(xx, yy, -F)
xlabel('X-value')
ylabel('Y-value')
shading interp
% to plot the markers on the optimum function value points
plot3(xopt3, yopt3, fval3, 'Marker','o','MarkerSize',5,'MarkerFaceColor','r')
title('Study 3: Unbounded Inputs with given population size')
subplot(2, 1, 2)
plot(-fval3)
xlabel('Iterations')
ylabel('Function Maxima')
study3_time = toc
[Max Iva1] = max(abs(fval3))
function[F] = stalagmite(input_vector)
x1= input_vector(1);
y1 = input_vector(2);
f1_x= (sin(5.1*pi*x1+0.5)).^6;
f2_x = exp(-4*log(2).*((x1-0.0667)^2)/0.64);
f1_y = (sin(5.1*pi*y1+0.5)).^6;
f2_y = exp(-4*log(2).*((y1-0.0667)^2)/0.64);
F = -(f1_x.*f2_x.*f1_y.*f2_y);
end


