GENETIC ALGORITHM
Genetic Algorithm is an optimization method based on the mechanics of natural genetics and natural selection.
Genetic Algorithm mimics the principle of natural genetics and natural selection to constitute search and optimization procedures.
GA is used for scheduling to find the near to optimum solution in a short time.
In a genetic algorithm, representation is done with a variable length of sub-chromosome.
GA is developed to generate the optimal order scheduling solution.
GA is used as a tool in different processes to optimize the process parameters.
Genetic algorithm is a multi-path algorithm that searches many peaks in parallel,
hence reducing the possibility of local minimum trapping and solve the multi-objective optimization problems.
GA is used to find minimum of a function.
x = ga(fun,nvars)
x = ga(fun,nvars,A,b)
x = ga(fun,nvars,A,b,Aeq,beq)
x = ga(fun,nvars,A,b,Aeq,beq,lb,ub)
x = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon)
x = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon,options)
x = ga(fun,nvars,A,b,[],[],lb,ub,nonlcon,IntCon)
x = ga(fun,nvars,A,b,[],[],lb,ub,nonlcon,IntCon,options)
x = ga(problem)
[x,fval] = ga(___)
[x,fval,exitflag,output] = ga(___)
[x,fval,exitflag,output,population,scores] = ga(___)
x = ga(fun,nvars) finds a local unconstrained minimum, x, to the objective function, fun. nvars is the dimension (number of design variables) of fun.
x = ga(fun,nvars,A,b,Aeq,beq,lb,ub) defines a set of lower and upper bounds on the design variables, x, so that a solution is found in the range
lb ≤ x ≤ ub. (Set Aeq=[] and beq=[] if no linear equalities exist.)
x = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon,options) minimizes with the default optimization parameters replaced by values in options. (Set nonlcon=[] if no nonlinear constraints exist.) Create options using optimoptions.
steps
1. Using linespace define search space.
2. Set number of iterations.
3. meshgrid command is used to produce 2Dimentional mesh
4. evaluation of stalignamite function by using for loop
5. tic and toc command is used to calculate the time in the process
6. case1 without changing we took normal GA function
7. case 2 we provided lower and upper bounds
8. case 3 we try to change the population which is set to default
9. By running the above case one by one we can slowly maintain the output at the end of the last case 3
clear all
close all
clc
x=linspace(0,0.6,150); %range for x inputs
y=linspace(0,0.6,150); %range for y inputs
rep=50; % setting counter for 50 iterations
[xx,yy]=meshgrid(x,y); % generating 2d array
tic %time counter start
for i=1:length(xx) %for i takes values of xx
for j=1:length(yy) %for j takes values of yy
int(1)=xx(i,j);
int(2)=yy(i,j);
f(i,j)=staglamite(int); %input get output of staglamite function
end
end
study_time=toc %time counter end
surfc(xx,yy,f) %plot contour ad 3d surface
shading interp %smoothens color connecting contour
xlabel(\'x values\')
ylabel(\'y values\')
tic
%1
for i=1:rep %50 interations
[inputs,fopt(i)]=ga(@staglamite,2); %usingga function genetic algorithm
xopt(i)=inputs(1);
yopt(i)=inputs(2);
end
study_time=toc;
figure(1)
subplot(2,1,1)
hold on
surfc(xx,yy,f)
shading interp
plot3(xopt,yopt,fopt,\'marker\',\'o\',\'markersize\',5,\'markerfacecolor\',\'r\')%plot 3 axix graph
title(\'random plot\')
subplot(2,1,2)
plot(fopt)
xlabel(\'iterations\')
ylabel(\'func min\')
tic
%2
for i=1:rep
[inputs,fopt(i)]=ga(@staglamite,2,[],[],[],[],[0;0],[1;1]);
xopt(i)=inputs(1);
yopt(i)=inputs(2);
end
study_time=toc;
figure(2)
subplot(2,1,1)
hold on
surfc(xx,yy,f)
shading interp
plot3(xopt,yopt,fopt,\'marker\',\'o\',\'markersize\',5,\'markerfacecolor\',\'b\')
title(\'Bounded inputs \')
subplot(2,1,2)
plot(fopt)
xlabel(\'iterations\')
ylabel(\'func min\')
tic
%3
options=optimoptions(\'ga\'); %getting optimum population
options=optimoptions(options,\'populationSize\',200);
for i=1:rep
[inputs,fopt(i)]=ga(@staglamite,2,[],[],[],[],[0;0],[1;1],[],[],options);
xopt(i)=inputs(1);
yopt(i)=inputs(2);
end
study_time=toc;
figure(3)
subplot(2,1,1)
hold on
surfc(xx,yy,f)
shading interp
plot3(xopt,yopt,fopt,\'marker\',\'o\',\'markersize\',5,\'markerfacecolor\',\'g\');
title(\'Bounded\')
subplot(2,1,2)
plot(fopt)
xlabel(\'iterations\')
ylabel(\'func min\')
functionmaximum = fopt;
function[f]=staglamite(int)
x=int(1);
y=int(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.667).^2)/(0.64));
f4=exp((-4*log(2)*(y-0.667).^2)/(0.64));
f=-(f1*f2*f3*f4);
end