-
Notifications
You must be signed in to change notification settings - Fork 0
/
package_sorting.py
53 lines (49 loc) · 2.38 KB
/
package_sorting.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
# James Spencer ID: 000486930
# import math
from address_book import AddressBook
# from priority_queue import PriorityQueue
class PackageSorting:
# A static class to presort packages into their truck
# based upon specific given constraints
# Overall complexity is O(n^2)
@staticmethod
def sort_packages(unsorted_package_list):
# Create variables to store our references
sorted_package_list = []
first_truck_load = []
second_truck_load = []
third_truck_load = []
first_truck_addresses = []
second_truck_addresses = []
addresses = AddressBook.address_reference()
# Find each item's destination ID to match the distance table
# Complexity of O(n^2)
for item in unsorted_package_list:
for index in range(len(addresses)):
if item.address == addresses[index][2]:
item.address_id = int(addresses[index][0])
# Assign each package to the correct truck
# Complexity of O(n)
for package in unsorted_package_list:
if 'Must' in package.notes or '09:00 AM' in package.deadline:
first_truck_load.append(package)
if package.address_id not in first_truck_addresses:
first_truck_addresses.append(package.address_id)
elif 'Can only' in package.notes or 'Delayed' in package.notes or '10:30 AM' in package.deadline:
if package.address_id not in second_truck_addresses:
second_truck_addresses.append(package.address_id)
second_truck_load.append(package)
elif 'Wrong' in package.notes:
third_truck_load.append(package)
for package in unsorted_package_list:
if 'EOD' in package.deadline and 'N/A' in package.notes:
if len(first_truck_load) < 16 and package.address_id in first_truck_addresses:
first_truck_load.append(package)
elif len(second_truck_load) < 16 and package.address_id in second_truck_addresses:
second_truck_load.append(package)
else:
third_truck_load.append(package)
sorted_package_list.insert(0, first_truck_load)
sorted_package_list.insert(1, second_truck_load)
sorted_package_list.insert(2, third_truck_load)
return sorted_package_list