-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedge_generator.py
40 lines (37 loc) · 1.35 KB
/
edge_generator.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
import string
from edge import Edge
class EdgeGenerator:
alphabet_list = list(string.ascii_uppercase)
@staticmethod
def generate(filePath):
def read_data(filePath):
number_of_cities = None
costs = None
reliabilities = None
input_file = open(filePath)
for line in input_file:
if '#' in line:
continue
if number_of_cities is None:
number_of_cities = line
continue
if reliabilities is None:
reliabilities = line.rstrip('\n').split(' ')
continue
if costs is None:
costs = line.rstrip('\n').split(' ')
continue
return number_of_cities,costs,reliabilities
number_of_cities, costs,reliabilities = read_data(filePath)
city_list = EdgeGenerator.alphabet_list[0:int(number_of_cities)]
edge_list = list()
row = 0
col = 1
for reliability,cost in zip(reliabilities,costs):
edge_list.append(Edge(city_list[row],city_list[col],float(cost),float(reliability)))
if(col == len(city_list)-1):
row = row+1
col = row+1
else:
col= col+1
return city_list, edge_list