Initial Commit

This commit is contained in:
Wu Han 2020-12-19 18:20:11 +00:00
commit e120708d8d
28 changed files with 2230 additions and 0 deletions

3
.dockerignore.txt Normal file
View File

@ -0,0 +1,3 @@
.vscode/
*.json
*.txt

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.vscode/
__pycache__/

8
README.md Normal file
View File

@ -0,0 +1,8 @@
## Windows
docker container run --rm -v /f/COM2014/template:/tsp python:3.8 /bin/bash -c "cd /tsp; ./run_all.sh"
## Linux
docker container run --rm -v $pwd:/tsp python:3.8 /bin/bash -c "cd /tsp; ./run_all.sh"

1007
data/hard/dsj1000.tsp Normal file

File diff suppressed because it is too large Load Diff

287
data/medium/a280.tsp Normal file
View File

@ -0,0 +1,287 @@
NAME : a280
COMMENT : drilling problem (Ludwig)
TYPE : TSP
DIMENSION: 280
EDGE_WEIGHT_TYPE : EUC_2D
NODE_COORD_SECTION
1 288 149
2 288 129
3 270 133
4 256 141
5 256 157
6 246 157
7 236 169
8 228 169
9 228 161
10 220 169
11 212 169
12 204 169
13 196 169
14 188 169
15 196 161
16 188 145
17 172 145
18 164 145
19 156 145
20 148 145
21 140 145
22 148 169
23 164 169
24 172 169
25 156 169
26 140 169
27 132 169
28 124 169
29 116 161
30 104 153
31 104 161
32 104 169
33 90 165
34 80 157
35 64 157
36 64 165
37 56 169
38 56 161
39 56 153
40 56 145
41 56 137
42 56 129
43 56 121
44 40 121
45 40 129
46 40 137
47 40 145
48 40 153
49 40 161
50 40 169
51 32 169
52 32 161
53 32 153
54 32 145
55 32 137
56 32 129
57 32 121
58 32 113
59 40 113
60 56 113
61 56 105
62 48 99
63 40 99
64 32 97
65 32 89
66 24 89
67 16 97
68 16 109
69 8 109
70 8 97
71 8 89
72 8 81
73 8 73
74 8 65
75 8 57
76 16 57
77 8 49
78 8 41
79 24 45
80 32 41
81 32 49
82 32 57
83 32 65
84 32 73
85 32 81
86 40 83
87 40 73
88 40 63
89 40 51
90 44 43
91 44 35
92 44 27
93 32 25
94 24 25
95 16 25
96 16 17
97 24 17
98 32 17
99 44 11
100 56 9
101 56 17
102 56 25
103 56 33
104 56 41
105 64 41
106 72 41
107 72 49
108 56 49
109 48 51
110 56 57
111 56 65
112 48 63
113 48 73
114 56 73
115 56 81
116 48 83
117 56 89
118 56 97
119 104 97
120 104 105
121 104 113
122 104 121
123 104 129
124 104 137
125 104 145
126 116 145
127 124 145
128 132 145
129 132 137
130 140 137
131 148 137
132 156 137
133 164 137
134 172 125
135 172 117
136 172 109
137 172 101
138 172 93
139 172 85
140 180 85
141 180 77
142 180 69
143 180 61
144 180 53
145 172 53
146 172 61
147 172 69
148 172 77
149 164 81
150 148 85
151 124 85
152 124 93
153 124 109
154 124 125
155 124 117
156 124 101
157 104 89
158 104 81
159 104 73
160 104 65
161 104 49
162 104 41
163 104 33
164 104 25
165 104 17
166 92 9
167 80 9
168 72 9
169 64 21
170 72 25
171 80 25
172 80 25
173 80 41
174 88 49
175 104 57
176 124 69
177 124 77
178 132 81
179 140 65
180 132 61
181 124 61
182 124 53
183 124 45
184 124 37
185 124 29
186 132 21
187 124 21
188 120 9
189 128 9
190 136 9
191 148 9
192 162 9
193 156 25
194 172 21
195 180 21
196 180 29
197 172 29
198 172 37
199 172 45
200 180 45
201 180 37
202 188 41
203 196 49
204 204 57
205 212 65
206 220 73
207 228 69
208 228 77
209 236 77
210 236 69
211 236 61
212 228 61
213 228 53
214 236 53
215 236 45
216 228 45
217 228 37
218 236 37
219 236 29
220 228 29
221 228 21
222 236 21
223 252 21
224 260 29
225 260 37
226 260 45
227 260 53
228 260 61
229 260 69
230 260 77
231 276 77
232 276 69
233 276 61
234 276 53
235 284 53
236 284 61
237 284 69
238 284 77
239 284 85
240 284 93
241 284 101
242 288 109
243 280 109
244 276 101
245 276 93
246 276 85
247 268 97
248 260 109
249 252 101
250 260 93
251 260 85
252 236 85
253 228 85
254 228 93
255 236 93
256 236 101
257 228 101
258 228 109
259 228 117
260 228 125
261 220 125
262 212 117
263 204 109
264 196 101
265 188 93
266 180 93
267 180 101
268 180 109
269 180 117
270 180 125
271 196 145
272 204 145
273 212 145
274 220 145
275 228 145
276 236 145
277 246 141
278 252 125
279 260 129
280 280 133
EOF

