【优化求解】基于自适应变异麻雀搜索算法求解单目标优化问题matlab代码(AMSSA)

148 阅读3分钟

1 简介

针对麻雀搜索算法前期易陷入局部极值点、后期寻优精度不高等问题,提出一种自适应变异麻雀搜索算法(AMSSA)。首先,通过猫映射混沌序列初始化种群,增强初始种群的随机性、遍历性,提高算法的全局搜索能力;其次,引入柯西变异和 Tent 混沌扰动,拓展局部搜索能力,使陷入局部极值点的个体跳出限制继续搜索;最后,提出探索者-跟随者数量自适应调整策略,利用各阶段探索者和跟随者数量的改变增强算法前期的全局搜索能力和后期的局部深度挖掘能力,提高算法的寻优精度。选取 16 个基准函数和 Wilcoxon 检验进行验证,实验结果表明,该算法与其他算法相比,寻优精度、收敛速度和稳定性都取得较大提升。

麻雀搜索算法的思想来自于麻雀种群的觅食行为和反捕食行为,可抽象为探索者-跟随者-预警者模型。探索者具有较高的能量储备,适应度值高,主要为跟随者提供觅食区域和方向。跟随者跟随适应度值最优的探索者寻找食物以获得自己的能量储备,增加自身的适应度值。部分跟随者也可能不断地监视探索者,从而争夺食物。预警者在意识到危险时会发出警报,同时迅速向安全区域移动来获得更好的位置,处于种群中间的麻雀则随机行走靠近别的麻雀,即反捕食行为。同时若警报值大于安全阈值时,探索者需要将所有的跟随者带离危险区域。

2 部分代码

function [fMin , bestX, Convergence_curve]SSA(X, N, M, c, d, dim, fobj)

P_percent = 0.2;    % 发现者的种群规模占总种群规模的百分比

pNum = round(N*P_percent);    % 发现者数量20%

SD = pNum/2;      % 警戒者数量10%

ST = 0.8;           % 安全阈值
lb = c.*ones(1, dim);     % 下限
ub = d.*ones(1,dim);    % 上限
% 初始化
for i = 1:N
%     X(i, :) = lb + (ub - lb) .* rand(1, dim);
   fitness(i) = fobj(X(i, :));
end
pFit = fitness;
pX = X;                            % 与pFit相对应的个体最佳位置
[fMin, bestI]min(fitness);      % fMin表示全局最优解
bestX = X(bestI, :);             % bestX表示全局最优位置

%% 迭代寻优
for t = 1 : M       
  [~, sortIndex] = sort(pFit);            % 排序
   
  [fmax, B]max(pFit);
   worst = X(B, :);
   
   %% 发现者位置更新
   r2 = rand(1);
   if r2 < ST
       for i = 1:pNum      % Equation (3)
           r1 = rand(1);
           X(sortIndex(i), :) = pX(sortIndex(i), :)*exp(-(i)/(r1*M));
           X(sortIndex(i), :) = Bounds(X(sortIndex(i), :), lb, ub);
           fitness(sortIndex(i)) = fobj(X(sortIndex(i), :));
       end
   else
       for i = 1:pNum
           X(sortIndex(i), :) = pX(sortIndex(i), :)+randn(1)*ones(1, dim);
           X(sortIndex(i), :) = Bounds(X(sortIndex(i), :), lb, ub);
           fitness(sortIndex(i)) = fobj(X(sortIndex(i), :));
       end
   end
   
  [~, bestII]min(fitness);
   bestXX = X(bestII, :);
   
   %% 跟随者位置更新
   for i = (pNum+1):N                     % Equation (4)
       A = floor(rand(1, dim)*2)*2-1;
       if i > N/2
           X(sortIndex(i), :) = randn(1)*exp((worst-pX(sortIndex(i), :))/(i)^2);
       else
           X(sortIndex(i), :) = bestXX+(abs((pX(sortIndex(i), :)-bestXX)))*(A'*(A*A')^(-1))*ones(1, dim);
       end
       X(sortIndex(i), :) = Bounds(X(sortIndex(i), :), lb, ub);
       fitness(sortIndex(i)) = fobj(X(sortIndex(i), :));
   end
   
   %% 警戒者位置更新
   c = randperm(numel(sortIndex));
   b = sortIndex(c(1:SD));
   for j = 1:length(b)      % Equation (5)
       if pFit(sortIndex(b(j))) > fMin
           X(sortIndex(b(j)), :) = bestX+(randn(1, dim)).*(abs((pX(sortIndex(b(j)), :) -bestX)));
       else
           X(sortIndex(b(j)), :) = pX(sortIndex(b(j)), :)+(2*rand(1)-1)*(abs(pX(sortIndex(b(j)), :)-worst))/(pFit(sortIndex(b(j)))-fmax+1e-50);
       end
       X(sortIndex(b(j)), :) = Bounds(X(sortIndex(b(j)), :), lb, ub);
       fitness(sortIndex(b(j))) = fobj(X(sortIndex(b(j)), :));
   end
   
   for i = 1:N
       % 更新个体最优
       if fitness(i) < pFit(i) 
           pFit(i) = fitness(i);
           pX(i, :) = X(i, :);
       end
       % 更新全局最优
       if pFit(i) < fMin
           fMin = pFit(i);
           bestX = pX(i, :);
       end
   end
   Convergence_curve(t) = fMin;
   
   disp(['SSA: At iteration ', num2str(t), ' ,the best fitness is ', num2str(fMin)]);
end

%% 边界处理
function s = Bounds(s, Lb, Ub)
% 下界
temp = s;
I = temp < Lb;
temp(I) = Lb(I);

% 上界
J = temp > Ub;
temp(J) = Ub(J);
% 更新
s = temp;

3 仿真结果

4 参考文献

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

部分理论引用网络文献,若有侵权联系博主删除。