蚁群算法源代码1
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
1.#include
2.#include
3.#include
ing namespace std;
5.
6.//该程序是以蚁群系统为模型写的蚁群算法程序(强调:非蚂蚁周模型),以三个著名的TSP问题
为测试对象
7.//通过微调参数,都可以获得较好的解
8.
9./*
10.//----------(1)问题一:Oliver 30 城市 TSP 问
题 best_length = 423.7406; ------------------------
11.//该程序最好的结果是423.741,可运行多次获得
12.//城市节点数目
13.#define N 30
14.//城市坐标
15.double C[N][2]={
16. {2,99},{4,50},{7,64},{13,40},{18,54},{18,40},{22,60},{24,42},{25,62},{25
,38},
17. {37,84},{41,94},{41,26},{44,35},{45,21},{54,67},{54,62},{58,35},{58,69},
{62,32},
18. {64,60},{68,58},{71,44},{71,71},{74,78},{82,7},{83,46},{83,69},{87,76},{
91,38}
19.};
20.//----------上面参数是固定的,下面的参数是可变的-----------
21.//蚂蚁数量
22.#define M 30
23.//最大循环次数NcMax
24.int NcMax = 500;
25.//信息启发因子,期望启发式因子,全局信息素挥发参数,局部信息素挥发参数, 状态转移公式
中的q0
26.double alpha = 2, beta = 3, rou = 0.1, alpha1 = 0.1, qzero = 0.01;
27.//-----------问题一结束
------------------------------------------------------------------------
28.*/
29.
30./*
31.//----------(2)问题二:Elion50 城市 TSP 问
题 best_length = 427.96; ----------------------------
32.//该程序最好的结果是428.468,可运行多次获得
33.//城市节点数目
34.#define N 50
35.//城市坐标
36.double C[N][2]={
37. {5,64}, {5,25}, {5,6}, {7,38}, {8,52}, {10,17},
38. {12,42}, {13,13}, {16,57}, {17,33}, {17,63},
39. {20,26}, {21,47}, {21,10}, {25,32}, {25,55},
40. {27,68}, {27,23}, {30,48}, {30,15}, {31,62},
41. {31,32}, {32,22}, {32,39}, {36,16}, {37,69},
42. {37,52}, {38,46}, {39,10}, {40,30}, {42,57},
43. {42,41}, {43,67}, {45,35}, {46,10}, {48,28},
44. {49,49}, {51,21}, {52,33}, {52,41}, {52,64},
45. {56,37}, {57,58}, {58,27}, {58,48}, {59,15},
46. {61,33}, {62,42}, {62,63}, {63,69}
47.};
48.//----------上面参数是固定的,下面的参数是可变的-----------
49.//蚂蚁数量
50.#define M 50
51.//最大循环次数NcMax
52.int NcMax = 1000;
53.//信息启发因子,期望启发式因子,全局信息素挥发参数,局部信息素挥发参数, 状态转移公式
中的q0
54.double alpha = 2, beta = 4, rou = 0.1, alpha1 = 0.1, qzero = 0.01;
55.//-----------问题二结束
------------------------------------------------------------------------
56.*/
57.
58.//----------(3)问题三:Elion75 城市 TSP 问题 best_length = 542.31;
59.//该程序最好的结果是542.309,可运行多次获得
60.//城市节点数目
61.#define N 75
62.//城市坐标
63.double C[N][2]={
64.{6,25}, {7,43}, {9,56}, {10,70}, {11,28},
65.{12,17}, {12,38}, {15,5}, {15,14}, {15,56},
66.{16,19}, {17,64}, {20,30}, {21,48}, {21,45},
67.{21,36}, {22,53}, {22,22}, {26,29}, {26,13},
68.{26,59}, {27,24}, {29,39}, {30,50}, {30,20},
69.{30,60}, {31,76}, {33,34}, {33,44}, {35,51},
70.{35,16}, {35,60}, {36,6}, {36,26}, {38,33},
71.{40,37}, {40,66}, {40,60}, {40,20}, {41,46},
72.{43,26}, {44,13}, {45,42}, {45,35}, {47,66},
73.{48,21}, {50,30}, {50,40}, {50,50}, {50,70},
74.{50,4}, {50,15}, {51,42}, {52,26}, {54,38},
75.{54,10}, {55,34}, {55,45}, {55,50}, {55,65},
76.{55,57}, {55,20}, {57,72}, {59,5}, {60,15},
77.{62,57}, {62,48}, {62,35}, {62,24}, {64,4},
78.{65,27}, {66,14}, {66,8}, {67,41}, {70,64}