-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulated_annealing_data.py
106 lines (96 loc) · 4.02 KB
/
simulated_annealing_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# data source: http://www.auslandversicherung.de/entfernungstabelle_schweiz.html
CITIES = [
'Aarau',
'Andermatt',
'Basel',
'Bellinzona',
'Bern',
'Biel',
'Brig',
'Chiasso',
'Chur',
'Davos',
'Fribourg',
'Genf',
'Glarus',
'Interlaken',
'Kreuzlingen',
'Lausanne',
'Locarno',
'Lugano',
'Luzern',
'Martigny',
'Montreux',
'Neuchatel',
'Olten',
'St. Gallen',
'St. Moritz',
'Schaffhausen',
'Schwyz',
'Sion',
'Solothurn',
'Thun',
'Vaduz',
'Winterthur',
'Zermatt',
'Zürich',
'Zug'
]
DISTANCES = [
[135],
[ 65, 168],
[209, 86, 240],
[ 84, 146, 96, 219],
[ 72, 188, 85, 255, 40],
[215, 80, 247, 128, 170, 204],
[260, 137, 291, 55, 270, 307, 187],
[164, 94, 199, 115, 241, 274, 172, 170],
[194, 154, 230, 134, 292, 330, 227, 194, 58],
[113, 168, 125, 251, 33, 70, 181, 290, 263, 320],
[234, 293, 246, 343, 154, 158, 215, 399, 387, 444, 137],
[116, 100, 152, 185, 225, 188, 178, 238, 72, 100, 240, 382],
[137, 97, 147, 178, 55, 92, 113, 216, 192, 247, 73, 190, 168],
[109, 171, 150, 242, 192, 188, 250, 296, 128, 157, 222, 345, 92, 195],
[185, 232, 197, 279, 105, 110, 152, 338, 325, 380, 74, 64, 332, 150, 288],
[226, 105, 158, 18, 238, 275, 107, 66, 126, 160, 256, 322, 195, 184, 278, 260],
[235, 112, 266, 29, 245, 281, 146, 27, 142, 166, 262, 360, 200, 190, 284, 299, 40],
[ 63, 73, 95, 145, 122, 105, 138, 196, 166, 170, 139, 255, 105, 66, 139, 200, 164, 170],
[212, 163, 112, 210, 131, 168, 85, 268, 256, 312, 102, 124, 311, 144, 314, 73, 190, 230, 235],
[169, 212, 181, 248, 90, 128, 122, 306, 306, 361, 60, 93, 292, 133, 272, 31, 229, 268, 272, 42],
[107, 177, 119, 284, 49, 34, 222, 322, 271, 326, 50, 125, 272, 105, 232, 76, 290, 295, 140, 142, 100],
[ 13, 125, 53, 199, 67, 62, 190, 249, 184, 212, 99, 220, 136, 120, 135, 172, 217, 222, 54, 197, 155, 96],
[124, 199, 165, 233, 206, 200, 275, 273, 104, 133, 236, 358, 80, 208, 40, 310, 240, 246, 132, 335, 292, 234, 148],
[238, 162, 284, 151, 309, 343, 240, 135, 75, 68, 330, 455, 148, 260, 205, 395, 165, 126, 274, 324, 374, 340, 260, 176],
[ 91, 154, 132, 265, 173, 168, 231, 316, 149, 178, 204, 326, 102, 176, 45, 277, 285, 290, 111, 303, 260, 202, 116, 80, 260],
[ 75, 56, 118, 126, 180, 142, 231, 178, 150, 141, 199, 342, 66, 124, 133, 238, 146, 152, 37, 218, 260, 176, 90, 95, 190, 100],
[238, 133, 250, 180, 159, 197, 55, 238, 227, 282, 130, 154, 233, 167, 343, 101, 160, 166, 105, 32, 70, 170, 260, 330, 295, 288, 190],
[ 52, 182, 65, 269, 40, 24, 204, 308, 211, 240, 70, 192, 164, 198, 155, 134, 275, 280, 81, 170, 128, 58, 38, 177, 290, 125, 128, 197],
[106, 125, 120, 205, 30, 65, 142, 244, 219, 275, 48, 182, 198, 30, 210, 123, 212, 219, 92, 136, 108, 80, 94, 231, 288, 200, 153, 164, 65],
[153, 133, 189, 153, 280, 224, 212, 208, 40, 70, 302, 426, 60, 230, 92, 366, 176, 182, 132, 295, 345, 310, 174, 66, 118, 145, 104, 266, 200, 258],
[ 66, 126, 105, 238, 144, 141, 202, 288, 121, 150, 175, 298, 74, 148, 43, 250, 257, 264, 84, 275, 233, 174, 88, 56, 235, 28, 73, 260, 116, 170, 111],
[260, 124, 290, 170, 212, 249, 445, 230, 217, 273, 208, 232, 222, 157, 295, 180, 150, 157, 195, 110, 148, 248, 250, 321, 285, 277, 180, 80, 275, 186, 256, 250],
[ 45, 111, 83, 231, 123, 117, 202, 287, 119, 148, 153, 277, 72, 123, 72, 230, 255, 260, 66, 255, 212, 154, 66, 85, 196, 53, 60, 244, 95, 150, 110, 25, 234],
[ 53, 79, 120, 150, 153, 130, 168, 226, 116, 145, 170, 285, 69, 96, 112, 232, 170, 175, 30, 265, 304, 170, 84, 97, 193, 92, 27, 212, 111, 126, 105, 65, 202, 41]
]
def distance(ix_loc1, ix_loc2):
if ix_loc1 < ix_loc2:
return DISTANCES[ix_loc2-1][ix_loc1]
elif ix_loc1 > ix_loc2:
return DISTANCES[ix_loc1-1][ix_loc2]
else:
return 0
def path_length(path):
dist = 0
depart = path[-1]
for destin in path:
dist += distance(depart, destin)
depart = destin
return dist
def path_print(path):
dist = 0
depart = path[-1]
print(dist, '\t', CITIES[depart])
for destin in path:
dist += distance(depart, destin)
print(dist, '\t', CITIES[destin])
depart = destin