本站首页    管理页面    写新日志    退出


[算法]MATLAB:TSP问题模拟退火算法
sunshine 发表于 2007/6/9 15:01:08

MATLAB:TSP问题模拟退火算法2006年11月16日 星期四 10:00%this program is written by 刘学智. Finished time is 05.1.23 16:03 %utilizing it solving TSP problem by simulating stealing algorithm% [fval,route]=sa_tsp(d,10,0.1,.87)% d=[0  2  1  2  0  0  1  0  1  2  1  1  1  1% 2  0  1  4  1  0  1  1  1  3  1  0  2  1% 1  1  0  1  0  0  0  3  1  1  0  2  2  1% 2  4  1  0  1  1  2  1  0  2  1  0  1  1% 0  1  0  1  0  2  0  1  1  1  0  1  1  2% 0  0  0  1  2  0  1  2  1  1  1  2  1  2% 1  1  0  2  0  1  0  1  1  1  0  2  2  1% 0  1  3  1  1  2  1  0  1  2  1  4  2  2% 1  1  1  0  1  1  1  1  0  1  1  1  3  1% 2  3  1  2  1  1  1  2  1  0  1  0  0  3% 1  1  0  1  0  1  0  1  1  1  0  3  1  1% 1  0  2  0  1  2  2  4  1  0  3  0  1  0% 1  2  2  1  1  1  2  2  3  0  1  1  0  4% 1  1  1  1  2  2  1  2  1  3  1  0  4  0];%the result is fval=2; route=14   9  4  13  10  12  2  6  3  11  7  5  1  8 function [fval,route]=sa_tsp(d,t0,tf,alpha)%d is the distance matrix;t0,tf is the initial and finil temperature;%alpha is controling temperature coeffientn=length(d);%the number of citiesL=100*n;%the length of Markov chainroute=randperm(n);%the initial traveling routefval=value(route,d);%the initial goal valuet=t0;ticwhile t>tffor i=1:L[fval_after,route_after]=exchange(route,d);if fval_after<fvalroute=route_after;fval=fval_after;elseif exp((fval-fval_after)/t)>randroute=route_after;fval=fval_after;else route=route;fval=fval;endendt=alpha*t;endtoc%----------------------------------------------------------------function fval=value(route,d)%used for reckoning the goal value of the selected traveling routen=length(d);fval=0;for i=1:n-1fval=fval+d(route(i),route(i+1));end%fval=fval+d(route(n),route(1));% if'%'is omited,it computes a circle,else%a chain------------------------------------------------------------------function [fval_after,route_after]=exchange(route,d)%changing traveling route by inversing the sequence between two selected 2 locations n=length(d);location1=ceil(n*rand);location2=ceil(n*rand);%the location of two exchanged numberloc1=min(location1,location2);loc2=max(location1,location2);middle_route=fliplr(route(loc1:loc2));%the part route which has been exchangedroute_after=[route(1:loc1-1) middle_route route(loc2+1:n)];%the after traveling routefval_after=value(route_after,d);  

阅读全文(3225) | 回复(0) | 编辑 | 精华

发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)

 
«September 2025»
123456
78910111213
14151617181920
21222324252627
282930

  公告

有一种鸟儿是永远关不住的
因为它的每片羽翼上都沾满了自由的光辉

方向:计算机视觉 人工智能 演化算法

 


  我的分类(专题)
  最近日志

  最新评论

  留言板

  链接

  Blog信息
blog名称:阳光海岸心
日志总数:166
评论数量:237
留言数量:-4
访问次数:1455642
建立时间:2006年6月2日



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.031 second(s), page refreshed 144765370 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号