-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_dist_matrix_eil76.py
97 lines (91 loc) · 1.87 KB
/
generate_dist_matrix_eil76.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
points = [
(1, 22, 22),
(2, 36, 26),
(3, 21, 45),
(4, 45, 35),
(5, 55, 20),
(6, 33, 34),
(7, 50, 50),
(8, 55, 45),
(9, 26, 59),
(10, 40, 66),
(11, 55, 65),
(12, 35, 51),
(13, 62, 35),
(14, 62, 57),
(15, 62, 24),
(16, 21, 36),
(17, 33, 44),
(18, 9, 56),
(19, 62, 48),
(20, 66, 14),
(21, 44, 13),
(22, 26, 13),
(23, 11, 28),
(24, 7, 43),
(25, 17, 64),
(26, 41, 46),
(27, 55, 34),
(28, 35, 16),
(29, 52, 26),
(30, 43, 26),
(31, 31, 76),
(32, 22, 53),
(33, 26, 29),
(34, 50, 40),
(35, 55, 50),
(36, 54, 10),
(37, 60, 15),
(38, 47, 66),
(39, 30, 60),
(40, 30, 50),
(41, 12, 17),
(42, 15, 14),
(43, 16, 19),
(44, 21, 48),
(45, 50, 30),
(46, 51, 42),
(47, 50, 15),
(48, 48, 21),
(49, 12, 38),
(50, 15, 56),
(51, 29, 39),
(52, 54, 38),
(53, 55, 57),
(54, 67, 41),
(55, 10, 70),
(56, 6, 25),
(57, 65, 27),
(58, 40, 60),
(59, 70, 64),
(60, 64, 4),
(61, 36, 6),
(62, 30, 20),
(63, 20, 30),
(64, 15, 5),
(65, 50, 70),
(66, 57, 72),
(67, 45, 42),
(68, 38, 33),
(69, 50, 4),
(70, 66, 8),
(71, 59, 5),
(72, 35, 60),
(73, 27, 24),
(74, 40, 20),
(75, 40, 37),
(76, 40, 40)
]
import math
dist_mat = [[math.dist((p[1], p[2]), (p2[1], p2[2])) for p2 in points] for p in points]
import pprint
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(dist_mat)
with open("mat.mat", "w") as out:
pprint.pprint(dist_mat, out)
tour = [1, 33, 63, 16, 3, 44, 32, 9, 39, 72, 58, 10, 31, 55, 25, 50, 18, 24, 49, 23, 56, 41, 43, 42, 64, 22, 61, 21, 47, 36, 69, 71, 60, 70, 20, 37, 5, 15, 57, 13, 54, 19, 14, 59, 66, 65, 38, 11, 53, 7, 35, 8, 46, 34, 52, 27, 45, 29, 48, 30, 4, 75, 76, 67, 26, 12, 40, 17, 51, 6, 68, 2, 74, 28, 62, 73, 1]
total_distance = 0
for i in range(len(tour) - 1):
total_distance += dist_mat[tour[i] - 1][tour[i + 1] - 1]
print(f"{tour[i]} -> {tour[i + 1]}: {dist_mat[tour[i] - 1][tour[i + 1] - 1]}")
print(total_distance)