449
data/medium/pcb442.tsp Normal file
View File

@ -0,0 +1,449 @@
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

55
data/simple/att48.tsp Normal file
View File

@ -0,0 +1,55 @@
NAME : att48
COMMENT : 48 capitals of the US (Padberg/Rinaldi)
TYPE : TSP
DIMENSION : 48
EDGE_WEIGHT_TYPE : ATT
NODE_COORD_SECTION
1 6734 1453
2 2233 10
3 5530 1424
4 401 841
5 3082 1644
6 7608 4458
7 7573 3716
8 7265 1268
9 6898 1885
10 1112 2049
11 5468 2606
12 5989 2873
13 4706 2674
14 4612 2035
15 6347 2683
16 6107 669
17 7611 5184
18 7462 3590
19 7732 4723
20 5900 3561
21 4483 3369
22 6101 1110
23 5199 2182
24 1633 2809
25 4307 2322
26 675 1006
27 7555 4819
28 7541 3981
29 3177 756
30 7352 4506
31 7545 2801
32 3245 3305
33 6426 3173
34 4608 1198
35 23 2216
36 7248 3779
37 7762 4595
38 7392 2244
39 3484 2829
40 6271 2135
41 4985 140
42 1916 1569
43 7280 4899
44 7509 3239
45 10 2676
46 6807 2993
47 5185 3258
48 3023 1942
EOF

77
data/simple/st70.tsp Normal file
View File

@ -0,0 +1,77 @@
NAME: st70
TYPE: TSP
COMMENT: 70-city problem (Smith/Thompson)
DIMENSION: 70
EDGE_WEIGHT_TYPE : EUC_2D
NODE_COORD_SECTION
1 64 96
2 80 39
3 69 23
4 72 42
5 48 67
6 58 43
7 81 34
8 79 17
9 30 23
10 42 67
11 7 76
12 29 51
13 78 92
14 64 8
15 95 57
16 57 91
17 40 35
18 68 40
19 92 34
20 62 1
21 28 43
22 76 73
23 67 88
24 93 54
25 6 8
26 87 18
27 30 9
28 77 13
29 78 94
30 55 3
31 82 88
32 73 28
33 20 55
34 27 43
35 95 86
36 67 99
37 48 83
38 75 81
39 8 19
40 20 18
41 54 38
42 63 36
43 44 33
44 52 18
45 12 13
46 25 5
47 58 85
48 5 67
49 90 9
50 41 76
51 25 76
52 37 64
53 56 63
54 10 55
55 98 7
56 16 74
57 89 60
58 48 82
59 81 76
60 29 60
61 17 22
62 5 45
63 79 70
64 9 100
65 17 82
66 74 67
67 10 68
68 48 19
69 83 86
70 84 94
EOF

25
data/simple/ulysses16.tsp Normal file
View File

@ -0,0 +1,25 @@
NAME: ulysses16.tsp
TYPE: TSP
COMMENT: Odyssey of Ulysses (Groetschel/Padberg)
DIMENSION: 16
EDGE_WEIGHT_TYPE: GEO
DISPLAY_DATA_TYPE: COORD_DISPLAY
NODE_COORD_SECTION
1 38.24 20.42
2 39.57 26.15
3 40.56 25.32
4 36.26 23.12
5 33.48 10.54
6 37.56 12.19
7 38.42 13.11
8 37.52 20.44
9 41.23 9.10
10 41.17 13.05
11 36.08 -5.21
12 38.47 15.13
13 38.15 15.35
14 37.51 15.17
15 35.49 14.32
16 39.36 19.56
EOF

98
main.py Normal file
View File

