diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 62019c0..0672e7e 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,9 +2,27 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -33,8 +51,8 @@
-
-
+
+
@@ -47,7 +65,7 @@
-
+
@@ -56,7 +74,7 @@
-
+
@@ -69,7 +87,7 @@
-
+
@@ -78,7 +96,7 @@
-
+
@@ -91,7 +109,7 @@
-
+
@@ -100,7 +118,7 @@
-
+
@@ -113,7 +131,7 @@
-
+
@@ -122,7 +140,7 @@
-
+
@@ -135,7 +153,7 @@
-
+
@@ -146,11 +164,11 @@
-
+
+
+
+
-
-
-
@@ -183,13 +201,27 @@
-
+
+
+
+
+
@@ -199,64 +231,72 @@
-
+
+
-
+
-
+
+
-
+
-
+
+
-
+
-
+
+
-
+
-
+
+
-
+
-
+
+
-
+
-
+
+
-
+
-
+
+
-
+
@@ -264,63 +304,23 @@
-
+
-
+
-
+
-
+
-
- file://$PROJECT_DIR$/foa_2opt_greedy_ga.py
- 290
-
-
-
- file://$PROJECT_DIR$/foa_shuffle_part.py
- 154
-
-
-
- file://$PROJECT_DIR$/foa_2opt_greedy.py
- 152
-
-
-
- file://$PROJECT_DIR$/foa_2opt_greedy_morebest.py
- 130
-
-
-
- file://$PROJECT_DIR$/foa_3opt_greedy.py
- 160
-
-
-
- file://$PROJECT_DIR$/foa_3opt_greedy.py
- 138
-
-
-
- file://$PROJECT_DIR$/foa_3opt_greedy.py
- 167
-
-
-
- file://$PROJECT_DIR$/foa_2opt_greedy.py
- 118
-
-
file://$PROJECT_DIR$/GA.py
122
@@ -346,6 +346,31 @@
97
+
+ file://$PROJECT_DIR$/ACO.py
+ 102
+
+
+
+ file://$PROJECT_DIR$/PSO.py
+ 177
+
+
+
+ file://$PROJECT_DIR$/PSO.py
+ 88
+
+
+
+ file://$PROJECT_DIR$/PSO.py
+ 93
+
+
+
+ file://$PROJECT_DIR$/TS.py
+ 106
+
+
@@ -359,20 +384,26 @@
+
+
+
+
+
+
+
-
-
-
+
-
-
+
+
+
\ No newline at end of file
diff --git a/ACO.py b/ACO.py
new file mode 100755
index 0000000..b6cd2a0
--- /dev/null
+++ b/ACO.py
@@ -0,0 +1,187 @@
+import random
+import math
+import numpy as np
+import matplotlib.pyplot as plt
+
+
+class ACO(object):
+ def __init__(self, num_city, data):
+ self.m = 30 # 蚂蚁数量
+ self.alpha = 1 # 信息素重要程度因子
+ self.beta = 5 # 启发函数重要因子
+ self.rho = 0.1 # 信息素挥发因子
+ self.Q = 1 # 常量系数
+ self.num_city = num_city # 城市规模
+ self.location = data # 城市坐标
+ self.Tau = np.ones([num_city, num_city]) # 信息素矩阵
+ self.Table = [[0 for _ in range(num_city)] for _ in range(self.m)] # 生成的蚁群
+ self.iter = 1
+ self.iter_max = 500
+ self.dis_mat = self.compute_dis_mat(num_city, self.location) # 计算城市之间的距离矩阵
+ self.Eta = 10. / self.dis_mat # 启发式函数
+ self.paths = None # 蚁群中每个个体的长度
+ # 存储存储每个温度下的最终路径,画出收敛图
+ self.iter_x = []
+ self.iter_y = []
+
+ # 轮盘赌选择
+ def rand_choose(self, p):
+ x = np.random.rand()
+ for i, t in enumerate(p):
+ x -= t
+ if x <= 0:
+ break
+ return i
+
+ # 生成蚁群
+ def get_ants(self, num_city):
+ for i in range(self.m):
+ start = np.random.randint(num_city - 1)
+ self.Table[i][0] = start
+ unvisit = list([x for x in range(num_city) if x != start])
+ current = start
+ j = 1
+ while len(unvisit) != 0:
+ P = []
+ # 通过信息素计算城市之间的转移概率
+ for v in unvisit:
+ P.append(self.Tau[current][v] ** self.alpha * self.Eta[current][v] ** self.beta)
+ P_sum = sum(P)
+ P = [x / P_sum for x in P]
+ # 轮盘赌选择一个一个城市
+ index = self.rand_choose(P)
+ current = unvisit[index]
+ self.Table[i][j] = current
+ unvisit.remove(current)
+ j += 1
+
+ # 计算不同城市之间的距离
+ def compute_dis_mat(self, num_city, location):
+ dis_mat = np.zeros((num_city, num_city))
+ for i in range(num_city):
+ for j in range(num_city):
+ if i == j:
+ dis_mat[i][j] = np.inf
+ continue
+ a = location[i]
+ b = location[j]
+ tmp = np.sqrt(sum([(x[0] - x[1]) ** 2 for x in zip(a, b)]))
+ dis_mat[i][j] = tmp
+ return dis_mat
+
+ # 计算一条路径的长度
+ def compute_pathlen(self, path, dis_mat):
+ a = path[0]
+ b = path[-1]
+ result = dis_mat[a][b]
+ for i in range(len(path) - 1):
+ a = path[i]
+ b = path[i + 1]
+ result += dis_mat[a][b]
+ return result
+
+ # 计算一个群体的长度
+ def compute_paths(self, paths):
+ result = []
+ for one in paths:
+ length = self.compute_pathlen(one, self.dis_mat)
+ result.append(length)
+ return result
+
+ # 更新信息素
+ def update_Tau(self):
+ delta_tau = np.zeros([self.num_city, self.num_city])
+ paths = self.compute_paths(self.Table)
+ for i in range(self.m):
+ for j in range(self.num_city - 1):
+ a = self.Table[i][j]
+ b = self.Table[i][j + 1]
+ delta_tau[a][b] = delta_tau[a][b] + self.Q / paths[i]
+ a = self.Table[i][0]
+ b = self.Table[i][-1]
+ delta_tau[a][b] = delta_tau[a][b] + self.Q / paths[i]
+ self.Tau = (1 - self.rho) * self.Tau + delta_tau
+
+ def aco(self):
+ best_lenth = math.inf
+ best_path = None
+ for cnt in range(self.iter_max):
+ # 生成新的蚁群
+ self.get_ants(self.num_city) # out>>self.Table
+ self.paths = self.compute_paths(self.Table)
+ # 取该蚁群的最优解
+ tmp_lenth = min(self.paths)
+ tmp_path = self.Table[self.paths.index(tmp_lenth)]
+ # 可视化初始的路径
+ if cnt == 0:
+ init_show = self.location[tmp_path]
+ init_show = np.vstack([init_show, init_show[0]])
+ plt.subplot(2, 2, 2)
+ plt.title('init best result')
+ plt.plot(init_show[:, 0], init_show[:, 1])
+ # 更新最优解
+ if tmp_lenth < best_lenth:
+ best_lenth = tmp_lenth
+ best_path = tmp_path
+ # 更新信息素
+ self.update_Tau()
+
+ # 保存结果
+ self.iter_x.append(cnt)
+ self.iter_y.append(best_lenth)
+ print(cnt)
+ return best_lenth, best_path
+
+ def run(self):
+ best_length, best_path = self.aco()
+ plt.subplot(2, 2, 4)
+ plt.title('convergence curve')
+ plt.plot(self.iter_x, self.iter_y)
+ return self.location[best_path], best_length
+
+
+# 读取数据
+def read_tsp(path):
+ lines = open(path, 'r').readlines()
+ assert 'NODE_COORD_SECTION\n' in lines
+ index = lines.index('NODE_COORD_SECTION\n')
+ data = lines[index + 1:-1]
+ tmp = []
+ for line in data:
+ line = line.strip().split(' ')
+ if line[0] == 'EOF':
+ continue
+ tmpline = []
+ for x in line:
+ if x == '':
+ continue
+ else:
+ tmpline.append(float(x))
+ if tmpline == []:
+ continue
+ tmp.append(tmpline)
+ data = tmp
+ return data
+
+
+data = read_tsp('data/st70.tsp')
+
+data = np.array(data)
+plt.suptitle('ACO in st70.tsp')
+data = data[:, 1:]
+plt.subplot(2, 2, 1)
+plt.title('raw data')
+# 加上一行因为会回到起点
+show_data = np.vstack([data, data[0]])
+plt.plot(data[:, 0], data[:, 1])
+
+aco = ACO(num_city=data.shape[0], data=data.copy())
+Best_path, Best = aco.run()
+print(Best)
+plt.subplot(2, 2, 3)
+
+
+Best_path = np.vstack([Best_path, Best_path[0]])
+plt.plot(Best_path[:, 0], Best_path[:, 1])
+plt.title('result')
+plt.show()
diff --git a/GA.py b/GA.py
index 3783c43..b2b4b42 100755
--- a/GA.py
+++ b/GA.py
@@ -205,6 +205,8 @@ def run(self):
if tmp_best_score > best_score:
best_score = tmp_best_score
BEST_LIST = tmp_best_one
+ print(i)
+ print(1./best_score)
plt.subplot(2, 2, 4)
plt.title('convergence curve')
plt.plot(self.iter_x, self.iter_y)
diff --git a/PSO.py b/PSO.py
new file mode 100755
index 0000000..6ae4a75
--- /dev/null
+++ b/PSO.py
@@ -0,0 +1,235 @@
+import random
+import math
+import numpy as np
+import matplotlib.pyplot as plt
+
+
+class PSO(object):
+ def __init__(self, num_city, data):
+ self.iter_max = 500 # 迭代数目
+ self.num = 150 # 粒子数目
+ self.num_city = num_city # 城市数
+ self.location = data # 城市的位置坐标
+ # 计算距离矩阵
+ self.dis_mat = self.compute_dis_mat(num_city, self.location) # 计算城市之间的距离矩阵
+ # 初始化所有粒子
+ self.particals = self.random_init(self.num, num_city)
+ self.lenths = self.compute_paths(self.particals)
+ # 得到初始化群体的最优解
+ init_l = min(self.lenths)
+ init_index = self.lenths.index(init_l)
+ init_path = self.particals[init_index]
+ # 画出初始的路径图
+ init_show = self.location[init_path]
+ plt.subplot(2, 2, 2)
+ plt.title('init best result')
+ plt.plot(init_show[:, 0], init_show[:, 1])
+ # 记录每个个体的当前最优解
+ self.local_best = self.particals
+ self.local_best_len = self.lenths
+ # 记录当前的全局最优解,长度是iteration
+ self.global_best = init_path
+ self.global_best_len = init_l
+ # 输出解
+ self.best_l = self.global_best_len
+ self.best_path = self.global_best
+ # 存储每次迭代的结果,画出收敛图
+ self.iter_x = [0]
+ self.iter_y = [init_l]
+
+ # 随机初始化
+ def random_init(self, num_total, num_city):
+ tmp = [x for x in range(num_city)]
+ result = []
+ for i in range(num_total):
+ random.shuffle(tmp)
+ result.append(tmp.copy())
+ return result
+
+ # 计算不同城市之间的距离
+ def compute_dis_mat(self, num_city, location):
+ dis_mat = np.zeros((num_city, num_city))
+ for i in range(num_city):
+ for j in range(num_city):
+ if i == j:
+ dis_mat[i][j] = np.inf
+ continue
+ a = location[i]
+ b = location[j]
+ tmp = np.sqrt(sum([(x[0] - x[1]) ** 2 for x in zip(a, b)]))
+ dis_mat[i][j] = tmp
+ return dis_mat
+
+ # 计算一条路径的长度
+ def compute_pathlen(self, path, dis_mat):
+ a = path[0]
+ b = path[-1]
+ result = dis_mat[a][b]
+ for i in range(len(path) - 1):
+ a = path[i]
+ b = path[i + 1]
+ result += dis_mat[a][b]
+ return result
+
+ # 计算一个群体的长度
+ def compute_paths(self, paths):
+ result = []
+ for one in paths:
+ length = self.compute_pathlen(one, self.dis_mat)
+ result.append(length)
+ return result
+
+ # 评估当前的群体
+ def eval_particals(self):
+ min_lenth = min(self.lenths)
+ min_index = self.lenths.index(min_lenth)
+ cur_path = self.particals[min_index]
+ # 更新当前的全局最优
+ if min_lenth < self.global_best_len:
+ self.global_best_len = min_lenth
+ self.global_best = cur_path
+ # 更新当前的个体最优
+ for i, l in enumerate(self.lenths):
+ if l < self.local_best_len[i]:
+ self.local_best_len[i] = l
+ self.local_best[i] = self.particals[i]
+
+ # 粒子交叉
+ def cross(self, cur, best):
+ one = cur.copy()
+ l = [t for t in range(self.num_city)]
+ t = np.random.choice(l,2)
+ x = min(t)
+ y = max(t)
+ cross_part = best[x:y]
+ tmp = []
+ for t in one:
+ if t in cross_part:
+ continue
+ tmp.append(t)
+ # 两种交叉方法
+ one = tmp + cross_part
+ l1 = self.compute_pathlen(one, self.dis_mat)
+ one2 = cross_part + tmp
+ l2 = self.compute_pathlen(one2, self.dis_mat)
+ if l1 self.taboo_size:
+ self.taboo = self.taboo[1:]
+ self.iter_x.append(cnt)
+ self.iter_y.append(self.best_length)
+ print(cnt, self.best_length)
+ print(self.best_length)
+
+ def run(self):
+ self.ts()
+ plt.subplot(2, 2, 4)
+ plt.title('convergence curve')
+ plt.plot(self.iter_x, self.iter_y)
+ return self.location[self.best_path], self.best_length
+
+
+# 读取数据
+def read_tsp(path):
+ lines = open(path, 'r').readlines()
+ assert 'NODE_COORD_SECTION\n' in lines
+ index = lines.index('NODE_COORD_SECTION\n')
+ data = lines[index + 1:-1]
+ tmp = []
+ for line in data:
+ line = line.strip().split(' ')
+ if line[0] == 'EOF':
+ continue
+ tmpline = []
+ for x in line:
+ if x == '':
+ continue
+ else:
+ tmpline.append(float(x))
+ if tmpline == []:
+ continue
+ tmp.append(tmpline)
+ data = tmp
+ return data
+
+
+data = read_tsp('data/st70.tsp')
+
+data = np.array(data)
+plt.suptitle('TS in st70.tsp')
+data = data[:, 1:]
+plt.subplot(2, 2, 1)
+plt.title('raw data')
+show_data = np.vstack([data, data[0]])
+plt.plot(data[:, 0], data[:, 1])
+
+func = TS(num_city=data.shape[0], data=data.copy())
+best_path, best_length = func.run()
+plt.subplot(2, 2, 3)
+# 加上一行因为会回到起点
+best_path = np.vstack([best_path, best_path[0]])
+plt.plot(best_path[:, 0], best_path[:, 1])
+plt.title('result')
+plt.show()
diff --git a/data/bayg29.tsp.gz b/data/bayg29.tsp.gz
deleted file mode 100755
index 0a9f4c3..0000000
Binary files a/data/bayg29.tsp.gz and /dev/null differ
diff --git a/data/berlin52.tsp b/data/berlin52.tsp
deleted file mode 100755
index 6f35791..0000000
--- a/data/berlin52.tsp
+++ /dev/null
@@ -1,60 +0,0 @@
-NAME: berlin52
-TYPE: TSP
-COMMENT: 52 locations in Berlin (Groetschel)
-DIMENSION: 52
-EDGE_WEIGHT_TYPE: EUC_2D
-NODE_COORD_SECTION
-1 565.0 575.0
-2 25.0 185.0
-3 345.0 750.0
-4 945.0 685.0
-5 845.0 655.0
-6 880.0 660.0
-7 25.0 230.0
-8 525.0 1000.0
-9 580.0 1175.0
-10 650.0 1130.0
-11 1605.0 620.0
-12 1220.0 580.0
-13 1465.0 200.0
-14 1530.0 5.0
-15 845.0 680.0
-16 725.0 370.0
-17 145.0 665.0
-18 415.0 635.0
-19 510.0 875.0
-20 560.0 365.0
-21 300.0 465.0
-22 520.0 585.0
-23 480.0 415.0
-24 835.0 625.0
-25 975.0 580.0
-26 1215.0 245.0
-27 1320.0 315.0
-28 1250.0 400.0
-29 660.0 180.0
-30 410.0 250.0
-31 420.0 555.0
-32 575.0 665.0
-33 1150.0 1160.0
-34 700.0 580.0
-35 685.0 595.0
-36 685.0 610.0
-37 770.0 610.0
-38 795.0 645.0
-39 720.0 635.0
-40 760.0 650.0
-41 475.0 960.0
-42 95.0 260.0
-43 875.0 920.0
-44 700.0 500.0
-45 555.0 815.0
-46 830.0 485.0
-47 1170.0 65.0
-48 830.0 610.0
-49 605.0 625.0
-50 595.0 360.0
-51 1340.0 725.0
-52 1740.0 245.0
-EOF
-
diff --git a/data/berlin52.tsp.gz b/data/berlin52.tsp.gz
deleted file mode 100755
index 23c8f2f..0000000
Binary files a/data/berlin52.tsp.gz and /dev/null differ
diff --git a/data/burma14.tsp b/data/burma14.tsp
deleted file mode 100755
index 81c6607..0000000
--- a/data/burma14.tsp
+++ /dev/null
@@ -1,24 +0,0 @@
-NAME: burma14
-TYPE: TSP
-COMMENT: 14-Staedte in Burma (Zaw Win)
-DIMENSION: 14
-EDGE_WEIGHT_TYPE: GEO
-EDGE_WEIGHT_FORMAT: FUNCTION
-DISPLAY_DATA_TYPE: COORD_DISPLAY
-NODE_COORD_SECTION
- 1 16.47 96.10
- 2 16.47 94.44
- 3 20.09 92.54
- 4 22.39 93.37
- 5 25.23 97.24
- 6 22.00 96.05
- 7 20.47 97.02
- 8 17.20 96.29
- 9 16.30 97.38
- 10 14.05 98.12
- 11 16.53 97.38
- 12 21.52 95.59
- 13 19.41 97.13
- 14 20.09 94.55
-
-
diff --git a/data/burma14.tsp.gz b/data/burma14.tsp.gz
deleted file mode 100755
index 203282e..0000000
Binary files a/data/burma14.tsp.gz and /dev/null differ
diff --git a/data/ch130.tsp b/data/ch130.tsp
deleted file mode 100755
index 29bd5f8..0000000
--- a/data/ch130.tsp
+++ /dev/null
@@ -1,137 +0,0 @@
-NAME: ch130
-TYPE: TSP
-COMMENT: 130 city problem (Churritz)
-DIMENSION: 130
-EDGE_WEIGHT_TYPE: EUC_2D
-NODE_COORD_SECTION
-1 334.5909245845 161.7809319139
-2 397.6446634067 262.8165330708
-3 503.8741827107 172.8741151168
-4 444.0479403502 384.6491809647
-5 311.6137146746 2.0091699828
-6 662.8551011379 549.2301263653
-7 40.0979030612 187.2375430791
-8 526.8941409181 215.7079092185
-9 209.1887938487 691.0262291948
-10 683.2674131973 414.2096286906
-11 280.7494438748 5.9206392047
-12 252.7493090080 535.7430385019
-13 698.7850451923 348.4413729766
-14 678.7574678104 410.7256424438
-15 220.0041131179 409.1225812873
-16 355.1528556851 76.3912076444
-17 296.9724227786 313.1312792361
-18 504.5154071733 240.8866564499
-19 224.1079496785 358.4872228907
-20 470.6801296968 309.6259188406
-21 554.2530513223 279.4242466521
-22 567.6332684419 352.7162027273
-23 599.0532671093 361.0948690386
-24 240.5232959211 430.6036007844
-25 32.0825972787 345.8551009775
-26 91.0538736891 148.7213270256
-27 248.2179894723 343.9528017384
-28 488.8909044347 3.6122311393
-29 206.0467939820 437.7639406167
-30 575.8409415632 141.9670960195
-31 282.6089948164 329.4183805862
-32 27.6581484868 424.7684581747
-33 568.5737309870 287.0975660546
-34 269.4638933331 295.9464636385
-35 417.8004856811 341.2596589955
-36 32.1680938737 448.8998721172
-37 561.4775136009 357.3543930067
-38 342.9482167470 492.3321423839
-39 399.6752075383 156.8435035519
-40 571.7371050025 375.7575350833
-41 370.7559842751 151.9060751898
-42 509.7093253204 435.7975189314
-43 177.0206999750 295.6044772584
-44 526.1674198605 409.4859418161
-45 316.5725171854 65.6400108214
-46 469.2908100279 281.9891445025
-47 572.7630641427 373.3208821255
-48 29.5176994283 330.0382309000
-49 454.0082936692 537.2178547659
-50 416.1546762271 227.6133100741
-51 535.2514330806 471.0648643744
-52 265.4455533675 684.9987192464
-53 478.0542110167 509.6452028741
-54 370.4781203413 332.5390063041
-55 598.3479202004 446.8693279856
-56 201.1521139175 649.0260268945
-57 193.6925360026 680.2322840744
-58 448.5792598859 532.7934059740
-59 603.2853485624 134.4006473609
-60 543.0102490781 481.5168231148
-61 214.5750793346 43.6460117543
-62 426.3501451825 61.7285415996
-63 89.0447037063 277.1158385868
-64 84.4920100219 31.8474816424
-65 220.0468614154 623.0778103080
-66 688.4613313444 0.4702312726
-67 687.2857531630 373.5346236130
-68 75.4934933967 312.9175377486
-69 63.4170993511 23.7039309674
-70 97.9363495877 211.0910930878
-71 399.5255884970 170.8221968365
-72 456.3167017346 597.1937161677
-73 319.8855102422 626.8396604886
-74 295.9250894897 664.6291554845
-75 288.4868857235 667.7284070537
-76 268.3951858954 52.9010181645
-77 140.4709056068 513.5566720960
-78 689.8079027159 167.5947003748
-79 280.5784506848 458.7533546925
-80 453.3884433554 282.9082328989
-81 213.5704943432 525.8681817779
-82 133.6953004520 677.1757808026
-83 521.1658690522 132.8617086506
-84 30.2657946347 450.0754502986
-85 657.0199585283 39.7772908299
-86 6.9252241961 23.8749241575
-87 252.4286967767 535.1659364856
-88 42.8551682504 63.8232081774
-89 145.8999393902 399.5255884970
-90 638.4885715591 62.6262558472
-91 489.2756391122 665.3131282446
-92 361.2231139311 564.2347787901
-93 519.9475425732 347.9711417040
-94 129.3349741063 435.6692740389
-95 259.7172815016 454.6495181318
-96 676.3421890013 371.0979706551
-97 84.5133841706 183.3260738572
-98 77.7164048671 354.3833863300
-99 335.9802442534 660.6321896676
-100 264.3554717810 377.5743377274
-101 51.6826916855 676.0429509187
-102 692.1376849300 543.8010925819
-103 169.2191356800 547.8194325476
-104 194.0131482339 263.4791316822
-105 415.1928395332 78.9133571973
-106 415.0432204919 479.0801701569
-107 169.8389859939 245.6103433244
-108 525.0987124228 213.5063718969
-109 238.6851191283 33.4932910965
-110 116.2112467718 363.5742702940
-111 16.9283258126 656.5711014044
-112 434.3440768162 92.6996831431
-113 40.5253860363 424.6829615797
-114 530.4849979086 183.8390534273
-115 484.3595848990 49.2460387276
-116 263.6501248722 426.5852608187
-117 450.2891917862 126.3853415784
-118 441.7822805823 299.7724362653
-119 24.2169105375 500.3474481664
-120 503.7886861157 514.6895019799
-121 635.5389390312 200.9811207275
-122 614.5922732529 418.8691931188
-123 21.7161351334 660.9741760476
-124 143.8266469611 92.6996831431
-125 637.7191022040 54.2048412384
-126 566.5645610042 199.9551615873
-127 196.6849168280 221.8209157619
-128 384.9270448985 87.4630166986
-129 178.1107815614 104.6905805938
-130 403.2874386776 205.8971749407
-EOF
diff --git a/data/ch130.tsp.gz b/data/ch130.tsp.gz
deleted file mode 100755
index a06017e..0000000
Binary files a/data/ch130.tsp.gz and /dev/null differ
diff --git a/data/ch150.tsp b/data/ch150.tsp
deleted file mode 100755
index b21eb0a..0000000
--- a/data/ch150.tsp
+++ /dev/null
@@ -1,157 +0,0 @@
-NAME: ch150
-TYPE: TSP
-COMMENT: 150 city Problem (churritz)
-DIMENSION: 150
-EDGE_WEIGHT_TYPE: EUC_2D
-NODE_COORD_SECTION
-1 37.4393516691 541.2090699418
-2 612.1759508571 494.3166877396
-3 38.1312338227 353.1484581781
-4 53.4418081065 131.4849013650
-5 143.0606355347 631.7200953923
-6 689.9451267256 468.5354998742
-7 112.7478815786 529.4177578260
-8 141.4875865042 504.8184855710
-9 661.0513901702 445.9375182115
-10 98.7899036592 384.5926031158
-11 697.3881696597 180.3962284275
-12 536.4894189738 287.2279085051
-13 192.4067320507 20.4394059310
-14 282.7865258765 229.8001556189
-15 240.8251726391 281.5141437200
-16 246.9281323057 322.4613321160
-17 649.7313216456 62.3331575282
-18 352.9658562600 666.7873101942
-19 633.3923676580 534.9398453712
-20 488.3117994040 437.4869439948
-21 141.4039286509 228.4325551488
-22 17.3632612602 240.2407068508
-23 397.5586451389 231.3591208928
-24 565.7853781464 282.3858748974
-25 475.8975387047 468.5392706317
-26 322.4224566559 550.3165478233
-27 397.5586634023 74.7588387765
-28 672.8618339396 432.8826409630
-29 571.2189680147 530.2616991530
-30 104.6531165914 482.8224768783
-31 356.7098388794 67.6477131712
-32 400.4070255527 253.6794479997
-33 282.3036243109 426.8380500923
-34 58.7766988363 507.1712386832
-35 189.7506224400 460.3815233617
-36 659.9124120147 226.6284156239
-37 639.0307636033 467.2302300719
-38 415.0258357432 233.3045376118
-39 547.2662016307 161.6589278401
-40 616.6547902644 339.3409309407
-41 494.8592427417 148.1217856389
-42 629.9980812186 433.4548164038
-43 471.1014312410 314.2219307579
-44 138.2440514421 137.1679919735
-45 91.5847556724 110.0203007516
-46 390.6972811808 423.9774318385
-47 565.1617825137 429.1598152874
-48 54.5248980387 438.5515408431
-49 334.3508329710 153.7969238040
-50 531.0291024509 612.3874827889
-51 475.7345905802 385.7844618897
-52 228.8325218994 410.4461939615
-53 578.3805347586 321.3303494537
-54 358.9170574485 404.4670352898
-55 486.4648554867 593.0429937016
-56 343.1693707670 509.3123571315
-57 530.3626972076 137.6881275684
-58 498.8065475299 576.2102674608
-59 224.3182715500 312.4677490415
-60 595.8360732590 81.8130051356
-61 661.5588724308 217.0456944477
-62 43.6892045516 305.4722789165
-63 79.4653452530 445.9641737689
-64 210.4163247004 130.7151137038
-65 432.2642292251 629.4092661116
-66 623.2487161301 69.1892850840
-67 436.5194739944 282.9356456070
-68 59.4163265482 40.1280234442
-69 630.9230074073 230.3429888130
-70 579.3265539688 601.0359410602
-71 117.8624507480 112.9796833705
-72 297.7912565664 166.3131886803
-73 22.7642703744 455.5340094037
-74 259.7095810385 10.6199925885
-75 342.3579873647 599.3880182608
-76 10.0260950143 488.9310558282
-77 315.2926064118 273.2275475579
-78 220.7044919297 270.0819745721
-79 192.1186059948 314.1839922798
-80 271.5042718992 225.2921989972
-81 530.7320005441 504.0670155337
-82 42.5331441666 656.3645162886
-83 396.1274792588 539.4648066027
-84 118.6631474021 508.7129103929
-85 395.6913876595 699.5376048429
-86 559.0157105844 560.8866941411
-87 22.6471035906 526.2470392816
-88 135.6377085256 325.8409901555
-89 141.4507014379 485.2477927763
-90 396.7741299332 460.7557115283
-91 87.7494562765 19.6170129082
-92 350.4245639661 420.6531186835
-93 216.7010817133 466.4816410995
-94 130.9237737024 351.1491733079
-95 72.6329856671 645.7852219213
-96 144.6002949996 457.4224283926
-97 212.3725077442 594.9216893413
-98 49.9186786455 541.4350825349
-99 656.6943525585 558.1109593509
-100 176.5941623792 648.5239953299
-101 500.3825200226 198.7428378322
-102 634.3178678420 612.8291643194
-103 59.7537372726 551.6321886765
-104 15.2145765106 143.0441928532
-105 283.0054378872 376.4439530184
-106 146.5389000907 39.4231794338
-107 101.8685605377 635.0986850180
-108 588.1968537448 580.5946976921
-109 457.2628632528 350.0164047376
-110 537.4663680494 472.5842276692
-111 269.3669098585 367.4763636538
-112 239.9045383695 102.6297653390
-113 88.4677500396 384.0507209275
-114 658.9133693395 583.9575181023
-115 97.7359146347 157.4558657632
-116 506.6191384007 233.0022156094
-117 500.2566898239 64.9136393489
-118 594.4048565021 275.8741868990
-119 66.2308146610 24.1317387604
-120 598.4162993909 414.5557574275
-121 172.3088330830 344.3963466366
-122 299.4812851800 251.8295121320
-123 303.8379894831 21.0526063790
-124 197.8969269840 512.3888960980
-125 56.0199567669 243.0663818382
-126 255.5566183121 448.8651882442
-127 608.4256112402 222.5421309272
-128 70.2722703273 77.9227026433
-129 398.2298999899 119.5576573860
-130 635.4970237093 133.3225902609
-131 378.3484559418 272.2907677147
-132 484.8029663388 677.0730379436
-133 278.8710882619 299.9308770828
-134 381.6537300653 360.3337602785
-135 557.6070707573 595.3185092281
-136 249.0589749342 76.6595112599
-137 562.9048787838 670.0382113114
-138 398.5504365580 392.6493259144
-139 590.8939720560 370.7414913742
-140 558.2008003726 0.4198814512
-141 461.4114714423 530.5254969413
-142 354.7242881504 685.4045361900
-143 193.6611295657 669.7432521028
-144 352.3140807211 140.3273323662
-145 308.4345709740 115.2054269847
-146 299.5881370080 530.5889619020
-147 334.2748764383 152.1494569394
-148 690.9658585947 134.5793307203
-149 48.0798124069 270.9680673720
-150 91.6467647724 166.3541158474
-EOF
diff --git a/data/ch150.tsp.gz b/data/ch150.tsp.gz
deleted file mode 100755
index 834f746..0000000
Binary files a/data/ch150.tsp.gz and /dev/null differ
diff --git a/data/gr96.tsp b/data/gr96.tsp
deleted file mode 100755
index d40ca22..0000000
--- a/data/gr96.tsp
+++ /dev/null
@@ -1,104 +0,0 @@
-NAME: gr96
-TYPE: TSP
-COMMENT: Africa-Subproblem of 666-city TSP (Groetschel)
-DIMENSION: 96
-EDGE_WEIGHT_TYPE: GEO
-DISPLAY_DATA_TYPE: COORD_DISPLAY
-NODE_COORD_SECTION
- 1 14.55 -23.31
- 2 28.06 -15.24
- 3 32.38 -16.54
- 4 31.38 -8.00
- 5 33.39 -7.35
- 6 34.02 -6.51
- 7 34.05 -4.57
- 8 35.48 -5.45
- 9 35.43 -0.43
- 10 36.47 3.03
- 11 22.56 5.30
- 12 36.22 6.37
- 13 36.48 10.11
- 14 34.44 10.46
- 15 32.54 13.11
- 16 32.07 20.04
- 17 31.12 29.54
- 18 31.16 32.18
- 19 29.58 32.33
- 20 30.03 31.15
- 21 24.05 32.53
- 22 19.37 37.14
- 23 15.36 32.32
- 24 13.11 30.13
- 25 13.38 25.21
- 26 15.20 38.53
- 27 9.00 38.50
- 28 11.36 43.09
- 29 18.06 -15.57
- 30 14.40 -17.26
- 31 13.28 -16.39
- 32 11.51 -15.35
- 33 16.46 -3.01
- 34 12.39 -8.00
- 35 10.23 -9.18
- 36 9.31 -13.43
- 37 8.30 -13.15
- 38 6.18 -10.47
- 39 5.19 -4.02
- 40 6.41 -1.35
- 41 5.33 -0.13
- 42 6.08 1.13
- 43 6.29 2.37
- 44 12.22 -1.31
- 45 13.31 2.07
- 46 12.00 8.30
- 47 11.51 13.10
- 48 12.07 15.03
- 49 6.27 3.24
- 50 6.27 7.27
- 51 0.20 6.44
- 52 3.45 8.47
- 53 3.52 11.31
- 54 4.22 18.35
- 55 0.23 9.27
- 56 -4.16 15.17
- 57 -4.18 15.18
- 58 0.04 18.16
- 59 -5.54 22.25
- 60 0.30 25.12
- 61 -3.23 29.22
- 62 -1.57 30.04
- 63 0.19 32.25
- 64 -1.17 36.49
- 65 2.01 45.20
- 66 -4.03 39.40
- 67 -6.10 39.11
- 68 -6.48 39.17
- 69 -8.48 13.14
- 70 -12.44 15.47
- 71 -11.40 27.28
- 72 -12.49 28.13
- 73 -15.25 28.17
- 74 -20.09 28.36
- 75 -17.50 31.03
- 76 -15.47 35.00
- 77 -19.49 34.52
- 78 -25.58 32.35
- 79 -15.57 -5.42
- 80 -37.15 -12.30
- 81 -22.59 14.31
- 82 -22.34 17.06
- 83 -26.38 15.10
- 84 -24.45 25.55
- 85 -25.45 28.10
- 86 -26.15 28.00
- 87 -29.12 26.07
- 88 -29.55 30.56
- 89 -33.00 27.55
- 90 -33.58 25.40
- 91 -33.55 18.22
- 92 -23.21 43.40
- 93 -18.55 47.31
- 94 -12.16 49.17
- 95 -20.10 57.30
- 96 -4.38 55.27
-EOF
diff --git a/data/gr96.tsp.gz b/data/gr96.tsp.gz
deleted file mode 100755
index 21f1467..0000000
Binary files a/data/gr96.tsp.gz and /dev/null differ
diff --git a/data/kroA100.tsp b/data/kroA100.tsp
deleted file mode 100755
index 05ebae9..0000000
--- a/data/kroA100.tsp
+++ /dev/null
@@ -1,107 +0,0 @@
-NAME: kroA100
-TYPE: TSP
-COMMENT: 100-city problem A (Krolak/Felts/Nelson)
-DIMENSION: 100
-EDGE_WEIGHT_TYPE : EUC_2D
-NODE_COORD_SECTION
-1 1380 939
-2 2848 96
-3 3510 1671
-4 457 334
-5 3888 666
-6 984 965
-7 2721 1482
-8 1286 525
-9 2716 1432
-10 738 1325
-11 1251 1832
-12 2728 1698
-13 3815 169
-14 3683 1533
-15 1247 1945
-16 123 862
-17 1234 1946
-18 252 1240
-19 611 673
-20 2576 1676
-21 928 1700
-22 53 857
-23 1807 1711
-24 274 1420
-25 2574 946
-26 178 24
-27 2678 1825
-28 1795 962
-29 3384 1498
-30 3520 1079
-31 1256 61
-32 1424 1728
-33 3913 192
-34 3085 1528
-35 2573 1969
-36 463 1670
-37 3875 598
-38 298 1513
-39 3479 821
-40 2542 236
-41 3955 1743
-42 1323 280
-43 3447 1830
-44 2936 337
-45 1621 1830
-46 3373 1646
-47 1393 1368
-48 3874 1318
-49 938 955
-50 3022 474
-51 2482 1183
-52 3854 923
-53 376 825
-54 2519 135
-55 2945 1622
-56 953 268
-57 2628 1479
-58 2097 981
-59 890 1846
-60 2139 1806
-61 2421 1007
-62 2290 1810
-63 1115 1052
-64 2588 302
-65 327 265
-66 241 341
-67 1917 687
-68 2991 792
-69 2573 599
-70 19 674
-71 3911 1673
-72 872 1559
-73 2863 558
-74 929 1766
-75 839 620
-76 3893 102
-77 2178 1619
-78 3822 899
-79 378 1048
-80 1178 100
-81 2599 901
-82 3416 143
-83 2961 1605
-84 611 1384
-85 3113 885
-86 2597 1830
-87 2586 1286
-88 161 906
-89 1429 134
-90 742 1025
-91 1625 1651
-92 1187 706
-93 1787 1009
-94 22 987
-95 3640 43
-96 3756 882
-97 776 392
-98 1724 1642
-99 198 1810
-100 3950 1558
-EOF
diff --git a/data/kroA100.tsp.gz b/data/kroA100.tsp.gz
deleted file mode 100755
index 58ee0bc..0000000
Binary files a/data/kroA100.tsp.gz and /dev/null differ
diff --git a/data/kroA200.tsp b/data/kroA200.tsp
deleted file mode 100755
index 2c0aa52..0000000
--- a/data/kroA200.tsp
+++ /dev/null
@@ -1,207 +0,0 @@
-NAME: kroA200
-TYPE: TSP
-COMMENT: 200-city problem A (Krolak/Felts/Nelson)
-DIMENSION: 200
-EDGE_WEIGHT_TYPE : EUC_2D
-NODE_COORD_SECTION
-1 1357 1905
-2 2650 802
-3 1774 107
-4 1307 964
-5 3806 746
-6 2687 1353
-7 43 1957
-8 3092 1668
-9 185 1542
-10 834 629
-11 40 462
-12 1183 1391
-13 2048 1628
-14 1097 643
-15 1838 1732
-16 234 1118
-17 3314 1881
-18 737 1285
-19 779 777
-20 2312 1949
-21 2576 189
-22 3078 1541
-23 2781 478
-24 705 1812
-25 3409 1917
-26 323 1714
-27 1660 1556
-28 3729 1188
-29 693 1383
-30 2361 640
-31 2433 1538
-32 554 1825
-33 913 317
-34 3586 1909
-35 2636 727
-36 1000 457
-37 482 1337
-38 3704 1082
-39 3635 1174
-40 1362 1526
-41 2049 417
-42 2552 1909
-43 3939 640
-44 219 898
-45 812 351
-46 901 1552
-47 2513 1572
-48 242 584
-49 826 1226
-50 3278 799
-51 86 1065
-52 14 454
-53 1327 1893
-54 2773 1286
-55 2469 1838
-56 3835 963
-57 1031 428
-58 3853 1712
-59 1868 197
-60 1544 863
-61 457 1607
-62 3174 1064
-63 192 1004
-64 2318 1925
-65 2232 1374
-66 396 828
-67 2365 1649
-68 2499 658
-69 1410 307
-70 2990 214
-71 3646 1018
-72 3394 1028
-73 1779 90
-74 1058 372
-75 2933 1459
-76 3099 173
-77 2178 978
-78 138 1610
-79 2082 1753
-80 2302 1127
-81 805 272
-82 22 1617
-83 3213 1085
-84 99 536
-85 1533 1780
-86 3564 676
-87 29 6
-88 3808 1375
-89 2221 291
-90 3499 1885
-91 3124 408
-92 781 671
-93 1027 1041
-94 3249 378
-95 3297 491
-96 213 220
-97 721 186
-98 3736 1542
-99 868 731
-100 960 303
-101 1380 939
-102 2848 96
-103 3510 1671
-104 457 334
-105 3888 666
-106 984 965
-107 2721 1482
-108 1286 525
-109 2716 1432
-110 738 1325
-111 1251 1832
-112 2728 1698
-113 3815 169
-114 3683 1533
-115 1247 1945
-116 123 862
-117 1234 1946
-118 252 1240
-119 611 673
-120 2576 1676
-121 928 1700
-122 53 857
-123 1807 1711
-124 274 1420
-125 2574 946
-126 178 24
-127 2678 1825
-128 1795 962
-129 3384 1498
-130 3520 1079
-131 1256 61
-132 1424 1728
-133 3913 192
-134 3085 1528
-135 2573 1969
-136 463 1670
-137 3875 598
-138 298 1513
-139 3479 821
-140 2542 236
-141 3955 1743
-142 1323 280
-143 3447 1830
-144 2936 337
-145 1621 1830
-146 3373 1646
-147 1393 1368
-148 3874 1318
-149 938 955
-150 3022 474
-151 2482 1183
-152 3854 923
-153 376 825
-154 2519 135
-155 2945 1622
-156 953 268
-157 2628 1479
-158 2097 981
-159 890 1846
-160 2139 1806
-161 2421 1007
-162 2290 1810
-163 1115 1052
-164 2588 302
-165 327 265
-166 241 341
-167 1917 687
-168 2991 792
-169 2573 599
-170 19 674
-171 3911 1673
-172 872 1559
-173 2863 558
-174 929 1766
-175 839 620
-176 3893 102
-177 2178 1619
-178 3822 899
-179 378 1048
-180 1178 100
-181 2599 901
-182 3416 143
-183 2961 1605
-184 611 1384
-185 3113 885
-186 2597 1830
-187 2586 1286
-188 161 906
-189 1429 134
-190 742 1025
-191 1625 1651
-192 1187 706
-193 1787 1009
-194 22 987
-195 3640 43
-196 3756 882
-197 776 392
-198 1724 1642
-199 198 1810
-200 3950 1558
-EOF
diff --git a/data/kroA200.tsp.gz b/data/kroA200.tsp.gz
deleted file mode 100755
index fa1dc40..0000000
Binary files a/data/kroA200.tsp.gz and /dev/null differ
diff --git a/data/kroB200.tsp b/data/kroB200.tsp
deleted file mode 100755
index 73b23c1..0000000
--- a/data/kroB200.tsp
+++ /dev/null
@@ -1,207 +0,0 @@
-NAME: kroB200
-TYPE: TSP
-COMMENT: 200-city problem B (Krolak/Felts/Nelson)
-DIMENSION: 200
-EDGE_WEIGHT_TYPE : EUC_2D
-NODE_COORD_SECTION
-1 3140 1401
-2 556 1056
-3 3675 1522
-4 1182 1853
-5 3595 111
-6 962 1895
-7 2030 1186
-8 3507 1851
-9 2642 1269
-10 3438 901
-11 3858 1472
-12 2937 1568
-13 376 1018
-14 839 1355
-15 706 1925
-16 749 920
-17 298 615
-18 694 552
-19 387 190
-20 2801 695
-21 3133 1143
-22 1517 266
-23 1538 224
-24 844 520
-25 2639 1239
-26 3123 217
-27 2489 1520
-28 3834 1827
-29 3417 1808
-30 2938 543
-31 71 1323
-32 3245 1828
-33 731 1741
-34 2312 1270
-35 2426 1851
-36 380 478
-37 2310 635
-38 2830 775
-39 3829 513
-40 3684 445
-41 171 514
-42 627 1261
-43 1490 1123
-44 61 81
-45 422 542
-46 2698 1221
-47 2372 127
-48 177 1390
-49 3084 748
-50 1213 910
-51 3 1817
-52 1782 995
-53 3896 742
-54 1829 812
-55 1286 550
-56 3017 108
-57 2132 1432
-58 2000 1110
-59 3317 1966
-60 1729 1498
-61 2408 1747
-62 3292 152
-63 193 1210
-64 782 1462
-65 2503 352
-66 1697 1924
-67 3821 147
-68 3370 791
-69 3162 367
-70 3938 516
-71 2741 1583
-72 2330 741
-73 3918 1088
-74 1794 1589
-75 2929 485
-76 3453 1998
-77 896 705
-78 399 850
-79 2614 195
-80 2800 653
-81 2630 20
-82 563 1513
-83 1090 1652
-84 2009 1163
-85 3876 1165
-86 3084 774
-87 1526 1612
-88 1612 328
-89 1423 1322
-90 3058 1276
-91 3782 1865
-92 347 252
-93 3904 1444
-94 2191 1579
-95 3220 1454
-96 468 319
-97 3611 1968
-98 3114 1629
-99 3515 1892
-100 3060 155
-101 2995 264
-102 202 233
-103 981 848
-104 1346 408
-105 781 670
-106 1009 1001
-107 2927 1777
-108 2982 949
-109 555 1121
-110 464 1302
-111 3452 637
-112 571 1982
-113 2656 128
-114 1623 1723
-115 2067 694
-116 1725 927
-117 3600 459
-118 1109 1196
-119 366 339
-120 778 1282
-121 386 1616
-122 3918 1217
-123 3332 1049
-124 2597 349
-125 811 1295
-126 241 1069
-127 2658 360
-128 394 1944
-129 3786 1862
-130 264 36
-131 2050 1833
-132 3538 125
-133 1646 1817
-134 2993 624
-135 547 25
-136 3373 1902
-137 460 267
-138 3060 781
-139 1828 456
-140 1021 962
-141 2347 388
-142 3535 1112
-143 1529 581
-144 1203 385
-145 1787 1902
-146 2740 1101
-147 555 1753
-148 47 363
-149 3935 540
-150 3062 329
-151 387 199
-152 2901 920
-153 931 512
-154 1766 692
-155 401 980
-156 149 1629
-157 2214 1977
-158 3805 1619
-159 1179 969
-160 1017 333
-161 2834 1512
-162 634 294
-163 1819 814
-164 1393 859
-165 1768 1578
-166 3023 871
-167 3248 1906
-168 1632 1742
-169 2223 990
-170 3868 697
-171 1541 354
-172 2374 1944
-173 1962 389
-174 3007 1524
-175 3220 1945
-176 2356 1568
-177 1604 706
-178 2028 1736
-179 2581 121
-180 2221 1578
-181 2944 632
-182 1082 1561
-183 997 942
-184 2334 523
-185 1264 1090
-186 1699 1294
-187 235 1059
-188 2592 248
-189 3642 699
-190 3599 514
-191 1766 678
-192 240 619
-193 1272 246
-194 3503 301
-195 80 1533
-196 1677 1238
-197 3766 154
-198 3946 459
-199 1994 1852
-200 278 165
-EOF
diff --git a/data/kroB200.tsp.gz b/data/kroB200.tsp.gz
deleted file mode 100755
index 9b04259..0000000
Binary files a/data/kroB200.tsp.gz and /dev/null differ
diff --git a/data/pcb442.tsp b/data/pcb442.tsp
deleted file mode 100755
index 2b74de7..0000000
--- a/data/pcb442.tsp
+++ /dev/null
@@ -1,449 +0,0 @@
-NAME : pcb442
-COMMENT : Drilling problem (Groetschel/Juenger/Reinelt)
-TYPE : TSP
-DIMENSION : 442
-EDGE_WEIGHT_TYPE : EUC_2D
-NODE_COORD_SECTION
-1 2.00000e+02 4.00000e+02
-2 2.00000e+02 5.00000e+02
-3 2.00000e+02 6.00000e+02
-4 2.00000e+02 7.00000e+02
-5 2.00000e+02 8.00000e+02
-6 2.00000e+02 9.00000e+02
-7 2.00000e+02 1.00000e+03
-8 2.00000e+02 1.10000e+03
-9 2.00000e+02 1.20000e+03
-10 2.00000e+02 1.30000e+03
-11 2.00000e+02 1.40000e+03
-12 2.00000e+02 1.50000e+03
-13 2.00000e+02 1.60000e+03
-14 2.00000e+02 1.70000e+03
-15 2.00000e+02 1.80000e+03
-16 2.00000e+02 1.90000e+03
-17 2.00000e+02 2.00000e+03
-18 2.00000e+02 2.10000e+03
-19 2.00000e+02 2.20000e+03
-20 2.00000e+02 2.30000e+03
-21 2.00000e+02 2.40000e+03
-22 2.00000e+02 2.50000e+03
-23 2.00000e+02 2.60000e+03
-24 2.00000e+02 2.70000e+03
-25 2.00000e+02 2.80000e+03
-26 2.00000e+02 2.90000e+03
-27 2.00000e+02 3.00000e+03
-28 2.00000e+02 3.10000e+03
-29 2.00000e+02 3.20000e+03
-30 2.00000e+02 3.30000e+03
-31 2.00000e+02 3.40000e+03
-32 2.00000e+02 3.50000e+03
-33 2.00000e+02 3.60000e+03
-34 3.00000e+02 4.00000e+02
-35 3.00000e+02 5.00000e+02
-36 3.00000e+02 6.00000e+02
-37 3.00000e+02 7.00000e+02
-38 3.00000e+02 8.00000e+02
-39 3.00000e+02 9.00000e+02
-40 3.00000e+02 1.00000e+03
-41 3.00000e+02 1.10000e+03
-42 3.00000e+02 1.20000e+03
-43 3.00000e+02 1.30000e+03
-44 3.00000e+02 1.40000e+03
-45 3.00000e+02 1.50000e+03
-46 3.00000e+02 1.60000e+03
-47 3.00000e+02 1.70000e+03
-48 3.00000e+02 1.80000e+03
-49 3.00000e+02 1.90000e+03
-50 3.00000e+02 2.00000e+03
-51 3.00000e+02 2.10000e+03
-52 3.00000e+02 2.20000e+03
-53 3.00000e+02 2.30000e+03
-54 3.00000e+02 2.40000e+03
-55 3.00000e+02 2.50000e+03
-56 3.00000e+02 2.60000e+03
-57 3.00000e+02 2.70000e+03
-58 3.00000e+02 2.80000e+03
-59 3.00000e+02 2.90000e+03
-60 3.00000e+02 3.00000e+03
-61 3.00000e+02 3.10000e+03
-62 3.00000e+02 3.20000e+03
-63 3.00000e+02 3.30000e+03
-64 3.00000e+02 3.40000e+03
-65 3.00000e+02 3.50000e+03
-66 4.00000e+02 4.00000e+02
-67 4.00000e+02 5.00000e+02
-68 4.00000e+02 6.00000e+02
-69 4.00000e+02 7.00000e+02
-70 4.00000e+02 8.00000e+02
-71 4.00000e+02 9.00000e+02
-72 4.00000e+02 1.00000e+03
-73 4.00000e+02 1.10000e+03
-74 4.00000e+02 1.20000e+03
-75 4.00000e+02 1.30000e+03
-76 4.00000e+02 1.40000e+03
-77 4.00000e+02 1.50000e+03
-78 4.00000e+02 1.60000e+03
-79 4.00000e+02 1.70000e+03
-80 4.00000e+02 1.80000e+03
-81 4.00000e+02 1.90000e+03
-82 4.00000e+02 2.00000e+03
-83 4.00000e+02 2.10000e+03
-84 4.00000e+02 2.20000e+03
-85 4.00000e+02 2.30000e+03
-86 4.00000e+02 2.40000e+03
-87 4.00000e+02 2.50000e+03
-88 4.00000e+02 2.60000e+03
-89 4.00000e+02 2.70000e+03
-90 4.00000e+02 2.80000e+03
-91 4.00000e+02 2.90000e+03
-92 4.00000e+02 3.00000e+03
-93 4.00000e+02 3.10000e+03
-94 4.00000e+02 3.20000e+03
-95 4.00000e+02 3.30000e+03
-96 4.00000e+02 3.40000e+03
-97 4.00000e+02 3.50000e+03
-98 4.00000e+02 3.60000e+03
-99 5.00000e+02 1.50000e+03
-100 5.00000e+02 1.82900e+03
-101 5.00000e+02 3.10000e+03
-102 6.00000e+02 4.00000e+02
-103 7.00000e+02 3.00000e+02
-104 7.00000e+02 6.00000e+02
-105 7.00000e+02 1.50000e+03
-106 7.00000e+02 1.60000e+03
-107 7.00000e+02 1.80000e+03
-108 7.00000e+02 2.10000e+03
-109 7.00000e+02 2.40000e+03
-110 7.00000e+02 2.70000e+03
-111 7.00000e+02 3.00000e+03
-112 7.00000e+02 3.30000e+03
-113 7.00000e+02 3.60000e+03
-114 8.00000e+02 3.00000e+02
-115 8.00000e+02 6.00000e+02
-116 8.00000e+02 1.03000e+03
-117 8.00000e+02 1.50000e+03
-118 8.00000e+02 1.80000e+03
-119 8.00000e+02 2.10000e+03
-120 8.00000e+02 2.40000e+03
-121 8.00000e+02 2.60000e+03
-122 8.00000e+02 2.70000e+03
-123 8.00000e+02 3.00000e+03
-124 8.00000e+02 3.30000e+03
-125 8.00000e+02 3.60000e+03
-126 9.00000e+02 3.00000e+02
-127 9.00000e+02 6.00000e+02
-128 9.00000e+02 1.50000e+03
-129 9.00000e+02 1.80000e+03
-130 9.00000e+02 2.10000e+03
-131 9.00000e+02 2.40000e+03
-132 9.00000e+02 2.70000e+03
-133 9.00000e+02 3.00000e+03
-134 9.00000e+02 3.30000e+03
-135 9.00000e+02 3.60000e+03
-136 1.00000e+03 3.00000e+02
-137 1.00000e+03 6.00000e+02
-138 1.00000e+03 1.10000e+03
-139 1.00000e+03 1.50000e+03
-140 1.00000e+03 1.62900e+03
-141 1.00000e+03 1.80000e+03
-142 1.00000e+03 2.10000e+03
-143 1.00000e+03 2.40000e+03
-144 1.00000e+03 2.60000e+03
-145 1.00000e+03 2.70000e+03
-146 1.00000e+03 3.00000e+03
-147 1.00000e+03 3.30000e+03
-148 1.00000e+03 3.60000e+03
-149 1.10000e+03 3.00000e+02
-150 1.10000e+03 6.00000e+02
-151 1.10000e+03 7.00000e+02
-152 1.10000e+03 9.00000e+02
-153 1.10000e+03 1.50000e+03
-154 1.10000e+03 1.80000e+03
-155 1.10000e+03 2.10000e+03
-156 1.10000e+03 2.40000e+03
-157 1.10000e+03 2.70000e+03
-158 1.10000e+03 3.00000e+03
-159 1.10000e+03 3.30000e+03
-160 1.10000e+03 3.60000e+03
-161 1.20000e+03 3.00000e+02
-162 1.20000e+03 6.00000e+02
-163 1.20000e+03 1.50000e+03
-164 1.20000e+03 1.70000e+03
-165 1.20000e+03 1.80000e+03
-166 1.20000e+03 2.10000e+03
-167 1.20000e+03 2.40000e+03
-168 1.20000e+03 2.70000e+03
-169 1.20000e+03 3.00000e+03
-170 1.20000e+03 3.30000e+03
-171 1.20000e+03 3.60000e+03
-172 1.30000e+03 3.00000e+02
-173 1.30000e+03 6.00000e+02
-174 1.30000e+03 7.00000e+02
-175 1.30000e+03 1.13000e+03
-176 1.30000e+03 1.50000e+03
-177 1.30000e+03 1.80000e+03
-178 1.30000e+03 2.10000e+03
-179 1.30000e+03 2.20000e+03
-180 1.30000e+03 2.40000e+03
-181 1.30000e+03 2.70000e+03
-182 1.30000e+03 3.00000e+03
-183 1.30000e+03 3.30000e+03
-184 1.30000e+03 3.60000e+03
-185 1.40000e+03 3.00000e+02
-186 1.40000e+03 6.00000e+02
-187 1.40000e+03 9.30000e+02
-188 1.40000e+03 1.50000e+03
-189 1.40000e+03 1.80000e+03
-190 1.40000e+03 2.00000e+03
-191 1.40000e+03 2.10000e+03
-192 1.40000e+03 2.40000e+03
-193 1.40000e+03 2.50000e+03
-194 1.40000e+03 2.70000e+03
-195 1.40000e+03 2.82000e+03
-196 1.40000e+03 2.90000e+03
-197 1.40000e+03 3.00000e+03
-198 1.40000e+03 3.30000e+03
-199 1.40000e+03 3.60000e+03
-200 1.50000e+03 1.50000e+03
-201 1.50000e+03 1.80000e+03
-202 1.50000e+03 1.90000e+03
-203 1.50000e+03 2.10000e+03
-204 1.50000e+03 2.40000e+03
-205 1.50000e+03 2.70000e+03
-206 1.50000e+03 2.80000e+03
-207 1.50000e+03 2.86000e+03
-208 1.50000e+03 3.00000e+03
-209 1.50000e+03 3.30000e+03
-210 1.50000e+03 3.60000e+03
-211 1.60000e+03 1.10000e+03
-212 1.60000e+03 1.30000e+03
-213 1.60000e+03 1.50000e+03
-214 1.60000e+03 1.80000e+03
-215 1.60000e+03 2.10000e+03
-216 1.60000e+03 2.40000e+03
-217 1.60000e+03 2.70000e+03
-218 1.60000e+03 3.00000e+03
-219 1.60000e+03 3.30000e+03
-220 1.60000e+03 3.60000e+03
-221 1.70000e+03 1.20000e+03
-222 1.70000e+03 1.50000e+03
-223 1.70000e+03 1.80000e+03
-224 1.70000e+03 2.10000e+03
-225 1.70000e+03 2.40000e+03
-226 1.70000e+03 3.60000e+03
-227 1.80000e+03 3.00000e+02
-228 1.80000e+03 6.00000e+02
-229 1.80000e+03 1.23000e+03
-230 1.80000e+03 1.50000e+03
-231 1.80000e+03 1.80000e+03
-232 1.80000e+03 2.10000e+03
-233 1.80000e+03 2.40000e+03
-234 1.90000e+03 3.00000e+02
-235 1.90000e+03 6.00000e+02
-236 1.90000e+03 3.00000e+03
-237 1.90000e+03 3.52000e+03
-238 2.00000e+03 3.00000e+02
-239 2.00000e+03 3.70000e+02
-240 2.00000e+03 6.00000e+02
-241 2.00000e+03 8.00000e+02
-242 2.00000e+03 9.00000e+02
-243 2.00000e+03 1.00000e+03
-244 2.00000e+03 1.10000e+03
-245 2.00000e+03 1.20000e+03
-246 2.00000e+03 1.30000e+03
-247 2.00000e+03 1.40000e+03
-248 2.00000e+03 1.50000e+03
-249 2.00000e+03 1.60000e+03
-250 2.00000e+03 1.70000e+03
-251 2.00000e+03 1.80000e+03
-252 2.00000e+03 1.90000e+03
-253 2.00000e+03 2.00000e+03
-254 2.00000e+03 2.10000e+03
-255 2.00000e+03 2.20000e+03
-256 2.00000e+03 2.30000e+03
-257 2.00000e+03 2.40000e+03
-258 2.00000e+03 2.50000e+03
-259 2.00000e+03 2.60000e+03
-260 2.00000e+03 2.70000e+03
-261 2.00000e+03 2.80000e+03
-262 2.00000e+03 2.90000e+03
-263 2.00000e+03 3.00000e+03
-264 2.00000e+03 3.10000e+03
-265 2.00000e+03 3.50000e+03
-266 2.10000e+03 3.00000e+02
-267 2.10000e+03 6.00000e+02
-268 2.10000e+03 3.20000e+03
-269 2.20000e+03 3.00000e+02
-270 2.20000e+03 4.69000e+02
-271 2.20000e+03 6.00000e+02
-272 2.20000e+03 3.20000e+03
-273 2.30000e+03 3.00000e+02
-274 2.30000e+03 6.00000e+02
-275 2.30000e+03 3.40000e+03
-276 2.40000e+03 3.00000e+02
-277 2.40000e+03 6.00000e+02
-278 2.40000e+03 2.10000e+03
-279 2.50000e+03 3.00000e+02
-280 2.50000e+03 8.00000e+02
-281 2.60000e+03 4.00000e+02
-282 2.60000e+03 5.00000e+02
-283 2.60000e+03 8.00000e+02
-284 2.60000e+03 9.00000e+02
-285 2.60000e+03 1.00000e+03
-286 2.60000e+03 1.10000e+03
-287 2.60000e+03 1.20000e+03
-288 2.60000e+03 1.30000e+03
-289 2.60000e+03 1.40000e+03
-290 2.60000e+03 1.50000e+03
-291 2.60000e+03 1.60000e+03
-292 2.60000e+03 1.70000e+03
-293 2.60000e+03 1.80000e+03
-294 2.60000e+03 1.90000e+03
-295 2.60000e+03 2.00000e+03
-296 2.60000e+03 2.10000e+03
-297 2.60000e+03 2.20000e+03
-298 2.60000e+03 2.30000e+03
-299 2.60000e+03 2.40000e+03
-300 2.60000e+03 2.50000e+03
-301 2.60000e+03 2.60000e+03
-302 2.60000e+03 2.70000e+03
-303 2.60000e+03 2.80000e+03
-304 2.60000e+03 2.90000e+03
-305 2.60000e+03 3.00000e+03
-306 2.60000e+03 3.10000e+03
-307 2.60000e+03 3.40000e+03
-308 2.70000e+03 7.00000e+02
-309 2.70000e+03 8.00000e+02
-310 2.70000e+03 9.00000e+02
-311 2.70000e+03 1.00000e+03
-312 2.70000e+03 1.10000e+03
-313 2.70000e+03 1.20000e+03
-314 2.70000e+03 1.30000e+03
-315 2.70000e+03 1.40000e+03
-316 2.70000e+03 1.50000e+03
-317 2.70000e+03 1.60000e+03
-318 2.70000e+03 1.70000e+03
-319 2.70000e+03 1.80000e+03
-320 2.70000e+03 1.90000e+03
-321 2.70000e+03 2.00000e+03
-322 2.70000e+03 2.10000e+03
-323 2.70000e+03 2.20000e+03
-324 2.70000e+03 2.30000e+03
-325 2.70000e+03 2.50000e+03
-326 2.70000e+03 2.60000e+03
-327 2.70000e+03 2.70000e+03
-328 2.70000e+03 2.80000e+03
-329 2.70000e+03 2.90000e+03
-330 2.70000e+03 3.00000e+03
-331 2.70000e+03 3.10000e+03
-332 2.70000e+03 3.20000e+03
-333 2.70000e+03 3.30000e+03
-334 2.70000e+03 3.40000e+03
-335 2.70000e+03 3.50000e+03
-336 2.70000e+03 3.60000e+03
-337 2.70000e+03 3.70000e+03
-338 2.70000e+03 3.80000e+03
-339 2.80000e+03 9.00000e+02
-340 2.80000e+03 1.13000e+03
-341 2.90000e+03 4.00000e+02
-342 2.90000e+03 5.00000e+02
-343 2.90000e+03 1.40000e+03
-344 2.90000e+03 2.40000e+03
-345 2.90000e+03 3.00000e+03
-346 3.00000e+03 7.00000e+02
-347 3.00000e+03 8.00000e+02
-348 3.00000e+03 9.00000e+02
-349 3.00000e+03 1.00000e+03
-350 3.00000e+03 1.10000e+03
-351 3.00000e+03 1.20000e+03
-352 3.00000e+03 1.30000e+03
-353 3.00000e+03 1.50000e+03
-354 3.00000e+03 1.60000e+03
-355 3.00000e+03 1.70000e+03
-356 3.00000e+03 1.80000e+03
-357 3.00000e+03 1.90000e+03
-358 3.00000e+03 2.00000e+03
-359 3.00000e+03 2.10000e+03
-360 3.00000e+03 2.20000e+03
-361 3.00000e+03 2.30000e+03
-362 3.00000e+03 2.50000e+03
-363 3.00000e+03 2.60000e+03
-364 3.00000e+03 2.70000e+03
-365 3.00000e+03 2.80000e+03
-366 3.00000e+03 2.90000e+03
-367 3.00000e+03 3.00000e+03
-368 3.00000e+03 3.10000e+03
-369 3.00000e+03 3.20000e+03
-370 3.00000e+03 3.30000e+03
-371 3.00000e+03 3.40000e+03
-372 3.00000e+03 3.50000e+03
-373 3.00000e+03 3.60000e+03
-374 3.00000e+03 3.70000e+03
-375 3.00000e+03 3.80000e+03
-376 1.50000e+02 3.50000e+03
-377 1.50000e+02 3.55000e+03
-378 4.69000e+02 2.55000e+03
-379 4.69000e+02 3.35000e+03
-380 4.69000e+02 3.45000e+03
-381 5.40000e+02 2.33000e+03
-382 5.40000e+02 2.43000e+03
-383 6.20000e+02 3.65000e+03
-384 6.20000e+02 3.70900e+03
-385 7.50000e+02 2.55000e+03
-386 8.50000e+02 5.20000e+02
-387 8.50000e+02 7.00000e+02
-388 8.50000e+02 2.28000e+03
-389 9.39000e+02 7.40000e+02
-390 9.50000e+02 2.22000e+03
-391 9.10000e+02 2.60000e+03
-392 1.05000e+03 1.05000e+03
-393 1.15000e+03 1.35000e+03
-394 1.17000e+03 2.28000e+03
-395 1.22000e+03 2.21000e+03
-396 1.35000e+03 7.50000e+02
-397 1.35000e+03 1.70000e+03
-398 1.35000e+03 2.14000e+03
-399 1.45000e+03 7.70000e+02
-400 1.55000e+03 3.00000e+02
-401 1.55000e+03 5.00000e+02
-402 1.55000e+03 1.85000e+03
-403 1.65000e+03 1.05000e+03
-404 1.69000e+03 2.68000e+03
-405 1.71000e+03 3.10000e+02
-406 1.71000e+03 5.10000e+02
-407 1.75000e+03 7.50000e+02
-408 1.79000e+03 2.58000e+03
-409 1.72000e+03 2.61000e+03
-410 1.79000e+03 3.33000e+03
-411 1.72000e+03 3.40900e+03
-412 1.82900e+03 2.70000e+03
-413 1.82900e+03 2.80000e+03
-414 1.82900e+03 3.45000e+03
-415 2.06000e+03 1.65000e+03
-416 2.05000e+03 3.15000e+03
-417 2.17000e+03 1.90000e+03
-418 2.11000e+03 2.00000e+03
-419 2.12000e+03 2.75000e+03
-420 2.15000e+03 3.25000e+03
-421 2.29000e+03 1.40000e+03
-422 2.22000e+03 2.82000e+03
-423 2.28000e+03 3.25000e+03
-424 2.39000e+03 1.30000e+03
-425 2.32000e+03 1.50000e+03
-426 2.45000e+03 7.10000e+02
-427 2.62000e+03 3.65000e+03
-428 2.75000e+03 5.20000e+02
-429 2.76000e+03 2.36000e+03
-430 2.85000e+03 2.20000e+03
-431 2.85000e+03 2.70000e+03
-432 2.85000e+03 3.35000e+03
-433 2.93000e+03 9.50000e+02
-434 2.95000e+03 1.75000e+03
-435 2.95000e+03 2.05000e+03
-436 5.20000e+02 3.20000e+03
-437 2.30000e+03 3.50000e+03
-438 2.32000e+03 3.15000e+03
-439 5.30000e+02 2.10000e+03
-440 2.55000e+03 7.10000e+02
-441 7.50000e+02 4.90000e+02
-442 0.00000e+00 0.00000e+00
-EOF
diff --git a/data/pcb442.tsp.gz b/data/pcb442.tsp.gz
deleted file mode 100755
index 66218c8..0000000
Binary files a/data/pcb442.tsp.gz and /dev/null differ
diff --git a/data/pr226.tsp b/data/pr226.tsp
deleted file mode 100755
index d25bcd4..0000000
--- a/data/pr226.tsp
+++ /dev/null
@@ -1,233 +0,0 @@
-NAME : pr226
-COMMENT : 226-city problem (Padberg/Rinaldi)
-TYPE : TSP
-DIMENSION : 226
-EDGE_WEIGHT_TYPE : EUC_2D
-NODE_COORD_SECTION
-1 15625 1150
-2 14625 1200
-3 14525 1200
-4 14425 1200
-5 14125 1200
-6 14025 1200
-7 13925 1200
-8 13975 1500
-9 13625 1200
-10 13475 1200
-11 13475 1600
-12 13475 1750
-13 13475 1900
-14 13325 1200
-15 13175 1200
-16 13100 1725
-17 12675 1725
-18 12025 1300
-19 11425 1600
-20 9725 1450
-21 7975 1150
-22 6975 1200
-23 6875 1200
-24 6775 1200
-25 6475 1200
-26 6375 1200
-27 6275 1200
-28 6325 1500
-29 5975 1200
-30 5825 1200
-31 5825 1600
-32 5825 1750
-33 5825 1900
-34 5675 1200
-35 5525 1200
-36 5450 1725
-37 5025 1725
-38 4375 1300
-39 3775 1600
-40 2075 1450
-41 2075 3850
-42 3775 2300
-43 4375 3300
-44 5025 2150
-45 5450 2150
-46 5475 2500
-47 5475 3000
-48 5825 2050
-49 6325 2200
-50 7975 2150
-51 8725 2550
-52 8725 2650
-53 8725 2750
-54 8725 2850
-55 8725 2950
-56 8725 3050
-57 8725 3200
-58 8725 3300
-59 8725 3400
-60 8725 3500
-61 8725 3600
-62 8725 3700
-63 8725 3800
-64 9725 3850
-65 11425 2300
-66 12025 3300
-67 12675 2150
-68 13100 2150
-69 13125 2500
-70 13125 3000
-71 13475 2050
-72 13975 2200
-73 15625 2150
-74 16375 2550
-75 16375 2650
-76 16375 2750
-77 16375 2850
-78 16375 2950
-79 16375 3050
-80 16375 3200
-81 16375 3300
-82 16375 3400
-83 16375 3500
-84 16375 3600
-85 16375 3700
-86 16375 3800
-87 4875 6500
-88 4875 6700
-89 4875 6600
-90 4875 6800
-91 4875 6900
-92 4875 7000
-93 4875 7100
-94 4875 7200
-95 4975 6500
-96 4975 6600
-97 4975 6700
-98 4975 6800
-99 4975 6900
-100 4975 7000
-101 4975 7100
-102 4975 7200
-103 12525 6500
-104 12525 6700
-105 12525 6600
-106 12525 6800
-107 12525 6900
-108 12525 7000
-109 12525 7100
-110 12525 7200
-111 12625 6500
-112 12625 6600
-113 12625 6700
-114 12625 6800
-115 12625 6900
-116 12625 7000
-117 12625 7100
-118 12625 7200
-119 12625 8450
-120 12625 8550
-121 12625 8650
-122 12625 8750
-123 12625 8850
-124 12625 8950
-125 12625 9050
-126 12525 8450
-127 12525 8650
-128 12525 8550
-129 12525 8750
-130 12525 8950
-131 12525 8850
-132 12525 9050
-133 10075 8800
-134 9975 8800
-135 9875 8800
-136 9775 8800
-137 4975 8450
-138 4975 8550
-139 4975 8650
-140 4975 8750
-141 4975 8850
-142 4975 8950
-143 4975 9050
-144 4875 8450
-145 4875 8650
-146 4875 8550
-147 4875 8750
-148 4875 8950
-149 4875 8850
-150 4875 9050
-151 2425 8800
-152 2325 8800
-153 2225 8800
-154 2125 8800
-155 1875 11850
-156 1975 11850
-157 2075 11850
-158 2425 11850
-159 2525 11850
-160 2625 11850
-161 2725 11850
-162 2825 11850
-163 2925 11850
-164 3025 11850
-165 3125 11850
-166 3375 11850
-167 3475 11850
-168 3575 11850
-169 3675 11850
-170 3775 11850
-171 4075 11850
-172 4175 11850
-173 4275 11850
-174 4375 11850
-175 4475 11850
-176 4575 11850
-177 4675 11850
-178 4775 11850
-179 4875 11850
-180 4975 11850
-181 5375 11850
-182 5475 11850
-183 5575 11850
-184 5675 11850
-185 5775 11850
-186 5875 11850
-187 5975 11850
-188 6075 11850
-189 6175 11850
-190 6275 11850
-191 9525 11850
-192 9625 11850
-193 9725 11850
-194 10075 11850
-195 10175 11850
-196 10275 11850
-197 10375 11850
-198 10475 11850
-199 10575 11850
-200 10675 11850
-201 10775 11850
-202 11025 11850
-203 11125 11850
-204 11225 11850
-205 11325 11850
-206 11425 11850
-207 11725 11850
-208 11825 11850
-209 11925 11850
-210 12025 11850
-211 12125 11850
-212 12225 11850
-213 12325 11850
-214 12425 11850
-215 12525 11850
-216 12625 11850
-217 13025 11850
-218 13125 11850
-219 13225 11850
-220 13325 11850
-221 13425 11850
-222 13525 11850
-223 13625 11850
-224 13725 11850
-225 13825 11850
-226 13925 11850
-EOF
diff --git a/data/pr226.tsp.gz b/data/pr226.tsp.gz
deleted file mode 100755
index 5b73c46..0000000
Binary files a/data/pr226.tsp.gz and /dev/null differ
diff --git a/data/pr76.tsp b/data/pr76.tsp
deleted file mode 100755
index ec1e7d4..0000000
--- a/data/pr76.tsp
+++ /dev/null
@@ -1,83 +0,0 @@
-NAME : pr76
-COMMENT : 76-city problem (Padberg/Rinaldi)
-TYPE : TSP
-DIMENSION : 76
-EDGE_WEIGHT_TYPE : EUC_2D
-NODE_COORD_SECTION
-1 3600 2300
-2 3100 3300
-3 4700 5750
-4 5400 5750
-5 5608 7103
-6 4493 7102
-7 3600 6950
-8 3100 7250
-9 4700 8450
-10 5400 8450
-11 5610 10053
-12 4492 10052
-13 3600 10800
-14 3100 10950
-15 4700 11650
-16 5400 11650
-17 6650 10800
-18 7300 10950
-19 7300 7250
-20 6650 6950
-21 7300 3300
-22 6650 2300
-23 5400 1600
-24 8350 2300
-25 7850 3300
-26 9450 5750
-27 10150 5750
-28 10358 7103
-29 9243 7102
-30 8350 6950
-31 7850 7250
-32 9450 8450
-33 10150 8450
-34 10360 10053
-35 9242 10052
-36 8350 10800
-37 7850 10950
-38 9450 11650
-39 10150 11650
-40 11400 10800
-41 12050 10950
-42 12050 7250
-43 11400 6950
-44 12050 3300
-45 11400 2300
-46 10150 1600
-47 13100 2300
-48 12600 3300
-49 14200 5750
-50 14900 5750
-51 15108 7103
-52 13993 7102
-53 13100 6950
-54 12600 7250
-55 14200 8450
-56 14900 8450
-57 15110 10053
-58 13992 10052
-59 13100 10800
-60 12600 10950
-61 14200 11650
-62 14900 11650
-63 16150 10800
-64 16800 10950
-65 16800 7250
-66 16150 6950
-67 16800 3300
-68 16150 2300
-69 14900 1600
-70 19800 800
-71 19800 10000
-72 19800 11900
-73 19800 12200
-74 200 12200
-75 200 1100
-76 200 800
-EOF
diff --git a/data/pr76.tsp.gz b/data/pr76.tsp.gz
deleted file mode 100755
index 044461e..0000000
Binary files a/data/pr76.tsp.gz and /dev/null differ
diff --git a/data/rat99.tsp b/data/rat99.tsp
deleted file mode 100755
index 2a6bcce..0000000
--- a/data/rat99.tsp
+++ /dev/null
@@ -1,106 +0,0 @@
-NAME : rat99
-COMMENT : Rattled grid (Pulleyblank)
-TYPE : TSP
-DIMENSION : 99
-EDGE_WEIGHT_TYPE : EUC_2D
-NODE_COORD_SECTION
- 1 6 4
- 2 15 15
- 3 24 18
- 4 33 12
- 5 48 12
- 6 57 14
- 7 67 10
- 8 77 10
- 9 86 15
- 10 6 21
- 11 17 26
- 12 23 25
- 13 32 35
- 14 43 23
- 15 55 35
- 16 65 36
- 17 78 39
- 18 87 35
- 19 3 53
- 20 12 44
- 21 28 53
- 22 33 49
- 23 47 46
- 24 55 52
- 25 64 50
- 26 71 57
- 27 87 57
- 28 4 72
- 29 15 78
- 30 22 70
- 31 34 71
- 32 42 79
- 33 54 77
- 34 66 79
- 35 78 67
- 36 87 73
- 37 7 81
- 38 17 95
- 39 26 98
- 40 32 97
- 41 43 88
- 42 57 89
- 43 64 85
- 44 78 83
- 45 83 98
- 46 5 109
- 47 13 111
- 48 25 102
- 49 38 119
- 50 46 107
- 51 58 110
- 52 67 110
- 53 74 113
- 54 88 110
- 55 2 124
- 56 17 134
- 57 23 129
- 58 36 131
- 59 42 137
- 60 53 123
- 61 63 135
- 62 72 134
- 63 87 129
- 64 2 146
- 65 16 147
- 66 25 153
- 67 38 155
- 68 42 158
- 69 57 154
- 70 66 151
- 71 73 151
- 72 86 149
- 73 5 177
- 74 13 162
- 75 25 169
- 76 35 177
- 77 46 172
- 78 54 166
- 79 65 174
- 80 73 161
- 81 86 162
- 82 2 195
- 83 14 196
- 84 28 189
- 85 38 187
- 86 46 195
- 87 57 194
- 88 63 188
- 89 77 193
- 90 85 194
- 91 8 211
- 92 12 217
- 93 22 210
- 94 34 216
- 95 47 203
- 96 58 213
- 97 66 206
- 98 78 210
- 99 85 204
-EOF
diff --git a/data/rat99.tsp.gz b/data/rat99.tsp.gz
deleted file mode 100755
index 8b9466b..0000000
Binary files a/data/rat99.tsp.gz and /dev/null differ
diff --git a/data/st70.tsp.gz b/data/st70.tsp.gz
deleted file mode 100755
index 759f2c4..0000000
Binary files a/data/st70.tsp.gz and /dev/null differ
diff --git a/data/tsp225.tsp b/data/tsp225.tsp
deleted file mode 100755
index 76340cd..0000000
--- a/data/tsp225.tsp
+++ /dev/null
@@ -1,232 +0,0 @@
-NAME : tsp225
-COMMENT : A TSP problem (Reinelt)
-TYPE : TSP
-DIMENSION : 225
-EDGE_WEIGHT_TYPE : EUC_2D
-NODE_COORD_SECTION
- 1 155.42 150.65
- 2 375.92 164.65
- 3 183.92 150.65
- 4 205.42 150.65
- 5 205.42 171.65
- 6 226.42 171.65
- 7 226.42 186.15
- 8 226.42 207.15
- 9 226.42 235.65
- 10 226.42 264.15
- 11 226.42 292.65
- 12 226.42 314.15
- 13 226.42 335.65
- 14 205.42 335.65
- 15 190.92 335.65
- 16 190.92 328.15
- 17 176.92 328.15
- 18 176.92 299.65
- 19 155.42 299.65
- 20 155.42 328.15
- 21 155.42 356.65
- 22 183.92 356.65
- 23 219.42 356.65
- 24 240.92 356.65
- 25 269.42 356.65
- 26 290.42 356.65
- 27 387.42 136.15
- 28 318.92 356.65
- 29 318.92 335.65
- 30 318.92 328.15
- 31 318.92 299.65
- 32 297.92 299.65
- 33 290.42 328.15
- 34 290.42 335.65
- 35 297.92 328.15
- 36 254.92 335.65
- 37 254.92 314.15
- 38 254.92 292.65
- 39 254.92 271.65
- 40 254.92 243.15
- 41 254.92 221.65
- 42 254.92 193.15
- 43 254.92 171.65
- 44 276.42 171.65
- 45 296.42 150.65
- 46 276.42 150.65
- 47 375.92 150.65
- 48 308.92 150.65
- 49 354.92 164.65
- 50 338.42 174.65
- 51 354.92 174.65
- 52 338.42 200.15
- 53 338.42 221.65
- 54 354.92 221.65
- 55 354.92 200.15
- 56 361.92 200.15
- 57 361.92 186.15
- 58 383.42 186.15
- 59 383.42 179.15
- 60 404.42 179.15
- 61 404.42 186.15
- 62 418.92 186.15
- 63 418.92 200.15
- 64 432.92 200.15
- 65 432.92 221.65
- 66 418.92 221.65
- 67 418.92 235.65
- 68 397.42 235.65
- 69 397.42 243.15
- 70 375.92 243.15
- 71 375.92 257.15
- 72 368.92 257.15
- 73 368.92 264.15
- 74 347.42 264.15
- 75 347.42 278.65
- 76 336.42 278.65
- 77 336.42 328.15
- 78 347.42 328.15
- 79 347.42 342.65
- 80 368.92 342.65
- 81 368.92 353.65
- 82 418.92 353.65
- 83 418.92 342.65
- 84 432.92 342.65
- 85 432.92 356.65
- 86 447.42 356.65
- 87 447.42 321.15
- 88 447.42 292.65
- 89 432.92 292.65
- 90 432.92 314.15
- 91 418.92 314.15
- 92 418.92 321.15
- 93 397.42 321.15
- 94 397.42 333.65
- 95 375.92 333.65
- 96 375.92 321.15
- 97 361.92 321.15
- 98 361.92 299.65
- 99 375.92 299.65
-100 375.92 285.65
-101 397.42 285.65
-102 397.42 271.65
-103 418.92 271.65
-104 418.92 264.15
-105 439.92 264.15
-106 439.92 250.15
-107 454.42 250.15
-108 454.42 243.15
-109 461.42 243.15
-110 461.42 214.65
-111 461.42 193.15
-112 447.42 193.15
-113 447.42 179.15
-114 439.92 179.15
-115 439.92 167.65
-116 419.92 167.65
-117 419.92 150.65
-118 439.92 150.65
-119 454.42 150.65
-120 475.92 150.65
-121 475.92 171.65
-122 496.92 171.65
-123 496.92 193.15
-124 496.92 214.65
-125 496.92 243.15
-126 496.92 271.65
-127 496.92 292.65
-128 496.92 317.15
-129 496.92 335.65
-130 470.42 335.65
-131 470.42 356.65
-132 496.92 356.65
-133 347.42 150.65
-134 539.92 356.65
-135 560.92 356.65
-136 589.42 356.65
-137 589.42 342.65
-138 603.92 342.65
-139 610.92 342.65
-140 610.92 335.65
-141 610.92 321.15
-142 624.92 321.15
-143 624.92 278.65
-144 610.92 278.65
-145 610.92 257.15
-146 589.42 257.15
-147 589.42 250.15
-148 575.42 250.15
-149 560.92 250.15
-150 542.92 250.15
-151 542.92 264.15
-152 560.92 264.15
-153 575.42 264.15
-154 575.42 271.65
-155 582.42 271.65
-156 582.42 285.65
-157 596.42 285.65
-158 560.92 335.65
-159 596.42 314.15
-160 582.42 314.15
-161 582.42 321.15
-162 575.42 321.15
-163 575.42 335.65
-164 525.42 335.65
-165 525.42 314.15
-166 525.42 299.65
-167 525.42 281.65
-168 525.42 233.15
-169 525.42 214.65
-170 525.42 193.15
-171 525.42 171.65
-172 546.92 171.65
-173 546.92 150.65
-174 568.42 150.65
-175 475.92 160.65
-176 603.92 150.65
-177 624.92 150.65
-178 624.92 136.15
-179 596.42 136.15
-180 575.42 136.15
-181 553.92 136.15
-182 532.42 136.15
-183 575.42 356.65
-184 489.92 136.15
-185 468.42 136.15
-186 447.42 136.15
-187 425.92 136.15
-188 404.42 136.15
-189 370.42 136.15
-190 361.92 150.65
-191 340.42 136.15
-192 326.42 136.15
-193 301.92 136.15
-194 276.42 136.15
-195 254.92 136.15
-196 315.92 136.15
-197 212.42 136.15
-198 190.92 136.15
-199 338.92 150.65
-200 155.42 136.15
-201 624.92 299.65
-202 318.92 321.65
-203 155.42 314.15
-204 311.92 356.65
-205 355.42 136.15
-206 318.92 314.15
-207 362.92 164.65
-208 254.92 356.65
-209 383.42 333.65
-210 447.42 335.65
-211 470.42 345.65
-212 525.42 250.15
-213 546.92 335.65
-214 525.42 261.15
-215 525.42 356.65
-216 336.42 298.65
-217 336.42 313.15
-218 293.42 136.15
-219 336.42 306.15
-220 425.92 264.15
-221 391.42 353.65
-222 482.92 335.65
-223 429.92 167.65
-224 330.92 150.65
-225 368.42 150.65
-EOF
diff --git a/data/tsp225.tsp.gz b/data/tsp225.tsp.gz
deleted file mode 100755
index 00001c8..0000000
Binary files a/data/tsp225.tsp.gz and /dev/null differ
diff --git a/foa_2opt_greedy.py b/foa_2opt_greedy.py
deleted file mode 100755
index 83b7dad..0000000
--- a/foa_2opt_greedy.py
+++ /dev/null
@@ -1,261 +0,0 @@
-import random
-import numpy as np
-import math
-import pandas as pd
-import tqdm
-
-
-class FOA(object):
- def __init__(self, num_city, num_total, iteration, data, save_path, save_freq, **kwargs):
- self.num_city = num_city
- self.num_total = num_total
- self.iteration = iteration
- self.save_path = save_path
- self.save_freq = save_freq
- self.location = data
- self.dis_mat = self.compute_dis_mat(num_city, self.location)
- # self.fruits = self.greedy_init(self.dis_mat, num_total, num_city)
- self.fruits = self.random_init(num_total,num_city)
-
- # 贪心初始化种群
- def greedy_init(self, dis_mat, num_total, num_city):
- start_index = 0
- result = []
- for i in range(num_total):
- rest = [x for x in range(0, num_city)]
- # 所有起始点都已经生成了
- if start_index >= num_city:
- start_index = np.random.randint(0, num_city)
- result.append(result[start_index].copy())
- continue
- current = start_index
- rest.remove(current)
- # 找到一条最近邻路径
- result_one = [current]
- while len(rest) != 0:
- tmp_min = math.inf
- tmp_choose = -1
- for x in rest:
- if dis_mat[current][x] < tmp_min:
- tmp_min = dis_mat[current][x]
- tmp_choose = x
-
- current = tmp_choose
- result_one.append(tmp_choose)
- rest.remove(tmp_choose)
- result.append(result_one)
- start_index += 1
- return result
-
- # def greedy_init_2(self,dis_mat,num_total,num_city):
- # start_index = 0
- # result = [[]]*num_total
- # rest = [x for x in range(0, num_city)]
- # # 所有起始点都已经生成了
- # if start_index >= num_city:
- # start_index = np.random.randint(0,num_city)
- # result[i] = result[start_index].copy()
- # continue
- # current = start_index
- # rest.remove(current)
- # # 找到一条最近邻路径
- # result_one = [current]
- # while len(rest) != 0:
- # tmp_min = math.inf
- # tmp_choose = -1
- # for x in rest:
- # if dis_mat[current][x] < tmp_min:
- # tmp_min = dis_mat[current][x]
- # tmp_choose = x
- #
- # current = tmp_choose
- # result_one.append(tmp_choose)
- # rest.remove(tmp_choose)
- # # result[i] = result_one
- # result[0] = result_one
- # start_index += 1
- # return result
- # 随机初始化种群
- def random_init(self, num_total, num_city):
- tmp = [x for x in range(num_city)]
- result = []
- for i in range(num_total):
- random.shuffle(tmp)
- result.append(tmp.copy())
- return result
-
- # 计算不同城市之间的距离
- def compute_dis_mat(self, num_city, location):
- dis_mat = np.zeros((num_city, num_city))
- for i in range(num_city):
- for j in range(num_city):
- if i == j:
- dis_mat[i][j] = np.inf
- continue
- a = location[i]
- b = location[j]
- tmp = np.sqrt(sum([(x[0] - x[1]) ** 2 for x in zip(a, b)]))
- dis_mat[i][j] = tmp
- return dis_mat
-
- # 计算路径长度
- def compute_pathlen(self, path, dis_mat):
- try:
- a = path[0]
- b = path[-1]
- except:
- import pdb
- pdb.set_trace()
- result = dis_mat[a][b]
- for i in range(len(path) - 1):
- a = path[i]
- b = path[i + 1]
- result += dis_mat[a][b]
- return result
-
- # 计算种群适应度
- def compute_adp(self, fruits):
- adp = []
- for fruit in fruits:
- if isinstance(fruit, int):
- import pdb
- pdb.set_trace()
- length = self.compute_pathlen(fruit, self.dis_mat)
- adp.append(1.0 / length)
- return np.array(adp)
-
- # 对序列做2opt操作
- def _2opt(self, x):
- city_list = [i for i in range(self.num_city)]
- choice = np.random.choice(city_list, 2)
- choice.sort()
- i, j = choice
- a = x[:i]
- b = x[i:j]
- c = x[j:]
- b = b[::-1]
- if isinstance(x, int) or isinstance(a + b + c, int):
- import pdb
- pdb.set_trace()
- adp1 = 1. / self.compute_pathlen(x, self.dis_mat)
- adp2 = 1. / self.compute_pathlen(a + b + c, self.dis_mat)
- if adp1 > adp2:
- result = x
- else:
- result = a + b + c
-
- # result = a+b+c
- return result
-
- # 迭代一次,返回适应度最高的个体和他的序列。
- def fly(self, fruits, num_total):
- # 选择适应度最高的个体
- self.dis_adp = self.compute_adp(self.fruits)
- # 从高到底适应度排序
- sortindex = np.argsort(-self.dis_adp)
- best_adp = self.dis_adp[sortindex[0]]
- best_fruit = self.fruits[sortindex[0]]
- # 保留种群中适应度最好的个体
- # self.fruits[0] = best_fruit
- self.fruits = [best_fruit]
- for i in range(1, num_total):
- # 2opt生成一个新个体
-
- opt_2_res = self._2opt(best_fruit.copy())
- self.fruits.append(opt_2_res)
- return best_adp, best_fruit
-
- # 总共的迭代过程,返回最终最好的长度,以及一段路径
- def run(self):
- best_fruit = None
- best_adp = -math.inf
- for i in range(self.iteration):
- tmp_adp, tmp_list = self.fly(self.fruits, self.num_total)
- if tmp_adp > best_adp:
- best_adp = tmp_adp
- best_fruit = tmp_list
- bestlen = 1.0 / best_adp
- return self.location[best_fruit], bestlen
-
-
-import pandas as pd
-
-
-def read_tsp(path):
- lines = open(path, 'r').readlines()
- assert 'NODE_COORD_SECTION\n' in lines
- index = lines.index('NODE_COORD_SECTION\n')
- data = lines[index + 1:-1]
- tmp = []
- for line in data:
- line = line.strip().split(' ')
- if line[0] == 'EOF':
- continue
- tmpline = []
- for x in line:
- if x == '':
- continue
- else:
- tmpline.append(float(x))
- if tmpline == []:
- continue
- tmp.append(tmpline)
- data = tmp
- return data
-
-
-data = read_tsp('data/st70.tsp')
-data = np.array(data)
-data = data[:, 1:]
-result_ = []
-runtimes = 20
-import time
-
-start_time = time.time()
-for _ in tqdm.trange(runtimes):
- foa = FOA(num_city=data.shape[0], num_total=50, iteration=1000, data=data.copy(), save_path='sdsdsdssd.txt',
- save_freq=10)
- res, length = foa.run()
- result_.append(length)
-end_time = time.time()
-result_ = np.array(result_)
-
-print('best:{:.2f}\tworst:{:.2f}\tmean:{:.2f}\tstd:{:.2f}\taverage_time:{:.2f}'.format(result_.min(), result_.max(),
- result_.mean(), result_.std(), (
- end_time - start_time) / runtimes))
-
-# import os
-# # print(os.getcwd())
-# import matplotlib.pyplot as plt
-# import numpy as np
-# from mpl_toolkits.mplot3d import Axes3D
-#
-# fig = plt.figure()
-# ax = Axes3D(fig)
-# colors = ('#377eb8', '#ff7f00', '#4daf4a','#aaaaaa')
-# def plot(i, data):
-#
-# x = data[:,0]
-# y = data[:,1]
-# z = data[:,2]
-# ax.scatter(x, y, z,color=colors[i],marker = '+')
-# # ax.set_zlabel('Z', fontdict={'size': 15, 'color': 'red'})
-# # ax.set_ylabel('Y', fontdict={'size': 15, 'color': 'red'})
-# # ax.set_xlabel('X', fontdict={'size': 15, 'color': 'red'})
-# ax.plot3D(data[:,0], data[:,1], data[:,2],color = colors[i])
-# result = []
-# for i in range(4):
-# data = pd.read_csv('path5_{}.csv'.format(i),header=None)
-# data = np.array(data)
-# foa = FOA(num_city=data.shape[0],num_total=20,iteration=100,adp_norm=1000,data=data,save_path='sdsdsdssd.txt',save_freq=10)
-# res,lenth = foa.run()
-#
-# res = np.array(res).astype(np.int)
-# plot(i,res)
-#
-# print(lenth)
-# # result.append(res)
-# # result = np.concatenate(result,axis = 0)
-# # print(result.shape)
-# # plot(result)
-# plt.show()
diff --git a/foa_2opt_greedy_ga.py b/foa_2opt_greedy_ga.py
deleted file mode 100755
index ddf0dc1..0000000
--- a/foa_2opt_greedy_ga.py
+++ /dev/null
@@ -1,386 +0,0 @@
-import random
-import numpy as np
-import math
-import pandas as pd
-
-
-class FOA(object):
- def __init__(self, num_city, num_total, iteration, adp_norm, data, save_path, save_freq, **kwargs):
- self.num_city = num_city
- self.num_total = num_total
- self.dis_adp = [0 for _ in range(self.num_total)]
- self.iteration = iteration
- self.adp_norm = adp_norm
- self.save_path = save_path
- self.save_freq = save_freq
- self.location = data
- self.dis_mat = self.distance_p2p_mat()
- # self.generate_best()
- self.ga_choose_num = 10
- self.ga_ratio = 0.5
- self.cross_ratio = 0.9
- self.mutate_ratio = 0.9
- self.generate_fruits()
- print('get data,she shape is {}'.format(self.location.shape))
-
- def get_data(self, data):
- return np.loadtxt(data)[:, 1:]
-
- # 贪心初始化一条最优路径
- def generate_best(self,flag = True):
- if flag:
- initial = [0]
- rest = [x for x in range(1, self.num_city)]
- initial_path = 0
- while len(rest) != 0:
- start = initial[-1]
- tmp_min = math.inf
- tmp_choose = -1
- for x in rest:
- if self.dis_mat[start][x] < tmp_min:
- tmp_min = self.dis_mat[start][x]
- tmp_choose = x
- initial_path += tmp_min
- initial.append(tmp_choose)
- rest.remove(tmp_choose)
- initial_path += self.dis_mat[tmp_choose][0]
- return initial, initial_path
- else:
- initial = [x for x in range(self.num_city)]
- initial_path = 0
- for index in range(self.num_city - 1):
- initial_path += self.dis_mat[index][index+1]
- initial_path += self.dis_mat[index][0]
- return initial, initial_path
-
- def generate_fruits(self):
- best, initial_path = self.generate_best(True)
- self.fruits = [np.array(best)]
- for _ in range(self.num_total - 1):
- tmp = best.copy()
- np.random.shuffle(tmp)
- self.fruits.append(np.array(tmp))
-
- # 对称矩阵,两个城市之间的距离 支持2d和3d
- def distance_p2p_mat(self):
- dis_mat = []
- for i in range(self.num_city):
- dis_mat_each = []
- for j in range(self.num_city):
- tmp = 0
- for k in range(len(self.location[i])):
- tmp += pow(self.location[i][k] - self.location[j][k], 2)
- tmp = math.sqrt(tmp)
- dis_mat_each.append(tmp)
- dis_mat.append(dis_mat_each)
- return dis_mat
-
- # 目标函数计算,适应度计算,中间计算。适应度为1/总距离*10000
- def dis_adp_total(self, ):
- self.dis_adp = []
- for i in range(self.num_total):
- try:
- dis = self.dis_mat[self.fruits[i][self.num_city - 1]][self.fruits[i][0]] # 回家
- except:
- import pdb
- pdb.set_trace()
- for j in range(self.num_city - 1):
- dis = self.dis_mat[self.fruits[i][j]][self.fruits[i][j + 1]] + dis
- dis_adp_each = self.adp_norm / dis
- self.dis_adp.append(dis_adp_each)
-
- def swap_part(self, list1, list2):
- index = len(list1)
- list = list1 + list2
- list = list[::-1]
- return list[:index], list[index:]
-
- def ga_cross(self, x, y):
- x = np.array(x)
- y = np.array(y)
- len_ = len(x)
- assert len(x) == len(y)
- path_list = [t for t in range(len_)]
- # start, end = np.random.choice(path_list,2)
- # order = list(random.sample(path_list,2))
- start = np.random.randint(len_-5)
- end = start +5
- # order.sort()
- # start, end = order
-
- # 找到冲突点并存下他们的下标,x中存储的是y中的下标
- tmp = x[start:end]
- x_conflict_index = []
- for sub in tmp:
- index = int(np.where(y == sub)[0])
- if not (index >= start and index < end):
- x_conflict_index.append(index)
- y_confict_index = []
- tmp = y[start:end]
- for sub in tmp:
- index = int(np.where(x == sub)[0])
- if not (index >= start and index < end):
- y_confict_index.append(index)
- assert len(x_conflict_index) == len(y_confict_index)
- # 交叉
- tmp = x[start:end].copy()
- x[start:end] = y[start:end]
- y[start:end] = tmp
- # 解决冲突
- for index in range(len(x_conflict_index)):
- i = x_conflict_index[index]
- j = y_confict_index[index]
- y[i], x[j] = x[j], y[i]
-
- assert len(set(x)) == len_ and len(set(y)) == len_
- return x, y
-
- def ga_cross(self, x, y):
- x = np.array(x)
- y = np.array(y)
- len_ = len(x)
- assert len(x) == len(y)
- path_list = [t for t in range(len_)]
- # start, end = np.random.choice(path_list,2)
- order = list(random.sample(path_list,2))
- # start = np.random.randint(len_-3)
- # end = start +3
- order.sort()
- start, end = order
-
- # 找到冲突点并存下他们的下标,x中存储的是y中的下标
- tmp = x[start:end]
- x_conflict_index = []
- for sub in tmp:
- index = int(np.where(y == sub)[0])
- if not (index >= start and index < end):
- x_conflict_index.append(index)
- y_confict_index = []
- tmp = y[start:end]
- for sub in tmp:
- index = int(np.where(x == sub)[0])
- if not (index >= start and index < end):
- y_confict_index.append(index)
- assert len(x_conflict_index) == len(y_confict_index)
- # 交叉
- tmp = x[start:end].copy()
- x[start:end] = y[start:end]
- y[start:end] = tmp
- # 解决冲突
- for index in range(len(x_conflict_index)):
- i = x_conflict_index[index]
- j = y_confict_index[index]
- y[i], x[j] = x[j], y[i]
-
- assert len(set(x)) == len_ and len(set(y)) == len_
- return list(x), list(y)
-
- def ga_parent(self,scores,choose_num):
- scores_order = np.argsort(scores)[::-1].copy()
- scores_order = scores_order[0:choose_num]
- genes_choose = []
- genes_score = []
- for sub in scores_order:
- genes_choose.append(self.fruits[sub])
- genes_score.append(scores[sub])
- return genes_score, genes_choose
-
- def ga_choose(self,genes_score,genes_choose):
- sum_score = sum(genes_score)
- score_ratio = [sub*1.0/sum_score for sub in genes_score]
- rand1 = np.random.rand()
- rand2 = np.random.rand()
- for i, sub in enumerate(score_ratio):
- if rand1 >= 0:
- rand1 -= sub
- if rand1 < 0:
- index1 = i
- if rand2 >= 0:
- rand2 -= sub
- if rand2 < 0:
- index2 = i
- if rand1 < 0 and rand2 < 0:
- break
- return list(genes_choose[index1]), list(genes_choose[index2])
-
- def ga_mutate(self,gene):
- path_list = [t for t in range(len(gene))]
- order = list(random.sample(path_list, 2))
- start, end = min(order), max(order)
- tmp = gene[start:end]
- # np.random.shuffle(tmp)
- tmp = tmp[::-1]
- gene[start:end] = tmp
- return list(gene)
-
- def ga(self):
- # 获得优质父代
- scores = self.dis_adp
- genes_score, genes_choose = self.ga_parent(scores,self.ga_choose_num)
- ga_result = []
- # for sub in genes_choose[0:self.ga_choose_num]:
- # ga_result.append(list(sub))
- # 轮盘赌方式对父代进行选择
- gene_x, gene_y = self.ga_choose(genes_score,genes_choose)
- # 交叉
- if np.random.rand() < self.cross_ratio:
- gene_x, gene_y = self.ga_cross(gene_x, gene_y)
- # 变异
- if np.random.rand() < self.mutate_ratio:
- gene_x_new = self.ga_mutate(gene_x)
- if np.random.rand() < self.mutate_ratio:
- gene_y_new = self.ga_mutate(gene_y)
-
- if not (gene_x in ga_result):
- ga_result.append(gene_x)
- if not (gene_y in ga_result):
- ga_result.append(gene_y)
-
- ga_result = ga_result[:self.num_total]
- ga_result = [np.array(x) for x in ga_result]
- return ga_result
-
- def get_best(self):
- self.dis_adp_total()
- sortindex = np.argsort(self.dis_adp)[::-1]
- best_adp = self.dis_adp[sortindex[0]]
- best_fruit = self.fruits[sortindex[0]]
- return best_adp, best_fruit
-
-
- def opt_2(self, x):
- city_list = [i for i in range(self.num_city)]
- choice = np.random.choice(city_list, 2)
- choice.sort()
- res_list = []
- a, b = list(choice)
- part1 = list(x[:a])
- part2 = list(x[a:b])
- part3 = list(x[b:])
-
- # 1
- res = part1 + part2[::-1] + part3
- res_list.append(res)
- # 2
- list1, list2 = self.swap_part(part1, part3)
- res = list1 + part2 + list2
- res_list.append(res)
- # 3
- res = list1 + part2[::-1] + list2
- res_list.append(res)
- return res_list
-
- def fly(self):
- self.dis_adp_total()
- sortindex = np.argsort(self.dis_adp)[::-1]
- best_adp = self.dis_adp[sortindex[0]]
- best_fruit = self.fruits[sortindex[0]]
- fruits = [best_fruit]
- while len(fruits) < self.num_total*2:
- if np.random.rand() < self.ga_ratio:
- ga_result = self.ga()
- fruits += ga_result
- else:
- opt_2_result = self.opt_2(best_fruit)
- fruits += opt_2_result
-
- self.dis_adp_total()
- sortindex = np.argsort(self.dis_adp)[::-1]
- keep_index = sortindex[:self.num_total]
-
- self.fruits = np.array(fruits)[keep_index]
- self.fruits = list(fruits)
-
- return best_adp, best_fruit
-
- def run(self):
- print('==================Running the code==================')
- BEST_LIST = None
- best_adp = -math.inf
-
- with open(self.save_path, 'w') as f:
- for i in range(1, self.iteration + 1):
- max_adp, best_list = self.fly()
- # self.ga()
- if max_adp > best_adp:
- best_adp = max_adp
- BEST_LIST = best_list
- bestlen = self.adp_norm / best_adp
- return self.location[BEST_LIST], bestlen
-
-
-import pandas as pd
-
-# x = [t for t in range(10)]
-# yy = x.copy()
-# np.random.shuffle(yy)
-#
-# tx,ty = FOA.ga_cross(x,yy)
-# print(tx,ty)
-
-
-def read_tsp(path):
- lines = open(path, 'r').readlines()
- assert 'NODE_COORD_SECTION\n' in lines
- index = lines.index('NODE_COORD_SECTION\n')
- data = lines[index + 1:-1]
- tmp = []
- for line in data:
- line = line.strip().split(' ')
- tmpline = []
- for x in line:
- if x == '':
- continue
- else:
- tmpline.append(int(x))
- tmp.append(tmpline)
- data = tmp
- return data
-
-
-data = read_tsp('data/st70.tsp')
-data = np.array(data)
-data = data[:, 1:]
-for _ in range(10):
- foa = FOA(num_city=data.shape[0], num_total=200, iteration=1000, adp_norm=1000, data=data.copy(),
- save_path='sdsdsdssd.txt', save_freq=10)
- res, result = foa.run()
- print(result)
-
-
-
-# import os
-# # print(os.getcwd())
-# import matplotlib.pyplot as plt
-# import numpy as np
-# from mpl_toolkits.mplot3d import Axes3D
-#
-# fig = plt.figure()
-# ax = Axes3D(fig)
-# colors = ('#377eb8', '#ff7f00', '#4daf4a','#aaaaaa')
-# def plot(i, data):
-#
-# x = data[:,0]
-# y = data[:,1]
-# z = data[:,2]
-# ax.scatter(x, y, z,color=colors[i],marker = '+')
-# # ax.set_zlabel('Z', fontdict={'size': 15, 'color': 'red'})
-# # ax.set_ylabel('Y', fontdict={'size': 15, 'color': 'red'})
-# # ax.set_xlabel('X', fontdict={'size': 15, 'color': 'red'})
-# ax.plot3D(data[:,0], data[:,1], data[:,2],color = colors[i])
-# result = []
-# for i in range(4):
-# data = pd.read_csv('path5_{}.csv'.format(i),header=None)
-# data = np.array(data)
-# foa = FOA(num_city=data.shape[0],num_total=20,iteration=100,adp_norm=1000,data=data,save_path='sdsdsdssd.txt',save_freq=10)
-# res,lenth = foa.run()
-#
-# res = np.array(res).astype(np.int)
-# plot(i,res)
-#
-# print(lenth)
-# # result.append(res)
-# # result = np.concatenate(result,axis = 0)
-# # print(result.shape)
-# # plot(result)
-# plt.show()
diff --git a/foa_2opt_greedy_morebest.py b/foa_2opt_greedy_morebest.py
deleted file mode 100755
index 97bae6f..0000000
--- a/foa_2opt_greedy_morebest.py
+++ /dev/null
@@ -1,232 +0,0 @@
-import random
-import numpy as np
-import math
-import pandas as pd
-import tqdm
-
-class FOA(object):
- def __init__(self, num_city, num_total, iteration, data, save_path, save_freq, **kwargs):
- self.num_city = num_city
- self.num_total = num_total
- self.iteration = iteration
- self.save_path = save_path
- self.save_freq = save_freq
- self.location = data
- self.dis_mat = self.compute_dis_mat(num_city,self.location)
- self.fruits = self.greedy_init(self.dis_mat,num_total,num_city)
- # self.fruits = self.random_init(num_total,num_city)
- # 贪心初始化种群
- def greedy_init(self,dis_mat,num_total,num_city):
- start_index = 0
- result = [[]]*num_total
- for i in range(num_total):
- rest = [x for x in range(0, num_city)]
- # 所有起始点都已经生成了
- if start_index >= num_city:
- start_index = np.random.randint(0,num_city)
- result[i] = result[start_index].copy()
- continue
- current = start_index
- rest.remove(current)
- # 找到一条最近邻路径
- result_one = [current]
- while len(rest) != 0:
- tmp_min = math.inf
- tmp_choose = -1
- for x in rest:
- if dis_mat[current][x] < tmp_min:
- tmp_min = dis_mat[current][x]
- tmp_choose = x
-
- current = tmp_choose
- result_one.append(tmp_choose)
- rest.remove(tmp_choose)
- result[i] = result_one
- start_index += 1
- return result
- # def greedy_init_2(self,dis_mat,num_total,num_city):
- # start_index = 0
- # result = [[]]*num_total
- # rest = [x for x in range(0, num_city)]
- # # 所有起始点都已经生成了
- # if start_index >= num_city:
- # start_index = np.random.randint(0,num_city)
- # result[i] = result[start_index].copy()
- # continue
- # current = start_index
- # rest.remove(current)
- # # 找到一条最近邻路径
- # result_one = [current]
- # while len(rest) != 0:
- # tmp_min = math.inf
- # tmp_choose = -1
- # for x in rest:
- # if dis_mat[current][x] < tmp_min:
- # tmp_min = dis_mat[current][x]
- # tmp_choose = x
- #
- # current = tmp_choose
- # result_one.append(tmp_choose)
- # rest.remove(tmp_choose)
- # # result[i] = result_one
- # result[0] = result_one
- # start_index += 1
- # return result
- # 随机初始化种群
- def random_init(self,num_total,num_city):
- tmp = [x for x in range(num_city)]
- result = [[]]*num_total
- for i in range(num_total):
- random.shuffle(tmp)
- result[i] = tmp
- return result
- # 计算不同城市之间的距离
- def compute_dis_mat(self,num_city,location):
- dis_mat = np.zeros((num_city,num_city))
- for i in range(num_city):
- for j in range(num_city):
- if i == j:
- dis_mat[i][j] = np.inf
- continue
- a = location[i]
- b = location[j]
- tmp = np.sqrt(sum([(x[0] - x[1]) ** 2for x in zip(a,b)]))
- dis_mat[i][j] = tmp
- return dis_mat
- # 计算路径长度
- def compute_pathlen(self,path,dis_mat):
- a = path[0]
- b = path[-1]
- result = dis_mat[a][b]
- for i in range(len(path) - 1):
- a = path[i]
- b = path[i+1]
- result += dis_mat[a][b]
- return result
- # 计算种群适应度
- def compute_adp(self,fruits):
- adp = []
- for fruit in fruits:
- length = self.compute_pathlen(fruit,self.dis_mat)
- adp.append(1.0/length)
- return np.array(adp)
- # 对序列做2opt操作
- def _2opt(self, x):
- city_list = [i for i in range(self.num_city)]
- choice = np.random.choice(city_list, 2)
- choice.sort()
- i,j = choice
- a = x[:i]
- b = x[i:j]
- c = x[j:]
- b = b[::-1]
- result = a+b+c
- return result
- # 迭代一次,返回适应度最高的个体和他的序列。
- def fly(self,fruits,num_total):
- best_ratio = 0.6
- best_num =best_ratio*num_total
- start_ge = best_num
- # 选择适应度最高的个体
- self.dis_adp = self.compute_adp(self.fruits)
- # 从高到底适应度排序
- sortindex = np.argsort(-self.dis_adp)
- best_adp = self.dis_adp[sortindex[0]]
- best_fruit = self.fruits[sortindex[0]]
- # 保留种群中适应度最好的个体
- tmp_fruits = self.fruits.copy()
- for i in range(int(best_num)):
- index = sortindex[i]
- self.fruits[i] = tmp_fruits[index]
- # self.fruits[0] = best_fruit
-
- for i in range(int(start_ge), num_total):
- # 2opt生成一个新个体
- index = np.random.randint(0,best_num-1)
- opt_2_res = self._2opt(self.fruits[index].copy())
- self.fruits[i] = opt_2_res
- return best_adp, best_fruit
- # 总共的迭代过程,返回最终最好的长度,以及一段路径
- def run(self):
- best_fruit = None
- best_adp = -math.inf
- for i in range(self.iteration):
- tmp_adp, tmp_list = self.fly(self.fruits,self.num_total)
- if tmp_adp > best_adp:
- best_adp = tmp_adp
- best_fruit = tmp_list
- bestlen = 1.0/best_adp
- return self.location[best_fruit],bestlen
-import pandas as pd
-def read_tsp(path):
- lines = open(path, 'r').readlines()
- assert 'NODE_COORD_SECTION\n' in lines
- index = lines.index('NODE_COORD_SECTION\n')
- data = lines[index + 1:-1]
- tmp = []
- for line in data:
- line = line.strip().split(' ')
- if line[0] == 'EOF':
- continue
- tmpline = []
- for x in line:
- if x == '':
- continue
- else:
- tmpline.append(float(x))
- if tmpline == []:
- continue
- tmp.append(tmpline)
- data = tmp
- return data
-data = read_tsp('data/st70.tsp')
-data = np.array(data)
-data = data[:,1:]
-result_ = []
-runtimes = 20
-import time
-start_time = time.time()
-for _ in tqdm.trange(runtimes):
- foa = FOA(num_city=data.shape[0],num_total=50,iteration=1000,data=data.copy(),save_path='sdsdsdssd.txt',save_freq=10)
- res, length = foa.run()
- result_.append(length)
-end_time = time.time()
-result_ = np.array(result_)
-
-print('best:{:.2f}\tworst:{:.2f}\tmean:{:.2f}\tstd:{:.2f}\taverage_time:{:.2f}'.format(result_.min(),result_.max(),result_.mean(), result_.std(),(end_time-start_time)/runtimes))
-
-# import os
-# # print(os.getcwd())
-# import matplotlib.pyplot as plt
-# import numpy as np
-# from mpl_toolkits.mplot3d import Axes3D
-#
-# fig = plt.figure()
-# ax = Axes3D(fig)
-# colors = ('#377eb8', '#ff7f00', '#4daf4a','#aaaaaa')
-# def plot(i, data):
-#
-# x = data[:,0]
-# y = data[:,1]
-# z = data[:,2]
-# ax.scatter(x, y, z,color=colors[i],marker = '+')
-# # ax.set_zlabel('Z', fontdict={'size': 15, 'color': 'red'})
-# # ax.set_ylabel('Y', fontdict={'size': 15, 'color': 'red'})
-# # ax.set_xlabel('X', fontdict={'size': 15, 'color': 'red'})
-# ax.plot3D(data[:,0], data[:,1], data[:,2],color = colors[i])
-# result = []
-# for i in range(4):
-# data = pd.read_csv('path5_{}.csv'.format(i),header=None)
-# data = np.array(data)
-# foa = FOA(num_city=data.shape[0],num_total=20,iteration=100,adp_norm=1000,data=data,save_path='sdsdsdssd.txt',save_freq=10)
-# res,lenth = foa.run()
-#
-# res = np.array(res).astype(np.int)
-# plot(i,res)
-#
-# print(lenth)
-# # result.append(res)
-# # result = np.concatenate(result,axis = 0)
-# # print(result.shape)
-# # plot(result)
-# plt.show()
\ No newline at end of file
diff --git a/foa_2opt_greedy_multi_best.py b/foa_2opt_greedy_multi_best.py
deleted file mode 100755
index 1d6c85e..0000000
--- a/foa_2opt_greedy_multi_best.py
+++ /dev/null
@@ -1,234 +0,0 @@
-import random
-import numpy as np
-import math
-import pandas as pd
-
-
-class FOA(object):
- def __init__(self, num_city, num_total, iteration, adp_norm, data, save_path, save_freq, **kwargs):
- self.num_city = num_city
- self.num_total = num_total
- self.dis_adp = [0 for _ in range(self.num_total)]
- self.iteration = iteration
- self.adp_norm = adp_norm
- self.save_path = save_path
- self.save_freq = save_freq
- self.location = data
- self.dis_mat = self.distance_p2p_mat()
- self.best_num = 1
- self.generate_best()
- self.generate_fruits()
- print('get data,she shape is {}'.format(self.location.shape))
-
- def get_data(self, data):
- return np.loadtxt(data)[:, 1:]
-
- # 贪心初始化一条最优路径
-
- def generate_best(self, flag=True):
- if flag:
- initial = [0]
- rest = [x for x in range(1, self.num_city)]
- initial_path = 0
- while len(rest) != 0:
- start = initial[-1]
- tmp_min = math.inf
- tmp_choose = -1
- for x in rest:
- if self.dis_mat[start][x] < tmp_min:
- tmp_min = self.dis_mat[start][x]
- tmp_choose = x
- initial_path += tmp_min
- initial.append(tmp_choose)
- rest.remove(tmp_choose)
- initial_path += self.dis_mat[tmp_choose][0]
- return initial, initial_path
- else:
- initial = [x for x in range(self.num_city)]
- initial_path = 0
- for index in range(self.num_city - 1):
- initial_path += self.dis_mat[index][index + 1]
- initial_path += self.dis_mat[index][0]
- return initial, initial_path
-
- def generate_fruits(self):
- best, initial_path = self.generate_best(True)
- self.fruits = [best]
- for _ in range(self.num_total - 1):
- a = np.random.randint(0, self.num_city)
- b = np.random.randint(0, self.num_city)
- a = min(a, b)
- b = max(a, b)
- part1 = list(best[:a])
- part2 = list(best[a:b])
- part3 = list(best[b:])
- if len(part2)>=1:
- try:
- np.random.shuffle(part2)
- part2 = list(part2)
- except:
- import pdb
- pdb.set_trace()
- res = part1 + part2 + part3
- self.fruits.append(res)
-
- # 对称矩阵,两个城市之间的距离 支持2d和3d
- def distance_p2p_mat(self):
- dis_mat = []
- for i in range(self.num_city):
- dis_mat_each = []
- for j in range(self.num_city):
- tmp = 0
- for k in range(len(self.location[i])):
- tmp += pow(self.location[i][k] - self.location[j][k], 2)
- tmp = math.sqrt(tmp)
- dis_mat_each.append(tmp)
- dis_mat.append(dis_mat_each)
- return dis_mat
-
- # 目标函数计算,适应度计算,中间计算。适应度为1/总距离*10000
- def dis_adp_total(self, ):
- self.dis_adp = []
- for i in range(self.num_total):
- try:
- dis = self.dis_mat[self.fruits[i][self.num_city - 1]][self.fruits[i][0]] # 回家
- except:
- import pdb
- pdb.set_trace()
- for j in range(self.num_city - 1):
- dis = self.dis_mat[self.fruits[i][j]][self.fruits[i][j + 1]] + dis
- dis_adp_each = self.adp_norm / dis
- self.dis_adp.append(dis_adp_each)
-
- def swap_part(self,list1,list2):
- index = len(list1)
- list = list1 + list2
- list = list[::-1]
- return list[:index], list[index:]
-
- def opt_2(self, x):
- city_list = [i for i in range(self.num_city)]
- res_list = []
- for i in range(3):
- choice = np.random.choice(city_list, 2)
- choice.sort()
- a, b = list(choice)
- part1 = list(x[:a])
- part2 = list(x[a:b])
- part3 = list(x[b:])
-
- # 1
- res = part1 + part2[::-1] + part3
- res_list.append(res)
- # 2
- list1, list2 = self.swap_part(part1, part3)
- res = list1 + part2 + list2
- res_list.append(res)
- # 3
- res = list1 + part2[::-1] + list2
- res_list.append(res)
- return res_list
-
- def fly(self):
- self.dis_adp_total()
- sortindex = np.argsort(self.dis_adp)[::-1]
- best_adps = []
- for sub in sortindex[:self.best_num]:
- best_adps.append(self.dis_adp[sub])
- best_fruits = []
- for sub in sortindex[:self.best_num]:
- best_fruits.append(self.fruits[sub])
- self.fruits = best_fruits
- tmp = 1
- while tmp < self.num_total:
- randint = np.random.randint(0,self.best_num)
- best_fruit = best_fruits[randint]
- opt_2_res = self.opt_2(best_fruit.copy())
- self.fruits += opt_2_res
- tmp += 3
- self.fruits = self.fruits[:self.num_total]
-
- return best_adps[0],best_fruit
-
- def run(self):
- print('==================Running the code==================')
- BEST_LIST = None
- best_adp = -math.inf
- cnt = 0
- with open(self.save_path, 'w') as f:
- for i in range(1, self.iteration + 1):
- max_adp, best_list = self.fly()
- cnt += 1
- if max_adp > best_adp:
- cnt = 0
- best_adp = max_adp
- BEST_LIST = best_list
- if cnt > 50:
- break
- bestlen = self.adp_norm/best_adp
- return self.location[BEST_LIST],bestlen
-import pandas as pd
-def read_tsp(path):
- lines = open(path, 'r').readlines()
- assert 'NODE_COORD_SECTION\n' in lines
- index = lines.index('NODE_COORD_SECTION\n')
- data = lines[index + 1:-1]
- tmp = []
- for line in data:
- line = line.strip().split(' ')
- if line[0] == 'EOF':
- continue
- tmpline = []
- for x in line:
- if x == '':
- continue
- else:
- tmpline.append(float(x))
- if tmpline == []:
- continue
- tmp.append(tmpline)
- data = tmp
- return data
-data = read_tsp('data/st70.tsp')
-# data = read_tsp('data/burma14.tsp')
-data = np.array(data)
-data = data[:,1:]
-for _ in range(10):
- foa = FOA(num_city=data.shape[0],num_total=50,iteration=3000,adp_norm=1000,data=data.copy(),save_path='sdsdsdssd.txt',save_freq=10)
- res, length = foa.run()
- print(length)
-# import os
-# # print(os.getcwd())
-# import matplotlib.pyplot as plt
-# import numpy as np
-# from mpl_toolkits.mplot3d import Axes3D
-#
-# fig = plt.figure()
-# ax = Axes3D(fig)
-# colors = ('#377eb8', '#ff7f00', '#4daf4a','#aaaaaa')
-# def plot(i, data):
-#
-# x = data[:,0]
-# y = data[:,1]
-# z = data[:,2]
-# ax.scatter(x, y, z,color=colors[i],marker = '+')
-# # ax.set_zlabel('Z', fontdict={'size': 15, 'color': 'red'})
-# # ax.set_ylabel('Y', fontdict={'size': 15, 'color': 'red'})
-# # ax.set_xlabel('X', fontdict={'size': 15, 'color': 'red'})
-# ax.plot3D(data[:,0], data[:,1], data[:,2],color = colors[i])
-# result = []
-# for i in range(4):
-# data = pd.read_csv('path5_{}.csv'.format(i),header=None)
-# data = np.array(data)
-# foa = FOA(num_city=data.shape[0],num_total=20,iteration=100,adp_norm=1000,data=data,save_path='sdsdsdssd.txt',save_freq=10)
-# res,lenth = foa.run()
-#
-# res = np.array(res).astype(np.int)
-# plot(i,res)
-#
-# print(lenth)
-# # result.append(res)
-# # result = np.concatenate(result,axis = 0)
-# # print(result.shape)
-# # plot(result)
-# plt.show()
\ No newline at end of file
diff --git a/foa_3opt_greedy.py b/foa_3opt_greedy.py
deleted file mode 100755
index 7cfb1ec..0000000
--- a/foa_3opt_greedy.py
+++ /dev/null
@@ -1,269 +0,0 @@
-import random
-import numpy as np
-import math
-import pandas as pd
-import tqdm
-
-class FOA(object):
- def __init__(self, num_city, num_total, iteration, data, save_path, save_freq, **kwargs):
- self.num_city = num_city
- self.num_total = num_total
- self.iteration = iteration
- self.save_path = save_path
- self.save_freq = save_freq
- self.location = data
- self.dis_mat = self.compute_dis_mat(num_city,self.location)
- self.fruits = self.greedy_init(self.dis_mat,num_total,num_city)
- # self.fruits = self.random_init(num_total,num_city)
- # 贪心初始化种群
- def greedy_init(self,dis_mat,num_total,num_city):
- start_index = 0
- result = [[]]*num_total
- for i in range(num_total):
- rest = [x for x in range(0, num_city)]
- # 所有起始点都已经生成了
- if start_index >= num_city:
- start_index = np.random.randint(0,num_city)
- result[i] = result[start_index].copy()
- continue
- current = start_index
- rest.remove(current)
- # 找到一条最近邻路径
- result_one = [current]
- while len(rest) != 0:
- tmp_min = math.inf
- tmp_choose = -1
- for x in rest:
- if dis_mat[current][x] < tmp_min:
- tmp_min = dis_mat[current][x]
- tmp_choose = x
-
- current = tmp_choose
- result_one.append(tmp_choose)
- rest.remove(tmp_choose)
- result[i] = result_one
- start_index += 1
- return result
- # def greedy_init_2(self,dis_mat,num_total,num_city):
- # start_index = 0
- # result = [[]]*num_total
- # rest = [x for x in range(0, num_city)]
- # # 所有起始点都已经生成了
- # if start_index >= num_city:
- # start_index = np.random.randint(0,num_city)
- # result[i] = result[start_index].copy()
- # continue
- # current = start_index
- # rest.remove(current)
- # # 找到一条最近邻路径
- # result_one = [current]
- # while len(rest) != 0:
- # tmp_min = math.inf
- # tmp_choose = -1
- # for x in rest:
- # if dis_mat[current][x] < tmp_min:
- # tmp_min = dis_mat[current][x]
- # tmp_choose = x
- #
- # current = tmp_choose
- # result_one.append(tmp_choose)
- # rest.remove(tmp_choose)
- # # result[i] = result_one
- # result[0] = result_one
- # start_index += 1
- # return result
- # 随机初始化种群
- def random_init(self,num_total,num_city):
- tmp = [x for x in range(num_city)]
- result = [[]]*num_total
- for i in range(num_total):
- random.shuffle(tmp)
- result[i] = tmp
- return result
- # 计算不同城市之间的距离
- def compute_dis_mat(self,num_city,location):
- dis_mat = np.zeros((num_city,num_city))
- for i in range(num_city):
- for j in range(num_city):
- if i == j:
- dis_mat[i][j] = np.inf
- continue
- a = location[i]
- b = location[j]
- tmp = np.sqrt(sum([(x[0] - x[1]) ** 2for x in zip(a,b)]))
- dis_mat[i][j] = tmp
- return dis_mat
- # 计算路径长度
- def compute_pathlen(self,path,dis_mat):
- a = path[0]
- b = path[-1]
- assert a!=b
- result = dis_mat[a][b]
- for i in range(len(path) - 1):
- a = path[i]
- b = path[i+1]
- assert a!= b
- result += dis_mat[a][b]
- return result
- # 计算种群适应度
- def compute_adp(self,fruits):
- adp = []
- for fruit in fruits:
- length = self.compute_pathlen(fruit,self.dis_mat)
- adp.append(1.0/length)
- return np.array(adp)
- # 对序列做2opt操作
- def _3opt(self, x):
- city_list = [i for i in range(self.num_city)]
- choice = np.random.choice(city_list, 2)
- choice.sort()
- i, j = choice
- a = x[:i]
- b = x[i:j]
- c = x[j:]
- tmp_best = []
- tmp_best_adp = []
- # param1
- # tmp = a+b+c
- # tmp_adp = 1./self.compute_pathlen(tmp, self.dis_mat)
- # tmp_best = [a + b + c, ]
- # tmp_best_adp = [tmp_adp]
- # param2
- tmp = a+b+c[::-1]
- tmp_adp = 1./self.compute_pathlen(tmp, self.dis_mat)
- tmp_best.append(tmp)
- tmp_best_adp.append(tmp_adp)
- # param3
- tmp = a+c[::-1]+b[::-1]
- tmp_best.append(tmp)
- tmp_best_adp.append(1./self.compute_pathlen(tmp, self.dis_mat))
- # param4
- tmp = a+b[::-1]+c
- tmp_best.append(tmp)
- tmp_best_adp.append(1./self.compute_pathlen(tmp,self.dis_mat))
- # param5
- tmp = a+c+b[::-1]
- tmp_best.append(tmp)
- tmp_best_adp.append(1./self.compute_pathlen(tmp, self.dis_mat))
- # param6
- tmp = a+c[::-1]+b
- tmp_best.append(tmp)
- tmp_best_adp.append(1./self.compute_pathlen(tmp, self.dis_mat))
- # param7
- tmp = a+b[::-1]+c[::-1]
- tmp_best.append(tmp)
- tmp_best_adp.append(1./self.compute_pathlen(tmp, self.dis_mat))
- # param8
- tmp = a+c+b
- tmp_best.append(tmp)
- tmp_best_adp.append(1./self.compute_pathlen(tmp, self.dis_mat))
-
- max_adp = max(tmp_best_adp)
- max_index = tmp_best_adp.index(max_adp)
- result = tmp_best[max_index]
- return result
- # 迭代一次,返回适应度最高的个体和他的序列。
- def fly(self,fruits,num_total):
- # 选择适应度最高的个体
- self.dis_adp = self.compute_adp(self.fruits)
- # 从高到底适应度排序
- sortindex = np.argsort(-self.dis_adp)
- best_adp = self.dis_adp[sortindex[0]]
- best_fruit = self.fruits[sortindex[0]]
- # 保留种群中适应度最好的个体
- self.fruits[0] = best_fruit
- for i in range(1, num_total):
- # 2opt生成一个新个体
-
- opt_2_res = self._3opt(best_fruit.copy())
- self.fruits[i] = opt_2_res
- return best_adp, best_fruit
- # 总共的迭代过程,返回最终最好的长度,以及一段路径
- def run(self):
- best_fruit = None
- best_adp = -math.inf
- best_list = []
- for i in range(self.iteration):
- tmp_adp, tmp_list = self.fly(self.fruits,self.num_total)
- if tmp_adp > best_adp:
- best_adp = tmp_adp
- best_fruit = tmp_list
- # best_list = []
- # best_list.append(best_adp)
- # if len(best_list) == 50:
- # break
- bestlen = 1.0/best_adp
- return self.location[best_fruit],bestlen
-import pandas as pd
-def read_tsp(path):
- lines = open(path, 'r').readlines()
- assert 'NODE_COORD_SECTION\n' in lines
- index = lines.index('NODE_COORD_SECTION\n')
- data = lines[index + 1:-1]
- tmp = []
- for line in data:
- line = line.strip().split(' ')
- if line[0] == 'EOF':
- continue
- tmpline = []
- for x in line:
- if x == '':
- continue
- else:
- tmpline.append(float(x))
- if tmpline == []:
- continue
- tmp.append(tmpline)
- data = tmp
- return data
-data = read_tsp('data/st70.tsp')
-data = np.array(data)
-data = data[:,1:]
-result_ = []
-runtimes = 20
-import time
-start_time = time.time()
-for _ in tqdm.trange(runtimes):
- foa = FOA(num_city=data.shape[0],num_total=50,iteration=1000,data=data.copy(),save_path='sdsdsdssd.txt',save_freq=10)
- res, length = foa.run()
- result_.append(length)
-end_time = time.time()
-result_ = np.array(result_)
-
-print('best:{:.2f}\tworst:{:.2f}\tmean:{:.2f}\tstd:{:.2f}\taverage_time:{:.2f}'.format(result_.min(),result_.max(),result_.mean(), result_.std(),(end_time-start_time)/runtimes))
-
-# import os
-# # print(os.getcwd())
-# import matplotlib.pyplot as plt
-# import numpy as np
-# from mpl_toolkits.mplot3d import Axes3D
-#
-# fig = plt.figure()
-# ax = Axes3D(fig)
-# colors = ('#377eb8', '#ff7f00', '#4daf4a','#aaaaaa')
-# def plot(i, data):
-#
-# x = data[:,0]
-# y = data[:,1]
-# z = data[:,2]
-# ax.scatter(x, y, z,color=colors[i],marker = '+')
-# # ax.set_zlabel('Z', fontdict={'size': 15, 'color': 'red'})
-# # ax.set_ylabel('Y', fontdict={'size': 15, 'color': 'red'})
-# # ax.set_xlabel('X', fontdict={'size': 15, 'color': 'red'})
-# ax.plot3D(data[:,0], data[:,1], data[:,2],color = colors[i])
-# result = []
-# for i in range(4):
-# data = pd.read_csv('path5_{}.csv'.format(i),header=None)
-# data = np.array(data)
-# foa = FOA(num_city=data.shape[0],num_total=20,iteration=100,adp_norm=1000,data=data,save_path='sdsdsdssd.txt',save_freq=10)
-# res,lenth = foa.run()
-#
-# res = np.array(res).astype(np.int)
-# plot(i,res)
-#
-# print(lenth)
-# # result.append(res)
-# # result = np.concatenate(result,axis = 0)
-# # print(result.shape)
-# # plot(result)
-# plt.show()
\ No newline at end of file
diff --git a/foa_3opt_greedy_bak.py b/foa_3opt_greedy_bak.py
deleted file mode 100755
index 86a9577..0000000
--- a/foa_3opt_greedy_bak.py
+++ /dev/null
@@ -1,225 +0,0 @@
-import random
-import numpy as np
-import math
-import pandas as pd
-import time
-
-class FOA(object):
- def __init__(self, num_city, num_total, iteration, adp_norm, data, save_path, save_freq, **kwargs):
- self.num_city = num_city
- self.num_total = num_total
- self.dis_adp = [0 for _ in range(self.num_total)]
- self.iteration = iteration
- self.adp_norm = adp_norm
- self.save_path = save_path
- self.save_freq = save_freq
- self.location = data
- self.dis_mat = self.distance_p2p_mat()
- self.generate_best()
- self.generate_fruits()
- print('get data,she shape is {}'.format(self.location.shape))
-
- def get_data(self, data):
- return np.loadtxt(data)[:, 1:]
-
- # 贪心初始化一条最优路径
- def generate_best(self):
- initial = [0]
- rest = [x for x in range(1, self.num_city)]
- initial_path = 0
- while len(rest) != 0:
- start = initial[-1]
- tmp_min = math.inf
- tmp_choose = -1
- for x in rest:
- if self.dis_mat[start][x] < tmp_min:
- tmp_min = self.dis_mat[start][x]
- tmp_choose = x
- initial_path += tmp_min
- initial.append(tmp_choose)
- rest.remove(tmp_choose)
- initial_path += self.dis_mat[tmp_choose][0]
- return initial, initial_path
-
- def generate_fruits(self):
- best, initial_path = self.generate_best()
- self.fruits = [best]
- for _ in range(self.num_total - 1):
- a = np.random.randint(0, self.num_city)
- b = np.random.randint(0, self.num_city)
- a = min(a, b)
- b = max(a, b)
- part1 = list(best[:a])
- part2 = list(best[a:b])
- part3 = list(best[b:])
- if len(part2)>=1:
- try:
- np.random.shuffle(part2)
- part2 = list(part2)
- except:
- import pdb
- pdb.set_trace()
- res = part1 + part2 + part3
- self.fruits.append(res)
-
- # 对称矩阵,两个城市之间的距离 支持2d和3d
- def distance_p2p_mat(self):
- dis_mat = []
- for i in range(self.num_city):
- dis_mat_each = []
- for j in range(self.num_city):
- tmp = 0
- for k in range(len(self.location[i])):
- tmp += pow(self.location[i][k] - self.location[j][k], 2)
- tmp = math.sqrt(tmp)
- dis_mat_each.append(tmp)
- dis_mat.append(dis_mat_each)
- return dis_mat
-
- # 目标函数计算,适应度计算,中间计算。适应度为1/总距离*10000
- def dis_adp_total(self, ):
- self.dis_adp = []
- for i in range(self.num_total):
- try:
- dis = self.dis_mat[self.fruits[i][self.num_city - 1]][self.fruits[i][0]] # 回家
- except:
- import pdb
- pdb.set_trace()
- for j in range(self.num_city - 1):
- dis = self.dis_mat[self.fruits[i][j]][self.fruits[i][j + 1]] + dis
- dis_adp_each = self.adp_norm / dis
- self.dis_adp.append(dis_adp_each)
-
- def swap_part(self,list1,list2):
- index = len(list1)
- list = list1 + list2
- list = list[::-1]
- return list[:index], list[index:]
-
- def fly(self):
- self.dis_adp_total()
- sortindex = np.argsort(self.dis_adp)[::-1]
- best_adp = self.dis_adp[sortindex[0]]
- best_fruit = self.fruits[sortindex[0]]
- self.fruits = [best_fruit]
- city_list = [i for i in range(self.num_city)]
- cnt = 0
- while cnt < self.num_total-1:
- choice = np.random.choice(city_list, 3)
- choice.sort()
- a, b, c = list(choice)
- part1 = list(best_fruit[:a])
- part2 = list(best_fruit[a:b])
- part3 = list(best_fruit[b:c])
- part4 = list(best_fruit[c:])
- # 1
- res = part1+part2[::-1]+part3+part4
- assert len(res) == 70,print(len)
- self.fruits.append(res)
- # 2
- res = part1 + part2 + part3[::-1] + part4
- assert len(res) == 70
- self.fruits.append(res)
- # 3
- list1, list2 = self.swap_part(part1, part4)
- res = list1 + part2 + part3 + list2
- assert len(res) == 70
- self.fruits.append(res)
- # 4
- res = part1 + part2[::-1] + part3[::-1] + part4
- assert len(res) == 70
- self.fruits.append(res)
- # 5
- res = list1 + part2[::-1] + part3 + list2
- assert len(res) == 70
- self.fruits.append(res)
- # 6
- res = list1 + part2 + part3[::-1] + list2
- assert len(res) == 70
- self.fruits.append(res)
- # # 7
- # res = part1 + part3 + part2 + part4
- # self.fruits.append(res)
- # # 8
- # res = part2 + part1 + part3 + part4
- # self.fruits.append(res)
- cnt += 6
- self.fruits = self.fruits[:self.num_total]
-
- return best_adp,best_fruit
-
- def run(self):
- print('==================Running the code==================')
- BEST_LIST = None
- best_adp = -math.inf
- with open(self.save_path, 'w') as f:
- for i in range(1, self.iteration + 1):
- aaaaa = time.time()
- max_adp, best_list = self.fly()
- if max_adp > best_adp:
- best_adp = max_adp
- BEST_LIST = best_list
- bbbb = time.time()
- print(bbbb - aaaaa)
- bestlen = self.adp_norm/best_adp
- return self.location[BEST_LIST],bestlen
-import pandas as pd
-def read_tsp(path):
- lines = open(path,'r').readlines()
- assert 'NODE_COORD_SECTION\n' in lines
- index = lines.index('NODE_COORD_SECTION\n')
- data = lines[index+1:-1]
- tmp = []
- for line in data:
- line = line.strip().split(' ')
- tmpline = []
- for x in line:
- if x == '':
- continue
- else:
- tmpline.append(int(x))
- tmp.append(tmpline)
- data = tmp
- return data
-data = read_tsp('data/st70.tsp')
-data = np.array(data)
-data = data[:,1:]
-for _ in range(10):
- foa = FOA(num_city=data.shape[0],num_total=50,iteration=1000,adp_norm=1000,data=data.copy().astype(np.int),save_path='sdsdsdssd.txt',save_freq=10)
- res, length = foa.run()
- print(length)
-# import os
-# # print(os.getcwd())
-# import matplotlib.pyplot as plt
-# import numpy as np
-# from mpl_toolkits.mplot3d import Axes3D
-#
-# fig = plt.figure()
-# ax = Axes3D(fig)
-# colors = ('#377eb8', '#ff7f00', '#4daf4a','#aaaaaa')
-# def plot(i, data):
-#
-# x = data[:,0]
-# y = data[:,1]
-# z = data[:,2]
-# ax.scatter(x, y, z,color=colors[i],marker = '+')
-# # ax.set_zlabel('Z', fontdict={'size': 15, 'color': 'red'})
-# # ax.set_ylabel('Y', fontdict={'size': 15, 'color': 'red'})
-# # ax.set_xlabel('X', fontdict={'size': 15, 'color': 'red'})
-# ax.plot3D(data[:,0], data[:,1], data[:,2],color = colors[i])
-# result = []
-# for i in range(4):
-# data = pd.read_csv('path5_{}.csv'.format(i),header=None)
-# data = np.array(data)
-# foa = FOA(num_city=data.shape[0],num_total=20,iteration=100,adp_norm=1000,data=data,save_path='sdsdsdssd.txt',save_freq=10)
-# res,lenth = foa.run()
-#
-# res = np.array(res).astype(np.int)
-# plot(i,res)
-#
-# print(lenth)
-# # result.append(res)
-# # result = np.concatenate(result,axis = 0)
-# # print(result.shape)
-# # plot(result)
-# plt.show()
\ No newline at end of file
diff --git a/foa_greedy_single_GA.py b/foa_greedy_single_GA.py
deleted file mode 100755
index aad7fa8..0000000
--- a/foa_greedy_single_GA.py
+++ /dev/null
@@ -1,297 +0,0 @@
-import random
-import numpy as np
-import math
-import pandas as pd
-import tqdm
-
-
-class FOA(object):
- def __init__(self, num_city, num_total, iteration, data, save_path, save_freq, **kwargs):
- self.num_city = num_city
- self.num_total = num_total
- self.iteration = iteration
- self.save_path = save_path
- self.save_freq = save_freq
- self.location = data
- self.dis_mat = self.compute_dis_mat(num_city, self.location)
- # self.fruits = self.greedy_init(self.dis_mat, num_total, num_city)
- self.fruits = self.random_init(num_total,num_city)
-
- # 贪心初始化种群
- def greedy_init(self, dis_mat, num_total, num_city):
- start_index = 0
- result = []
- for i in range(num_total):
- rest = [x for x in range(0, num_city)]
- # 所有起始点都已经生成了
- if start_index >= num_city:
- start_index = np.random.randint(0, num_city)
- result.append(result[start_index].copy())
- continue
- current = start_index
- rest.remove(current)
- # 找到一条最近邻路径
- result_one = [current]
- while len(rest) != 0:
- tmp_min = math.inf
- tmp_choose = -1
- for x in rest:
- if dis_mat[current][x] < tmp_min:
- tmp_min = dis_mat[current][x]
- tmp_choose = x
-
- current = tmp_choose
- result_one.append(tmp_choose)
- rest.remove(tmp_choose)
- result.append(result_one)
- start_index += 1
- return result
-
- # def greedy_init_2(self,dis_mat,num_total,num_city):
- # start_index = 0
- # result = [[]]*num_total
- # rest = [x for x in range(0, num_city)]
- # # 所有起始点都已经生成了
- # if start_index >= num_city:
- # start_index = np.random.randint(0,num_city)
- # result[i] = result[start_index].copy()
- # continue
- # current = start_index
- # rest.remove(current)
- # # 找到一条最近邻路径
- # result_one = [current]
- # while len(rest) != 0:
- # tmp_min = math.inf
- # tmp_choose = -1
- # for x in rest:
- # if dis_mat[current][x] < tmp_min:
- # tmp_min = dis_mat[current][x]
- # tmp_choose = x
- #
- # current = tmp_choose
- # result_one.append(tmp_choose)
- # rest.remove(tmp_choose)
- # # result[i] = result_one
- # result[0] = result_one
- # start_index += 1
- # return result
- # 随机初始化种群
- def random_init(self, num_total, num_city):
- tmp = [x for x in range(num_city)]
- result = []
- for i in range(num_total):
- random.shuffle(tmp)
- result.append(tmp.copy())
- return result
-
- # 计算不同城市之间的距离
- def compute_dis_mat(self, num_city, location):
- dis_mat = np.zeros((num_city, num_city))
- for i in range(num_city):
- for j in range(num_city):
- if i == j:
- dis_mat[i][j] = np.inf
- continue
- a = location[i]
- b = location[j]
- tmp = np.sqrt(sum([(x[0] - x[1]) ** 2 for x in zip(a, b)]))
- dis_mat[i][j] = tmp
- return dis_mat
-
- # 计算路径长度
- def compute_pathlen(self, path, dis_mat):
- a = path[0]
- b = path[-1]
- assert a != b
- result = dis_mat[a][b]
- for i in range(len(path) - 1):
- a = path[i]
- b = path[i + 1]
- assert a != b
- result += dis_mat[a][b]
- return result
-
- # 计算种群适应度
- def compute_adp(self, fruits):
- adp = []
- for fruit in fruits:
- length = self.compute_pathlen(fruit, self.dis_mat)
- adp.append(1.0 / length)
- return np.array(adp)
-
- # 对序列做2opt操作
- def single_GA(self, best, x):
- # 1.翻转法,根据序列的差异长度选择反转长度
- tmp = np.array(best) - np.array(x)
- l = np.where(tmp != 0)
- l = len(l[0])
- # top = max(self.num_city - l,3)
- top = 5
- print(l)
- a = np.random.randint(top)
- t = x[a:a+l]
- return x[:a] + t[::-1]+x[a+l:]
-
-
- # def _3opt(self, x):
- # city_list = [i for i in range(self.num_city)]
- # choice = np.random.choice(city_list, 2)
- # choice.sort()
- # i, j = choice
- # a = x[:i]
- # b = x[i:j]
- # c = x[j:]
- # tmp_best = []
- # tmp_best_adp = []
- # # param1
- # # tmp = a+b+c
- # # tmp_adp = 1./self.compute_pathlen(tmp, self.dis_mat)
- # # tmp_best = [a + b + c, ]
- # # tmp_best_adp = [tmp_adp]
- # # param2
- # tmp = a + b + c[::-1]
- # tmp_adp = 1. / self.compute_pathlen(tmp, self.dis_mat)
- # tmp_best.append(tmp)
- # tmp_best_adp.append(tmp_adp)
- # # param3
- # tmp = a + c[::-1] + b[::-1]
- # tmp_best.append(tmp)
- # tmp_best_adp.append(1. / self.compute_pathlen(tmp, self.dis_mat))
- # # param4
- # tmp = a + b[::-1] + c
- # tmp_best.append(tmp)
- # tmp_best_adp.append(1. / self.compute_pathlen(tmp, self.dis_mat))
- # # param5
- # tmp = a + c + b[::-1]
- # tmp_best.append(tmp)
- # tmp_best_adp.append(1. / self.compute_pathlen(tmp, self.dis_mat))
- # # param6
- # tmp = a + c[::-1] + b
- # tmp_best.append(tmp)
- # tmp_best_adp.append(1. / self.compute_pathlen(tmp, self.dis_mat))
- # # param7
- # tmp = a + b[::-1] + c[::-1]
- # tmp_best.append(tmp)
- # tmp_best_adp.append(1. / self.compute_pathlen(tmp, self.dis_mat))
- # # param8
- # tmp = a + c + b
- # tmp_best.append(tmp)
- # tmp_best_adp.append(1. / self.compute_pathlen(tmp, self.dis_mat))
- #
- # max_adp = max(tmp_best_adp)
- # max_index = tmp_best_adp.index(max_adp)
- # result = tmp_best[max_index]
- # return result
-
- # 迭代一次,返回适应度最高的个体和他的序列。
- def fly(self, fruits, num_total):
- # 选择适应度最高的个体
- self.dis_adp = self.compute_adp(self.fruits)
- # 从高到底适应度排序
- sortindex = np.argsort(-self.dis_adp)
- best_adp = self.dis_adp[sortindex[0]]
- best_fruit = self.fruits[sortindex[0]]
- # 保留种群中适应度最好的个体
- self.fruits[0] = best_fruit
- for i in range(1, num_total):
- # 2opt生成一个新个体
- x = self.fruits[i]
- opt_2_res = self.single_GA(best_fruit,x)
- self.fruits[i] = opt_2_res
- return best_adp, best_fruit
-
- # 总共的迭代过程,返回最终最好的长度,以及一段路径
- def run(self):
- best_fruit = None
- best_adp = -math.inf
- for i in range(self.iteration):
- tmp_adp, tmp_list = self.fly(self.fruits, self.num_total)
- if tmp_adp > best_adp:
- print('wwww')
- best_adp = tmp_adp
- best_fruit = tmp_list
- bestlen = 1.0 / best_adp
- return self.location[best_fruit], bestlen
-
-
-import pandas as pd
-
-
-def read_tsp(path):
- lines = open(path, 'r').readlines()
- assert 'NODE_COORD_SECTION\n' in lines
- index = lines.index('NODE_COORD_SECTION\n')
- data = lines[index + 1:-1]
- tmp = []
- for line in data:
- line = line.strip().split(' ')
- if line[0] == 'EOF':
- continue
- tmpline = []
- for x in line:
- if x == '':
- continue
- else:
- tmpline.append(float(x))
- if tmpline == []:
- continue
- tmp.append(tmpline)
- data = tmp
- return data
-
-
-data = read_tsp('data/st70.tsp')
-data = np.array(data)
-data = data[:, 1:]
-result_ = []
-runtimes = 1
-import time
-
-start_time = time.time()
-for _ in tqdm.trange(runtimes):
- foa = FOA(num_city=data.shape[0], num_total=50, iteration=1000, data=data.copy(), save_path='sdsdsdssd.txt',
- save_freq=10)
- res, length = foa.run()
- result_.append(length)
-end_time = time.time()
-result_ = np.array(result_)
-
-print('best:{:.2f}\tworst:{:.2f}\tmean:{:.2f}\tstd:{:.2f}\taverage_time:{:.2f}'.format(result_.min(), result_.max(),
- result_.mean(), result_.std(), (
- end_time - start_time) / runtimes))
-
-# import os
-# # print(os.getcwd())
-# import matplotlib.pyplot as plt
-# import numpy as np
-# from mpl_toolkits.mplot3d import Axes3D
-#
-# fig = plt.figure()
-# ax = Axes3D(fig)
-# colors = ('#377eb8', '#ff7f00', '#4daf4a','#aaaaaa')
-# def plot(i, data):
-#
-# x = data[:,0]
-# y = data[:,1]
-# z = data[:,2]
-# ax.scatter(x, y, z,color=colors[i],marker = '+')
-# # ax.set_zlabel('Z', fontdict={'size': 15, 'color': 'red'})
-# # ax.set_ylabel('Y', fontdict={'size': 15, 'color': 'red'})
-# # ax.set_xlabel('X', fontdict={'size': 15, 'color': 'red'})
-# ax.plot3D(data[:,0], data[:,1], data[:,2],color = colors[i])
-# result = []
-# for i in range(4):
-# data = pd.read_csv('path5_{}.csv'.format(i),header=None)
-# data = np.array(data)
-# foa = FOA(num_city=data.shape[0],num_total=20,iteration=100,adp_norm=1000,data=data,save_path='sdsdsdssd.txt',save_freq=10)
-# res,lenth = foa.run()
-#
-# res = np.array(res).astype(np.int)
-# plot(i,res)
-#
-# print(lenth)
-# # result.append(res)
-# # result = np.concatenate(result,axis = 0)
-# # print(result.shape)
-# # plot(result)
-# plt.show()
diff --git a/foa_shuffle_part.py b/foa_shuffle_part.py
deleted file mode 100755
index 8a397ab..0000000
--- a/foa_shuffle_part.py
+++ /dev/null
@@ -1,235 +0,0 @@
-import random
-import numpy as np
-import math
-import pandas as pd
-
-
-class FOA(object):
- def __init__(self, num_city, num_total, iteration, adp_norm, data, save_path, save_freq, **kwargs):
- self.num_city = num_city
- self.num_total = num_total
- self.dis_adp = [0 for _ in range(self.num_total)]
- self.iteration = iteration
- self.adp_norm = adp_norm
- self.save_path = save_path
- self.save_freq = save_freq
- self.location = data
- self.dis_mat = self.distance_p2p_mat()
- self.generate_best()
- self.generate_fruits()
- print('get data,she shape is {}'.format(self.location.shape))
-
- def get_data(self, data):
- return np.loadtxt(data)[:, 1:]
-
- # 贪心初始化一条最优路径
-
- def generate_best(self, flag=True):
- if flag:
- initial = [0]
- rest = [x for x in range(1, self.num_city)]
- initial_path = 0
- while len(rest) != 0:
- start = initial[-1]
- tmp_min = math.inf
- tmp_choose = -1
- for x in rest:
- if self.dis_mat[start][x] < tmp_min:
- tmp_min = self.dis_mat[start][x]
- tmp_choose = x
- initial_path += tmp_min
- initial.append(tmp_choose)
- rest.remove(tmp_choose)
- initial_path += self.dis_mat[tmp_choose][0]
- return initial, initial_path
- else:
- initial = [x for x in range(self.num_city)]
- initial_path = 0
- for index in range(self.num_city - 1):
- initial_path += self.dis_mat[index][index + 1]
- initial_path += self.dis_mat[index][0]
- return initial, initial_path
-
- def generate_fruits(self):
- best, initial_path = self.generate_best(True)
- self.fruits = [best]
- for _ in range(self.num_total - 1):
- a = np.random.randint(0, self.num_city)
- b = np.random.randint(0, self.num_city)
- a = min(a, b)
- b = max(a, b)
- part1 = list(best[:a])
- part2 = list(best[a:b])
- part3 = list(best[b:])
- if len(part2)>=1:
- try:
- np.random.shuffle(part2)
- part2 = list(part2)
- except:
- import pdb
- pdb.set_trace()
- res = part1 + part2 + part3
- self.fruits.append(res)
-
- # 对称矩阵,两个城市之间的距离 支持2d和3d
- def distance_p2p_mat(self):
- dis_mat = []
- for i in range(self.num_city):
- dis_mat_each = []
- for j in range(self.num_city):
- tmp = 0
- for k in range(len(self.location[i])):
- tmp += pow(self.location[i][k] - self.location[j][k], 2)
- tmp = math.sqrt(tmp)
- dis_mat_each.append(tmp)
- dis_mat.append(dis_mat_each)
- return dis_mat
-
- # 目标函数计算,适应度计算,中间计算。适应度为1/总距离*10000
- def dis_adp_total(self, ):
- self.dis_adp = []
- for i in range(self.num_total):
- try:
- dis = self.dis_mat[self.fruits[i][self.num_city - 1]][self.fruits[i][0]] # 回家
- except:
- import pdb
- pdb.set_trace()
- for j in range(self.num_city - 1):
- dis = self.dis_mat[self.fruits[i][j]][self.fruits[i][j + 1]] + dis
- dis_adp_each = self.adp_norm / dis
- self.dis_adp.append(dis_adp_each)
-
- def swap_part(self,list1,list2):
- index = len(list1)
- list = list1 + list2
- list = list[::-1]
- return list[:index], list[index:]
-
- def opt_2(self, x):
- city_list = [i for i in range(self.num_city)]
- choice = np.random.choice(city_list, 2)
- choice.sort()
- res_list = []
- a, b = list(choice)
- part1 = list(x[:a])
- part2 = list(x[a:b])
- part3 = list(x[b:])
-
- # 1
- res = part1 + part2[::-1] + part3
- res_list.append(res)
- # 2
- list1, list2 = self.swap_part(part1, part3)
- res = list1 + part2 + list2
- res_list.append(res)
- # 3
- res = list1 + part2[::-1] + list2
- res_list.append(res)
- return res_list
-
- def shuffle_part(self,data):
- x = np.random.randint(0,len(data))
- y = np.random.randint(0,len(data))
- start = min(x,y)
- end = max(y,x)
- # x = np.random.randint(0,len(data)-10)
- # y = x+10
- part1 = data[:start]
- part2 = data[start:end]
- part3 = data[end:]
- # np.random.shuffle(part2)
- part2 = part2[::-1]
- res_list = [part1+part2+part3]
- return res_list
- def fly(self):
- self.dis_adp_total()
- sortindex = np.argsort(self.dis_adp)[::-1]
- best_adp = self.dis_adp[sortindex[0]]
- best_fruit = self.fruits[sortindex[0]]
- self.fruits = [best_fruit]
- tmp = 1
- while tmp < self.num_total:
- opt_2_res = self.shuffle_part(best_fruit.copy())
- self.fruits += opt_2_res
- tmp += len(opt_2_res)
- self.fruits = self.fruits[:self.num_total]
-
- return best_adp,best_fruit
-
- def run(self):
- print('==================Running the code==================')
- BEST_LIST = None
- best_adp = -math.inf
- with open(self.save_path, 'w') as f:
- for i in range(1, self.iteration + 1):
- max_adp, best_list = self.fly()
- if max_adp > best_adp:
- best_adp = max_adp
- BEST_LIST = best_list
- bestlen = self.adp_norm/best_adp
- return self.location[BEST_LIST],bestlen
-import pandas as pd
-def read_tsp(path):
- lines = open(path, 'r').readlines()
- assert 'NODE_COORD_SECTION\n' in lines
- index = lines.index('NODE_COORD_SECTION\n')
- data = lines[index + 1:-1]
- tmp = []
- for line in data:
- line = line.strip().split(' ')
- if line[0] == 'EOF':
- continue
- tmpline = []
- for x in line:
- if x == '':
- continue
- else:
- tmpline.append(float(x))
- if tmpline == []:
- continue
- tmp.append(tmpline)
- data = tmp
- return data
-data = read_tsp('data/st70.tsp')
-# data = read_tsp('data/burma14.tsp')
-data = np.array(data)
-data = data[:,1:]
-for _ in range(10):
- foa = FOA(num_city=data.shape[0],num_total=50,iteration=1000,adp_norm=1000,data=data.copy(),save_path='sdsdsdssd.txt',save_freq=10)
- res, length = foa.run()
- print(length)
-# import os
-# # print(os.getcwd())
-# import matplotlib.pyplot as plt
-# import numpy as np
-# from mpl_toolkits.mplot3d import Axes3D
-#
-# fig = plt.figure()
-# ax = Axes3D(fig)
-# colors = ('#377eb8', '#ff7f00', '#4daf4a','#aaaaaa')
-# def plot(i, data):
-#
-# x = data[:,0]
-# y = data[:,1]
-# z = data[:,2]
-# ax.scatter(x, y, z,color=colors[i],marker = '+')
-# # ax.set_zlabel('Z', fontdict={'size': 15, 'color': 'red'})
-# # ax.set_ylabel('Y', fontdict={'size': 15, 'color': 'red'})
-# # ax.set_xlabel('X', fontdict={'size': 15, 'color': 'red'})
-# ax.plot3D(data[:,0], data[:,1], data[:,2],color = colors[i])
-# result = []
-# for i in range(4):
-# data = pd.read_csv('path5_{}.csv'.format(i),header=None)
-# data = np.array(data)
-# foa = FOA(num_city=data.shape[0],num_total=20,iteration=100,adp_norm=1000,data=data,save_path='sdsdsdssd.txt',save_freq=10)
-# res,lenth = foa.run()
-#
-# res = np.array(res).astype(np.int)
-# plot(i,res)
-#
-# print(lenth)
-# # result.append(res)
-# # result = np.concatenate(result,axis = 0)
-# # print(result.shape)
-# # plot(result)
-# plt.show()
\ No newline at end of file
diff --git a/foa_shufllepart_greedy.py b/foa_shufllepart_greedy.py
deleted file mode 100755
index c97def1..0000000
--- a/foa_shufllepart_greedy.py
+++ /dev/null
@@ -1,187 +0,0 @@
-import random
-import numpy as np
-import math
-import pandas as pd
-
-
-class FOA(object):
- def __init__(self, num_city, num_total, iteration, adp_norm, data, save_path, save_freq, **kwargs):
- self.num_city = num_city
- self.num_total = num_total
- self.dis_adp = [0 for _ in range(self.num_total)]
- self.iteration = iteration
- self.adp_norm = adp_norm
- self.save_path = save_path
- self.save_freq = save_freq
- self.location = data
- self.dis_mat = self.distance_p2p_mat()
- self.generate_best()
- self.generate_fruits()
- print('get data,she shape is {}'.format(self.location.shape))
-
- def get_data(self, data):
- return np.loadtxt(data)[:, 1:]
-
- # 贪心初始化一条最优路径
- def generate_best(self):
- initial = [0]
- rest = [x for x in range(1, self.num_city)]
- initial_path = 0
- while len(rest) != 0:
- start = initial[-1]
- tmp_min = math.inf
- tmp_choose = -1
- for x in rest:
- if self.dis_mat[start][x] < tmp_min:
- tmp_min = self.dis_mat[start][x]
- tmp_choose = x
- initial_path += tmp_min
- initial.append(tmp_choose)
- rest.remove(tmp_choose)
- initial_path += self.dis_mat[tmp_choose][0]
- return initial, initial_path
-
- def generate_fruits(self):
- best, initial_path = self.generate_best()
- self.fruits = [best]
- for _ in range(self.num_total - 1):
- a = np.random.randint(0, self.num_city)
- b = np.random.randint(0, self.num_city)
- a = min(a, b)
- b = max(a, b)
- part1 = list(best[:a])
- part2 = list(best[a:b])
- part3 = list(best[b:])
- if len(part2) >= 1:
- try:
- np.random.shuffle(part2)
- part2 = list(part2)
- except:
- import pdb
- pdb.set_trace()
- res = part1 + part2 + part3
- self.fruits.append(res)
-
- # 对称矩阵,两个城市之间的距离 支持2d和3d
- def distance_p2p_mat(self):
- dis_mat = []
- for i in range(self.num_city):
- dis_mat_each = []
- for j in range(self.num_city):
- tmp = 0
- for k in range(len(self.location[i])):
- tmp += pow(self.location[i][k] - self.location[j][k], 2)
- tmp = math.sqrt(tmp)
- dis_mat_each.append(tmp)
- dis_mat.append(dis_mat_each)
- return dis_mat
-
- # 目标函数计算,适应度计算,中间计算。适应度为1/总距离*10000
- def dis_adp_total(self, ):
- self.dis_adp = []
- for i in range(self.num_total):
- dis = self.dis_mat[self.fruits[i][self.num_city - 1]][self.fruits[i][0]] # 回家
- for j in range(self.num_city - 1):
- dis = self.dis_mat[self.fruits[i][j]][self.fruits[i][j + 1]] + dis
- dis_adp_each = self.adp_norm / dis
- self.dis_adp.append(dis_adp_each)
-
- def fly(self):
- self.dis_adp_total()
- sortindex = np.argsort(self.dis_adp)[::-1]
- best_adp = self.dis_adp[sortindex[0]]
- best_fruit = self.fruits[sortindex[0]]
- self.fruits = [best_fruit]
- for _ in range(self.num_total - 1):
- a = np.random.randint(0, self.num_city)
- b = np.random.randint(0, self.num_city)
- a = min(a, b)
- b = max(a, b)
- part1 = list(best_fruit[:a])
- part2 = list(best_fruit[a:b])
- part3 = list(best_fruit[b:])
- if len(part2) >= 1:
- np.random.shuffle(part2)
- part2 = list(part2)
- res = part1 + part2 + part3
- self.fruits.append(res)
- return best_adp, best_fruit
-
- def run(self):
- print('==================Running the code==================')
- BEST_LIST = None
- best_adp = -math.inf
- with open(self.save_path, 'w') as f:
- for i in range(1, self.iteration + 1):
- max_adp, best_list = self.fly()
- if max_adp > best_adp:
- best_adp = max_adp
- BEST_LIST = best_list
- bestlen = self.adp_norm / best_adp
- return self.location[BEST_LIST], bestlen
-
-
-import pandas as pd
-
-
-def read_tsp(path):
- lines = open(path, 'r').readlines()
- assert 'NODE_COORD_SECTION\n' in lines
- index = lines.index('NODE_COORD_SECTION\n')
- data = lines[index + 1:-1]
- tmp = []
- for line in data:
- line = line.strip().split(' ')
- tmpline = []
- for x in line:
- if x == '':
- continue
- else:
- tmpline.append(int(x))
- tmp.append(tmpline)
- data = tmp
- return data
-
-
-data = read_tsp('data/st70.tsp')
-data = np.array(data)
-data = data[:, 1:]
-foa = FOA(num_city=data.shape[0], num_total=50, iteration=1000, adp_norm=1000, data=data, save_path='sdsdsdssd.txt',
- save_freq=10)
-res, len = foa.run()
-print(len)
-# import os
-# # print(os.getcwd())
-# import matplotlib.pyplot as plt
-# import numpy as np
-# from mpl_toolkits.mplot3d import Axes3D
-#
-# fig = plt.figure()
-# ax = Axes3D(fig)
-# colors = ('#377eb8', '#ff7f00', '#4daf4a','#aaaaaa')
-# def plot(i, data):
-#
-# x = data[:,0]
-# y = data[:,1]
-# z = data[:,2]
-# ax.scatter(x, y, z,color=colors[i],marker = '+')
-# # ax.set_zlabel('Z', fontdict={'size': 15, 'color': 'red'})
-# # ax.set_ylabel('Y', fontdict={'size': 15, 'color': 'red'})
-# # ax.set_xlabel('X', fontdict={'size': 15, 'color': 'red'})
-# ax.plot3D(data[:,0], data[:,1], data[:,2],color = colors[i])
-# result = []
-# for i in range(4):
-# data = pd.read_csv('path5_{}.csv'.format(i),header=None)
-# data = np.array(data)
-# foa = FOA(num_city=data.shape[0],num_total=20,iteration=100,adp_norm=1000,data=data,save_path='sdsdsdssd.txt',save_freq=10)
-# res,lenth = foa.run()
-#
-# res = np.array(res).astype(np.int)
-# plot(i,res)
-#
-# print(lenth)
-# # result.append(res)
-# # result = np.concatenate(result,axis = 0)
-# # print(result.shape)
-# # plot(result)
-# plt.show()
diff --git a/img/ACO.png b/img/ACO.png
new file mode 100644
index 0000000..c1b3c44
Binary files /dev/null and b/img/ACO.png differ
diff --git a/img/PSO.png b/img/PSO.png
new file mode 100644
index 0000000..3bd4c2b
Binary files /dev/null and b/img/PSO.png differ
diff --git a/img/SI.png b/img/SI.png
new file mode 100644
index 0000000..f965791
Binary files /dev/null and b/img/SI.png differ
diff --git a/img/SOM.png b/img/SOM.png
new file mode 100644
index 0000000..6fbbc33
Binary files /dev/null and b/img/SOM.png differ
diff --git a/img/TS.png b/img/TS.png
new file mode 100644
index 0000000..32e6ca4
Binary files /dev/null and b/img/TS.png differ