-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
41 lines (30 loc) · 1.07 KB
/
main.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
import pandas as pd
import math
df = pd.read_excel("D:\\OneDrive\\10_Project_Datascience\Java\computational_logistics\src\TSP.xlsx")
class TSPSolution:
def eucl_dist_m(self, x, y):
return [[math.sqrt(sum([(val[i] - val[j]) ** 2 for val in (x, y)])) for j in range(len(y))] for i in
range(len(x))]
def manh_dist_m(self, x, y):
return [[(sum([abs(val[i] - val[j]) for val in (x, y)])) for j in range(len(y))] for i in range(len(x))]
class TSPData:
id_values = []
x_values = []
y_values = []
def __init__(self, id_values=[], x_values=[], y_values=[]):
self.id_values = id_values
self.x_values = id_values
self.y_values = y_values;
def addCustomer(self, x, y):
self.x_values += [x]
self.y_values += [y]
if __name__ == "__main__":
x = list(df["x coordinate"])
y = list(df["y coordinate"])
# create data
dat = TSPData()
for i in range(len(x)):
dat.addCustomer(x[i], y[i])
inst = TSPSolution()
print(inst.eucl_dist_m(x, y))
print(inst.manh_dist_m(x, y))