@ -0,0 +1,98 @@
import os
import argparse
import json
import matplotlib
# matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
from utils import visualize_tsp
from model.anneal_model import SimAnneal
from model.my_model import MyModel
def write_to_file(solution, fitness):
with open('output/' + os.path.splitext(os.path.basename(args.tsp_file))[0] + '.txt', "w") as outfile:
outfile.write(", ".join(str(item) for item in solution))
outfile.write("\n")
outfile.write(str(fitness))
def plot_learning(fitness_list):
"""
Plot the fitness through iterations.
"""
plt.plot([i for i in range(len(fitness_list))], fitness_list)
plt.ylabel("Fitness")
plt.xlabel("Iteration")
plt.show()
def load_data(file):
coords = []
with open(file, "r") as infile:
line = infile.readline()
# Skip instance header
while "NODE_COORD_SECTION" not in line:
line = infile.readline()
for line in infile.readlines():
line = line.replace("\n", "")
if line and 'EOF' not in line:
line = [float(x) for x in line.lstrip().split(" ", 1)[1].split(" ") if x]
coords.append(line)
return coords
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='TSP Solver')
parser.add_argument(
'tsp_file',
type=str,
help='Path to tsp file.'
)
parser.add_argument(
'--plot',
action="store_true",
help='Plot results'
)
args = parser.parse_args()
coords = load_data(args.tsp_file)
# model = MyModel(coords)
# best_solution, fitness_list = model.fit(max_it=100000)
sa = SimAnneal(coords)
best_solution, fitness_list = sa.fit(max_it=100000)
if best_solution:
if args.plot:
visualize_tsp.plotTSP([best_solution], coords)
if fitness_list:
plot_learning(fitness_list)
print("Writing the best solution to file" )
write_to_file(best_solution, sa.fitness(best_solution))
data = {}
data['nodes'] = []
for i in range(len(coords)):
data['nodes'].append({
'title': str(i),
'id': i,
'x': int(coords[i][0]),
'y': int(coords[i][1])
})
data['edges'] = []
for i in range(len(best_solution)):
if i == len(best_solution)-1:
data['edges'].append({
'source': best_solution[i],
'target': best_solution[0]
})
else:
data['edges'].append({
'source': best_solution[i],
'target': best_solution[i+1]
})
with open('output/' + os.path.splitext(os.path.basename(args.tsp_file))[0] + '.json', 'w') as outfile:
json.dump(data, outfile)

83
model/anneal_model.py Normal file
View File

@ -0,0 +1,83 @@
import math
import random
import matplotlib.pyplot as plt
from model.base_model import Model
class SimAnneal(Model):
def __init__(self, coords, T=-1, alpha=-1, stopping_T=-1):
super().__init__(coords)
self.iteration = 0
self.T = math.sqrt(self.N) if T == -1 else T
self.T_save = self.T # save inital T to reset if batch annealing is used
self.alpha = 0.995 if alpha == -1 else alpha
self.stopping_temperature = 1e-8 if stopping_T == -1 else stopping_T
def initial_solution(self):
"""
Greedy algorithm to get an initial solution (closest-neighbour).
"""
cur_node = random.choice(self.nodes) # start from a random node
solution = [cur_node]
free_nodes = set(self.nodes)
free_nodes.remove(cur_node)
while free_nodes:
next_node = min(free_nodes, key=lambda x: self.dist(cur_node, x)) # nearest neighbour
free_nodes.remove(next_node)
solution.append(next_node)
cur_node = next_node
cur_fit = self.fitness(solution)
if cur_fit < self.best_fitness: # If best found so far, update best fitness
self.best_fitness = cur_fit
self.best_solution = solution
self.fitness_list.append(cur_fit)
return solution, cur_fit
def p_accept(self, candidate_fitness):
"""
Probability of accepting if the candidate is worse than current.
Depends on the current temperature and difference between candidate and current.
"""
return math.exp(-abs(candidate_fitness - self.cur_fitness) / self.T)
def accept(self, candidate):
"""
Accept with probability 1 if candidate is better than current.
Accept with probabilty p_accept(..) if candidate is worse.
"""
candidate_fitness = self.fitness(candidate)
if candidate_fitness < self.cur_fitness:
self.cur_fitness, self.cur_solution = candidate_fitness, candidate
if candidate_fitness < self.best_fitness:
self.best_fitness, self.best_solution = candidate_fitness, candidate
else:
if random.random() < self.p_accept(candidate_fitness):
self.cur_fitness, self.cur_solution = candidate_fitness, candidate
def fit(self, max_it=1000):
"""
Execute simulated annealing algorithm.
"""
# Initialize with the greedy solution.
self.cur_solution, self.cur_fitness = self.initial_solution()
self.log("Starting annealing.")
while self.T >= self.stopping_temperature and self.iteration < max_it:
candidate = list(self.cur_solution)
l = random.randint(2, self.N - 1)
i = random.randint(0, self.N - l)
candidate[i : (i + l)] = reversed(candidate[i : (i + l)])
self.accept(candidate)
self.T *= self.alpha
self.iteration += 1
self.fitness_list.append(self.cur_fitness)
self.log(f"Best fitness obtained: {self.best_fitness}")
improvement = 100 * (self.fitness_list[0] - self.best_fitness) / (self.fitness_list[0])
self.log(f"Improvement over greedy heuristic: {improvement : .2f}%")
return self.best_solution, self.fitness_list

34
model/base_model.py Normal file
View File

