Project

To write a program to show global maxima and minima of a stalagmite function using genetic algorithm in MATLAB.

OBJECTIVE

1.To write a program in MATLAB to optiise athe stalagmite function and find global maxima.

2.To explain the Genetic Algorithm and syntex in MATLAB.

3.To plot the studies of all graphs.

THEORY

A mound or tapering column rising from the floor of a cave, formed of calcium salts deposited by dripping water and often uniting with a stalactite.

GENETIC ALGORITHM

The genetic algorithm is a method for solving both constrained and unconstrained optimization problems that is based on natural selection, the process that drives biological evolution. 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. You can apply the genetic algorithm to solve a variety of optimization problems that are not well suited for standard optimization algorithms, including problems in which the objective function is discontinuous, nondifferentiable, stochastic, or highly nonlinear. The genetic algorithm can address problems of mixed integer programming, where some components are restricted to be integer-valued.

MATHEMATICAL EQUATION

To find Global Minima:`f=(f1*f2*f3*f4)`

To find global Maxima:`f=-(f1*f2*f3*f4)`

where

`f1=[sin(5.1pix+0.5)]^6`

`f2=[sin(5.1pix+0.5)]^6`

`f3=exp[-4log(2)-(x-0.667)^2/0.64]`

`f4=exp[-4log(2)-(y-0.667)^2/0.64]`

here x and y are two variables

PROGRAM

FOR PLOTTING GLOBAL Minima

clear all
close all
clc

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

%creating two dimensional mesh
[xx, yy]=meshgrid(x,y);

%evaluating 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_func(input_vector);
     
  end
end


surfc(xx, yy ,f)
shading interp

xlabel('x value')
ylabel('y value')
zlabel('z value')


[x_output,fval]= ga(@stalagmite_func,2);

FUNCTION

function stalagmite = stalagmite_func (input_vector)
  x = input_vector (1)
  y = input_vector (2)
  f1_x = (sin (5.1 * pi * x + 0.5)) .^ 6;
  f2_y = (sin (5.1 * pi * y + 0.5)) .^ 6;
  f3_x = exp ((-4 * 0.6931) .* (x - 0.0667) .^ 2 / (0.64));
  f4_y = exp ((-4 * 0.6931) .* (y - 0.0667) .^ 2 / (0.64));
  stalagmite = (f1_x .* f2_y .* f3_x .* f4_y)
end

CODE TO FIND OUT GLOBAL MAXIMA USING GENETIC ALGORITHM AND PLOT THE FIGURE

close all
clear all
clc

%defining our search space
%one dimension
x=linspace(0,0.6,150);
y=linspace(0,0.6,150);
num_cases=50
%2 dimension
[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)=get_stalagmite(input_vector);
  
    end
end

%study_1 stastical behaviour

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


figure (1) 
subplot(2,1,1)
hold on
surfc(xx,yy,f)
shading interp
plot3(xopt,yopt,fopt,'marker','o','markersize',5,'markerfacecolor','r')
title('unbounded inputs')
subplot(2,1,2)
plot(fopt)
xlabel('iteration')
ylabel('function miximum')

%bounding the values

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

figure (2)
subplot(2,1,1)
hold on
surfc(xx,yy,f)
shading interp
plot3(xopt,yopt,fopt,'marker','o','markersize',5,'markerfacecolor','r')
title('unbounded inputs')
subplot(2,1,2)
plot(fopt)
xlabel('iteration')
ylabel('function miximum')

%study_3 bounding the values and increasing population size
tic
for i=1:num_cases
  [inputs,fopt(i)]=ga(@get_stalagmite,2,[],[],[],[],[0:0],[1:1])
  xopt(i)=inputs(1);
  yopt(i)=inputs(2);
end
study_time_2=toc;

figure (3)
subplot(2,1,1)
hold on
surfc(xx,yy,f)
shading interp
plot3(xopt,yopt,fopt,'marker','o','markersize',5,'markerfacecolor','r')
title('unbounded inputs')
subplot(2,1,2)
plot(fopt)
xlabel('iteration')
ylabel('function miximum')

FUNCTION

function stalagmite = get_stalagmite(input_vector)
  x = input_vector (1)
  y = input_vector (2)
  f1_x = (sin (5.1 * pi * x + 0.5)) .^ 6;
  f2_y = (sin (5.1 * pi * y + 0.5)) .^ 6;
  f3_x = exp ((-4 * 0.6931) .* (x - 0.0667) .^ 2 / (0.64));
  f4_y = exp ((-4 * 0.6931) .* (y - 0.0667) .^ 2 / (0.64));
  stalagmite = -(f1_x .* f2_y .* f3_x .* f4_y)
end

OUTPUT

FOR GLOBAL MINIMA

FOR FINDING MAXIMA FUNCTION BY GA

STUDY1

STUDY2

STUDY3

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.