Aim :- To calculate the global maxima of stalagmite function
Objective
- code the stalagmite function in matlab.
- Optimize stalagmite function and find the global maxima of the function.
- study 3 case of options of genetic Algorithm 'ga' in matlab.
Equation of governing
Genetic algorithm :-
The genetic algorithm is a method for solving both constrained and unconstrained optimization problems that is based on natural selection, the process that drives biological evolution. The genetic algorithm repeatedly modifies a population of individual solutions. At each step, the genetic algorithm selects individuals from the current population to be parents and uses them 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 a variety of optimization problems that are not well suited for standard optimization algorithms, including problems in which the objective function is discontinuous, nondifferentiable, stochastic, or highly nonlinear. The genetic algorithm can address problems of mixed integer programming, where some components are restricted to be integer-valued.
This flow chart outlines the main algorithmic steps

The genetic algorithm uses three main types of rules at each step to create the next generation from the current population:
-
Selection rules select the individuals, called parents, that contribute to the population at the next generation. The selection is generally stochastic, and can depend on the individuals' scores.
-
Crossover rules combine two parents to form children for the next generation.
-
Mutation rules apply random changes to individual parents to form children.

Syntax for Genetic Algorithm ('ga') :
:- x=ga(fun,nvars): finds a local unconstrained minimum x, to the objective functions, 'fun.navars' is the dimension of 'fun'(function).
:- x=ga(fun,nvars,a, b lb, ub,intcon,option)requires that the variables listed in 'intcon'take integer values.
where, 'x' is the output
'ga' is the genetic algorithm.
'func' is the function.
'a' real matrix
'b' is the real vector
'lb' is the lower bond
'ub' is the uper bond
'intcon' is the positive intregal
'option' is the optimazation option
Main program of genetic Algorithms
clear all
close all
clc
% Defining our search sapce
x = linspace(0,0.6,150);
y = linspace(0,0.6,150);
num_cases = 50;
% f = stalagmite(x,y);
% Creating the 2 Dimentional mesh
[xx, yy] = meshgrid(x,y);
% Evaluating the 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
figure(1)
surfc(xx,yy,f);
xlabel('x value')
ylabel('y value');
shading interp
%
tic
% study 1 - statistical beheviour
for i = 1:num_cases
[inputs, fopt(i)] = ga(@stalagmite,2);
xopt(i) = inputs(1);
yopt(i) = inputs(2);
end
study_time1 = toc;
figure(2)
subplot(2,1,1);
surfc(x,y,-f);
shading interp
hold on
plot3(xopt,yopt,-fopt,'marker','o','markerSize',5,'MarkerFaceColor','r')
title('unbounded inputs')
subplot(2,1,2)
plot(-fopt)
xlabel('iterations')
ylabel('funcation maximum')
% Stalagmite Mathematical model
tic
%study 2 - statistical behaviours with uper and lower bounds
for i= 1:num_cases
[inputs, fopt(i)] = ga(@stalagmite,2,[],[],[],[],[0;0],[0.6;0.6]);
xopt(i) = inputs(1);
yopt(i) = inputs(2);
end
study_time2 = toc
figure(3)
subplot(2,1,1)
hold on
surfc(x,y,-f);
shading interp
plot3(xopt,yopt,-fopt,'marker','o','markerSize',5,'MarkerFaceColor','r')
title('unbounded inputs')
subplot(2,1,2)
plot(-fopt)
xlabel('iterations')
ylabel('funcation maximum')
% study 3 increasing ga iterations
options = optimoptions('ga')
options = optimoptions(options,'PopulationSize',500);
tic
for i= 1:num_cases
[inputs, fopt(i)] = ga(@stalagmite,2,[],[],[],[],[0;0],[0.1;0.1],[],[],options);
xopt(i) = inputs(1);
yopt(i) = inputs(2);
end
study_time3 = toc
figure(4)
subplot(2,1,1)
hold on
surfc(x,y,-f);
shading interp
plot3(xopt,yopt,-fopt,'marker','o','markerSize',5,'MarkerFaceColor','r')
title('bunded inputs with increasing ga')
subplot(2,1,2)
plot(-fopt)
xlabel('iterations')
ylabel('funcation maximum')
function program
function A = stalagmite(input_vector)
x = input_vector(1);
y = input_vector(2);
f1 = (sin(5.1*pi*x +0.5)).^6;
f2 = exp(-4*log(2)*((x-0.0667)^2)/(0.64));
f3 = (sin(5.1*pi*y +0.5)).^6;
f4 = exp(-4*log(2)*((y-0.0667)^2)/(0.64));
A = -(f1*f2*f3*f4);
end
statistical beheviour global maxima
study 1 - statistical beheviour
study 2- statistical behaviours with uper and lower bounds
study 3 - increasing ga iterations
workspace result when a study time 1,2,3
Referances :-
Conclusion :- Stalagmite function is coded in matlab is the global maxima of the function is found use genetic algorithm 'ga' in MATLAB.