1.背景
2019年,Arora等人受到蝴蝶捕食自然行为影响,提出了蝴蝶优化算法(Butterfly optimization algorithm,BOA)。
2.算法原理
2.1算法思想
蝴蝶会释放一定的气味浓度(跟适应度函数有关),气味浓度会吸引蝴蝶飞行。当蝴蝶从一个位置移动到另一个位置时其适应度将相应地变化。
2.2算法过程
群体位置初始化:
x
=
l
b
+
r
a
n
d
∗
(
u
b
−
l
b
)
x=lb+rand*(ub-lb)
x=lb+rand∗(ub−lb)
其中,
u
b
,
l
b
ub,lb
ub,lb分别代表蝴蝶上下位置边界。
气味浓度:
f
=
c
I
a
f=cI^{a}
f=cIa
其中,
f
,
c
,
I
,
a
f,c,I,a
f,c,I,a分别表示蝴蝶气味强度,感知因子,刺激强度(适应度)和控制常数。论文对这里的解释是:自然界中的昆虫随着刺激度增强,敏感度会变得越低,因此
a
=
0.1
a=0.1
a=0.1对
I
I
I进行压缩。另一方面,根据
S
t
e
v
e
n
s
Stevens
Stevens幂律,为了区分气味间的区别,用感知因子
c
c
c表述。
探索阶段:
{
x
i
t
+
1
=
x
i
t
+
(
r
2
×
g
∗
−
x
i
t
)
×
f
i
,
r
a
n
d
<
p
x
i
t
+
1
=
x
i
t
+
(
r
2
×
x
j
t
−
x
k
t
)
×
f
i
,
o
t
h
e
r
w
i
s
e
\begin{cases}{x_i}^{t+1}={x_i}^t+\left(r^2\times g^*-{x_i}^t\right)\times f_i, rand<p \\ {x_i}^{t+1}={x_i}^t+\left(r^2\times{x_j}^t-{x_k}^t\right)\times f_i,otherwise \end{cases}
{xit+1=xit+(r2×g∗−xit)×fi,rand<pxit+1=xit+(r2×xjt−xkt)×fi,otherwise
这里采用采用的全局搜索和局部搜索机制,这里用控制参数
p
p
p控制。其中,
g
∗
g^{*}
g∗表示目前最优蝴蝶位置。
伪代码:
3.代码实现
% 蝴蝶算法
function [fmin,best_pos,Convergence_curve, History_pos, History_best]=BOA(n,N_iter,Lb,Ub,dim,fobj)
%input
%n 种群数量
%dim 问题维数
%Lb 变量上边界最大值
%Ub 变量下边界最小值
%fobj 适应度函数
%N_iter 最大迭代次数
%output
%best_pos 最优位置
%fmin 最优适应度值
%Convergence_curve 每代最优适应度值
%History_pos 每代种群位置
%History_best 每代最优个体
%% 控制参数
p=0.8;
power_exponent=0.1;
sensory_modality=0.01;
%% 初始化种群
Sol = zeros(n, dim);
for i = 1:dim
Sol(:,i) = rand(n, 1) * (Ub(i) - Lb(i)) + Lb(i);
end
%% 计算适应度
for i=1:n
Fitness(i)=fobj(Sol(i,:));
end
%% 记录
[fmin,I]=min(Fitness);
best_pos=Sol(I,:);
S=Sol;
%% 迭代
for t=1:N_iter
for i=1:n
Fnew=fobj(S(i,:));
FP=(sensory_modality*(Fnew^power_exponent));
% 全局搜索
if rand<p
dis = rand * rand * best_pos - Sol(i,:);
S(i,:)=Sol(i,:)+dis*FP;
else
% 局部搜索
epsilon=rand;
JK=randperm(n);
dis=epsilon*epsilon*Sol(JK(1),:)-Sol(JK(2),:);
S(i,:)=Sol(i,:)+dis*FP;
end
% 边界处理
S(i,:)=simplebounds(S(i,:),Lb,Ub);
Fnew=fobj(S(i,:));
if (Fnew<=Fitness(i))
Sol(i,:)=S(i,:);
Fitness(i)=Fnew;
end
if Fnew<=fmin
best_pos=S(i,:);
fmin=Fnew;
end
end
Convergence_curve(t,1)=fmin;
History_pos{t} = Sol;
History_best{t} = best_pos;
sensory_modality=sensory_modality_NEW(sensory_modality, N_iter);
end
end
%%
function s=simplebounds(s,Lb,Ub)
m = length(s);
for i = 1:m
if s(i) > Ub(i)
s(i) = Ub(i);
end
if s(i) < Lb(i)
s(i) = Lb(i);
end
end
end
%%
function y=sensory_modality_NEW(x,Ngen)
y=x+(0.025/(x*Ngen));
end
优化问题
以CEC2005测试函数为例
clear,clc,close all
x=-10:0.1:10;
y = x;
L = length(x);
for i = 1:L
for j = 1:L
f(i,j) = fun([x(i) y(j)]);
end
end
surfc(x, y, f, 'LineStyle', 'none', 'FaceAlpha',0.5);
% 设定种群参数
pop = 50;
dim = 2;
ub = [10, 10];
lb = [-10, -10];
maxIter = 100;
fobj = @(x) fun(x);
% 求解
[Best_fitness, Best_pos, Iter_curve, History_pos, History_best] = BOA(pop, maxIter, lb, ub, dim, fobj);
4.参考文献
【1】Arora S, Singh S. Butterfly optimization algorithm: a novel approach for global optimization[J]. Soft Computing, 2019, 23: 715-734.