% W. Zhao, L. Wang and Z. Zhang, Artificial ecosystem-based optimization:
% A novel nature-inspired meta-heuristic algorithm, Neural Computing and
% Applications, DOI:10.1007/s00521-019-04452-x.
% --------------------------------------------------------------------------
% Artificial ecosystem-based optimization (AEO)
function [BestF,BestX,new_HisBestFit]=IAEO(nPop,MaxIt,lb,ub,Dim,fobj)
% FunIndex: Index of function.
% MaxIt: The maximum number of iterations.
% PopSize: The size of population.
% PopPos: The position of population.
% PopFit: The fitness of population.
% Dim: The dimensionality of prloblem.
% C: The consumption factor.
% D: The decomposition factor.
% BestX: The best solution found so far.
% BestF: The best fitness corresponding to BestX.
% HisBestFit: History best fitness over iterations.
% Low: The low bound of search space.
% Up: The up bound of search space.
for i=1:nPop
PopPos(i,:)=rand(1,Dim).*(ub-lb)+lb;
PopFit(i)=fobj(PopPos(i,:));
end
BestF=inf;
BestX=[];
[NFit, indF]=sort(PopFit,'descend');
PopPos=PopPos(indF,:);
PopFit=PopFit(indF);
BestF=PopFit(end);
BestX=PopPos(end,:);
HisBestFit=zeros(MaxIt,1);
Matr=[1,Dim];
for It=1:MaxIt
%% 精英策略
PopPos=elite_reverse_learning(PopPos,lb,ub,fobj);
% 由于反向精英是适应度升序故需要反转
PopPos=flipud(PopPos);
%% 精英策略结束
r1=rand;
a=(1-It/MaxIt)*r1;
xrand=rand(1,Dim).*(ub-lb)+lb;
newPopPos(1,:)=(1-a)*PopPos(nPop,:)+a*xrand; %equation (1)
u=randn(1,Dim);
v=randn(1,Dim);
C=1/2*u./abs(v); %equation (4)
newPopPos(2,:)=PopPos(2,:)+C.*(PopPos(2,:)-newPopPos(1,:)); %equation (6)
for i=3:nPop
u=randn(1,Dim);
v=randn(1,Dim);
C=1/2*u./abs(v);
r=rand;
if r<1/3
newPopPos(i,:)=PopPos(i,:)+C.*(PopPos(i,:)-newPopPos(1,:)); %equation (6)
else
if 1/3<r<2/3
newPopPos(i,:)=PopPos(i,:)+C.*(PopPos(i,:)- PopPos(randi([2 i-1]),:)); %equation (7)
else
r2=rand;
newPopPos(i,:)=PopPos(i,:)+C.*(r2.*(PopPos(i,:)- newPopPos(1,:))+(1-r2).*(PopPos(i,:)-PopPos(randi([2 i-1]),:))); %equation (8)
end
end
end
for i=1:nPop
newPopPos(i,:)=SpaceBound(newPopPos(i,:),ub,lb);
newPopFit(i)=fobj(newPopPos(i,:));
if newPopFit(i)<PopFit(i)
PopFit(i)=newPopFit(i);
PopPos(i,:)=newPopPos(i,:);
end
end
[BestOne indOne]=min(PopFit);
for i=1:nPop
r3=rand; Ind=round(rand)+1;
newPopPos(i,:)=PopPos(indOne,:)+3*randn(1,Matr(Ind)).*((r3*randi([1 2])-1)*PopPos(indOne,:)-(2*r3-1)*PopPos(i,:)); %equation (9)
end
for i=1:nPop
newPopPos(i,:)=SpaceBound(newPopPos(i,:),ub,lb);
newPopFit(i)=fobj(newPopPos(i,:));
if newPopFit(i)<PopFit(i)
PopPos(i,:)=newPopPos(i,:);
PopFit(i)=newPopFit(i);
end
end
% 降序排列
[NFit,indF]=sort(PopFit,'descend');
PopPos=PopPos(indF,:);
PopFit=PopFit(indF);
if PopFit(end)<BestF
BestF=PopFit(end);
BestX=PopPos(end,:);
end
%% LBES
%生成种群回溯
m=3;%回溯个数;
if It==1
best_X_record=PopPos(end,:);
else
best_X_record=[best_X_record;PopPos(end,:)];
end
if It>m
best_X_record(1,:)=[];
end
if It>=3
PopPos=LBES(best_X_record,PopPos,lb,ub,fobj);
end
% 由于反向精英是适应度升序故需要反转
PopPos=flipud(PopPos);
%% LBES结束
HisBestFit(It)=fobj(PopPos(end,:));
new_HisBestFit=HisBestFit';
end