@ -0,0 +1,34 @@
import math
class Model:
def __init__(self, coords):
self.coords = coords
self.N = len(coords)
self.nodes = [i for i in range(self.N)]
self.best_solution = None
self.best_fitness = float("Inf")
self.fitness_list = []
def dist(self, node_0, node_1):
"""
Euclidean distance between two nodes.
"""
coord_0, coord_1 = self.coords[node_0], self.coords[node_1]
return math.sqrt((coord_0[0] - coord_1[0]) ** 2 + (coord_0[1] - coord_1[1]) ** 2)
def fitness(self, solution):
"""
Total distance of the current solution path.
"""
cur_fit = 0
for i in range(self.N):
cur_fit += self.dist(solution[i % self.N], solution[(i + 1) % self.N])
return cur_fit
def fit(self):
raise NotImplementedError("Your fitting method not implemented yet")
def log(self, message):
print('[{name}] {msg}'.format(name=self.__class__.__name__, msg=message))

19
model/my_model.py Normal file
View File

@ -0,0 +1,19 @@
import math
import random
from model.base_model import Model
class MyModel(Model):
def __init__(self, coords):
super().__init__(coords)
"""
Put your initialization here.
"""
self.log("Nothing to initialize in your model now")
def fit(self, max_it=1000, visualize=False):
"""
Put your iteration process here.
"""
self.log("Nothing happens in your model now")
return self.best_solution, self.fitness_list

1
output/a280.json Normal file

File diff suppressed because one or more lines are too long

1
output/a280.txt Normal file
View File

@ -0,0 +1 @@
198, 199, 201, 202, 142, 143, 144, 145, 146, 148, 149, 177, 150, 151, 155, 152, 154, 153, 128, 129, 130, 131, 132, 14, 269, 133, 134, 135, 136, 137, 265, 264, 263, 262, 261, 260, 259, 258, 257, 256, 253, 252, 251, 254, 255, 248, 247, 0, 4, 5, 8, 6, 7, 9, 10, 11, 12, 13, 23, 22, 24, 21, 25, 26, 27, 28, 31, 30, 29, 124, 125, 126, 127, 20, 19, 18, 17, 16, 15, 270, 271, 272, 273, 274, 275, 276, 3, 277, 278, 2, 279, 1, 241, 242, 244, 245, 236, 235, 234, 233, 232, 231, 230, 237, 238, 239, 240, 243, 246, 249, 250, 229, 228, 227, 226, 225, 224, 223, 222, 221, 220, 219, 218, 217, 216, 215, 214, 213, 212, 211, 206, 210, 209, 208, 207, 203, 204, 205, 268, 267, 266, 139, 138, 147, 140, 141, 119, 120, 121, 122, 123, 33, 32, 35, 34, 37, 36, 38, 39, 40, 41, 42, 59, 60, 117, 116, 114, 113, 110, 109, 107, 103, 82, 87, 111, 108, 88, 89, 90, 91, 96, 95, 94, 93, 92, 97, 98, 99, 100, 101, 102, 81, 80, 79, 78, 75, 74, 73, 72, 71, 70, 69, 66, 65, 64, 63, 62, 61, 115, 85, 84, 83, 86, 112, 106, 172, 104, 105, 77, 76, 68, 67, 57, 56, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 58, 118, 156, 157, 158, 159, 173, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 174, 184, 183, 182, 181, 180, 175, 176, 179, 178, 185, 186, 187, 188, 189, 190, 191, 192, 200, 195, 194, 193, 196, 197

1
output/att48.json Normal file
View File

