資源簡介
用模擬退火的方法解TSP問題,思路明晰,有注釋。
代碼片段和文件信息
%用模擬退火的方法解TSP問題?total?search?paht
%開始是隨機產生的10個坐標點,保存成了address數據.
%address(:1)=rand(101)*100;
%address(:2)=rand(101)*100;
function?aneal_test
order1=randperm(10)‘;
load?address;
%plot(address(order11)address(order12)‘*r-‘)
T_max=1000;%input(‘please?input?the?start?temprature‘)%最大的溫度
T_min=1;%;input(‘please?input?the?end?temprature‘)%最小的溫度
iter_max=3000;%input(‘please?input?the?most?interp?steps?on?the?fit?temp‘)%一個溫度最多迭代次數
s_max=30;%input(‘please?input?the?most?steady?steps?ont?the?fit?temp‘)%如果新解比上一個解差,最多嘗試幾次放棄新解
T=T_max;
totaldis1=distance(addressorder1);
zhe=[];
while?T>=T_min??%溫度控制
????iter_num=1;
????s_num=1;
??????%plot(Ttotaldis1)
??????TT=[Ttotaldis1];
??????zhe=[zhe;TT];
????hold?on
????while?(iter_num ????????order2=exhgpath(order1);
????????totaldis2=distance(addressorder2);
????????R=rand;
????????DeltaDis=totaldis2-totaldis1;
????????if?DeltaDis<0;%若新解好
?????????????order1=order2;
?????????????totaldis1=totaldis2;
?
評論
共有 條評論