一、获取代码方式
获取代码方式1: 通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。
获取代码方式2: 通过紫极神光博客主页开通CSDN会员,凭支付凭证,私信博主,可获得此代码。
获取代码方式3: 完整代码已上传我的资源:【优化算法】学生心理学优化算法(SPBO)【含Matlab源码 1430期】
备注:开通CSDN会员,仅只能免费获得1份代码(有效期为开通日起,三天内有效); 订阅紫极神光博客付费专栏,可免费获得2份代码(有效期为订阅日起,三天内有效);
二、部分源代码
% Student psychology based optimization (SPBO)algorithm
%
%
%
%
% Main paper:
% Bikash Das, V Mukherjee, Debapriya Das, Student psychology based optimization algorithm: A new population based
% optimization algorithm for solving optimization problems, Advances in Engineering Software, 146 (2020) 102804.
%_______________________________________________________________________________________________
% You can simply define your objective function in a seperate file and load its handle to fobj
% The initial parameters that you need are:
%__________________________________________
% fobj = @Objective function
% variable = number of your variables
% Max_iteration = maximum number of iterations
% student = number of search agents
% mini=[mini1,mini2,...,minin] where mini is the lower bound of variable n
% maxi=[maxi1,maxi2,...,maxin] where maxi is the upper bound of variable n
% If all the variables have equal lower bound you can just
% define mini and maxi as two single numbers
% To run SPBO: [Best_fitness,Best_student,Convergence_curve]=SPBO(student,Max_iteration,mini,maxi,variable,fobj)
%______________________________________________________________________________________________
clear all
clc
student=20; % Number of student (population)
Function_name='F5'; % Name of the test function that can be from F1 to F23
Max_iteration=1000; % Maximum number of iterations
% Load details of the selected benchmark function
[mini,maxi,variable,fobj]=Functions(Function_name);
%Solution obtained using SPBO
[Best_fitness,Best_student,Convergence_curve]=SPBO(student,Max_iteration,maxi,mini,variable,fobj);
% Converging Curve
figure (1)
plot (Convergence_curve);
title('Convergence curve')
xlabel('Iteration');
ylabel('Fitness of best student so far');
display(['The best solution obtained by SPBO is : ', num2str(Best_student)]);
display(['The best optimal value of the objective funciton found by SPBO is : ', num2str(Best_fitness)]);
% Student psychology based optimization (SPBO)algorithm
%
% Source codes demo version 1.0
%
% Developed in MATLAB R2017b
%
% Author and programmer: Bikash Das, V. Mukherjee, D. Das
%
% e-Mail: bcazdas@gmail.com, vivek_agamani@yahoo.com, ddas@ee.iitkgp.ernet.in
%
%
% Main paper:
% Bikash Das, V Mukherjee, Debapriya Das, Student psychology based optimization algorithm: A new population based
% optimization algorithm for solving optimization problems, Advances in Engineering Software, 146 (2020) 102804.
%_______________________________________________________________________________________________
% You can simply define your objective function in a seperate file and load its handle to fobj
% The initial parameters that you need are:
%__________________________________________
% fobj = @Objective function
% variable = number of your variables
% Max_iteration = maximum number of iterations
% student = number of search agents
% mini=[mini1,mini2,...,minin] where mini is the lower bound of variable n
% maxi=[maxi1,maxi2,...,maxin] where maxi is the upper bound of variable n
% If all the variables have equal lower bound you can just
% define mini and maxi as two single numbers
% To run SPBO: [Best_fitness,Best_student,Convergence_curve]=SPBO(student,Max_iteration,mini,maxi,variable,fobj)
%______________________________________________________________________________________________
function [mini,maxi,variable,fobj] = Functions(F)
switch F
case 'F1'
fobj = @F1;
mini=-5.12;
maxi=5.12;
variable=10;
case 'F2'
fobj = @F2;
mini=-10;
maxi=10;
variable=10;
case 'F3'
fobj = @F3;
mini=-100;
maxi=100;
variable=10;
case 'F4'
fobj = @F4;
mini=-5.12;
maxi=5.12;
variable=10;
case 'F5'
fobj = @F5;
mini=-1.28;
maxi=1.28;
variable=10;
end
end
% Step
% F1
function o = F1(x)
o=sum(((x+.5)).^2);
end
% Sum Square
% F2
function o = F2(x)
variable=size(x,2);
o=sum([1:variable].*(x.^2));
end
% Sphere
% F3
function o = F3(x)
o=sum((x).^2);
end
% Rastrigin
% F4
function o = F4(x)
variable=size(x,2);
o=sum(x.^2-10*cos(2*pi.*x))+10*variable;
end
% Quartic
% F5
function o = F5(x)
variable=size(x,2);
o=sum([1:variable].*(x.^4));
end
三、运行结果
四、matlab版本及参考文献
1 matlab版本 2014a
2 参考文献 [1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016. [2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.