@ -0,0 +1 @@
{"nodes": [{"title": "0", "id": 0, "x": 6734, "y": 1453}, {"title": "1", "id": 1, "x": 2233, "y": 10}, {"title": "2", "id": 2, "x": 5530, "y": 1424}, {"title": "3", "id": 3, "x": 401, "y": 841}, {"title": "4", "id": 4, "x": 3082, "y": 1644}, {"title": "5", "id": 5, "x": 7608, "y": 4458}, {"title": "6", "id": 6, "x": 7573, "y": 3716}, {"title": "7", "id": 7, "x": 7265, "y": 1268}, {"title": "8", "id": 8, "x": 6898, "y": 1885}, {"title": "9", "id": 9, "x": 1112, "y": 2049}, {"title": "10", "id": 10, "x": 5468, "y": 2606}, {"title": "11", "id": 11, "x": 5989, "y": 2873}, {"title": "12", "id": 12, "x": 4706, "y": 2674}, {"title": "13", "id": 13, "x": 4612, "y": 2035}, {"title": "14", "id": 14, "x": 6347, "y": 2683}, {"title": "15", "id": 15, "x": 6107, "y": 669}, {"title": "16", "id": 16, "x": 7611, "y": 5184}, {"title": "17", "id": 17, "x": 7462, "y": 3590}, {"title": "18", "id": 18, "x": 7732, "y": 4723}, {"title": "19", "id": 19, "x": 5900, "y": 3561}, {"title": "20", "id": 20, "x": 4483, "y": 3369}, {"title": "21", "id": 21, "x": 6101, "y": 1110}, {"title": "22", "id": 22, "x": 5199, "y": 2182}, {"title": "23", "id": 23, "x": 1633, "y": 2809}, {"title": "24", "id": 24, "x": 4307, "y": 2322}, {"title": "25", "id": 25, "x": 675, "y": 1006}, {"title": "26", "id": 26, "x": 7555, "y": 4819}, {"title": "27", "id": 27, "x": 7541, "y": 3981}, {"title": "28", "id": 28, "x": 3177, "y": 756}, {"title": "29", "id": 29, "x": 7352, "y": 4506}, {"title": "30", "id": 30, "x": 7545, "y": 2801}, {"title": "31", "id": 31, "x": 3245, "y": 3305}, {"title": "32", "id": 32, "x": 6426, "y": 3173}, {"title": "33", "id": 33, "x": 4608, "y": 1198}, {"title": "34", "id": 34, "x": 23, "y": 2216}, {"title": "35", "id": 35, "x": 7248, "y": 3779}, {"title": "36", "id": 36, "x": 7762, "y": 4595}, {"title": "37", "id": 37, "x": 7392, "y": 2244}, {"title": "38", "id": 38, "x": 3484, "y": 2829}, {"title": "39", "id": 39, "x": 6271, "y": 2135}, {"title": "40", "id": 40, "x": 4985, "y": 140}, {"title": "41", "id": 41, "x": 1916, "y": 1569}, {"title": "42", "id": 42, "x": 7280, "y": 4899}, {"title": "43", "id": 43, "x": 7509, "y": 3239}, {"title": "44", "id": 44, "x": 10, "y": 2676}, {"title": "45", "id": 45, "x": 6807, "y": 2993}, {"title": "46", "id": 46, "x": 5185, "y": 3258}, {"title": "47", "id": 47, "x": 3023, "y": 1942}], "edges": [{"source": 36, "target": 5}, {"source": 5, "target": 27}, {"source": 27, "target": 6}, {"source": 6, "target": 17}, {"source": 17, "target": 43}, {"source": 43, "target": 30}, {"source": 30, "target": 37}, {"source": 37, "target": 8}, {"source": 8, "target": 7}, {"source": 7, "target": 0}, {"source": 0, "target": 15}, {"source": 15, "target": 21}, {"source": 21, "target": 2}, {"source": 2, "target": 39}, {"source": 39, "target": 14}, {"source": 14, "target": 11}, {"source": 11, "target": 10}, {"source": 10, "target": 22}, {"source": 22, "target": 33}, {"source": 33, "target": 40}, {"source": 40, "target": 1}, {"source": 1, "target": 28}, {"source": 28, "target": 4}, {"source": 4, "target": 47}, {"source": 47, "target": 41}, {"source": 41, "target": 9}, {"source": 9, "target": 25}, {"source": 25, "target": 3}, {"source": 3, "target": 34}, {"source": 34, "target": 44}, {"source": 44, "target": 23}, {"source": 23, "target": 31}, {"source": 31, "target": 38}, {"source": 38, "target": 24}, {"source": 24, "target": 13}, {"source": 13, "target": 12}, {"source": 12, "target": 20}, {"source": 20, "target": 46}, {"source": 46, "target": 19}, {"source": 19, "target": 32}, {"source": 32, "target": 45}, {"source": 45, "target": 35}, {"source": 35, "target": 29}, {"source": 29, "target": 42}, {"source": 42, "target": 16}, {"source": 16, "target": 26}, {"source": 26, "target": 18}, {"source": 18, "target": 36}]}

2
output/att48.txt Normal file
View File

@ -0,0 +1,2 @@
36, 5, 27, 6, 17, 43, 30, 37, 8, 7, 0, 15, 21, 2, 39, 14, 11, 10, 22, 33, 40, 1, 28, 4, 47, 41, 9, 25, 3, 34, 44, 23, 31, 38, 24, 13, 12, 20, 46, 19, 32, 45, 35, 29, 42, 16, 26, 18
34767.13377984314

1
output/dsj1000.json Normal file

File diff suppressed because one or more lines are too long

1
output/dsj1000.txt Normal file
View File

