飞蛾火焰优化算法(Moth-flame optimization algorithm, MFO)是一种新颖的群体智能算法,该算法由飞蛾和火焰两部分构成!通过横向定位导航机制来解决探索和开采之间的平衡问题。MFO具有参数简单、容易实现且鲁棒性好等优点,因此,自提出以来,便受到国内外学者的广泛关注,使其在诸多领域得到应用。
在MFO算法中,飞蛾个体为优化问题的候选解,飞蛾在优化空间的位置代表求解优化问题的变量,通过在优化空间中改变位置向量来向全局最佳点靠拢。MFO算法的种群 M \boldsymbol M M由下列矩阵描述: M = [ m 1 , m 2 , ⋯ , m n ] T m i = [ m i , 1 , m i , 2 , ⋯ , m i , d ] T (1) \begin{aligned}&\boldsymbol M=[\boldsymbol m_1,\boldsymbol m_2,\cdots,\boldsymbol m_n]^T\\&\boldsymbol m_i=[m_{i,1},m_{i,2},\cdots,m_{i,d}]^T\end{aligned}\tag{1} M=[m1,m2,⋯,mn]Tmi=[mi,1,mi,2,⋯,mi,d]T(1)其中, n n n为飞蛾数量, d d d为优化问题维数。飞蛾个体适应度值存储在 O M \boldsymbol{OM} OM矩阵中: O M = [ O M 1 O M 2 ⋯ O M n ] T (2) \boldsymbol{OM}=[OM_1\,OM_2\cdots OM_n]^T\tag{2} OM=[OM1OM2⋯OMn]T(2)火焰为当前迭代所获得的最佳位置,式(3)描述了最优位置矩阵 F \boldsymbol F F,其适应度值存放在 O F \boldsymbol{OF} OF中。 F = [ f 1 , f 2 , ⋯ , f n ] T f i = [ f i , 1 , f i , 2 , ⋯ , f i , d ] T (3) \begin{aligned}&\boldsymbol F=[\boldsymbol f_1,\boldsymbol f_2,\cdots,\boldsymbol f_n]^T\\&\boldsymbol f_i=[f_{i,1},f_{i,2},\cdots,f_{i,d}]^T\end{aligned}\tag{3} F=[f1,f2,⋯,fn]Tfi=[fi,1,fi,2,⋯,fi,d]T(3) O F = [ O F 1 O F 2 ⋯ O F n ] T (4) \boldsymbol{OF}=[OF_1\,OF_2\,\cdots\,OF_n]^T\tag{4} OF=[OF1OF2⋯OFn]T(4)
受自然界飞蛾行为启发提出了MFO算法,飞蛾个体围绕在火焰周围迭代更新其位置直到搜索到最佳解决方案为止,其数学描述分为捕焰行为和弃焰行为。
(1)捕焰行为。自然界中具有趋光特性的飞蛾 M i M_i Mi会朝着距离自身最近的亮光(火焰) F j F_j Fj移动。选择式(5)描述的对数螺线作为飞蛾捕焰的移动轨迹: S ( M i , F j ) = D i × e b t × cos ( 2 π t ) + F j (5) S(M_i,F_j)=D_i×e^{bt}×\cos(2\pi t)+F_j\tag{5} S(Mi,Fj)=Di×ebt×cos(2πt)+Fj(5)其中, S ( M i , F j ) S(M_i,F_j) S(Mi,Fj)为更新后的飞蛾位置; b b b为与螺线形状相关的常量; t t t为随机数,取值区间为 [ − 1 , 1 ] [-1,1] [−1,1], t = − 1 t=-1 t=−1是最接近火焰, t = 1 t=1 t=1是离火焰最远; D i = ∣ F j − M i ∣ D_i=|F_j-M_i| Di=∣Fj−Mi∣为飞蛾 M i M_i Mi到火焰 F j F_j Fj的距离。
(2) 弃焰行为。MFO算法通过弃焰行为自适应减少火焰数量,直到保持一个最优的火焰位置为止,火焰减少过程如式(6)所示: f l a m e _ n o = r o u n d ( N − t × N − 1 T ) (6) flame\_{no}=round(N-t×\frac{N-1}{T})\tag{6} flame_no=round(N−t×TN−1)(6)其中, t t t和 T T T分别为当前迭代次数和最大迭代次数; N N N为最大火焰数量。
飞蛾火焰优化算法的一般步骤如下:
步骤1 初始化算法参数:飞蛾数量 n n n、维数 d d d、最大迭代次数 T T T等,随机初始化种群;
步骤2 计算种群中飞蛾的适应度值,并按适应度值进行升序排序;
步骤3 利用式(6)更新火焰数量;
步骤4 利用式(5)更新飞蛾位置;
步骤5 若满足给定的迭代次数!算法结束,获得最优解;否则,返回步骤2。
%% 火焰自适应减少的数量
clear;
clc;
%%
N = 30; % 种群规模
T = 1000; % 最大迭代次数
for t = 1:T
flame_no(t) = round(N-t*(N-1)/T);
end
%%
figure;
plot(flame_no, 'b', 'linewidth', 1.5);
xlabel '迭代次数'; ylabel '火焰数量';
function [Best_flame_score,Best_flame_pos,Convergence_curve]=MFO(N,Max_iteration,lb,ub,dim,fobj)
% 初始化飞蛾位置
Moth_pos = initialization(N, dim, ub, lb);
Convergence_curve = zeros(1, Max_iteration);
Iteration = 1;
%% 迭代
while Iteration < Max_iteration+1
%% 弃焰行为
% Eq. (3.14) in the paper--火焰自适应数量
Flame_no = round(N-Iteration*((N-1)/Max_iteration));
for i = 1:size(Moth_pos,1)
% 边界处理
Flag4ub = Moth_pos(i, :) > ub;
Flag4lb = Moth_pos(i, :) < lb;
Moth_pos(i, :) = (Moth_pos(i, :).*(~(Flag4ub+Flag4lb)))+ub.*Flag4ub+lb.*Flag4lb;
% 计算适应度值
Moth_fitness(i) = fobj(Moth_pos(i, :));
end
if Iteration == 1
% 排序
[fitness_sorted, I] = sort(Moth_fitness);
sorted_population = Moth_pos(I, :);
% 更新火焰
best_flames = sorted_population;
best_flame_fitness = fitness_sorted;
else
% 排序
double_population = [previous_population; best_flames];
double_fitness = [previous_fitness best_flame_fitness];
[double_fitness_sorted,I] = sort(double_fitness);
double_sorted_population = double_population(I, :);
fitness_sorted = double_fitness_sorted(1:N);
sorted_population = double_sorted_population(1:N, :);
% 更新火焰
best_flames = sorted_population;
best_flame_fitness = fitness_sorted;
end
% 更新全局最优解
Best_flame_score = fitness_sorted(1);
Best_flame_pos = sorted_population(1,:);
previous_population = Moth_pos;
previous_fitness = Moth_fitness;
%% 捕焰行为
% a从-1到-2线性递减,以计算公式(3.12)中的t
a = -1+Iteration*((-1)/Max_iteration);
for i = 1:size(Moth_pos, 1)
for j = 1:size(Moth_pos, 2)
if i <= Flame_no % 更新飞蛾相对于相应火焰的位置
% D in Eq. (3.13)
distance_to_flame = abs(sorted_population(i,j)-Moth_pos(i,j));
b = 1;
t = (a-1)*rand+1;
% Eq. (3.12)
Moth_pos(i, j) = distance_to_flame*exp(b.*t).*cos(t.*2*pi)+sorted_population(i, j);
else % 更新飞蛾相对于相应火焰的位置
% Eq. (3.13)
distance_to_flame = abs(sorted_population(i, j)-Moth_pos(i, j));
b = 1;
t = (a-1)*rand+1;
% Eq. (3.12)
Moth_pos(i, j) = distance_to_flame*exp(b.*t).*cos(t.*2*pi)+sorted_population(Flame_no, j);
end
end
end
Convergence_curve(Iteration) = Best_flame_score;
% 显示迭代信息
display(['MFO:At iteration ', num2str(Iteration), ' the best fitness is ', num2str(Best_flame_score)]);
Iteration = Iteration+1;
end
对文献[1]中的F1、F2、F3的10维函数进行测试,种群规模 N = 30 N=30 N=30,最大迭代次数 M a x _ i t e r a t i o n = 1000 Max\_iteration=1000 Max_iteration=1000,结果如下:
The best solution obtained by MFO is : -1.7505e-16 1.9705e-16 -1.2058e-16 -5.9773e-18 3.4731e-17 -6.391e-18 -4.2794e-17 6.2151e-17 1.1133e-16 1.135e-16
The best optimal value of the objective funciton found by MFO is : 1.1626e-31
The best solution obtained by MFO is : 8.2602e-20 -5.6014e-20 -6.5107e-20 1.1034e-19 1.239e-19 -7.165e-20 9.1319e-20 -2.1942e-19 9.8067e-20 -2.1097e-19
The best optimal value of the objective funciton found by MFO is : 1.1294e-18
The best solution obtained by MFO is : 4.2418e-05 -6.9891e-05 5.7333e-05 -3.0783e-05 5.1278e-06 9.7225e-06 1.0513e-05 -2.1992e-05 -1.4548e-05 8.8871e-06
The best optimal value of the objective funciton found by MFO is : 4.4182e-09
[1] Mirjalili S. Moth-flame optimization algorithm: a novel nature- inspired heuristic paradigm[J]. Knowledge-Based Systems, 2015, 89: 228-249.
[2] 田鸿, 陈国彬, 刘超. 新型飞蛾火焰优化算法的研究[J]. 计算机工程与应用, 2019, 55(16): 138-143.
[3] 刘倩, 冯艳红, 陈嶷瑛. 基于混沌初始化和高斯变异的飞蛾火焰优化算法[J]. 郑州大学学报(工学版), 2021, 42(3): 53-58.