-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtruck.py
78 lines (67 loc) · 2.59 KB
/
truck.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
74
75
76
77
78
#Katherine Caudill
#Student #: 005252042
#WGU: Data Structures and Algorithms II - C950
# get current location of truck and check distance to next location
# and time to get there and return time to get there
from package import Package
class Truck:
def __init__(self):
self.truck1 = []
self.truck2 = []
self.truck3 = []
def sort_packages_into_priorities(self, packages):
priority_truck_1 = []
np_truck_1 = []
priority_truck_2 = []
np_truck_2 = []
non_priority = []
for p in packages:
notes = p.get_notes()
deadline = p.get_deadline()
address = p.get_address()
id = p.get_package_id()
if id in [13, 14, 15, 16, 19, 20, 29]:
priority_truck_1.append(p)
elif 'Can only be on truck 2' in notes or 'Delayed on flight' in notes:
priority_truck_2.append(p)
elif 'Wrong address listed' in notes:
p.set_address('410 S State St')
p.set_zip('84111')
non_priority.append(p)
elif 'Must be delivered with' in notes and deadline != 'EOD':
priority_truck_1.append(p)
elif deadline != 'EOD':
ft_address = [t.get_address() for t in priority_truck_1]
if address in ft_address:
np_truck_1.append(p)
else:
np_truck_2.append(p)
else:
non_priority.append(p)
self._load_trucks(priority_truck_1, np_truck_1, priority_truck_2, np_truck_2, non_priority)
def _load_trucks(self, priority_truck_1, np_truck_1, priority_truck_2, np_truck_2, non_priority):
for t in priority_truck_1:
if len(self.truck1) < 16:
self.truck1.append(t)
for t in np_truck_1:
if len(self.truck1) < 16:
self.truck1.append(t)
for t in priority_truck_2:
if len(self.truck2) < 16:
self.truck2.append(t)
for t in np_truck_2:
if len(self.truck2) < 16:
self.truck2.append(t)
elif len(self.truck1) < 16:
self.truck1.append(t)
else:
self.truck3.append(t)
for t in non_priority:
if len(self.truck3) < 16:
self.truck3.append(t)
elif len(self.truck2) < 16:
self.truck2.append(t)
elif len(self.truck1) < 16:
self.truck1.append(t)
else:
print('Not enough room on trucks')