麻雀搜索算法(Sparrow search algorithm,SSA)是期刊“Systems Science & Control Engineering”(IF 2.7)的2020年智能优化算法
01.引言
本文根据麻雀的群体智慧、觅食和反捕食行为,提出了一种新的群体优化方法——麻雀搜索算法(SSA)。通过19个基准函数的实验验证了该算法的性能,并与灰狼优化器(GWO)、引力搜索算法(GSA)、粒子群优化算法(PSO)等算法进行了性能比较。仿真结果表明,该算法在精度、收敛速度、稳定性和鲁棒性方面均优于GWO、PSO和GSA。最后,通过两个工程实例验证了该方法的有效性
02.优化算法的流程
(1)生产者通常有高水平的能量储备,并为所有的拾荒者提供觅食区域或方向。它负责确定可以找到丰富食物来源的地区。能量储备的水平取决于对个体适应度值的评估。
(2)一旦麻雀发现捕食者,它们就开始鸣叫,作为警告信号。当告警值大于安全阈值时,生产者需要将所有行乞者引导至安全区域。
(3)每只麻雀都可以成为生产者,只要它寻找更好的食物来源,但生产者和乞丐的比例在整个种群中是不变的。
(4)能量较高的麻雀将充当生产者。几个饥饿的乞丐更有可能飞到其他地方寻找食物,以获得更多的能量。
(5)行乞者跟随能提供最好食物的生产者寻找食物。与此同时,一些行窃者可能会不断地监视生产者并争夺食物,以提高自己的捕食率。
(6)群中边缘的麻雀在意识到危险时迅速向安全区域移动,以获得更好的位置,而群中中间的麻雀则随机行走,以接近其他麻雀。
03.论文中算法对比图
04.部分代码
function [fMin , bestX,Convergence_curve ] = SSA(pop, M,c,d,dim,fobj )
P_percent = 0.2; % The population size of producers accounts for "P_percent" percent of the total population size
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pNum = round( pop * P_percent ); % The population size of the producers
lb= c.*ones( 1,dim ); % Lower limit/bounds/ a vector
ub= d.*ones( 1,dim ); % Upper limit/bounds/ a vector
%Initialization
for i = 1 : pop
x( i, : ) = lb + (ub - lb) .* rand( 1, dim );
fit( i ) = fobj( x( i, : ) ) ;
end
pFit = fit;
pX = x; % The individual's best position corresponding to the pFit
[ fMin, bestI ] = min( fit ); % fMin denotes the global optimum fitness value
bestX = x( bestI, : ); % bestX denotes the global optimum position corresponding to fMin
% Start updating the solutions.
for t = 1 : M
[ ans, sortIndex ] = sort( pFit );% Sort.
[fmax,B]=max( pFit );
worse= x(B,:);
r2=rand(1);
if(r2<0.8)
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 );
fit( 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 );
fit( sortIndex( i ) ) = fobj( x( sortIndex( i ), : ) );
end
end
[ fMMin, bestII ] = min( fit );
bestXX = x( bestII, : );
for i = ( pNum + 1 ) : pop % Equation (4)
A=floor(rand(1,dim)*2)*2-1;
if( i>(pop/2))
x( sortIndex(i ), : )=randn(1)*exp((worse-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 );
fit( sortIndex( i ) ) = fobj( x( sortIndex( i ), : ) );
end
c=randperm(numel(sortIndex));
b=sortIndex(c(1:20));
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) ), : )-worse))/ ( pFit( sortIndex( b(j) ) )-fmax+1e-50);
end
x( sortIndex(b(j) ), : ) = Bounds( x( sortIndex(b(j) ), : ), lb, ub );
fit( sortIndex( b(j) ) ) = fobj( x( sortIndex( b(j) ), : ) );
end
for i = 1 : pop
if ( fit( i ) < pFit( i ) )
pFit( i ) = fit( i );
pX( i, : ) = x( i, : );
end
if( pFit( i ) < fMin )
fMin= pFit( i );
bestX = pX( i, : );
end
end
Convergence_curve(t)=fMin;
end
% Application of simple limits/bounds
function s = Bounds( s, Lb, Ub)
% Apply the lower bound vector
temp = s;
I = temp < Lb;
temp(I) = Lb(I);
% Apply the upper bound vector
J = temp > Ub;
temp(J) = Ub(J);
% Update this new move
s = temp;
%---------------------------------------------------------------------------------------------------------------------------
04.本代码效果图