All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Aim :- To study the genetic algorithm & finding the global maxima of the function. Theory:- In computer science and operations research, a genetic algorithm (GA) is a metaheuristic inspired by the process of natural selection that belongs to the larger class of evolutionary…
Sachin Barse
updated on 02 Jun 2022
Aim :- To study the genetic algorithm & finding the global maxima of the function.
Theory:- In computer science and operations research, a genetic algorithm (GA) is a metaheuristic inspired by the process of natural selection that belongs to the larger class of evolutionary algorithms (EA). Genetic algorithms are commonly used to generate high-quality solutions to optimization and search problems by relying on biologically inspired operators such as mutation, crossover and selection.
Five phases are considered in a genetic algorithm.
The process begins with a set of individuals which is called a Population. Each individual is a solution to the problem you want to solve.
An individual is characterized by a set of parameters (variables) known as Genes. Genes are joined into a string to form a Chromosome (solution).
In a genetic algorithm, the set of genes of an individual is represented using a string, in terms of an alphabet. Usually, binary values are used (string of 1s and 0s). We say that we encode the genes in a chromosome.
The fitness function determines how fit an individual is (the ability of an individual to compete with other individuals). It gives a fitness score to each individual. The probability that an individual will be selected for reproduction is based on its fitness score.
The idea of selection phase is to select the fittest individuals and let them pass their genes to the next generation.
Crossover is the most significant phase in a genetic algorithm. For each pair of parents to be mated, a crossover point is chosen at random from within the genes.
In certain new offspring formed, some of their genes can be subjected to a mutation with a low random probability. This implies that some of the bits in the bit string can be flipped.
Matcode to solve the problem:-
% To solve the genetic algorithm equation for three studies
clear all
close all
clc
% Independent variable
x= linspace(0,0.5,150);
y= linspace(0,0.6,150);
%matrix
[xx,yy] = meshgrid(x,y);
% Number of iterations
num_cases = 50;
% starting the loop
for i = 1:length(xx);
for j=1:lenght(yy)
input_vector(1) = xx(i,j);
input_vector(2) = yy(i,j);
f(i,j) = stalagmite(input_vector);
end
% Create a three dimensional surface
figure(1)
surfc(xx,yy,-f)
shading interp %makes the surface look more smoother
xlabel('x value')
ylabel('y label')
title('Stalagmite Function')
% case 1 study
tic
for i=1:num_cases
[inputs,fopt(i)] = ga(@stalagmite,2);
xopt(i)= inputs(1);
yopt(i)= inputs(2);
end
% case_1 = toc
figure(2)
subplot(2,1,1)
hold on
surfc(x,y,-f)
title('Unbounder inputs')
xlabel('x value')
ylabel('y value')
shading interp
hold on
plot3(xopt,yopt,-fopt,'marker','o','Markersize',5,'Markerfacecolor','r')
subplot(2,1,2)
plot(-fopt)
xlabel('iterations')
ylabel('function maximun')
% case 2nd with upper and lower bounds
tic;
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
% case_2_time = toc
figure(3)
subplot(2,1,1)
surfc(x,y,-f)
shading interp
title('Bounded inputs')
xlabel('x value')
ylabel('y value')
hold on
plot3(xopt,yopt,-fopt,'marker','o','markersize',5,'markerfacecolor','r')
subplot(2,1,2)
xlabel('iterations')
ylabel('function maximun')
% case study 3 increasing the population size
% by doing so we are increasing the probability of the function
% to converge at global maximum
options = optimoptions(@ga)
options = options(@ga,'Populationsize',500)
% increasing the population size
tic
for i=1:num_cases
[inputs,fopt(i)] = ga(@stalagmite,2,[],[],[],[],[0;0],[0.6;0.6],[],[],options);
xopt(i) = inputs(1);
yopt(i) = inputs(2);
end
% case_3_time = toc
%gives the time taken for study
figure(4)
subplot(2,1,1)
surfc(x,y,-f)
%creates a surface to visualise 3D
shading interp
title('bounded inputs with increased population size')
xlabel('x value')
ylabel('y value')
hold on
plot3(xopt,yopt,-fopt,'markersize',4,'markerfacecolor','r')
subplot(2,1,2)
plot(-fopt)
%plotting -f vs number of iterations
xlabel('iterations')
ylabel('funation maximun')
Function code to solve the equation:-
% function code
function[f] = stalagmite (input_vector);
a = input_vector(1);
b = input_vector(2);
term1 = (sin((5.1*pia)+0.5))^6;
term2 = exp(-4*log(2)*((a-0.0667)^2)/0.64);
term3 = (sin((5.1*pi*b)+0.5))^6;
term2 = exp((-4)*log(2)*((b-0.0667)^2)/0.64);
[f] = (term1*term2*term3*term4);
%inverts the objective function
end
Grapical output of program:-
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...
FINAL INDEPENDENT PROJECT
Project : Design & Animate the drone camera for project model. Attached Link For Model Review : https://drive.google.com/file/d/1f6sjaJc6Od2AEnmh-JYFFoLMmUveWk61/view?usp=drive_link
15 May 2024 05:42 PM IST
Week - 4
AIM: Implement control logic of a “washing machine” using Stateflow as per given sequence: If the power supply is available, the system gets activated. If the Water supply is not available, stop the process & indicate through LED Soaking time should be 200s followed by Washing…
13 Mar 2024 10:27 AM IST
Week -2
1.Door Bell Simulink Model: Simulink Model Explanation: The pulse generator is used to create square wave pulses at regular intervals.The block waveform parameters Amplitude,pulse width,period and phase delay,determine the shape of the output waveform. …
12 Mar 2024 12:23 PM IST
Project 1
Attached Model for Project :- Attached link for grading :- https://drive.google.com/file/d/13bjiEKi2h1sYtm9LzZMouMksFAZYnVIQ/view?usp=drive_link
29 Oct 2023 11:00 AM 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.