-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader.py
34 lines (30 loc) · 929 Bytes
/
loader.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
class Problem:
def __init__(self, filepath):
f = open(filepath, 'r')
lines = f.readlines()
self.coordinations = []
start = False
for line in lines:
if start:
line = line.strip().split()
if len(line) < 3:
break
self.coordinations.append((float(line[1]), float(line[2])))
continue
if 'DIMENSION' in line:
line = line.split(':')
self.dimension = int(line[1].strip())
continue
if 'NODE_COORD_SECTION' in line:
start = True
self.calculate_weights()
def calculate_weights(self):
self.weights = []
for first_coordination in self.coordinations:
weights = []
for second_coordination in self.coordinations:
weights.append((((first_coordination[0]-second_coordination[0])**2) +
((first_coordination[1]-second_coordination[1])**2))**0.5)
self.weights.append(weights)
def get_weight(self, start, end):
return self.weights[start-1][end-1]