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
|
"""
Functions to read input data from files
"""
import csv
from nodeOPP import Node
def read_nodes(depot_num):
"""
Read nodes from input file.
Attributes
----------
depot_num : int
Number of depots
Returns
-------
list
List of Nodes. The first `depot_num` nodes are the depots.
"""
depots = []
no_depots = []
with open('odiparpack/inf226.oficinas_mod.csv', newline='') as csvfile:
orders = csv.reader(csvfile)
count = 1
index_customer = depot_num
index_depot = 0
for row in orders:
if count == 1:
count += 1
continue
ubigeo, dept, prov, lat, lon, region_natural, is_depot = row[:7]
demand, ready_time, due_time, service_time = row[7:]
n = Node(
-1, ubigeo, float(lat), float(lon),
int(is_depot),
demand=float(demand), ready_time=0,
due_time=float(due_time), service_time=60
)
if n.is_depot:
n.index = index_depot
depots.append(n)
index_depot += 1
else:
n.index = index_customer
no_depots.append(n)
index_customer += 1
count += 1
return depots + no_depots
def read_tramos():
"""
Lee archivo de tramos
Returns
-------
list
Lista de tuplas con los tramos (ubigeo1, ubigeo2)
"""
tramos = []
with open('odiparpack/inf226.tramos.v.2.0.csv', newline='') as f:
rows = csv.reader(f)
count = 1
for row in rows:
if count >= 2:
tramos.append([row[0], row[1]])
count += 1
return tramos
|