【路径规划】基于帝国企鹅算法求解三维旅行商问题附matlab代码

网友投稿 226 2022-09-05


【路径规划】基于帝国企鹅算法求解三维旅行商问题附matlab代码

1 简介

2 部分代码

function [bestY,bestX,recording]=AFO2(x,y,option,data)% Update log.% 1. 2021.1.1 % Version 1.0% All experiments of the paper are run based on this version, except for the experiments of running time.% 2. 2021.1.7 % Version 1.1% Disadvantages of version 1.0% (1) Too slow% (2) The total number of evaluations is T*(N+m) after the catastrophe strategy is triggered, and m is the number of times the catastrophe strategy is triggered. % However, this problem will not affect the results of this experiment because the maximum number of iterations of the experiment is 50, and the catastrophe strategy will basically not be triggered.% The runtime experiments of the paper are based on this version% Updated content.% (1) Optimization based on the advantages of MATLAB. The problem of too slow speed is solved.% The core reason for the excessive slowness was that strategy 2 did not use matrix operations in version 1.0.% Note: In order to use matrix operations, this version updates all individuals of the population when using the third strategy, but calculates the fitness value only for those individuals that are eligible. The total number of evaluations is still T*N.% (2) After using the catastrophe strategy, the current iteration number +1,the total evaluation number reverts to T*N%% Input% x----positions of initialized populaiton% y----fitnesses of initialized populaiton% option-----parameters set of the algorithm% data------Pre-defined parameters% This parameter is used for solving complex problems is passing case data%% outPut% bestY ----fitness of best individual% bestX ----position of best individual% recording ---- somme data was recorded in this variable%% initializationpe=option.pe;L=option.L;gap0=option.gap0;gap=gap0;dim=option.dim;maxIteration=option.maxIteration;recording.bestFit=zeros(maxIteration+1,1);recording.meanFit=zeros(maxIteration+1,1);numAgent=option.numAgent;At=randn(numAgent,dim);w2=option.w2; %weight of Moving strategy IIIw4=option.w4;%weight of Moving strategy IIIw5=option.w5;%weight of Moving strategy IIIpe=option.pe; % rate to judge Premature convergencegapMin=option.gapMin;dec=option.dec;ub=option.ub;lb=option.lb;v_lb=option.v_lb;v_ub=option.v_ub;fobj=option.fobj;count=1;%% center of population[y_c,position]=min(y);x_c=x(position(1),:);At_c=At(position(1),:);%% memory of populationy_m=y;x_m=x;%% update recordingrecording.bestFit(1)=y_c;recording.meanFit(1)=mean(y_m);%% main loopiter=1;while iter<=maxIteration %Dmp(['AFO,iter:',num2str(iter),',minFit:',num2str(y_c)]) %% Moving Strategy I for center of population if rem(iter, gap)==0 && dimub(j) tempX(j,j)=ub(j); Dx(1,j)=tempX(j,j)-x_c(1,j); end if tempX(j,j)v_ub)=G0(1,G0(1,:)>v_ub)/max(G0(1,G0(1,:)>v_ub))*max(v_ub(G0(1,:)>v_ub)); G0(1,G0(1,:)ub(j) tempX(j+dim,j)=ub(j); Dx(1,j)=tempX(j,j)-x_c(1,j); end if tempX(j+dim,j)v_ub)=G0(1,G0(1,:)>v_ub)/max(G0(1,G0(1,:)>v_ub))*max(v_ub(G0(1,:)>v_ub)); G0(1,G0(1,:)ub)=ub(tempX(j,:)>ub); tempY(j,:)=fobj(tempX(j,:),option,data); end else N=numAgent-2*dim; r1=exp(-10*(0:N-1)/(N-1)); unitG=norm(Dx)/norm(G0); %EQ.2-19 if unitG~=1 r2=1:-(1-unitG)/(N-1):unitG; a=r1.*r2; %EQ.2-17 else a=r1; end for j=2*dim+(1:N) tempX(j,:)=x_c+G0*a(j-2*dim); %EQ,2-20 tempX(j,tempX(j,:)ub)=ub(tempX(j,:)>ub); tempY(j,:)=fobj(tempX(j,:),option,data); end end [minY,no]=min(tempY); if minY(no-dim*2)/(numAgent-dim*2)*(maxIteration-iter)/maxIteration gap=max(gapMin,gap-dec); %EQ.2-15 end else R1=rand(numAgent,dim); R2=rand(numAgent,dim); R3=rand(numAgent,dim); Rn=rand(numAgent,dim); indexR1=ceil(rand(numAgent,dim)*numAgent); indexR2=ceil(rand(numAgent,dim)*numAgent); std0=exp(-20*iter/maxIteration)*(v_ub-v_lb)/2; std1=std(x_m); % In order to use matrix operations, all individuals of the population are updated. % Although more individuals were updated, the running time of the algorithm dropped tremendously. % This is because MATLAB is extremely good at matrix operations. % If you want to rewrite this code in another language, we suggest you refer to AFO1. % AFO2 is optimized for MATLAB and may not be suitable for your language. for j=1:dim x_m1(:,j)=x_m(indexR1(:,j),j); x_m2(:,j)=x_m(indexR2(:,j),j); y_m1(:,j)=y_m(indexR1(:,j)); y_m2(:,j)=y_m(indexR2(:,j)); AI(:,j)=R1(:,j).*sign(y_m1(:,j)-y_m2(:,j)).*(x_m1(:,j)-x_m2(:,j)); if std1(j)<=std0(j) position=find(AI(:,j)==0); AI(position,j)=Rn(position,j)*(v_ub(j)-v_lb(j))/2; position=find(AI(:,j)~=0); AI(position,j)=R2(:,j).*sign(y_m1(:,j)-y_m2(:,j)).*sign(x_m1(:,j)-x_m2(:,j))*(v_ub(j)-v_lb(j))/2; end end for i=1:numAgent p =tanh(abs(y(i)-y_c)); %EQ.2-30 if randub)=ub(x(i,:)>ub); tempY(i,:)=y(i); y(i)=fobj(x(i,:),option,data); if tempY(i,:)ub)=ub(x(i,:)>ub); y(i)=fobj(x(i,:),option,data); end if y(i)L for i=1:numAgent x(i,:)=(ub-lb)*rand+lb; y(i)=fobj(x(i,:),option,data); if y(i)

3 仿真结果

4 参考文献

[1]黄丽韶, 朱喜基. 基于MATLAB的蚁群算法求解旅行商问题[J]. 无线互联科技, 2012(3):3.

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Python Synchronous、Asynchronous(python入门教程(非常详细))
下一篇:【天鹰优化算法】基于天鹰优化算法求解单目标优化问题附matlab代码
相关文章

 发表评论

暂时没有评论,来抢沙发吧~