注:网上有关蝠鲼觅食优化算法的原理介绍很多,但是没有付源码。即使有源码的文章,也是付费
才能得到源码。违背共享自由的学术精神。在这里我将把蝠鲼觅食优化(MRFO)算法的源码公开。
希望大家关注点赞
---------东南大学---刘博士。
下面直接说重点,上代码。如果代码对你有用,请点赞,收藏,加关注。
如果分享的代码对您有用,请各位看官 点赞,收藏,加关注
% 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.
% Alpha: The weight coefficient in chain foraging.
% Beta: The weight coefficient in cyclone foraging.
% S: The somersault factor.
% 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.
function [BestX,BestF,HisBestFit]=MRFO(F_index,MaxIt,nPop)
[Low,Up,Dim]=FunRange(F_index);
for i=1:nPop
PopPos(i,:)=rand(1,Dim).*(Up-Low)+Low;
PopFit(i)=BenFunctions(PopPos(i,:),F_index,Dim);
end
BestF=inf;
BestX=[];
for i=1:nPop
if PopFit(i)<=BestF
BestF=PopFit(i);
BestX=PopPos(i,:);
end
end
HisBestFit=zeros(MaxIt,1);
for It=1:MaxIt
Coef=It/MaxIt;
if rand<0.5
r1=rand;
Beta=2*exp(r1*((MaxIt-It+1)/MaxIt))*(sin(2*pi*r1));
if Coef>rand
newPopPos(1,:)=BestX+rand(1,Dim).*(BestX-PopPos(1,:))+Beta*(BestX-PopPos(1,:)); %Equation (4)
else
IndivRand=rand(1,Dim).*(Up-Low)+Low;
newPopPos(1,:)=IndivRand+rand(1,Dim).*(IndivRand-PopPos(1,:))+Beta*(IndivRand-PopPos(1,:)); %Equation (7)
end
else
Alpha=2*rand(1,Dim).*(-log(rand(1,Dim))).^0.5;
newPopPos(1,:)=PopPos(1,:)+rand(1,Dim).*(BestX-PopPos(1,:))+Alpha.*(BestX-PopPos(1,:)); %Equation (1)
end
for i=2:nPop
if rand<0.5
r1=rand;
Beta=2*exp(r1*((MaxIt-It+1)/MaxIt))*(sin(2*pi*r1));
if Coef>rand
newPopPos(i,:)=BestX+rand(1,Dim).*(PopPos(i-1,:)-PopPos(i,:))+Beta*(BestX-PopPos(i,:)); %Equation (4)
else
IndivRand=rand(1,Dim).*(Up-Low)+Low;
newPopPos(i,:)=IndivRand+rand(1,Dim).*(PopPos(i-1,:)-PopPos(i,:))+Beta*(IndivRand-PopPos(i,:)); %Equation (7)
end
else
Alpha=2*rand(1,Dim).*(-log(rand(1,Dim))).^0.5;
newPopPos(i,:)=PopPos(i,:)+rand(1,Dim).*(PopPos(i-1,:)-PopPos(i,:))+Alpha.*(BestX-PopPos(i,:)); %Equation (1)
end
end
for i=1:nPop
newPopPos(i,:)=SpaceBound(newPopPos(i,:),Up,Low);
newPopFit(i)=BenFunctions(newPopPos(i,:),F_index,Dim);
if newPopFit(i)<PopFit(i)
PopFit(i)=newPopFit(i);
PopPos(i,:)=newPopPos(i,:);
end
end
S=2;
for i=1:nPop
newPopPos(i,:)=PopPos(i,:)+S*(rand*BestX-rand*PopPos(i,:)); %Equation (8)
end
for i=1:nPop
newPopPos(i,:)=SpaceBound(newPopPos(i,:),Up,Low);
newPopFit(i)=BenFunctions(newPopPos(i,:),F_index,Dim);
if newPopFit(i)<PopFit(i)
PopFit(i)=newPopFit(i);
PopPos(i,:)=newPopPos(i,:);
end
end
for i=1:nPop
if PopFit(i)<BestF
BestF=PopFit(i);
BestX=PopPos(i,:);
end
end
HisBestFit(It)=BestF;
end
谢谢各位看官顾客的点赞,收藏,加关注