matlab 算法程序.docVIP

  • 16
  • 0
  • 约1.52万字
  • 约 15页
  • 2016-02-25 发布于江苏
  • 举报
matlab 算法程序.doc

一基于matlab Dijkstra算法的实现 function [l,z]=Dijkstra(W) n = size (W,1); for i = 1 :n ??? l(i)=W(1,i); ??? z(i)=1; end i=1; while i=n ??? for j =1 :n ??????? if l(i)l(j)+W(j,i) ??????????? l(i)=l(j)+W(j,i); ??????????? z(i)=j; ??????????? if ji ??????????????? i=j-1; ??????????? end ??????? end ??? end ??? i=i+1; end % W =[ 0???? 2???? 1???? 8?? Inf?? Inf?? Inf?? Inf %???? 2???? 0?? Inf???? 6???? 1?? Inf?? Inf?? Inf %????? 1?? Inf???? 0???? 7?? Inf?? Inf???? 9?? Inf %????? 8???? 6???? 7???? 0???? 5???? 1???? 2?? Inf %??? Inf???? 1?? Inf???? 5???? 0???? 3?? Inf???? 9 %??? Inf?? Inf?? Inf???? 1???? 3???? 0???? 4???? 6 %??? Inf?? Inf???? 9???? 2?? Inf???? 4???? 0???? 3 %??? Inf?? Inf?? Inf?? Inf???? 9???? 6???? 3???? 0? ]; 二/基于matlab TSP问题模拟退火法实现 %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 coeffient n=length(d);%the number of cities L=100*n;%the length of Markov chain route=randperm(n);%the initial traveling route fval=value(route,d);%the initial goal value t=t0; tic while ttf for i=1:L [fval_after,route_after]=exchange(route,d); if f

文档评论(0)

1亿VIP精品文档

相关文档