@ -0,0 +1 @@
694, 113, 939, 256, 50, 268, 148, 225, 578, 555, 618, 839, 110, 565, 336, 169, 719, 645, 22, 988, 71, 426, 203, 924, 157, 216, 905, 904, 981, 61, 920, 27, 280, 348, 477, 604, 586, 133, 86, 942, 33, 761, 695, 840, 548, 361, 838, 226, 89, 774, 321, 460, 272, 932, 400, 165, 470, 862, 444, 830, 688, 293, 125, 69, 552, 340, 66, 317, 949, 790, 376, 474, 175, 923, 166, 598, 91, 692, 625, 57, 664, 935, 999, 525, 241, 164, 350, 457, 691, 879, 387, 735, 849, 243, 158, 700, 53, 287, 757, 616, 270, 220, 109, 54, 418, 965, 998, 60, 919, 928, 887, 946, 911, 955, 933, 982, 636, 617, 914, 143, 150, 120, 325, 356, 172, 452, 505, 315, 333, 486, 288, 327, 817, 85, 889, 64, 730, 469, 876, 722, 909, 822, 337, 745, 250, 18, 813, 439, 716, 238, 490, 2, 902, 568, 1, 630, 690, 708, 627, 668, 468, 709, 373, 612, 424, 798, 814, 132, 812, 11, 802, 882, 379, 984, 750, 967, 642, 845, 402, 715, 180, 652, 35, 874, 826, 357, 521, 459, 210, 52, 499, 608, 219, 45, 329, 921, 257, 571, 605, 67, 77, 507, 346, 105, 184, 233, 723, 8, 558, 808, 714, 343, 682, 332, 886, 888, 675, 729, 401, 3, 393, 147, 508, 601, 269, 846, 858, 378, 58, 129, 950, 893, 117, 947, 580, 285, 101, 683, 587, 196, 326, 182, 78, 576, 183, 677, 420, 246, 141, 208, 957, 433, 769, 394, 827, 660, 413, 301, 562, 788, 569, 989, 185, 530, 389, 539, 335, 375, 903, 742, 82, 943, 994, 676, 739, 98, 964, 349, 137, 410, 396, 743, 324, 986, 762, 556, 776, 538, 991, 810, 799, 144, 746, 952, 405, 437, 531, 42, 929, 298, 179, 828, 661, 895, 996, 665, 372, 63, 689, 121, 75, 311, 465, 509, 199, 48, 853, 993, 599, 510, 30, 574, 831, 451, 685, 478, 344, 93, 733, 657, 663, 978, 138, 969, 713, 41, 785, 559, 693, 209, 65, 979, 95, 207, 438, 171, 448, 328, 248, 330, 670, 367, 430, 309, 239, 440, 192, 359, 339, 43, 875, 278, 899, 191, 228, 631, 39, 892, 768, 633, 863, 254, 56, 613, 201, 533, 523, 384, 756, 970, 76, 299, 323, 0, 913, 816, 727, 870, 658, 421, 247, 883, 600, 259, 619, 291, 951, 796, 560, 609, 511, 726, 149, 543, 513, 654, 255, 561, 265, 881, 678, 841, 181, 963, 386, 371, 966, 614, 84, 135, 347, 520, 632, 195, 607, 623, 249, 20, 857, 189, 385, 740, 687, 140, 279, 650, 151, 824, 891, 537, 829, 206, 284, 504, 320, 634, 446, 703, 566, 805, 635, 17, 363, 641, 498, 198, 747, 593, 236, 864, 620, 44, 15, 355, 139, 681, 163, 916, 527, 835, 749, 671, 70, 651, 995, 649, 976, 304, 930, 290, 119, 759, 990, 23, 388, 901, 512, 698, 240, 878, 126, 251, 253, 837, 792, 118, 961, 653, 155, 34, 488, 721, 364, 844, 815, 271, 992, 443, 771, 5, 557, 72, 366, 953, 900, 10, 544, 496, 4, 382, 99, 370, 515, 134, 850, 734, 940, 186, 753, 781, 314, 804, 87, 322, 473, 342, 260, 302, 704, 88, 463, 501, 19, 374, 583, 673, 896, 123, 997, 503, 975, 725, 136, 977, 922, 859, 567, 528, 414, 49, 292, 106, 731, 194, 908, 403, 594, 592, 492, 485, 534, 843, 114, 907, 399, 471, 787, 591, 884, 46, 755, 679, 934, 854, 390, 820, 973, 818, 795, 710, 427, 154, 640, 680, 867, 526, 581, 550, 834, 24, 28, 639, 717, 624, 51, 79, 274, 936, 408, 319, 590, 177, 821, 754, 295, 267, 419, 29, 103, 737, 242, 546, 111, 877, 395, 116, 656, 575, 286, 885, 603, 313, 825, 397, 235, 237, 338, 861, 648, 540, 218, 383, 434, 748, 779, 915, 549, 416, 773, 73, 415, 354, 142, 458, 487, 570, 391, 707, 483, 728, 643, 153, 766, 647, 204, 628, 958, 494, 466, 851, 168, 252, 602, 244, 780, 906, 124, 289, 97, 823, 152, 985, 584, 532, 775, 941, 261, 701, 702, 622, 377, 786, 873, 227, 454, 432, 447, 987, 331, 772, 758, 365, 744, 96, 316, 442, 541, 406, 156, 491, 535, 334, 564, 514, 223, 597, 644, 345, 712, 763, 341, 234, 423, 765, 422, 791, 711, 193, 944, 684, 74, 476, 300, 160, 263, 767, 596, 778, 782, 666, 793, 706, 972, 221, 971, 962, 264, 37, 637, 231, 522, 90, 453, 577, 100, 130, 435, 59, 582, 294, 68, 450, 662, 282, 230, 13, 484, 202, 610, 16, 638, 848, 407, 224, 480, 718, 353, 9, 159, 938, 832, 736, 983, 128, 428, 871, 215, 489, 112, 801, 855, 167, 777, 529, 732, 307, 398, 869, 102, 847, 968, 62, 866, 751, 273, 524, 436, 455, 174, 358, 32, 927, 277, 38, 974, 836, 217, 669, 931, 412, 720, 800, 200, 360, 784, 312, 297, 21, 629, 6, 760, 872, 12, 211, 789, 266, 880, 910, 926, 588, 481, 409, 572, 621, 368, 925, 411, 495, 868, 752, 589, 456, 699, 197, 615, 536, 553, 188, 472, 842, 819, 794, 585, 865, 579, 646, 104, 674, 245, 464, 92, 55, 352, 351, 229, 595, 310, 429, 214, 449, 275, 431, 222, 506, 960, 705, 131, 146, 738, 811, 190, 860, 890, 94, 551, 741, 945, 563, 362, 917, 912, 764, 127, 667, 894, 606, 425, 14, 806, 545, 672, 956, 852, 213, 81, 145, 303, 36, 176, 547, 25, 783, 809, 697, 696, 519, 122, 626, 276, 107, 80, 318, 833, 7, 26, 500, 283, 445, 897, 47, 205, 381, 980, 380, 770, 392, 948, 187, 517, 305, 959, 542, 807, 803, 573, 369, 475, 462, 482, 467, 170, 232, 417, 115, 40, 306, 262, 659, 308, 161, 954, 83, 108, 497, 281, 516, 898, 296, 518, 441, 404, 173, 162, 178, 937, 479, 461, 918, 724, 502, 212, 655, 686, 493, 856, 797, 31, 554, 258, 611

