All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
AIM : To optimize a stalagmite function and to find the global maxima using genetic algorithm . THEORY: Genetic algorithm: Genetic algorithm is based on the mechanics of natural selection and natural genetics.It is based on the survival of the fittest theory.It simulates the process of evolution. It was developed…
Sayan Chatterjee
updated on 08 Oct 2020
AIM :
To optimize a stalagmite function and to find the global maxima using genetic algorithm .
THEORY:
Genetic algorithm:
Genetic algorithm is based on the mechanics of natural selection and natural genetics.It is based on the survival of the fittest theory.It simulates the process of evolution. It was developed by Prof. Holland , his colleagues and students at university of Michigan ,1995.
These features are not common in even sophisticated man made systems
If we come down to comparing living and artificial systems , then it boils down to a inference :
Robustness is the balance between efficiency and efficacy and it is nessecary for survival in different environmental conditions.
Goal of optimization is to keep improving the performance to reach a or some optimal points.
The following outline summarizes how the genetic algorithm works:
The algorithm begins by creating a random initial population. This is the search space.
The algorithm then creates a sequence of new populations. At each step, the algorithm uses the individuals in the current generation to create the next population. To create the new population, the algorithm performs the following steps:
Scores each member of the current population by computing its fitness value. These values are called the raw fitness scores.
Scales the raw fitness scores to convert them into a more usable range of values. These scaled values are called expectation values.
Selects members, called parents, based on their expectation.
Some of the individuals in the current population that have lower fitness are chosen as elite. These elite individuals are passed to the next population.
Produces children from the parents. Children are produced either by making random changes to a single parent—mutation—or by combining the vector entries of a pair of parents—crossover.
Replaces the current population with the children to form the next generation.
The algorithm stops when one of the stopping criteria is met.
Syntax for genetic algorithm:
The basic syntax for genetic algorithm is as follows :
clear all
close all
clc
%defining the search space
x = linspace(0,0.6,150);
y = linspace(0,0.6,150);
% creating an 2D array from the 1D array
[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
surfc(xx,yy,f)
shading interp
[x ,fval] = ga(@stalagmite,2)
function [f] = stalagmite_g(input_vector)
x=input_vector(1);
y=input_vector(2);
f1 = (sin(5.1*pi.*x+0.5).^6);
f2 = (sin(5.1*pi.*y+0.5).^6);
f3 = exp(-4*log(2).*(x-0.0667).^2/0.64);
f4 = exp(-4*log(2).*(y-0.0667).^2/0.64);
f = -(f1.*f2.*f3.*f4);
end
clear all
close all
clc
%defining the search space
x = linspace(0,0.6,150);
y = linspace(0,0.6,150);
%creating 2D array
[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_g(input_vector);
end
end
%study1_unbounded inputs
num_cases = 50 ;%setting the number of iterations to 50
tic
for i = 1:num_cases
[inputs,fopt(i)]= ga(@stalagmite_g,2);%stalagmite_g is the function
xopt(i) = inputs(1);
yopt(i) = inputs(2);
end
study_time = toc
%plotting
figure(1)
subplot(2,1,1)
surfc(xx,yy,f)
hold on
shading interp %hiding the mesh
plot3(xopt,yopt,fopt,'marker','o','markersize',5,'markerfacecolor','black')
title('Unbounded inputs')
subplot(2,1,2)
plot(fopt)
xlabel('Iteration')
ylabel('Function minimum value')
%study2_bounded inputs
tic
for j = 1:num_cases
[inputs,fopt(j)]= ga(@stalagmite_g,2,[],[],[],[],[0;0],[0.6;0.6]);%giving the upper and lower bounds
xopt(j) = inputs(1);
yopt(j) = inputs(2);
end
study_time = toc
figure(2)
subplot(2,1,1)
surfc(xx,yy,f)
hold on
plot3(xopt,yopt,fopt,'marker','o','markersize',5,'markerfacecolor','black')
title('bounded inputs')
shading interp
subplot(2,1,2)
plot(fopt)
xlabel('Iteration')
ylabel('Function minimum value')
%study3_increasing population
num_cases = 50; %setting the number of iterations to 50
options = optimoptions('ga');
options = optimoptions(options,'populationsize',200);
tic
for k = 1:num_cases
[inputs,fopt(k)]= ga(@stalagmite_g,2,[],[],[],[],[0;0],[0.6;0.6],[],[],options);
xopt(k) = inputs(1);
yopt(k) = inputs(2);
end
study_time = toc
figure(3)
subplot(2,1,1)
surfc(xx,yy,f)
hold on
plot3(xopt,yopt,fopt,'marker','o','markersize',5,'markerfacecolor','black')
title('bounded inputs with more population size')
shading interp
subplot(2,1,2)
plot(fopt)
xlabel('Iteration')
ylabel('Function minimum value')
CODING EXPLANATION:
By using the linspace command the search space is created for x and y . An array is created for the x and y values.
A 2D array is created using the meshgrid command ;
No of itaretions is set to 50 as num_cases = 50;
We use the tic and toc command to estimate the time taken for optimisation
A for loop is executed for running the optimization
we call the stalagmite_g function coded ago and there are two variables. This is for the unbounded case study.
We create a separate figure, To have multiple plots inside the same figure we use the subplot command . surfc is used to create the surface .To hide the mesh, shading interp command is used. Plot 3 command is used to plot the xoptimum value, yoptimum value and the optimum value of the fitness function .
Same procedure is followed for the bounded inputs and the bounded inputs with more population size study, only difference is the bounds given.
OUTPUT :
The plot for the unbounded case is as below:
we see here our results are all over the place . It is not at all that helpful .
The plot for the bounded inputs case study is as follows :
This time it is much more specific . but now we increase the population size .
Now we can see it is more or less uniform with only one rise .
CONCLUSION:
REFERENCES:
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...
Week 8 - Simulation of a backward facing step in OpenFOAM
Objective: To simulate an incompressible-laminar-viscous flow through the backward facing step geometry. To perform a transient simulation. The solver can be chosen based on the described physics of the flow. To explain the entire simulation procedure (how you set up the case). Procedure: To choose the solve To Set up…
14 Mar 2024 12:12 PM IST
Week 11- Broadband Noise modelling over Ahmed body
Introduction: The Ahmed body is a geometric shape proposed by Ahmed and ram in 1984. The shape provides a model to study geometric effect on wakes of ground vehicles. The Ahmed Body was first created by S.R. Ahmed in his research “Some Salient Features of the Time-Averaged Ground Vehicle Wake” in 1984.…
16 Aug 2021 06:54 PM IST
Week 8- Moving zones approach in Fluent
There are two types of motion encountered in fluid flow, they are rectilinear and rotary. There are two approaches to model rotary motion: Moving reference frame Moving mesh appraoch. Moving refernce frame: A Moving Reference Frame (MRF) is a relatively simple, robust, and efficient steady-state, Computational fluid…
22 Jul 2021 07:43 PM IST
Week 5 - Turbulence modelling challenge
Turbulence : Introduction: Turbulence is an irregular motion which in general makes its appearwnce in fluids, gases or liquids, when they flow past solid surfaces or even when neighbouring streams of same flow past or over one another. Turbulent fluid motion is an irregular condition of flow in which various quantities…
20 Jul 2021 09:30 PM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.