飞蛾扑火优化(Moth-flame optimization,MFO),由Seyedali Mirjalili在2015年提出,为优化领域提供了一种新的启发式搜索范式:螺旋搜索。
飞蛾在夜间有一种特殊的导航方式:横向定向。即它会与月亮(光源)保持一定的角度飞行,从而能够保持直线的飞行路径,但是,这种方式只在光源离飞蛾较远的情况下才有效。当有人造光源存在时,飞蛾会被人工灯光所欺骗,一直保持与人造灯光相同的角度飞行,由于它与光源的距离过近,它飞行的路径已经不是直线,而是一种螺旋的路径。
受这种自然现象的启发,Seyedali Mirjalili将飞蛾绕着光源螺旋飞行的过程抽象成为一个寻优的过程,飞蛾飞行的整个空间即是问题的解空间,一只飞蛾即是问题的一个解,而火焰(光源)即是问题的一个较优解,每一只飞蛾对应一个光源,避免了算法陷入局部最优;当飞蛾与火焰足够多的时候,飞蛾的飞行能够搜索解空间的绝大部分区域,从而保证了算法的探索能力;而在寻优的过程中,火焰数随着迭代次数的增加而减少,使飞蛾能够充分搜索更优解的邻域空间,保证了算法的利用能力。
正是基于以上特点,MFO在探索与利用之间找到了平衡,从而使算法在优化问题中有一个较好的效果。
总的来说MFO也是一种基于种群的随机启发式搜索算法,它与PSO、GSA等算法最大的区别就在于其粒子搜索路径是螺旋形的,粒子围绕着更优解以一种螺旋的方式移动,而不是直线移动。
MFO的过程如下:
1.初始化飞蛾种群
2.对飞蛾种群进行适应度评价
3.重复如下过程直到达到停止标准:
3.1自适应更新火焰个数n,当迭代次数为1时,飞蛾个数即为火焰个数
3.2对飞蛾种群适应度进行排序,取出适应度较好的n个飞蛾作为火焰
3.3更新飞蛾的搜索参数。
3.4根据每只飞蛾对应的火焰与飞行参数更新飞蛾的位置
4.输出所得最优解(火焰)
具体的飞蛾位置更新公式见论文:Moth-flame optimization algorithm: A novel nature-inspired heuristic paradigm
示例:
%______________________________________________________________________________________________
% Moth-Flame Optimization Algorithm (MFO)
% Main paper:
% S. Mirjalili, Moth-Flame Optimization Algorithm: A Novel Nature-inspired Heuristic Paradigm,
% Knowledge-Based Systems, DOI: http://dx.doi.org/10.1016/j.knosys.2015.07.006
%_______________________________________________________________________________________________
% You can simply define your cost in a seperate file and load its handle to fobj
% The initial parameters that you need are:
%__________________________________________
% fobj = @YourCostFunction
% dim = number of your variables
% Max_iteration = maximum number of generations
% SearchAgents_no = number of search agents
% lb=[lb1,lb2,...,lbn] where lbn is the lower bound of variable n
% ub=[ub1,ub2,...,ubn] where ubn is the upper bound of variable n
% If all the variables have equal lower bound you can just
% define lb and ub as two single number numbers
% To run MFO: [Best_score,Best_pos,cg_curve]=MFO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj)
%______________________________________________________________________________________________
clear all
clc
SearchAgents_no=30; % Number of search agents
Function_name='F1'; % Name of the test function that can be from F1 to F23 (Table 1,2,3 in the paper)
Max_iteration=1000; % Maximum numbef of iterations
% Load details of the selected benchmark function
[lb,ub,dim,fobj]=Get_Functions_details(Function_name);
[Best_score,Best_pos,cg_curve]=MFO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj);
figure('Position',[284 214 660 290])
%Draw search space
subplot(1,2,1);
func_plot(Function_name);
title('Test function')
xlabel('x_1');
ylabel('x_2');
zlabel([Function_name,'( x_1 , x_2 )'])
grid off
%Draw objective space
subplot(1,2,2);
semilogy(cg_curve,'Color','b')
title('Convergence curve')
xlabel('Iteration');
ylabel('Best flame (score) obtained so far');
axis tight
grid off
box on
legend('MFO')
display(['The best solution obtained by MFO is : ', num2str(Best_pos)]);
display(['The best optimal value of the objective funciton found by MFO is : ', num2str(Best_score)]);
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
- 108.
- 109.