今天为大家带来一期蝴蝶优化算法。并与麻雀,蜣螂,灰狼算法比较。
蝴蝶优化算法( BOA) 是 Arora [1]等人于2019年提出的一种模拟蝴蝶觅食和求偶行为的新型元启发式优化算法。基本 BOA 中参 数少、原理简单、易于实现。
原理详解
蝴蝶优化算法是模拟自然界中蝴蝶觅食( 花蜜) 和求偶行 为而衍生出的一种新型群智能优化算法。从生物学上讲,蝴蝶 有感官感受器用来闻/感觉食物及花朵的香味,这些感受器被称为化学感受器,分散在蝴蝶身体的各个部位,如腿、触须等。
步骤:
a) 所有的蝴蝶会散发香味,使蝴蝶个体之间相互吸引。
b) 每只蝴蝶都会随机移动或向发出最多香味的蝴蝶移动。
c) 蝴蝶的刺激强度受目标函数的影响或决定。
d) 全局搜索和局部搜索使用切换概率 p 来控制,由于物理近似度以及风雨、雷电等各种其他自然因素等,局部搜索和全 局开采的切换概率 p 有重要意义。在BOA 中,每一只蝴蝶有它自己独特的感觉和个体感知能力,同时这也是区别于其他群智能算法的一个重要特征。蝴蝶产生香味的数学公式:
(1)
其中: f 是香味的感知强度,即香味能够被其他蝴蝶感知的强 度; c 是蝴蝶的感觉模态; I 是刺激强度; a 是依赖于模态的幂指数,它解释了不同程度香味的吸收。在全局搜索阶段,蝴蝶朝着最优的蝴蝶 ( 解 g* ) 移动,全局位置更新公式: (2)
其中: xti是第 t 次迭代中第 i 只蝴蝶的解向量 xi ; g* 表示在当 前迭代的所有解中的最优解; 第 i 只蝴蝶发出的香味用fi表示; r 是[0,1]的随机数。局部位置更新公式为: (3)
基本蝴蝶算法流程如图所示:
结果展示
CEC2005测试结果:
CEC2021测试结果:
CEC2022测试结果:
可以看到蝴蝶算法的寻优能力令人堪忧呀,不过这也说明了该算法的改进空间很大!
代码展示
%Butterfly optimization algorithm
% AroraS,SinghS.Butterflyoptimizationalgorithm:Anovel approach for global optimization [J].
% SoftComputing,2019,23 (3):715-734.
function [fmin,best_pos,Convergence_curve]=BOA(n,N_iter,Lb,Ub,dim,fobj)
% n is the population size
% N_iter represnets total number of iterations
p=0.8; % probabibility switch
power_exponent=0.1;
sensory_modality=0.01;
%Initialize the positions of search agents
Sol=initialization(n,dim,Ub,Lb);
for i=1:n
Fitness(i)=fobj(Sol(i,:));
end
% Find the current best_pos
[fmin,I]=min(Fitness);
best_pos=Sol(I,:);
S=Sol;
% Start the iterations -- Butterfly Optimization Algorithm
for t=1:N_iter
for i=1:n% Loop over all butterflies/solutions
%Calculate fragrance of each butterfly which is correlated with objective function
Fnew=fobj(S(i,:));
FP=(sensory_modality*(Fnew^power_exponent));
%Global or local search
if rand<p
dis = rand * rand * best_pos - Sol(i,:); %Eq. (2) in paper
S(i,:)=Sol(i,:)+dis*FP;
else
% Find random butterflies in the neighbourhood
epsilon=rand;
JK=randperm(n);
dis=epsilon*epsilon*Sol(JK(1),:)-Sol(JK(2),:);
S(i,:)=Sol(i,:)+dis*FP; %Eq. (3) in paper
end
% Check if the simple limits/bounds are OK
S(i,:)=simplebounds(S(i,:),Lb,Ub);
% Evaluate new solutions
Fnew=fobj(S(i,:)); %Fnew represents new fitness values
% If fitness improves (better solutions found), update then
if (Fnew<=Fitness(i))
Sol(i,:)=S(i,:);
Fitness(i)=Fnew;
end
% Update the current global best_pos
if Fnew<=fmin
best_pos=S(i,:);
fmin=Fnew;
end
end
Convergence_curve(t,1)=fmin;
%Update sensory_modality
sensory_modality=sensory_modality_NEW(sensory_modality, N_iter);
end
end
% Boundary constraints
function s=simplebounds(s,Lb,Ub)
% Apply the lower bound
ns_tmp=s;
I=ns_tmp<Lb;
ns_tmp(I)=Lb;
% Apply the upper bounds
J=ns_tmp>Ub;
ns_tmp(J)=Ub;
% Update this new move
s=ns_tmp;
end
function y=sensory_modality_NEW(x,Ngen)
y=x+(0.025/(x*Ngen));
end
下一期对蝴蝶算法进行改进!
代码免费获取方式
完整代码获取方式:后台回复关键字,不区分大小写。关键字:
TGDM827