Project

Program for Maximization of Stalagmite Function Using Genetic Algorithm

Genetic Algorithm :

A genetic algorithm is a method for solving both constrained and unconstrained optimization problems based on a natural selection process that is similar to the biological evolution. The algorithm repeatedly modifies a population of individual solutions. At each step the genetic algorithm randonly selects individuals from the current polpulation and uses them as parents to produce children for the next generation. Over successive generations, the population evolves towards evolves towards an optimal solution.

We can apply genetic algoritms to solve problems that are not well suited for standard optimisation algoritms including problems in which the objective function is discontinuous, non-differentiable, or highly nonlinear.

So the genetic algorithm :

1) Generates a population of points at each iteration. The best point in the population approaches an optimal solution.

2) Selects the next population by computation which uses random number generators.

3) The genetic alogorithm tool in MATLAB minimizes a function.

The negative value of the function is taken to maximize the function.

%Write a program for Maximization of Stalagmite Function
clear all
close all
clc

% Defining search space
x = linspace(0,0.6,150);
y = linspace(0,0.6,150);

%Performing stalagmite function
f = get_stalagmite(x,y);

%Number of Iterations
num_iteration = 100;

%Modifying the population size
options = optimoptions(\'ga\');
options = optimoptions(options,\'PopulationSize\',500);

tic
for i = 1:num_iteration
[inputs,fopt(i)] = ga(@stalagmite_func,2,[],[],[],[],[0;0],[1;1],[],[],options);
xopt(i) = inputs(1);
yopt(i) = inputs(2);
end
study_time = toc

%Plotting
figure(1)
subplot(2,1,1)
hold on
surfc(x,y,f)
shading interp
plot3(xopt,yopt,fopt,\'marker\',\'o\',\'markersize\',10,\'markerfacecolor\',\'b\');
title(\'Bounded Inputs\');
subplot(2,1,2)
plot(fopt)
xlabel(\'Number of Iterations\');
ylabel(\'Function Maximum\');

%Printing x and y values
fprintf(\'x : %g\\n\', inputs(1));
fprintf(\'y : %g\', inputs(2));

Stalagmite Function :--

function [fxy] = stalagmite(input_vect)
f1x = (sin((5.1*pi*input_vect(1))+0.5))^6;
f1y = (sin((5.1*pi*input_vect(2))+0.5))^6;
ln2 = 0.69314718056;
f2x = exp((-4)*ln2*(((input_vect(1)-0.0667)^2)/0.64));
f2y = exp((-4)*ln2*(((input_vect(2)-0.0667)^2)/0.64));

fxy = -f1x*f2x*f1y*f2y;
end

Get Stalagmite Function :--

function [f] = get_stalagmite(x,y)
[xx yy] = meshgrid(x,y);

for i=1:length(xx)
    for j=1:length(yy)
        input_vect(1) = xx(i,j);
        input_vect(2) = yy(i,j);
        f(i,j) = stalagmite_func(input_vect);
    end
end
end

Plots :---

\"\"

Values :---

x : 0.0668316

y : 0.0668332

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.