summaryrefslogtreecommitdiffstats
path: root/nodeOPP.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 /nodeOPP.py
parenta7c5bec4705708eb87fb8d9a60b2868471ce702a (diff)
downloadVRPTW-ACO-python-master.tar.gz
VRPTW-ACO-python-master.tar.bz2
VRPTW-ACO-python-master.zip
Refactor some functions out of example1.pyHEADmaster
Diffstat (limited to 'nodeOPP.py')
-rw-r--r--nodeOPP.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/nodeOPP.py b/nodeOPP.py
new file mode 100644
index 0000000..0f792f4
--- /dev/null
+++ b/nodeOPP.py
@@ -0,0 +1,68 @@
+"""
+Custom Node class for OdiParPack
+"""
+
+import math
+
+class Node:
+ """
+ Attributes
+ ----------
+ index : int
+ Index in some arrays
+ ubigeo : str
+ 6 digit ID
+ lat : float
+ Latitud (angulo de los Paralelos) en grados sexagesimales
+ lon : float
+ Longitud (angulo de los Meridianos) en grados sexagesimales
+ is_depot : bool
+ demand : int
+ ready_time : float
+ due_time : float
+ service_time : float
+ x : float
+ Aproximacion local, en Km respecto
+ y : float
+ Aproximacion local, en Km respecto ("Lima")
+
+ Notes
+ -----
+ Web Mercator projection (BAD):
+
+ x = floor(256 / (2 * math.pi) * 2**(zoom_level) * (lon + math.pi))
+ y = floor(265 / (2 * math.pi) * 2**(zoom_level) * (math.pi - math.ln(math.tan( math.pi / 4 + lat / 2 ))))
+
+ x = R * lon
+ y = R * ln(tan(pi/4 + lat/2)
+
+ Both `lon` and `lat` in radians.
+
+ "Lima": -12.04591952,-77.03049615 (lat, long)
+ """
+
+ def __init__(self, index: int, ubigeo, lat, lon, is_depot,
+ demand, ready_time, due_time, service_time):
+ super()
+ self.index = index
+ self.ubigeo = ubigeo
+
+ if is_depot:
+ self.is_depot = True
+ else:
+ self.is_depot = False
+
+ earth_radius_km = 6371 # Avg. radius
+ lima_lat = -12.04591952
+ lima_lon = -77.03049615
+
+ self.lat = lat
+ self.lon = lon
+ self.x = (lon - lima_lon) * (math.pi / 180) * earth_radius_km
+ self.y = (lat - lima_lat) * (math.pi / 180) * earth_radius_km
+ self.x = round(self.x, 3)
+ self.y = round(self.y, 3)
+ self.demand = demand
+ self.ready_time = 0 # ready_time
+ self.due_time = due_time
+ self.service_time = service_time