summaryrefslogtreecommitdiffstats
path: root/readerOPP.py
diff options
context:
space:
mode:
authorMitsuo Tokumori <[email protected]>2022-05-06 03:11:18 -0500
committerMitsuo Tokumori <[email protected]>2022-05-06 03:11:18 -0500
commit9ac1b21b42571c0e8e3dee9619931a670f1a3c10 (patch)
tree1d8dcc5c828927f0bc291a0c146182a20382b25b /readerOPP.py
parenta7c5bec4705708eb87fb8d9a60b2868471ce702a (diff)
downloadVRPTW-ACO-python-9ac1b21b42571c0e8e3dee9619931a670f1a3c10.tar.gz
VRPTW-ACO-python-9ac1b21b42571c0e8e3dee9619931a670f1a3c10.tar.bz2
VRPTW-ACO-python-9ac1b21b42571c0e8e3dee9619931a670f1a3c10.zip
Refactor some functions out of example1.pyHEADmaster
Diffstat (limited to 'readerOPP.py')
-rw-r--r--readerOPP.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/readerOPP.py b/readerOPP.py
new file mode 100644
index 0000000..ccd213e
--- /dev/null
+++ b/readerOPP.py
@@ -0,0 +1,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