1
output/pcb442.json Normal file

File diff suppressed because one or more lines are too long

1
output/pcb442.txt Normal file
View File

@ -0,0 +1 @@
18, 17, 16, 15, 14, 13, 70, 71, 72, 73, 74, 75, 99, 78, 79, 80, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 0, 1, 2, 3, 4, 441, 69, 68, 67, 66, 65, 101, 102, 113, 125, 135, 148, 160, 171, 184, 399, 404, 226, 233, 237, 238, 265, 268, 272, 275, 278, 280, 281, 427, 341, 340, 345, 346, 347, 432, 348, 349, 350, 351, 342, 352, 353, 354, 433, 355, 356, 357, 434, 358, 359, 360, 343, 361, 362, 363, 364, 365, 366, 344, 367, 368, 369, 370, 371, 372, 373, 374, 337, 336, 426, 335, 334, 333, 306, 332, 331, 330, 305, 304, 303, 302, 301, 300, 299, 298, 297, 296, 295, 294, 293, 292, 291, 290, 289, 288, 287, 286, 285, 284, 283, 282, 279, 425, 439, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 428, 324, 325, 326, 327, 328, 329, 430, 429, 277, 416, 417, 252, 431, 421, 418, 411, 412, 206, 205, 194, 195, 110, 122, 132, 145, 157, 168, 181, 196, 207, 217, 225, 219, 209, 198, 183, 170, 159, 147, 134, 124, 112, 383, 382, 97, 96, 379, 95, 378, 94, 62, 63, 64, 32, 376, 375, 31, 30, 29, 28, 61, 93, 92, 100, 435, 111, 123, 133, 146, 158, 169, 182, 197, 208, 218, 410, 409, 413, 236, 264, 436, 274, 437, 422, 271, 419, 267, 415, 263, 235, 262, 261, 260, 259, 258, 257, 256, 255, 254, 253, 231, 223, 214, 202, 178, 394, 393, 389, 387, 143, 390, 384, 120, 109, 121, 131, 144, 156, 167, 180, 193, 204, 216, 403, 408, 407, 232, 224, 215, 203, 192, 191, 179, 166, 155, 142, 130, 119, 108, 381, 380, 438, 107, 118, 129, 141, 154, 165, 177, 397, 190, 189, 201, 401, 200, 188, 176, 163, 164, 153, 140, 128, 117, 106, 105, 104, 116, 115, 137, 391, 151, 150, 388, 386, 440, 103, 114, 385, 126, 136, 149, 161, 172, 185, 400, 405, 227, 234, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 414, 249, 250, 251, 230, 222, 213, 396, 175, 162, 152, 138, 127, 139, 392, 174, 186, 398, 395, 173, 406, 402, 210, 220, 228, 211, 212, 199, 187, 221, 229, 420, 424, 423, 339, 338, 276, 273, 270, 266, 269, 98, 77, 76, 5, 6, 7, 8, 9, 10, 11, 12, 48, 49, 50, 51, 52, 53, 54, 55, 56, 19, 20, 21, 22, 23, 24, 25, 26, 27, 60, 57, 58, 59, 91, 90, 89, 88, 87, 377, 86, 85, 84, 83, 82, 81

1
output/st70.json Normal file

File diff suppressed because one or more lines are too long

1
output/st70.txt Normal file
View File

