模拟退火算法和禁忌搜索算法的matlab源程序
WORD 格式可编辑 模拟退火算法源程序 此题以中国 31 会城市的最短径为 clear;clc; function [MinD,BestPath]MainAnealpn CityPosition 存储的为每个城市的二维坐标x 和 y; CityPosition[1304 2312;3639 1315;4177 2244;3712 1399;3488 1535;3326 1556;3238 1229;. 4196 1044;4312 790;4386 570;3007 1970;2562 1756;2788 1491;2381 1676;. 1332 695;3715 1678;3918 2179;4061 2370;3780 2212;3676 2578;4029 2838;. 4263 2931;3429 1908;3507 2376;3394 2643;3439 3201;2935 3240;3140 3550;. 2545 2357;2778 2826;2370 2975]; figure1; plotCityPosition,1,CityPosition,2,o msizeCityPosition,1;城市的数目 D sqrtCityPosition,ones1,m - CityPosition,ones1,m.2 . CityPosition,2*ones1,m - CityPosition,2*ones1,m.2; pathzerospn,m; for i1pn pathi,randpermm; end iter_max100;i m_max5; Len1zeros1,pn;Len2zeros1,pn;path2zerospn,m; tzeros1,pn; T1e5; tau1e-5; N1; while Ttau iter_num1; m_num1; while m_num 0 break; end end IR1;JR2; if IJ p21Ip11I; p2I1Jp1J-1I1; p2J1CityNump1J1CityNum; else p21J-1p11J-1; p2JI1p1I1-1J; p2ICityNump1ICityNum; end 专业知识分享 WORD 格式可编辑 禁忌搜索算法解决 TSP 问题 此题以中国 31 省会城市的最短旅行路径为例 禁忌搜索是对局部领域搜索的一种扩展,是一种全局逐步寻优算法,搜索过程可以接受劣解, 有较强的爬山能力.领域结构对收敛性有很大影响。 function [BestShortcut,theMinDistance]TabuSearch clear; clc; Clist[1304 2312;3639 1315;4177 2244;3712 1399;3488 1535;3326 1556;3238 1229;. 4196 1044;4312 790;4386 570;3007 1970;2562 1756;2788 1491;2381 1676;. 1332 695;3715 1678;3918 2179;4061 2370;3780 2212;3676 2578;4029 2838;. 4263 2931;3429 1908;3507 2376;3394 2643;3439 3201;2935 3240;3140 3550;. 2545 2357;2778 2826;2370 2975]; CityNumsizeClist,1;TSP问题的规模,即城市数目 dislistzerosCityNum; for i1CityNum for j1CityNum dislisti,jClisti,1-Clistj,12Clisti,2-Clistj,220.5; end end TabuListzerosCityNum; tabu list TabuLengthroundCityNum*CityNum-1/20.5;禁忌长度tabu length Candidates200;候选集的个数 全部领域解个数 CandidateNumzerosCandidates,CityNum;候选解集合 S0randpermCityNum;随机产生初始解 BSFS0; BestLInf; clf; figure1; stop uicontrolstyle,toggle,string ,stop,background,white; tic; p1; StopL80*CityNum; while pCityNum*CityNum-1/2 disp候选解个数不大于 n*n-1/2; break; end ALongpFundislist,S0; i1; AzerosCandidates,2; while iCandidates 专业知识分享 WORD 格式可编辑 MCityNum*rand1,2; MceilM; if M1M2 Ai,1maxM1,M2; Ai,2minM1,M2; if i1 isa0; else for j1i-1 if Ai,1Aj,1 break; else isa0; end end end if isa ii1; else end else end end BestCandidateNum100;保前BestCandidateNum 个最好候选解 BestCandidateInf*onesBestCandidateNum,4; Fzeros1,Candidates; for i1Candidates CandidateNumi,S0; CandidateNumi,[Ai,2,Ai,1]S0[Ai,1,Ai,2]; FiFundislist,CandidateNumi,; if iBestCandidateNum BestCandidatei,2Fi; BestCandidatei,1i; BestCandidatei,3S0Ai,1; BestCandidatei,4S0Ai,2; else for j1BestCandidateNum if FiBestCandidatej,2 BestCandidatej,2Fi; BestCandidatej,1i; BestCandi