Project

OPTIMIZATION USING GENETIC ALGORITHM IN MATLAB

What is the need of optimization?

Process optimization is the discipline of adjusting a process so as to optimize (make the best or most effective use of) some specified set of parameters without violating some constraint. The most common goals are minimizing cost and maximizing throughput and/or efficiency. This is one of the major quantitave tools in industrial decison making.

What is ga?

Genetic algorithm (GA) 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.

You can apply the genetic algorithm 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.

Following is a code which will give an idea regarding optmization:

close all
clc

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

%creating a 2Dmensional 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

surfc(xx,yy,f)
xlabel(\'x value\')
ylabel(\'y value\')

shading interp

[inputs,fval]=ga(@stalagmite,2);






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

figure(2)
subplot(2,1,2)
hold on 
surf(x,y,f)
shading interp
plot3(xopt,yopt,fopt,\'marker\',\'o\',\'markerfacecolor\',\'r\')
title(\'bounded input\')
subplot(2,1,2)
plot(fopt)
xlabel(\'iterations\')
ylabel(\'function minimum\')



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

figure(3)
subplot(2,1,2)
hold on 
surf(x,y,f)
shading interp
plot3(xopt,yopt,fopt,\'marker\',\'o\',\'markersize\',\'5\',\'markerfacecolor\'\'r\')
title(\'bounded input with more iter\')
subplot(2,1,2)
plot(fopt)
xlabel(\'iterations\')
ylabel(\'function minimum\')




EXPLANATION OF THE CODE

In the beginning we have created one dimensional arrays using linspace in x and y respectively with 150 values ranging from 0 to 0.6.

Since the given function is in two variables and will require two variables on the graph we have used meshgrid command to create 2D arrays.

After that we have defined the stalagamite function which is dependent on the values of the 2D arrays.The function is :

function [f] = stalagmite(input_vector)
a=input_vector(1);
b=input_vector(2);



f1x =(sin(5.1*pi*a+0.5))^6;
f1y=(sin(5.1*pi*b+0.5))^6;
f2x=exp((-4*ln(2)*n(a-0.0667)^2/0.64);
f2y=exp((-4*ln(2)*(b-0.0667)^2/0.64);
f=-(f1x*f1y*f2x*f2y);
end

In study 1 we are plotting the global maxima and global minima which is tha maximum value and minmum value of the function for a particular value of x and y points.The following is the result:

STUDY 2

In the below graph we can see that three points have maximum value .GA algorithms runs the code by choosing random values,so by running the code several times we can run arrive the optimal solution. In the subplot we can see the solution is optimized but having more than one maxima

STUDY 3

In the below plot we have arrive to a optimized solution having only two maximum values having by increasing the iterationcount with the upper and lower bound values .Also from the subplot we can observe that the solution is giving with more iterations.

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.