200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > 【优化算法】自治群体粒子群优化算法(AGPSO)【含Matlab源码 1450期】

【优化算法】自治群体粒子群优化算法(AGPSO)【含Matlab源码 1450期】

时间:2021-10-13 16:23:03

相关推荐

【优化算法】自治群体粒子群优化算法(AGPSO)【含Matlab源码 1450期】

一、获取代码方式

获取代码方式1:

通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。

获取代码方式2:

完整代码已上传我的资源:【优化算法】自治群体粒子群优化算法(AGPSO)【含Matlab源码 1450期】

备注:

订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);

二、部分源代码

% Autonomous Groups Particles Swarm Optimization (AGPSO) source codes version 1.1 %% %% Developed in MATLAB Ra(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 clcSearchAgents_no=30; % Number of search agentsFunction_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 spacesubplot(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 curvessubplot(1,2,2);semilogy(AGPSO1_cg_curve,'Color','r')hold onsemilogy(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 tightgrid onbox onlegend('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);%Initializationfor 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();endendfor i=1:NpBestScore(i)=inf;end%initialize gBestScore for mingBestScore=inf;for l=1:Max_iteration%Calculate Score Functionfor 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,:);endif(gBestScore>fitness)gBestScore=fitness;gBest=pos(i,:);endendc1=2.5+2*(l/Max_iteration)^2-2*(2*l/Max_iteration);c2=3-c1; %update the W of PSOw=wMax-l*((wMax-wMin)/Max_iteration);%Update the Velocity and Position of particlesfor 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);endendcg_curve(l)=gBestScore;endend

三、运行结果

四、matlab版本及参考文献

1 matlab版本

a

2 参考文献

[1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,.

[2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,.

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