@ -0,0 +1 @@
63, 10, 66, 47, 53, 32, 59, 51, 9, 4, 52, 20, 16, 42, 40, 3, 17, 41, 5, 11, 33, 61, 60, 39, 38, 24, 44, 45, 26, 8, 67, 43, 29, 19, 13, 27, 7, 25, 48, 54, 18, 6, 31, 2, 1, 23, 14, 56, 62, 65, 21, 58, 37, 22, 12, 68, 30, 34, 69, 28, 35, 0, 15, 46, 36, 57, 49, 50, 55, 64

1
output/ulysses16.json Normal file
View File

@ -0,0 +1 @@
{"nodes": [{"title": "0", "id": 0, "x": 38, "y": 20}, {"title": "1", "id": 1, "x": 39, "y": 26}, {"title": "2", "id": 2, "x": 40, "y": 25}, {"title": "3", "id": 3, "x": 36, "y": 23}, {"title": "4", "id": 4, "x": 33, "y": 10}, {"title": "5", "id": 5, "x": 37, "y": 12}, {"title": "6", "id": 6, "x": 38, "y": 13}, {"title": "7", "id": 7, "x": 37, "y": 20}, {"title": "8", "id": 8, "x": 41, "y": 9}, {"title": "9", "id": 9, "x": 41, "y": 13}, {"title": "10", "id": 10, "x": 36, "y": -5}, {"title": "11", "id": 11, "x": 38, "y": 15}, {"title": "12", "id": 12, "x": 38, "y": 15}, {"title": "13", "id": 13, "x": 37, "y": 15}, {"title": "14", "id": 14, "x": 35, "y": 14}, {"title": "15", "id": 15, "x": 39, "y": 19}], "edges": [{"source": 7, "target": 3}, {"source": 3, "target": 1}, {"source": 1, "target": 2}, {"source": 2, "target": 0}, {"source": 0, "target": 15}, {"source": 15, "target": 12}, {"source": 12, "target": 11}, {"source": 11, "target": 6}, {"source": 6, "target": 5}, {"source": 5, "target": 9}, {"source": 9, "target": 8}, {"source": 8, "target": 10}, {"source": 10, "target": 4}, {"source": 4, "target": 14}, {"source": 14, "target": 13}, {"source": 13, "target": 7}]}

1
output/ulysses16.txt Normal file
View File

@ -0,0 +1 @@
7, 3, 1, 2, 0, 15, 12, 11, 6, 5, 9, 8, 10, 4, 14, 13

4
requirements.txt Normal file
View File

@ -0,0 +1,4 @@
matplotlib
scikit-learn
scipy
numpy

12
run_all.sh Normal file
View File

@ -0,0 +1,12 @@
#!/bin/bash
pip install -r requirements.txt
python main.py data/simple/ulysses16.tsp
python main.py data/simple/att48.tsp
python main.py data/simple/st70.tsp
python main.py data/medium/a280.tsp
python main.py data/medium/pcb442.tsp
python main.py data/hard/dsj1000.tsp

54
utils/visualize_tsp.py Normal file
View File

@ -0,0 +1,54 @@
import matplotlib.pyplot as plt
def plotTSP(paths, points, num_iters=1):
"""
path: List of lists with the different orders in which the nodes are visited
points: coordinates for the different nodes
num_iters: number of paths that are in the path list
"""
# Unpack the primary TSP path and transform it into a list of ordered
# coordinates
x = []; y = []
for i in paths[0]:
x.append(points[i][0])
y.append(points[i][1])
plt.plot(x, y, 'co')
# Set a scale for the arrow heads (there should be a reasonable default for this, WTF?)
# a_scale = float(max(x))/float(100)
# Draw the older paths, if provided
if num_iters > 1:
for i in range(1, num_iters):
# Transform the old paths into a list of coordinates
xi = []; yi = [];
for j in paths[i]:
xi.append(points[j][0])
yi.append(points[j][1])
plt.arrow(xi[-1], yi[-1], (xi[0] - xi[-1]), (yi[0] - yi[-1]),
color = 'r', length_includes_head = True, ls = 'dashed',
width = 0.001/float(num_iters))
for i in range(0, len(x) - 1):
plt.arrow(xi[i], yi[i], (xi[i+1] - xi[i]), (yi[i+1] - yi[i]),
color = 'r', length_includes_head = True,
ls = 'dashed', width = 0.001/float(num_iters))
# Draw the primary path for the TSP problem
plt.arrow(x[-1], y[-1], (x[0] - x[-1]), (y[0] - y[-1]),
color ='g', length_includes_head=True)
for i in range(0,len(x)-1):
plt.arrow(x[i], y[i], (x[i+1] - x[i]), (y[i+1] - y[i]),
color = 'g', length_includes_head = True)
#Set axis too slitghtly larger than the set of x and y
# plt.xlim(min(x)*1.1, max(x)*1.1)
# plt.ylim(min(y)*1.1, max(y)*1.1)
plt.show()