clear all
clc
close all
d=4;
options.ECPSize=2;
options.MaxIter=2;
options.V=[1 2 1];
options.ObjFunction=@myfitness;
options.lb=[0 0 0 0];
options.ub=[10 10 pi pi];
options.ProblemSize=length(options.ub);
options.Display_Flag=1;
options.run_parallel_index=0;
options.run=2;
bestFitnessEvolution=[];
ECPSize = options.ECPSize;
MaxIter = options.MaxIter;
Strategy=options.V(1);
NPI=options.V(2);
archSize=ECPSize/options.V(3);
ObjFunction=options.ObjFunction;
lb=options.lb;
ub=options.ub;
ProblemSize=options.ProblemSize;
ECP=repmat(lb,ECPSize,1)+rand(ECPSize,ProblemSize).*repmat((ub-lb),ECPSize,1);
F_ECP = feval(ObjFunction,ECP); nEval=ECPSize;
[F_ECP, ind] = sort(F_ECP);
ECP = ECP(ind,:);
if Strategy==1
pop_fac=2*nchoosek(NPI,2);
elseif Strategy==2
pop_fac=NPI;
elseif Strategy==3
pop_fac=2*nchoosek(NPI,2)+NPI;
end
for iter=1:MaxIter
pop_arch = ECP(1:archSize,:);
F_arch=F_ECP(1:archSize);
newECP=[];
newECP1=[];
newECP2=[];
for i=1:1:ceil(ECPSize/pop_fac)
Force = normrnd(0.7,0.2);
SP=sort(randperm(ECPSize,NPI));
SP=SP(1:NPI);
if Strategy==1
for ii=1:NPI
for jj=1:NPI
S1=ECP(SP(ii),:)+ Force * (ECP(1,:) - ECP(SP(ii),:));
if jj<ii
S1= S1 + Force * (ECP(SP(jj),:) - ECP(SP(ii),:));
newECP(end+1,:)=S1;
elseif jj>ii
S1= S1 - Force * (ECP(SP(jj),:) - ECP(SP(ii),:));
newECP(end+1,:)=S1;
end
end
end
elseif Strategy==2
for ii=1:NPI
S1=ECP(SP(ii),:)+ 0*Force * (ECP(1,:) - ECP(SP(ii),:));
for jj=1:NPI
if jj<ii
S1= S1 + Force * (ECP(SP(jj),:) - ECP(SP(ii),:));
elseif jj>ii
S1= S1 - Force * (ECP(SP(jj),:) - ECP(SP(ii),:));
end
end
newECP(end+1,:)=S1;
end
elseif Strategy==3
for ii=1:NPI
S2=ECP(SP(ii),:)+ 1*Force * (ECP(1,:) - ECP(SP(ii),:));
for jj=1:NPI
S1=ECP(SP(ii),:)+ Force * (ECP(1,:) - ECP(SP(ii),:));
if jj<ii
S1= S1 + Force * (ECP(SP(jj),:) - ECP(SP(ii),:));
S2= S2 + Force * (ECP(SP(jj),:) - ECP(SP(ii),:));
newECP1(end+1,:)=S1;
elseif jj>ii
S1= S1 - Force * (ECP(SP(jj),:) - ECP(SP(ii),:));
S2= S2 - Force * (ECP(SP(jj),:) - ECP(SP(ii),:));
newECP1(end+1,:)=S1;
end
end
newECP2(end+1,:)=S2;
end
newECP=[newECP1; newECP2];
end
end
newECP = bound(newECP,lb, ub);
for i1=1:size(newECP,1)
for j=1:ProblemSize
r=rand;
if (r<0.2)
pos= randi(archSize(1));
newECP(i1,j)= pop_arch(pos,j);
end
end
end
ECP_All=[pop_arch; newECP];
F_All=[F_arch feval(ObjFunction,newECP)];
nEval=nEval+size(newECP,1);
[F_All, index] = sort(F_All);
ECP_All = ECP_All( index, : );
ECP = ECP_All (1:ECPSize,:);
F_ECP = F_All(1:ECPSize);
bestX=ECP(1,:);
bestFitnessEvolution(iter)=F_ECP(1);
if options.Display_Flag==1
fprintf('Iteration N�� is %g Best Fitness is %g\n',iter,F_ECP(1))
end
end
bestFitness=F_ECP(1);
3 Comments
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/711333-why-i-get-this-message#comment_1251813
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/711333-why-i-get-this-message#comment_1251813
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/711333-why-i-get-this-message#comment_1254953
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/711333-why-i-get-this-message#comment_1254953
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/711333-why-i-get-this-message#comment_1256208
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/711333-why-i-get-this-message#comment_1256208
Sign in to comment.