%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 t>tf
for i=1:L
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余2页未读,立即下载