-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroute.py
73 lines (57 loc) · 2 KB
/
route.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import numpy as np
class Route:
def __init__(self,capacity):
self.capacity = int(capacity),
self.customers = []
self.payload = 0
self.cost = np.inf
self.savings =0
def addCustomer(self,index, demand , onTop):
if(demand > self.capacity[0]):
#print("Customer demand too large")
return -1
else:
tempPayload = int(self.payload + demand)
if(tempPayload > self.capacity[0]):
#print("Route Overloaded")
return -1
else:
self.payload = tempPayload
if onTop == True :
self.customers.insert(0,index)
return 1
else:
self.customers.insert(len(self.customers),index)
return 1
def checkCustomer(self, index):
if index not in self.customers:
#print("Customer: " + str(index) +" not present")
return -1
else:
i = self.customers.index(index)
if (0<i<len(self.customers)-1):
#print("Customer: " + str(index) +" interior in the tour")
return -2
else:
return i #Yeah, it's the starting point or the end point
def getCustomers(self):
return self.customers
def getPayload(self):
return self.payload
def setPayload(self,payload):
self.payload = payload
def getCost(self):
return self.cost
def setCost(self,cost):
self.cost = cost
def getCapacity(self):
return self.capacity
def printRoute(self,name):
textRoute = "Route_"+str(name)+": "
print("Route:", end =" ")
for c in self.customers:
print(str(c), end="-" )
textRoute += str(c) + "-"
print("END")
textRoute += "END"
return textRoute