3、utelength%找到一条更好的路径 routelength=lengthk; bestroute=routek; end fori=1:NC-1%第K只蚂蚁在路径上释放的信息量 deltatao(routek(i),routek(i+1))=deltatao(routek(i),routek(i+1))+Q/lengthk; end deltatao(routek(48),1)=deltatao(routek(48),1)+Q
4、/lengthk; end fori=1:NC-1 forj=i+1:NC ifdeltatao(i,j)==0 deltatao(i,j)=deltatao(j,i); y=bestroute; end val=routelength; end toc end tao=(1-rho).*tao+deltatao;endy=bestroute;val=routelength;tocfunction[y,val]=travel(dist
6、e(np,j); p_sum=p_sum+tao(np,j)^alpha*ada^beta; end end cp=zeros(1,m);%转移概率 forj=1:m ifisin(j,tabuk) continue; else ada=1/distance(np,j); cp(j)=tao(np,j)^alpha*ada^beta/p_sum; end end NextCity=pchoice