【优化算法】自治群体粒子群优化算法(AGPSO)【含Matlab源码 1450期】
【摘要】
一、获取代码方式
获取代码方式1: 通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。
获取代码方式2: 完整代码已上传我的资源:【优化算法】自治群体粒子群优化算法(AGPSO)【含M...
一、获取代码方式
获取代码方式1:
通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。
获取代码方式2:
完整代码已上传我的资源:【优化算法】自治群体粒子群优化算法(AGPSO)【含Matlab源码 1450期】
备注:
订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);
二、部分源代码
% Autonomous Groups Particles Swarm Optimization (AGPSO) source codes version 1.1 %
% %
% Developed in MATLAB R2014a(7.13) %
% %
%
% 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 AGPSO3: [Best_score,Best_pos,GWO_cg_curve]=AGPSO3(SearchAgents_no,Max_iteration,lb,ub,dim,fobj)
%__________________________________________
clear all
clc
SearchAgents_no=30; % Number of search agents
Function_name='F8'; % Name of the test function that can be from F1 to F23 (Table 1,2,3 in the paper)
Max_iteration=500; % Maximum numbef of iterations
% Load details of the selected benchmark function
[lb,ub,dim,fobj]=Get_Functions_details(Function_name);
[Best_score1,Best_pos1,AGPSO1_cg_curve]= AGPSO1(SearchAgents_no,Max_iteration,lb,ub,dim,fobj);
[Best_score2,Best_pos2,AGPSO2_cg_curve]= AGPSO2(SearchAgents_no,Max_iteration,lb,ub,dim,fobj);
[Best_score3,Best_pos3,AGPSO3_cg_curve]= AGPSO3(SearchAgents_no,Max_iteration,lb,ub,dim,fobj);
[Best_score4,Best_pos4,PSO_cg_curve] = PSO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj);
[Best_score5,Best_pos5,IPSO_cg_curve]= IPSO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj);
[Best_score6,Best_pos6,TACPSO_cg_curve]= TACPSO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj);
[Best_score7,Best_pos7,MPSO_cg_curve]= MPSO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj);
figure('Position',[300 300 660 290])
%Draw search space
subplot(1,2,1);
func_plot(Function_name);
title('Parameter space')
xlabel('x_1');
ylabel('x_2');
zlabel([Function_name,'( x_1 , x_2 )'])
%Draw convergence curves
subplot(1,2,2);
semilogy(AGPSO1_cg_curve,'Color','r')
hold on
semilogy(AGPSO2_cg_curve,'Color','b')
semilogy(AGPSO3_cg_curve,'Color','k')
semilogy(PSO_cg_curve,'Color','g')
semilogy(MPSO_cg_curve,'Color','y')
semilogy(TACPSO_cg_curve,'Color','c')
semilogy(IPSO_cg_curve,'Color','m')
title('Objective space')
xlabel('Iteration');
ylabel('Best score obtained so far');
axis tight
grid on
box on
legend('AGPSO1','AGPSO2','AGPSO3', 'PSO', 'MPSO', 'TACPSO', 'IPSO')
display(['The best solution obtained by AGPSO1 is : ', num2str(Best_pos1)]);
display(['The best optimal value obtained by AGPSO1 is : ', num2str(Best_score1)]);
display(['The best solution obtained by AGPSO2 is : ', num2str(Best_pos2)]);
display(['The best optimal value obtained by AGPSO2 is : ', num2str(Best_score2)]);
display(['The best solution obtained by AGPSO3 is : ', num2str(Best_pos3)]);
display(['The best optimal value obtained by AGPSO3 is : ', num2str(Best_score3)]);
display(['The best solution obtained by SPSO is : ', num2str(Best_pos4)]);
display(['The best optimal value obtained by SPSO is : ', num2str(Best_score4)]);
display(['The best solution obtained by MPSO is : ', num2str(Best_pos5)]);
display(['The best optimal value obtained by MPSO is : ', num2str(Best_score5)]);
display(['The best solution obtained by TACPSO is : ', num2str(Best_pos6)]);
display(['The best optimal value obtained by TACPSO is : ', num2str(Best_score6)]);
display(['The best solution obtained by IPSO is : ', num2str(Best_pos1)]);
display(['The best optimal value obtained by IPSO is : ', num2str(Best_score1)]);
function [gBestScore,gBest,cg_curve]=IPSO(N,Max_iteration,lb,ub,dim,fobj)
wMax=0.9;
wMin=0.4;
c1=2;
c2=2;
vel=zeros(N,dim);
pos=zeros(N,dim);
pBestScore=zeros(N);
pBest=zeros(N,dim);
gBestScore=0;
gBest=zeros(1,dim);
%Initialization
for i=1:size(pos,1)
for j=1:size(pos,2)
pos(i,j)=(ub(j)-lb(j))*rand()+lb(j);
vel(i,j)=0.3*rand();
end
end
for i=1:N
pBestScore(i)=inf;
end
%initialize gBestScore for min
gBestScore=inf;
for l=1:Max_iteration
%Calculate Score Function
for i=1:size(pos,1)
fitness=0;
Tp=pos(i,:)>ub;Tm=pos(i,:)<lb;pos(i,:)=(pos(i,:).*(~(Tp+Tm)))+ub.*Tp+lb.*Tm;
fitness=fobj(pos(i,:));
if(pBestScore(i)>fitness)
pBestScore(i)=fitness;
pBest(i,:)=pos(i,:);
end
if(gBestScore>fitness)
gBestScore=fitness;
gBest=pos(i,:);
end
end
c1=2.5+2*(l/Max_iteration)^2-2*(2*l/Max_iteration);
c2=3-c1;
%update the W of PSO
w=wMax-l*((wMax-wMin)/Max_iteration);
%Update the Velocity and Position of particles
for i=1:size(pos,1)
for j=1:size(pos,2)
vel(i,j)=w*vel(i,j)+c1*rand()*(pBest(i,j)-pos(i,j))+c2*rand()*(gBest(j)-pos(i,j));
pos(i,j)=pos(i,j)+vel(i,j);
end
end
cg_curve(l)=gBestScore;
end
end
三、运行结果
四、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016.
[2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.
文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。
原文链接:qq912100926.blog.csdn.net/article/details/120937668
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)