下沙小僧 发表于 2014-8-21 23:45

模拟退火算法代码

T_max=input('please input the start temprature'); T_min=input('please input the end temprature'); iter_max=input('please input the most interp steps on the fit temp'); *










s_max=input('please input the most steady steps ont the fit temp'); T=T_max; load d:\address.txt; order1=randperm(size(address,1))';%生成初始解。
plot(address(order1,1),address(order1,2),'*r-') totaldis1=distance(address,order1); while T>=T_min



iter_num=1;



s_num=1;





plot(T,totaldis1)



hold on



while iter_num<iter_max&s_num<s_max;







order2=exhgpath(order1);







totaldis2=distance(address,order2);







R=rand;







DeltaDis=totaldis2-totaldis1;







if DeltaDis<0;











order1=order2;












totaldis1=totaldis2;







elseif (exp((totaldis1-totaldis2)/(T))>R)











order1=order2;











totaldis1=totaldis2;


















else s_num=s_num+1;







end







iter_num=iter_num+1;



end



T=T*0.99; end order1 totaldis1 figure(2) plot(address(order1,1),address(order1,2),'*r-')








yuzhenbo1995 发表于 2014-8-23 10:34

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~·

戴上耳机 发表于 2014-9-1 09:11

水仙花他要看见人
页: [1]
查看完整版本: 模拟退火算法代码