Project

Optimization uisng GA in MATLAB of Stalagmite Function

OBJECTIVE

To maximize the stalagmite function (optimize the given stalagmite function to maximum) by the Genetic Algorithm (GA) in MATLAB.

INTRODUCTION

Genetic Algorithm (GA)

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

GA can be used to solve problems that are not well suited for standard optimization algorithms, including problems in which the objective function is discontinuous, nondifferentiable, stochastic, or highly nonlinear [1].

Working of GA

  1. The algorithm begins by creating a random initial population.
  2. 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:
    1. Scores each member of the current population by computing its fitness value. These values are called the raw fitness scores.
    2. Scales the raw fitness scores to convert them into a more usable range of values. These scaled values are called expectation values.
    3. Selects members, called parents, based on their expectation.
    4. 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.
    5. 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.
    6. Replaces the current population with the children to form the next generation.
  3. The algorithm stops when one of the stopping criteria is met. some of the criteria are- Generations, Time limit, Fitness limit, Stall generations, Stall time limit, Stall test, Function tolerance, Constraint tolerance [2].

Solvers attempt to minimize an objective function. To obtain the solution for maximization problem, that is, a problem of the formmaxxf(x),then define g(x) = –f(x), and minimize g.

MATLAB PROGRAM

Main Program

clear all
close all
clc

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

%% Creating a 2D mesh
[xx yy]= meshgrid(x,y);

%% Evaluating the stalagmite function

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

%% Evaluating GA

numcases= 100; 
options= optimoptions('ga');
options= optimoptions(options, 'populationsize',250);

tic
for i=1:numcases
    [inputs, fopt(i)] = ga(@stalagmite,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
surf(x,y,-(f))
shading interp
plot3(xopt, yopt, -(fopt), 'marker', 'o', 'markersize',5,'markerfacecolor', 'r')
title('Optimization by GA with bounded inputs')
subplot(2,1,2)
plot(-(fopt))
str = ['study time is =', num2str(study_time) ];
annotation('textbox','String',str,'FitBoxToText','on');

Stalagmite Function

%stalagmite function
function [fxy]=stalagmite(input_array)
x=input_array(1);
y=input_array(2);
f_1x=(sin(5.1*pi.*x+0.5)).^6;
f_1y=(sin(5.1*pi.*y+0.5)).^6;
f_2x=exp(-4*log(2).*(x-0.0667).^2/0.64);
f_2y=exp(-4*log(2).*(y-0.0667).^2/0.64);
[fxy1]=(f_1x.*f_1y.*f_2x.*f_2y);
[fxy]=[-fxy1];
end

RESULTS AND DISCUSSION

Fig 1: the maximaization result obtained for the population size 250 and UB [1;1]

Fig 2: the maximaization result obtained for the population size 300 and UB [0.8;0.8]

From the figures it is seen that the figure 2 is resulting is good results. The changes in Upper Boundary (UB) conditions yeild in better results along with the increase in population size. It can be observed from the study that increase in the population size would require additional time to arrive at the best results. Combined selection of Boundary Conditions and population size would result in optimised results relatevely quickly. And this is shown in figure 3.

Fig 3: the maximaization result obtained for the population size 100 and UB [0.3;0.3] , LB [0.05;0.05]

CONCLUSIONS

It can be concluded that one of the best ways to obtain results quickly is by carefully selecting the boundarry conditions and the population. The more the number of iterations the acuurate is the results.

REFERENCES

  1. https://in.mathworks.com/discovery/genetic-algorithm.html
  2. https://in.mathworks.com/help/gads/how-the-genetic-algorithm-works.html
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.