蚁群算法与模拟退火算法对旅游路线问题的探究(附matlab程序) -(5)

2020-06-24 16:23

R_best(NC,:)=Tabu(pos(1),:); L_ave(NC)=mean(L); NC=NC+1 %迭代继续 %更新信息素

Delta_Tau=zeros(n,n); for i=1:m

for j=1:(n-1)

Delta_Tau(Tabu(i,j),Tabu(i,j+1))=Delta_Tau(Tabu(i,j),Tabu(i,j+1))+Q/L(i); end

Delta_Tau(Tabu(i,n),Tabu(i,1))=Delta_Tau(Tabu(i,n),Tabu(i,1))+Q/L(i); end

%禁忌表清零

Tau=(1-Rho).*Tau+Delta_Tau; Tabu=zeros(m,n); end

Pos=find(L_best==min(L_best)); Shortest_Route=R_best(Pos(1),:)

Shortest_Length=L_best(Pos(1)) subplot(1,2,2) %绘制图形 plot(L_best)

附录6

模拟退火算法求解程序:

%模拟退火算法求解TSP问题 %主函数 tsp.m %d 邻接矩阵 %th 初始温度 %tl 终止温度 %a 控制温度系数 %输出: %long

%route

function[long,route]=tsp(d,th,tl,a) n=length(d);

L=200*n;

route=randperm(n); %初始化路径 long=route_long(route,d) %初始化路径长度 t=th;

i=0;

tic %开始计时 while t>tl

46

for j=1:L

[long_new,route_new]=exchange(route,d); if long_new

route=route_new; long=long_new;

elseif exp((long-long_new)*1000000000000./t)>rand route=route_new; long=long_new; else route=route; long=long; end end t=a*t; i=i+1;

long_sequence(i)=long; long_sequence

end

toc %结束及时

plot(1:i,long_sequence); %绘制算法效果图 %计算路径长度的子函数 route_long.m %输入:

%route 路径编号 %d 邻接矩阵 %输出:

%route_value 路径长度

function long=route_long(route,d) n=length(d);

long=0;

for i=1:n-1

long=long+d(route(i),route(i+1)); end

%随机交换两个节点的顺序函数 exchange.m

function [long_new,route_new]=exchange(route,d) %输入

%route 初始路径 %d 邻接矩阵 %输出:

%long_new 新路径长度

%route_new 新路径经由结点 n=length(d);

temp1=ceil(n*rand); temp2=ceil(n*rand); tem1=min(temp1,temp2); tem2=max(temp1,temp2);

47

route_temp=fliplr(route(tem1:tem2)); route_new=[route(1:(tem1-1)) route_temp route((tem2+1):n)]; long_new=route_long(route_new,d);%重新计算路径长度

附录7:

x1=126.6;x2=87.6;x3=125.316;x4=123.416;x5=111.68333;x6=116.4;x7=117.2;x8=106.266;x9=114.5;x10=112.55;x11=117;x12=101.8;x13=103.85;x14=113.666;x15=108.95;x16=118.766;x17=117.28;x18=121.483;x19=114.2833;x20=104;x21=120.16;x22=106.9;x23=91;x24=116;x25=113;x26=107;x27=119;x28=103;x29=122;x30=113;x31=108;x32=115;x33=115;x34=110; y1=46;y2=44;y3=43.9;y4=41.8;y5=40.8;y6=39.92;y7=39;y8=38.45;y9=38;y10=37.9;y11=36.67;y12=36.63;y13=36;y14=34.77;y15=34.28;y16=32;y17=31.8;y18=31.2;y19=30.58;y20=30.66;y21=30.26;y22=29.98;y23=29.65;y24=28.67;y25=28.2;y26=26.58;y27=26;y28=25;y29=25;y30=23;y31=22.8;y32=21.38;y33=21.55;y34=20; plot(x1,y1,'p') hold on;

plot(x2,y2,'p') hold on;

plot(x3,y3,'p') hold on;

plot(x4,y4,'p') hold on;

plot(x5,y5,'p') hold on;

plot(x6,y6,'p') hold on;

plot(x7,y7,'p') hold on;

plot(x8,y8,'p') hold on;

plot(x9,y9,'p') hold on;

plot(x10,y10,'p') hold on;

plot(x11,y11,'p') hold on;

plot(x12,y12,'p') hold on;

plot(x13,y13,'p') hold on;

plot(x14,y14,'p')

48

hold on;

plot(x15,y15,'p') hold on;

plot(x16,y16,'p') hold on;

plot(x17,y17,'p') hold on;

plot(x18,y18,'p') hold on;

plot(x19,y19,'p') hold on;

plot(x20,y20,'p') hold on;

plot(x21,y21,'p') hold on;

plot(x22,y22,'p') hold on;

plot(x23,y23,'p') hold on;

plot(x24,y24,'p') hold on;

plot(x25,y25,'p') hold on;

plot(x26,y26,'p') hold on;

plot(x27,y27,'p') hold on;

plot(x28,y28,'p') hold on;

plot(x29,y29,'p') hold on;

plot(x30,y30,'p') hold on;

plot(x31,y31,'p') hold on;

plot(x32,y32,'p') hold on;

plot(x33,y33,'p') hold on;

plot(x34,y34,'p') hold on;

49


蚁群算法与模拟退火算法对旅游路线问题的探究(附matlab程序) -(5).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:工程项目招投标与合同管理试卷

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: