Project

OPTIMIZATION OF STALAGMITE FUNCTION USING GENETIC ALGORITHM

INTRODUCTION TO THE OPTIMIZATION AND STALAGMITE FUNCTION USING GENTIC ALGORITHM.

Optimization: Optimization is the process ,where we find the optimal and the maximum values in the particular problem after a certain iterations. in other words we can say that optimiztion is the area of the study where it deals with the maximum and minimum values of the function.

eg: Suppose the air foil of the aeroplane wing must provide the certain lift to the plane so that the plane can have higher lift and the minimum drag so,to find the certain combination we need to do certain itterations to find the point by making changes in the design. To make it ease and to save the time we use the stalgamite function to plot the graphs wich shows the maximum and optimum values.

stalagmite Function: stalagmite function is the mathematical model which plots the local maxima and the local minima in the 3-D view. this function is designed to show the global mxima and global minima in the 3-D plot.

Genetic Alogorithm: Genetic algorithm is the way of developing the different random solutions at first and takes the random samples as the parents for the new genration and develops the results.Making this we can get the optimum results. the genetic algorithm gives the minimum results,by making some adjustments in the code we can make it to display the local maxima.

Genetic Algorithm follows three rules

1. Selection- selecting the parents for the next generation

2.Cross over- combing the parents to form new generation

3.Mutation- random changes in parents

The code to find the Global maxima and optimization of the stalagmite function was:

clear all
close all
clc

% Define search space
x = linspace(0,0.6,150);
y = linspace(0,0.6,150);
num_cases = 50;

% Creating a 2Dimensional 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

% Study 1 - Statistical behaviour
tic
for i = 1:num_cases
    [inputs,fopt(i)] = ga(@stalagmite, 2);
    xopt(i) = inputs(1);
    yopt(i) = inputs(2);
end

study1_time = toc;

figure(1)
subplot(2,1,1)
hold on
surfc(xx,yy,f)
shading interp
title(\'Unbounded Inputs\')
xlabel(\'X value\')
ylabel(\'Y value\')
plot3(xopt,yopt,fopt,\'marker\',\'o\',\'markersize\',6,\'markerfacecolor\',\'r\')
subplot(2,1,2)
plot(fopt)
xlabel(\'Iterations\')
ylabel(\'Function maximum\')

% Study 2 - Statistical behaviour with upper and lower bounds
tic
for i = 1:num_cases
    [inputs, fopt(i)] = ga(@stalagmite,2,[],[],[],[],[0;0],[1;1]);
    xopt(i) = inputs(1);
    yopt(i) = inputs(2);
end
study2_time = toc

figure(2)
subplot(2,1,1)
hold on
surfc(xx,yy,f)
shading interp
title(\'Bounded Inputs\')
xlabel(\'X value\')
ylabel(\'Y value\')
plot3(xopt,yopt,fopt,\'marker\',\'o\',\'markersize\',6,\'markerfacecolor\',\'r\')
subplot(2,1,2)
plot(fopt)
xlabel(\'Iterations\')
ylabel(\'Function maximum\')

% Study 3 - Increasing GA Iterations
options = optimoptions(\'ga\')
options = optimoptions(options,\'PopulationSize\', 170)

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

study3_time = toc
figure(3)
subplot(2,1,1)
hold on
surfc(xx,yy,f)
shading interp
title(\'Bounded Inputs with modified population size\')
xlabel(\'X value\')
ylabel(\'Y value\')
plot3(xopt,yopt,fopt,\'marker\',\'o\',\'markersize\',6,\'markerfacecolor\',\'r\')
subplot(2,1,2)
plot(fopt)
xlabel(\'Iterations\')
ylabel(\'Function maximum\')
hold off

max_value = fopt;

code for the stalagmite function was

function [f] = stalagmite(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

case1:

by executing the following code

tic
for i = 1:num_cases
    [inputs,fopt(i)] = ga(@stalagmite, 2);
    xopt(i) = inputs(1);
    yopt(i) = inputs(2);
end

study1_time = toc;

figure(1)
subplot(2,1,1)
hold on
surfc(xx,yy,f)
shading interp
title(\'Unbounded Inputs\')
xlabel(\'X value\')
ylabel(\'Y value\')
plot3(xopt,yopt,fopt,\'marker\',\'o\',\'markersize\',6,\'markerfacecolor\',\'r\')
subplot(2,1,2)
plot(fopt)
xlabel(\'Iterations\')
ylabel(\'Function maximum\')

Results:

\"\"

Case Discussion:

From the above results we can say that the result that was ploted in the was difficult to understand and the value was lying beyond zero. to optimise the result and get a clean graph to understand we do the second case by defining the boundary.

Case2:

code for the case 2

% Study 2 - Statistical behaviour with upper and lower bounds
tic
for i = 1:num_cases
    [inputs, fopt(i)] = ga(@stalagmite,2,[],[],[],[],[0;0],[1;1]);
    xopt(i) = inputs(1);
    yopt(i) = inputs(2);
end
study2_time = toc

figure(2)
subplot(2,1,1)
hold on
surfc(xx,yy,f)
shading interp
title(\'Bounded Inputs\')
xlabel(\'X value\')
ylabel(\'Y value\')
plot3(xopt,yopt,fopt,\'marker\',\'o\',\'markersize\',6,\'markerfacecolor\',\'r\')
subplot(2,1,2)
plot(fopt)
xlabel(\'Iterations\')
ylabel(\'Function maximum\')

Result:

By executing the above code we get the result as

\"\"

Case Discussion:

from the above results we can see that by defining the limits/boundaries for the problem we are getting global maxima result between the four points by increasing the popultion size to200 so that we can get the accurate and precise results.

Case3:

code for the case study 3

% Study 3 - Increasing GA Iterations
options = optimoptions(\'ga\')
options = optimoptions(options,\'PopulationSize\', 170)

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

study3_time = toc
figure(3)
subplot(2,1,1)
hold on
surfc(xx,yy,f)
shading interp
title(\'Bounded Inputs with modified population size\')
xlabel(\'X value\')
ylabel(\'Y value\')
plot3(xopt,yopt,fopt,\'marker\',\'o\',\'markersize\',6,\'markerfacecolor\',\'r\')
subplot(2,1,2)
plot(fopt)
xlabel(\'Iterations\')
ylabel(\'Function maximum\')
hold off

max_value = fopt;

Results:

\"\"

Case Discussion:

in this case 3 we have used the used the \"optimoptionssolver \" function to identify the global maxima accurately.in this case we can see that the results were acurate and more precise than the above case.

Cnclusion:

GA(genetic Algorithm) is the function that can be used find the global maxima and the global minima and making the calculations simpler for the designers.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.