All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
AIM: OPTIMIZATION OF STALAGMITE FUNCTION USING GENETIC ALGORITHM. THEORY AND GOVERNING EQUATIONS: Stalagmite Function: Stalagmite is a type of rock formation that rises from the floor of a cave due to the accumulation of material deposited on the floor from ceiling drippings. …
NAVEEN SWAMI
updated on 09 May 2020
AIM: OPTIMIZATION OF STALAGMITE FUNCTION USING GENETIC ALGORITHM.
THEORY AND GOVERNING EQUATIONS:
Stalagmite Function: Stalagmite is a type of rock formation that rises from the floor of a cave due to the accumulation of material deposited on the floor from ceiling drippings.
A stalagmite function is similar to stalagmite which consists of several peaks in its domain. The local peaks are local maxima region while there is only one global peak i.e. global maxima. In this project, we are interested in finding this global maximum of a stalagmite function.
The mathematic definition of stalagmite function is,
OBJECTIVE:
WHAT IS GENETIC ALGORITHM?
Genetic Algorithm is an optimization technique which is based on natural selection i.e. the process that drives biological evolution. It can be used for both constrained and unconstrained optimization problems. The genetic algorithm repeatedly modifies a population of individual solutions. At each step, the genetic algorithm selects individuals at random 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.
HOW GENETIC ALGORITHM WORKS?
Let’s take a hypothetical situation in which the ruling government of a country decide to remove all bad people from the country.
To make this happen, the government comes up the following policy which states that:
So by using biological evolution, the government came to find the solution to the problem.
So basically,
This is how the genetic algorithm actually works, which basically tries to mimic human evolution to some extent.
STEPS INVOLVED IN GENETIC ALGORITHM:
1. Initialization: To solve this problem using a genetic algorithm, our first step would be defining our population.
2. Fitness function: The fitness function is the function you want to optimize. For standard optimization algorithms, this is known as the objective function.
3. Selection: Now, we select the parent species from our population which can mate and produce off-springs. The general thought is that we should select the fit members and allow them to produce off-springs. But that would lead to a population that is more close to one another in a few next generations, and therefore less diversity. Therefore, the selection is completely random.
4. Crossover: So in this previous step, we have selected parent chromosomes that will produce off-springs. So in biological terms, crossover is nothing but reproduction.
5. Mutation: During the growth of children, there is some change in the genes of children which makes them different from its parents. This process is known as mutation, which may be defined as a random tweak in the chromosome, which also promotes the idea of diversity in the population.
The off-springs thus produced are again validated using our fitness function, and if considered fit then will replace the less fit chromosomes from the population. This process continues until there is no improvement in the population and finally we obtain an optimized solution.
SYNTAX OF GA IN MATLAB:
func = fitness function(objective function), nvars = no. of variables in fitness function
MAIN CODE:
%to find global maxima of a slalagmite function
clear all
close all
clc
%creating 1-D array
xi=linspace(0,0.6,150);
yi=linspace(0,0.6,150);
%creating 2-D array
[xx yy]=meshgrid(xi,yi);
%Getting output from stalagmite function and storing it
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)=slalagmite(input_vector);
end
end
% STUDY:1 Unbound input values
iterations=100;
tic
for i=1:iterations
[input1, f_val1(i)]= ga(@slalagmite, 2);
x1(i)=input1(1);
y1(i)=input1(2);
end
time1=toc;
%plotting unbound iteration case
figure(1)
subplot(2,1,1)
surfc(xx,yy,-f);
shading interp;
hold on;
plot3(x1,y1,-f_val1,'marker','*');
title('Study1: unbound input values');
xlabel('x_input');
ylabel('y_input');
zlabel('Z_value');
subplot(2,1,2)
plot(-f_val1);
axis([0,100,0,1]);
xlabel('iterations');
ylabel('z_max_1');
%STUDY:2 bounding input values
tic
for i=1:iterations
[input2, f_val2(i)]= ga(@slalagmite, 2,[],[],[],[],[0;0],[1;1]);
x2(i)=input2(1);
y2(i)=input2(2);
end
time2=toc;
%plotting bound iteration case
figure(2)
subplot(2,1,1)
surfc(xx,yy,-f);
shading interp;
hold on;
plot3(x2,y2,-f_val2,'marker','*');
title('Study2: bounding input values');
xlabel('x_input');
ylabel('y_input');
zlabel('Z_value');
subplot(2,1,2)
plot(-f_val2);
axis([0,100,0,1]);
xlabel('iterations');
ylabel('z_max_2');
%STUDY:3 Bounding input with increased poplation size
opti=optimoptions('ga');
opti=optimoptions(opti,'PopulationSize',350);
tic
for i=1:iterations
[input3, f_val3(i)]= ga(@slalagmite, 2,[],[],[],[],[0;0],[1;1],[],[],opti);
x3(i)=input3(1);
y3(i)=input3(2);
end
time3=toc;
time1
time2
time3
x_optimum=x3(1)
y_optimum=y3(1)
z_optimum=-f_val3(1)
%plotting with increased population
figure(3)
subplot(2,1,1)
surfc(xx,yy,-f);
shading interp;
hold on;
plot3(x3,y3,-f_val3,'marker','*');
title('Study3: bounding input with increased population');
xlabel('x_input');
ylabel('y_input');
zlabel('Z_value');
subplot(2,1,2)
plot(-f_val3);
axis([0,100,0,1]);
xlabel('iterations');
ylabel('z_max_3');
FUNCTION USED:
function z = slalagmite(input)
x=input(1);
y=input(2);
fx_1 = (sin((5.1*pi.*x) + 0.5)).^6;
fx_2 = exp((-4*log(2).*((x-0.0667).^2))./0.64);
fy_1 = (sin((5.1*pi.*y) + 0.5)).^6;
fy_2 = exp((-4*log(2).*((y-0.0667).^2))./0.64);
z = -fx_1.*fx_2.*fy_1.*fy_2;
end
STEPS:
1. Using 'linspace', xi and yi 1D array generated to form 2D matrix.
2. Using 'meshgrid' command, a 2D set of input matrix was generated.
3. Each pair of xx and yy was given as an argument to stalagmite function which calculates the z value for it.
4. The output values are stored in f matrix.
5. study 1: for 100 iterations, genetic algorithm was executed to find minimum values (note: we have defined stalagmite function as negative so mini value in it is max. value in positive stalagmite function) of function.
6. figure(1) was plotted for study 1, in which we create subplot to divide the figure window.
7. In figure1, max value of Z was plotted against no. of iterations and also a 3D plot of all mini value points were plotted.
8. study:2 using input bound syntax of GA, we can see the result's accuracy is increased.
9. study: 3 by increasing the population size, we get the optimized result.
ERROR FACED: no error encountered
OUTPUT:
Figure1
Figure 2
figure 3
REFERENCES:
https://in.mathworks.com/help/gads/how-the-genetic-algorithm-works.html
https://www.analyticsvidhya.com/blog/2017/07/introduction-to-genetic-algorithm/
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
MBD Simulation on IC Engine Valve Train
AIM: MOTION ANALYSIS OF IC ENGINE VALVE TRAIN MECHANISM THEORY: Valve Train is a mechanical system in an IC engine that is responsible for controlling the intake and the exhaust of the combustion process. During the intake process, the intake valve opens to let air enter the combustion chamber and during the exhaust process,…
21 Jun 2020 08:00 AM IST
MOTION ANALYSIS OF IC ENGINE PISTON ASSEMBLY MECHANISM
AIM: MOTION ANALYSIS OF IC ENGINE PISTON ASSEMBLY MECHANISM. THEORY: In IC Engine, the combustion is driven by Slider Crank Mechanism. Inside the cylinder, the piston performs reciprocating motion which results in compression and expansion of gas inside the cylinder. This motion of the piston is guided by the Slider Crank…
18 Jun 2020 06:12 AM IST
MOTION ANALYSIS OF PLANETARY GEAR SYSTEM
AIM: MOTION ANALYSIS OF PLANETARY GEAR SYSTEM THEORY: A planetary gear mechanism also is known as Epicyclic Gear Train, is a gear mechanism consisting of 4 components, namely, sun gear A, several planet gears B, internal gear(ring gear) C and carrier D that connects planet gears as seen in the image below. It has a very…
11 Jun 2020 11:28 AM IST
MULTI-BODY DYNAMICS SIMULATION OF INTERNAL GENEVA MECHANISM IN SOLIDWORKS
AIM: MULTI-BODY DYNAMICS SIMULATION OF INTERNAL GENEVA MECHANISM IN SOLIDWORKS. THEORY: Geneva mechanism is the mechanism through which continuous rotation motion is converted into intermittent rotation motion. In this, the driver wheel rotates continuously and the driven wheel has rotation in regular intervals not continuously.…
02 Jun 2020 09:49 AM IST
Related Courses
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.