蝠鲼觅食优化(MRFO)-Matlab代码

注:网上有关蝠鲼觅食优化算法的原理介绍很多,但是没有付源码。即使有源码的文章,也是付费

才能得到源码。违背共享自由的学术精神。在这里我将把蝠鲼觅食优化(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

谢谢各位看官顾客的点赞,收藏,加关注

  • 13
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
以下是觅食优化算法MRFO的伪代码: ``` Initialize the population of bats While stopping criterion is not met: For each bat i in the population: Generate a new solution x_i by updating the bat's position: x_i = x_i + A*sin(2*pi*f)*|r_i,j - x_j| where A is the loudness of the bat, f is the frequency, r_i,j is the position of a randomly selected bat, and x_j is the position of the best bat in the population If the new solution x_i is better than the current solution x_i, replace x_i with the new solution With probability r_i, generate a new solution x_i by random walk: x_i = x_i + epsilon_i where epsilon_i is a vector of random values drawn from a normal distribution Update the loudness A and frequency f of the bat: A = alpha*A f = f_min + (f_max - f_min)*rand() If the loudness A is less than a threshold value A_min, reset the bat's position to a new random solution If the new solution x_i is better than the best solution in the population, update the best solution End for End while ``` 其中,觅食优化算法通过模拟蝙觅食的行为来进行优化。每个蝙代表一个潜在解,其位置表示解的参数值。蝙根据当前最优解和其他蝙的位置信息来更新自己的位置。此外,每个蝙还具有一个“响度”和“频率”的属性,可以调整其搜索范围和速度。在搜索过程中,每个蝙还有一定概率进行随机游走以增加搜索多样性。最终,算法的输出结果是最优解。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值