資源描述:
《模擬退火算法TSP問題matlab.doc》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、TSP問題數(shù)據(jù),52個城市的坐標(biāo):城市編號X坐標(biāo)Y坐標(biāo)城市編號X坐標(biāo)Y坐標(biāo)城市編號X坐標(biāo)Y坐標(biāo)15655751951087537770610225185205603653879564533457502130046539720635494568522520585407606505845655234804154147596068806602483562542952607252302597558043875920852510002612152454470050095801175271320315455558151065011302812504004683048511
2、1605620296601804711706512122058030410250488306101314652003142055549605625141530532575665505953601584568033115011605113407251672537034700580521740245171456653568559553184156353668561052clearclca=0.99;%溫度衰減函數(shù)的參數(shù)t0=97;tf=3;t=t0;Markov_length=10000;%Markov鏈長度coordinates=[1565.0575.0;225
3、.0185.0;3345.0750.0;4945.0685.0;5845.0655.0;6880.0660.0;725.0230.0;8525.01000.0;9580.01175.0;10650.01130.0;111605.0620.0;121220.0580.0;131465.0200.0;141530.05.0;15845.0680.0;16725.0370.0;17145.0665.0;18415.0635.0;19510.0875.0;20560.0365.0;21300.0465.0;22520.0585.0;23480.0415.0;24835
4、.0625.0;25975.0580.0;261215.0245.0;271320.0315.0;281250.0400.0;29660.0180.0;30410.0250.0;31420.0555.0;32575.0665.0;331150.01160.0;34700.0580.0;35685.0595.0;36685.0610.0;37770.0610.0;38795.0645.0;39720.0635.0;40760.0650.0;41475.0960.0;4295.0260.0;43875.0920.0;44700.0500.0;45555.0815.
5、0;46830.0485.0;471170.065.0;48830.0610.0;49605.0625.0;50595.0360.0;511340.0725.0;521740.0245.0;];coordinates(:,1)=[];amount=size(coordinates,1);%城市的數(shù)目%通過向量化的方法計算距離矩陣dist_matrix=zeros(amount,amount);coor_x_tmp1=coordinates(:,1)*ones(1,amount);coor_x_tmp2=coor_x_tmp1';coor_y_tmp1=coor
6、dinates(:,2)*ones(1,amount);coor_y_tmp2=coor_y_tmp1';dist_matrix=sqrt((coor_x_tmp1-coor_x_tmp2).^2+...(coor_y_tmp1-coor_y_tmp2).^2);sol_new=1:amount;%產(chǎn)生初始解%sol_new是每次產(chǎn)生的新解;sol_current是當(dāng)前解;sol_best是冷卻中的最好解;E_current=inf;E_best=inf;%E_current是當(dāng)前解對應(yīng)的回路距離;%E_new是新解的回路距離;%E_best是最優(yōu)解的sol_
7、current=sol_new;sol_best=sol_new;p=1;whilet>=tfforr=1:Markov_length%Markov鏈長度%產(chǎn)生隨機(jī)擾動if(rand<0.5)%隨機(jī)決定是進(jìn)行兩交換還是三交換%兩交換ind1=0;ind2=0;while(ind1==ind2)ind1=ceil(rand.*amount);ind2=ceil(rand.*amount);endtmp1=sol_new(ind1);sol_new(ind1)=sol_new(ind2);sol_new(ind2)=tmp1;else%三交換ind1=0;ind2
8、=0;ind3=0;while(ind