基于某遗传算法的TSP路径规划算法设计Word下载.docx
《基于某遗传算法的TSP路径规划算法设计Word下载.docx》由会员分享,可在线阅读,更多相关《基于某遗传算法的TSP路径规划算法设计Word下载.docx(19页珍藏版)》请在冰豆网上搜索。
4.2适应度评估
适应度用来度量群体中各个体在优化过程中达到或接近于或有助于找到最优解的优良程度。
适应度较高的个体被选中遗传到下一代的概率较大;
而适应度较低的个体被选中遗传到下一代的概率相对较小一些。
本文用个体所表示的循环路线的倒数来作为适应度评估值,路线越短,个体适应度值越大。
4.3选择、交叉、变异
选择操作。
是从群体中选择生命力强的个体产生新种群的过程.选择操作以个体的适应度评估为基础。
其主要目的是避免有用遗传信息的丢失。
从而提高算法的全局收敛性和计算效率。
常用的选择算子有赌轮选择、联赛选择、最佳保留等。
其中,最佳个体保存策略可保证迄今为止所得到的最优个体不会被交叉、变异等遗传操作所破坏。
它是遗传算法收敛性的一个重要保证条件。
但它也容易使得某个局部最优个体不易被淘汰反而快速扩散。
从而使得算法的全局搜索能力不强。
因此,最佳个体保存一般要与其他选择方法配合使用方可取得良好的效果[3]。
交叉运算产生子代,子代继承父代的基本特征。
交叉算子一般包括两个容:
一是对种群中的个体随机配对并按预先设定的交叉概率来确定需要进行交叉操作的个体对;
二是设定个体的交叉点,并对的部分结构进行相互交换。
交叉算子的设计与编码方式有关。
在TSP问题中几种有代表性的交叉算子如顺序交叉、类OX交叉等,这些交叉算子在产生新个体的过程中没有目的性,对于自然数编码的TSP问题,这些交叉可能破坏亲代的较优基因,从而使交叉算子的搜索能力大大降低。
变异操作是对个体的某些基因值做变动。
变异操作的目的有两个,一是使遗传算法具有局部的随机搜索能力,当经过交叉操作群体已接近最优解领域时,利用变异算子可以加速向最优解收敛;
二是使遗传算法可维持群体的多样性,以防止早熟现象。
变异算子的设计也与编码方法有关,对于自然数编码的TSP问题,可采用逆转变异、对换变异和插入变异等。
逆转变异,也称倒位变异,是指在个体编码中,随机选择两点(两点间称为逆转区域),再将这两点的字串按反序插入到原位置中.倒位变异考虑了原有边的邻接关系,能将巡回路线上的优良基因性能较好地遗传到下一代,提高寻优速度。
5.仿真结果
ans=
1.0e+003*
Columns1through10
02.53892.87382.57532.31812.15872.21663.17403.37113.5402
2.538901.07350.11130.26680.39500.41010.63790.85361.0550
2.87381.073500.96450.98861.09431.38271.24011.46031.6870
2.57530.11130.964500.26210.41670.50360.62470.85491.0684
2.31810.26680.98860.262100.16340.39510.88501.11091.3182
2.15870.39501.09430.41670.163400.33861.03031.24861.4477
2.21660.41011.38270.50360.39510.338600.98411.16031.3237
3.17400.63791.24010.62470.88501.03030.984100.24340.4738
3.37110.85361.46030.85491.11091.24861.16030.243400.2321
3.54021.05501.68701.06841.31821.44771.32370.47380.23210
1.73700.91021.20170.90720.64850.52260.77621.53201.75941.9651
1.37541.16381.68711.20410.95200.78970.85711.79871.99892.1757
1.69600.86901.58000.92860.70140.54190.52071.48981.67751.8444
1.25081.30881.88371.35951.11590.95260.96661.93542.12462.2898
1.61722.38893.23942.48192.31392.17191.97942.88062.98153.0566
2.49300.37090.73060.27900.26830.40770.65510.82801.07001.2953
2.61740.90790.26700.80670.77440.85941.16831.20741.44381.6757
2.75761.13630.17131.03181.01271.09671.40681.37271.59981.8291
2.47800.90800.39830.81580.73730.79781.12251.27761.51831.7503
2.38691.26350.60211.17951.05981.08031.41831.65771.89772.1298
2.77531.57210.61221.47351.41081.46211.79291.84162.06752.2959
3.02311.73230.69241.62811.59671.66391.98681.92822.14162.3642
2.16310.62910.82000.58240.37760.36680.70541.18551.42461.6450
2.20371.06020.68120.98950.83220.83101.16941.52721.77062.0005
2.11601.35040.87881.28401.11201.08911.42261.82472.06792.2981
2.31271.89661.20851.82261.66671.64891.98222.32382.56422.7962
1.87652.04971.59201.99831.79241.72882.03372.56712.81043.0388
2.21442.29001.66762.22582.04482.00272.32312.75632.99853.2300
1.24181.51081.63591.50991.25101.11871.32392.13462.36172.5657
1.56101.73911.51521.70551.47341.38321.66192.30882.54922.7704
1.25542.08951.94932.07001.82311.71101.94992.68682.92333.1382
Columns11through20
1.73701.37541.69601.25081.61722.49302.61742.75762.47802.3869
0.91021.16380.86901.30882.38890.37090.90791.13630.90801.2635
1.20171.68711.58001.88373.23940.73060.26700.17130.39830.6021
0.90721.20410.92861.35952.48190.27900.80671.03180.81581.1795
0.64850.95200.70141.11592.31390.26830.77441.01270.73731.0598
0.52260.78970.54190.95262.17190.40770.85941.09670.79781.0803
0.77620.85710.52070.96661.97940.65511.16831.40681.12251.4183
1.53201.79871.48981.93542.88060.82801.20741.37271.27761.6577
1.75941.99891.67752.12462.98151.07001.44381.59981.51831.8977
1.96512.17571.84442.28983.05661.29531.67571.82911.75032.1298
00.49380.52670.69162.10510.76590.93471.12730.81000.9040
0.493800.34830.19791.62441.15561.42041.61991.30061.3844
0.52670.348300.44711.65940.94571.32301.54701.22631.4036
0.69160.19790.447101.43621.33401.61721.81771.49821.5782
2.10511.62441.65941.436202.57782.98163.20202.87993.0067
0.76591.15560.94571.33402.577800.54060.77370.53790.9008
0.93471.42041.32301.61722.98160.540600.23860.14190.4667
1.12731.61991.54701.81773.20200.77370.238600.32240.4376
0.81001.30061.22631.49822.87990.53790.14190.322400.3805
0.90401.38441.40361.57823.00670.90080.46670.43760.38050
1.34091.82291.83152.01653.44471.20170.66830.46910.67370.4384
1.58152.06742.06142.26213.68651.36760.82740.59630.86620.6850
0.42650.88020.76471.07342.42260.36700.55910.78290.46430.7141
0.63841.12531.13331.32112.74340.71970.45200.55400.31390.2703
0.77631.21611.30171.40042.83661.01700.69990.72070.57860.2894
1.30461.69031.82971.85613.27411.54781.12871.03801.04610.6666
1.27201.53021.75521.65923.00781.74591.44641.42291.33070.9936
1.58561.88482.08892.02193.37931.95831.57641.49691.48321.1100
0.60270.60120.89940.70052.05761.35281.38451.51611.24351.1524
0.88611.09161.33501.21662.57531.48181.31081.36161.17520.9316
1.18991.23401.54171.29902.50521.86851.74071.79601.60321.3650
Columns21through30
2.77533.02312.16312.20372.11602.31271.87652.21441.24181.5610
1.57211.73230.62911.06021.35041.89662.04972.29001.51081.7391
0.61220.69240.82000.68120.87881.20851.59201.66761.63591.5152
1.47351.62810.58240.98951.28401.82261.99832.22581.50991.7055
1.41081.59670.37760.83221.11201.66671.79242.04481.25101.4734
1.46211.66390.36680.83101.08911.64891.72882.00271.11871.3832
1.79291.98680.70541.16941.42261.98222.03372.32311.32391.6619
1.84161.92821.18551.52721.82472.32382.56712.75632.13462.3088
2.06752.14161.42461.77062.06792.56422.81042.99852.36172.5492
2.29592.36421.64502.00052.29812.79623.03883.23002.56572.7704
1.34091.58150.42650.63840.77631.30461.27201.58560.60270.8861
1.82292.06740.88021.12531.21611.69031.53021.88480.60121.0916
1.83152.06140.76471.13331.30171.82971.75522.08890.89941.3350
2.01652.26211.07341.32111.40041.85611.65922.02190.70051.2166
3.44473.68652.42262.74342.83663.27413.00783.37932.05762.5753
1.20171.36760.36700.71971.01701.54781.74591.95831.35281.4818
0.66830.82740.55910.45200.69991.12871.44641.57641.38451.3108
0.46910.59630.78290.55400.72071.03801.42291.49691.51611.3616
0.67370.86620.46430.31390.57861.04611.33071.48321.24351.1752
0.43840.68500.71410.27030.28940.66660.99361.11001.15240.9316
00.25181.10680.70310.66430.69271.16551.13901.56001.2511
0.251801.31990.94320.91550.86711.36351.28231.81141.4887
1.10681.319900.46560.73581.29301.42071.66720.99151.1254
0.70310.94320.465600.29820.83681.04371.23860.96210.8615
0.66430.91550.73580.298200.55980.75310.94190.89590.6426
0.69270.86711.29300.83680.559800.50550.45961.22950.7600
1.16551.36351.42071.04370.75310.505500.37170.96530.4428
1.13901.28231.66721.23860.94190.45960.371701.33310.8095
1.56001.81140.99150.96210.89591.22950.96531.333100.5237
1.25111.48871.12540.86150.64260.76000.44280.80950.52370
1.66461.89351.50331.28941.07651.09260.62410.96100.64230.4344
Column31
1.2554
2.0895
1.9493
2.0700
1.8231
1.7110
1.9499
2.6868
2.9233
3.1382
1.1899
1.2340
1.5417
1.2990
2.5052
1.8685
1.7407
1.7960
1.6032
1.3650
1.6646
1.8935
1.5033
1.2894
1.0765
1.0926
0.6241
0.9610
0.6423
0.4344
0
BestShortcut=
Columns1through17
29313027282625202122183171924168
Columns18through31
910245762311131214151
theMinDistance=
1.5727e+004
图231城市搜索图
图3搜索过程
6.总结
本文针对TSP问题,首先给出了基于遗传算法求解TSP问题的一般性流程,设计了基于遗传算法的求解算法,包括编码设计、适应度函数选择、终止条件设定、选择算子设定、交叉算子设定以及变异算子设定等,然后设计并实现了基于遗传算法的TSP问题求解系统,并编制了完整的Matlab程序予以仿真实现。
根据仿真结果可知,遗传算法是寻求这种满意解的最佳工具之一,是一种高效、并行、全局搜索的方法。
7.参考文献
[1]雷英杰,等.2009MATLAB遗传算法工具箱及应用[M].:
电子科技大学,8-9.
[2]储理才.2001基于MATLAB的遗传算法程序设计及TSP问题求解[J].集美大学学报(自然科学版),6
(1):
14-19.
[3]郎茂祥.2009配送车辆优化调度模型与算法[M].:
电子工业,75.
程序清单:
31城市坐标图(x)程序:
load('
x.txt'
'
-ascii'
);
y.txt'
plot(x,y,'
x'
)
xlabel('
X坐标'
),ylabel('
Y坐标'
gridon
CalDist程序:
functionF=CalDist(dislist,s)
DistanV=0;
n=size(s,2);
fori=1:
(n-1)
DistanV=DistanV+dislist(s(i),s(i+1));
end
DistanV=DistanV+dislist(s(n),s
(1));
F=DistanV;
drawTSP程序:
functionm=drawTSP(Clist,BSF,bsf,p,f)
CityNum=size(Clist,1);
CityNum-1
plot([Clist(BSF(i),1),Clist(BSF(i+1),1)],[Clist(BSF(i),2),Clist(BSF(i+1),2)],'
ms-'
LineWidth'
2,'
MarkerEdgeColor'
k'
MarkerFaceColor'
g'
holdon;
plot([Clist(BSF(CityNum),1),Clist(BSF
(1),1)],[Clist(BSF(CityNum),2),Clist(BSF
(1),2)],'
Line