-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
50 lines (42 loc) · 1.2 KB
/
models.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
41
42
43
44
45
46
47
48
49
50
from utils import *
class Coordinate:
def __init__(self, id, name, latitude, longitude):
self.id = id
self.name = name
self.latitude = latitude
self.longitude = longitude
class Customer(Coordinate):
def __init__(self, id, name, latitude, longitude, demand):
super().__init__(id, name, latitude, longitude)
self.demand = demand
class Vehicle:
def __init__(self, name, capacity, cost):
self.name = name
self.capacity = capacity
self.cost = cost
class Route:
def __init__(self, vehicle):
self.length = 0
self.stops = []
self.vehicle = vehicle
self.remaining = vehicle.capacity
def visit(self, coordinate):
if len(self.stops) > 0:
self.length += distance(self.stops[-1], coordinate)
if isinstance(coordinate, Customer):
self.remaining -= coordinate.demand
self.stops.append(coordinate)
class Path:
def __init__(self):
self.routes = []
self.length = 0
def add(self, route):
self.routes.append(route)
self.length += route.length
def full_path_without_depot(self):
full_path_without_depot = []
for route in self.routes:
for coordinate in route.stops:
if coordinate.id != -1:
full_path_without_depot.append(coordinate.id)
return full_path_without_depot