二、部分源代码
%---------------------------------------------------------------------------------------------------------------------------
%
%---------------------------------------------------------------------------------------------------------------------------
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear
close all
clc
nP=50; % Number of Population
Func_name='F1'; % Name of the test function, range from F1-F14
MaxIt=500; % Maximum number of iterations
% Load details of the selected benchmark function
[lb,ub,dim,fobj]=BenchmarkFunctions(Func_name);
[Best_fitness,BestPositions,Convergence_curve] = GBO(nP,MaxIt,lb,ub,dim,fobj);
%% Plots
figure,
hold on
semilogy(Convergence_curve,'Color','b','LineWidth',3);
title('Convergence curve')
xlabel('Iteration');
ylabel('Best fitness obtained so far');
axis tight
grid off
box on
legend('GBO')
%___________________________________________________________________% %
% Gradien-Based Optimizer source code (Developed in MATLAB R2017a) %
% %
% programming: Iman Ahmadianfar %
% %
% e-Mail: im.ahmadian@gmail.com %
% i.ahmadianfar@bkatu.ac.ir %
% %
% Source codes demo version 1.0
% ------------------------------------------------------------------------------------------------------------
% Main paper (Please refer to the main paper):
% Gradient-Based Optimizer: A New Metaheuristic Optimization Algorithm
% Iman Ahmadianfar, Omid Bozorg-Haddad, Xuefeng Chu
% Information Sciences,2020
% DOI: https://doi.org/10.1016/j.ins.2020.06.037
% https://www.sciencedirect.com/science/article/pii/S0020025520306241
% ------------------------------------------------------------------------------------------------------------
% Website of GBO: http://imanahmadianfar.com/
% You can find and run the GBO code online at http://imanahmadianfar.com/
% You can find the GBO paper at https://doi.org/10.1016/j.ins.2020.06.037
% Please follow the paper for related updates in researchgate: https://www.researchgate.net/profile/Iman_Ahmadianfar
% ------------------------------------------------------------------------------------------------------------
% Co-author:
% Omid Bozorg-Haddad(OBHaddad@ut.ac.ir)
% Xuefeng Chu(xuefeng.chu@ndsu.edu)
% _____________________________________________________
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function initialize the first population
function X=initialization(nP,dim,ub,lb)
Boundary_no= size(ub,2); % numnber of boundaries
% If the boundaries of all variables are equal and user enter a signle
% number for both ub and lb
if Boundary_no==1
X=rand(nP,dim).*(ub-lb)+lb;
end
% If each variable has a different lb and ub
if Boundary_no>1
for i=1:dim
X(:,i)=rand(nP,1).*(ub(i)-lb(i))+lb(i);
end
end
三、运行结果
四、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016.
[2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.
[3]施媛波.基于改进的群居蜘蛛优化云计算任务调度算法[J].电脑编程技巧与维护. 2021,(04)