optimization using genetic algorithm using two variable

조회 수: 15 (최근 30일)
shyam kishor sharma
shyam kishor sharma 2021년 3월 8일
답변: Alan Weiss 2021년 3월 9일
I am new to use GA, I want to implement genetic algorithm to find out the optimize variables for the maxiamum value of my Power function ,which is calculted by solving a differential equation but when I run my GA code then it gives only initial value (lower bond value) for the optimize variables. I here write my fitness function and GA function.please anyone suggest the possible mistakes in my GA code. Thanks
% fitness function
function [Fitness_fun] = tribo1(X)
R = X(1);
d = X(2);
sigma = 15e-5;
S = 22.5e-4;
epslno = 8.854e-12;
epslnr=3.4;
Ao = 5e-3;
f = 3.3;
w = 2*pi*f;
thita = 1.5*pi;
h=1e-5;
x = 0:h:0.8;
y = zeros(1,length(x));
I = zeros(1,length(x));
I(1)=0;
y(1)=0;
F_xy = @(t,Q) ((sigma/(epslno*R))*(Ao*sin(w*t+thita)+Ao)...
-Q*((d/epslnr)+Ao*sin(w*t+thita)+Ao)/(S*epslno*R));
for i=1:(length(x)-1)
k_1 = F_xy(x(i),y(i));
k_2 = F_xy(x(i)+0.5*h,y(i)+0.5*h*k_1);
k_3 = F_xy((x(i)+0.5*h),(y(i)+0.5*h*k_2));
k_4 = F_xy((x(i)+h),(y(i)+k_3*h));
y(i+1) = y(i) + (1/6)*(k_1+2*k_2+2*k_3+k_4)*h;
I(i+1)=((sigma/(epslno*R))*(Ao*sin(w*x(i+1)+thita)+Ao)...
-y(i+1)*((d/epslnr)+Ao*sin(w*x(i+1)+thita)+Ao)/(S*epslno*R));
end
V=I*R;
P=V.*I;
[Power_IND]=max(P);
Fitness_fun=1/(1+Power_IND);
end
%%
% GA code-
clc
format long g
%*********************************************************
%GA Inputs
rng default
FitnessFunction = @tribo1;
numberOfVariables = 2;
lb = [10e6 50e-6];
ub = [10e13 550e-6];
Aeq = [];
beq = [];
A = [];
b = [];
Ini_Popu = [10e6 50e-6];
NonLinFunction=[];
options = gaoptimset('PlotFcns',{@gaplotbestf,@gaplotbestindiv,@gaplotstopping,@gaplotselection},...
'PopulationSize',50,...
'Generations',10000,...
'EliteCount',2,...
'CrossoverFraction',0.8,...
'ParetoFraction',0.035,...
'MigrationDirection','forward',...
'MigrationInterval',20,...
'MigrationFraction',0.2,...
'TimeLimit',Inf,...
'StallGenLimit',100,...
'FitnessLimit',-Inf,...
'TolFun',1e-50,...
'TolCon',1e-12,...
'InitialPopulation',Ini_Popu,...
'PenaltyFactor',100);
options
[x,Fval,exitFlag,Output,population,scores] = ...
ga(FitnessFunction,numberOfVariables,A,b,Aeq,beq,lb,ub,NonLinFunction,[],options); %NonLinFunction
fprintf('The number of generations was : %d\n', Output.generations);
fprintf('The number of function evaluations was : %d\n', Output.funccount);
fprintf('The best function value found was : %g\n', Fval);
exitFlag
population
scores
min(scores)
x

답변 (1개)

Alan Weiss
Alan Weiss 2021년 3월 9일
You might want to try to copy the coding techniques in Optimize an ODE in Parallel.
Alan Weiss
MATLAB mathematical toolbox documentation

카테고리

Help CenterFile Exchange에서 Genetic Algorithm에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by