% Five-elements Cycle Optimization Algorithm for benchmark functions % By Mandan Liu, East China University of Science and Technology, Shanghai, China % Email: liumandan@ecust.edu.cn % Nov. 2017
function BasicFECO
rand('state',sum(100*clock)); L=5; %L is the number of element in one cycle; q=20; %q is the number of cycles; Ps=1.0; %Ps is the scale factor; Pm=0.9; %Pm is the pre-given probability;
cN=30; %cN is the dimension of function; maxiter=1500; %maxiter is maximum iteration; xlo=-32; %xlo is the lower limit of x; xhi=32; %xhi is the high limit of x;
for i=2:maxiter for k=1:q Ffive((k-1)*L+1,1,i)=fmother(1)*log(Mfive((k-1)*L+L,1,i-1)/Mfive((k-1)*L+1,1,i-1))+fgrandmother(1)*log(Mfive((k-1)*L+L-1,1,i-1)/Mfive((k-1)*L+1,1,i-1))+fson(1)*log(Mfive((k-1)*L+1,1,i-1)/Mfive((k-1)*L+2,1,i-1))+fgrandson(1)*log(Mfive((k-1)*L+1,1,i-1)/Mfive((k-1)*L+3,1,i-1)); Ffive((k-1)*L+2,1,i)=fmother(2)*log(Mfive((k-1)*L+1,1,i-1)/Mfive((k-1)*L+2,1,i-1))+fgrandmother(2)*log(Mfive((k-1)*L+L,1,i-1)/Mfive((k-1)*L+2,1,i-1))+fson(2)*log(Mfive((k-1)*L+2,1,i-1)/Mfive((k-1)*L+3,1,i-1))+fgrandson(2)*log(Mfive((k-1)*L+2,1,i-1)/Mfive((k-1)*L+4,1,i-1)); for j=3:L-2 Ffive((k-1)*L+j,1,i)=fmother(j)*log(Mfive((k-1)*L+j-1,1,i-1)/Mfive((k-1)*L+j,1,i-1))+fgrandmother(j)*log(Mfive((k-1)*L+j-2,1,i-1)/Mfive((k-1)*L+j,1,i-1))+fson(j)*log(Mfive((k-1)*L+j,1,i-1)/Mfive((k-1)*L+j+1,1,i-1))+fgrandson(j)*log(Mfive((k-1)*L+j,1,i-1)/Mfive((k-1)*L+j+2,1,i-1)); end Ffive((k-1)*L+L-1,1,i)=fmother(L-1)*log(Mfive((k-1)*L+L-2,1,i-1)/Mfive((k-1)*L+L-1,1,i-1))+fgrandmother(L-1)*log(Mfive((k-1)*L+L-3,1,i-1)/Mfive((k-1)*L+L-1,1,i-1))+fson(L-1)*log(Mfive((k-1)*L+L-1,1,i-1)/Mfive((k-1)*L+L,1,i-1))+fgrandson(L-1)*log(Mfive((k-1)*L+L-1,1,i-1)/Mfive((k-1)*L+1,1,i-1)); Ffive((k-1)*L+L,1,i)=fmother(L)*log(Mfive((k-1)*L+L-1,1,i-1)/Mfive((k-1)*L+L,1,i-1))+fgrandmother(L)*log(Mfive((k-1)*L+L-2,1,i-1)/Mfive((k-1)*L+L,1,i-1))+fson(L)*log(Mfive((k-1)*L+L,1,i-1)/Mfive((k-1)*L+1,1,i-1))+fgrandson(L)*log(Mfive((k-1)*L+L,1,i-1)/Mfive((k-1)*L+2,1,i-1));
[maxFfive kno]=max(Ffive((k-1)*L+1:k*L,1,i)); for j=1:L x((k-1)*L+j,:,i)=x((k-1)*L+j,:,i-1); if Ffive((k-1)*L+j,1,i)<0 || Ffive((k-1)*L+j,1,i)==0 for a=1:cN if rand<Pm x((k-1)*L+j,a,i)=x((k-1)*L+kno,a,i-1)+(rand*2-1)*Ps*(x((k-1)*L+kno,a,i-1)-x((k-1)*L+j,a,i-1)); x((k-1)*L+j,a,i)=max(xlo,min(xhi,x((k-1)*L+j,a,i))); else x((k-1)*L+j,a,i)=bestx(a)+(rand*2-1)*Ps*(x((k-1)*L+kno,a,i-1)-bestx(a)); x((k-1)*L+j,a,i)=max(xlo,min(xhi,x((k-1)*L+j,a,i))); end end end Mfive((k-1)*L+j,1,i)=fm(x((k-1)*L+j,:,i)); end end
if Mmaxminfive(i)<bestF bestF=Mmaxminfive(i); bestx=xmaxmin(i,:); end display(['The ' num2str(i) ' iteration, bestF is ' num2str(bestF)]); end end
function z=fm(x) r=size(x,2); zhe1=0; zhe2=0; for i=1:r zhe1=zhe1+x(i)^2; zhe2=zhe2+cos(2*pi*x(i)); end z=-20*exp(-0.2*sqrt(zhe1/r))-exp(zhe2/r)+20+exp(1); %Ackley's Function -32~+32/0 end