【自私羊群优化算法】基于自私羊群优化算法求解单目标优化问题-附Matlab代码

253 阅读2分钟

1 简介

自私羊群优化SHO算法是由Fausto于2017年提出的元启发式算法[16],它主要基于汉密尔顿[17]提出的自私群理论来模拟猎物与捕食者之间的狩猎关系。当群体中的个体受到捕食者的攻击时,为了增加生存机会,群体中的个体产生聚集行为,个体更有可能移动到相对安全的位置(群体的中心位置),并且群体的边缘个体更容易受到攻击,这也导致群体的边缘个体逃离群体,以增加他们被捕食者攻击时的生存机会。该方法假设整个平原是一个解空间,该算法包含两个不同的搜索因子:被狩猎群和狩猎群。每个搜索因子通过一组不同的进化算子指导算法的计算,以便更好地模拟猎物与捕食者关系之间的关系。

2 部分代码

function [Best_hyena_score,Best_hyena_pos,Convergence_curve]=sho(N,Max_iterations,lowerbound,upperbound,dimension,fitness)

hyena_pos=init(N,dimension,upperbound,lowerbound);

Convergence_curve=zeros(1,Max_iterations);

Iteration=1;


while Iteration<Max_iterations
   
   
   for i=1:size(hyena_pos,1)
       

       H_ub=hyena_pos(i,:)>upperbound;
       H_lb=hyena_pos(i,:)<lowerbound;
       hyena_pos(i,:)=(hyena_pos(i,:).*(~(H_ub+H_lb)))+upperbound.*H_ub+lowerbound.*H_lb;  
       hyena_fitness(1,i)=fitness(hyena_pos(i,:));  
       
   end
      
   if Iteration==1
      [fitness_sorted FS]=sort(hyena_fitness);
       sorted_population=hyena_pos(FS,:);
       best_hyenas=sorted_population;
       best_hyena_fitness=fitness_sorted;
       
   else
       double_population=[pre_population;best_hyenas];
       double_fitness=[pre_fitness best_hyena_fitness];
      [double_fitness_sorted FS]=sort(double_fitness);
       double_sorted_population=double_population(FS,:);
       fitness_sorted=double_fitness_sorted(1:N);
       sorted_population=double_sorted_population(1:N,:);
       best_hyenas=sorted_population;
       best_hyena_fitness=fitness_sorted;
   end
   
   NOH=noh(best_hyena_fitness);
   
  
   Best_hyena_score=fitness_sorted(1);
   Best_hyena_pos=sorted_population(1,:);
   pre_population=hyena_pos;
   pre_fitness=hyena_fitness;
   
   a=5-Iteration*((5)/Max_iterations);
   HYE=0;
   CV=0;
   for i=1:size(hyena_pos,1)
       
       for j=1:size(hyena_pos,2)
            for k=1:NOH
           HYE=0;
            r1=rand();
            r2=rand()
           Var1=2*a*r1-a
           Var2=2*r2
           distance_to_hyena=abs(Var2*sorted_population(k)-hyena_pos(i,j));
           HYE=sorted_population(k)-Var1*distance_to_hyena;
           CV=CV+HYE;        
           distance_to_hyena=0;
            end
       
       hyena_pos(i,j)=(CV/(NOH+1));
       CV=0;
       end
       
   end
   
   Convergence_curve(Iteration)=Best_hyena_score;
   
    Iteration=Iteration+1
end

3 仿真结果

4 参考文献

[1]朱惠娟, 王永利, 陈琳琳. 面向三维模型轻量化的自私羊群优化算法研究[J]. 计算机工程与应用, 2020, 56(3):7.

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。