一、获取代码方式
获取代码方式1:
通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。
获取代码方式2:
完整代码已上传我的资源:【优化算法】闪电连接过程优化算法(LAPO)【含Matlab源码 1444期】
备注:
订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);
二、部分源代码
%___________________________________________________________________%
% Lightning Attachment Procedure Optimization (LAPO) source codes demo version 1.0 %
% %
% Developed in MATLAB R2015b %
% %
% %
%___________________________________________________________________%
% 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 LAPO_main: [Best_score,Best_pos,cg_curve]=LAPO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj)
clc
clear
close all
Function_name='F2'; % Name of the test function
SearchAgents_no=40; % Number of test point
Max_iteration=1000; % Maximum numbef of iterations
[lb,ub,dim,fobj]=Get_Functions_details(Function_name);
tic
[Best_score,Best_pos,cg_curve]=LAPO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj);
toc
figure('Position',[300 300 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','r')
title('Convergence curve')
xlabel('Iteration');
ylabel('Best score obtained so far');
axis tight
grid off
box on
legend('LAPO')
display(['The best solution obtained by LAPO is : ', num2str(Best_pos)]);
display(['The best optimal value of the objective funciton found by LAPO is : ', num2str(Best_score)]);
三、运行结果
四、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016.
[2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.