• 大小: 4KB
    文件类型: .m
    金币: 1
    下载: 0 次
    发布日期: 2021-06-06
  • 语言: Matlab
  • 标签: BFO  BFA  matlab  多头菌  

资源简介

BFO的的详细代码,可以直接运行,其优化函数已经提供,在Cost里。代码附带注释(包括参数含义 ),可以自己学习。

资源截图

代码片段和文件信息

% Bacterial Foraging Algorithm
clear all;
clc;
% parameters initializing
ExtraSpeed=0.1;
Bounds=[-5.125.12;-5.125.12];%boundaries of variable
Dimension=2;% the number of every bacteria features
Number=26;% bacteria number
Iteration=100; %the iteration
MaxMoving=4;%the maximum length of moving in  one direction
C(:1)=0.001*ones(Number1);%after reverse direction the length of moving forward
NumberReplication=6;
NumberMigration=3;
NumberDivision=Number/2;
ProbabilityMigration=0.25+ExtraSpeed+ExtraSpeed;
DoseAttract=0.05+ExtraSpeed;
SpeedToReleaseDoseAttract=0.05+ExtraSpeed;
DoseRepellant=0.05+ExtraSpeed;
SpeedToReleaseDoseRepellant=0.05+ExtraSpeed;
% initializing bacteria position
for i=1:Number
    P(1i111) = -5.12 + rand*10.24;
    P(2i111) = -5.12 + rand*10.24; 
end
% now for iteration
for l=1:NumberMigration
    for k=1:NumberReplication
        for j=1:Iteration
            for i=1:Number
                %J means fitness
                J(ijkl) = Cost(P(:ijkl)); 
                %Jcc is a akin of pheromone
                Jcc=sum(-DoseAttract*exp(-SpeedToReleaseDoseAttract*((P(1ijkl)-...
                    P(11:Numberjkl)).^2+(P(2ijkl)-P(21:Numberjkl)).^2))) +...
                    sum(DoseRepellant*exp(-SpeedToReleaseDoseRepellant*((P(1ijkl)-... 
                    P(11:Numberjkl)).^2+(P(2ijkl)-P(21:Numberjkl)).^2))); 
                J(ijkl) = J(ijkl) + Jcc;  
                Jlast = J(ijkl);
                %Delta mean reverse
                Delta(:i) = (2*round(rand(Dimension1))-1).*rand(Dimension1); 
                %PHI mean after reversing choose a random direction move forward
                PHI = Delta(:i)/sqrt(Delta(:i)‘*Delta(:i));  
                P(:ij+1kl) = P(:ijkl) + C(ik)*PHI;
                J(ij+1kl) = Cost(P(:ij+1kl)); 
                %m means roamming
                m =

评论

共有 条评论