""" 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