1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 【优化求解】飞蛾扑火算法(MFO)matlab源码

【优化求解】飞蛾扑火算法(MFO)matlab源码

时间:2023-10-18 21:40:16

相关推荐

【优化求解】飞蛾扑火算法(MFO)matlab源码

飞蛾扑火优化(Moth-flame optimization,MFO),由Seyedali Mirjalili在提出,为优化领域提供了一种新的启发式搜索范式:螺旋搜索

飞蛾在夜间有一种特殊的导航方式:横向定向。即它会与月亮(光源)保持一定的角度飞行,从而能够保持直线的飞行路径,但是,这种方式只在光源离飞蛾较远的情况下才有效。当有人造光源存在时,飞蛾会被人工灯光所欺骗,一直保持与人造灯光相同的角度飞行,由于它与光源的距离过近,它飞行的路径已经不是直线,而是一种螺旋的路径。\

受这种自然现象的启发,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: /10.1016/j.knosys..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: [Bestscore,Bestpos,cgcurve]=MFO(SearchAgentsno,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]=GetFunctionsdetails(Function_name);

[Bestscore,Bestpos,cgcurve]=MFO(SearchAgentsno,Max_iteration,lb,ub,dim,fobj);

figure('Position',[284 214 660 290])

%Draw search space

subplot(1,2,1);

funcplot(Functionname);

title('Test function')

xlabel('x_1');

ylabel('x_2');

zlabel([Functionname,'( x1 , 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)]); ```

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。