Beispiel #1
0
 def load_delayed_truck(self, truck: Truck, has_deadline=True):
     """
     Loads a truck with delayed packages
     :param truck:
     :param has_deadline:
     :return:
     """
     for pkg in self.database.table:
         if truck.not_full() is False:
             break
         if pkg.delivery_status != "At Hub":
             continue
         if has_deadline:
             if pkg.deadline == "EOD":
                 continue
         if pkg.special_notes.__contains__("Delayed"):
             delay = pkg.special_notes[-8:]
             later_time = pkg.calculate_deadline(delay)
             depart_time = Package.calculate_deadline(truck.depart_at)
             if later_time > depart_time:
                 truck.depart_at = delay
             if truck.load_package(
                     pkg.pkg_id,
                     self.destinations.get_location(pkg.address)):
                 pkg.delivery_status = "In Route"
Beispiel #2
0
 def load_any_truck_(self, truck: Truck):
     """
     Loads the next available package from hash table onto the truck.
     :param truck:Truck
     :return:None
     """
     for pkg in self.database.table:
         if truck.not_full() is False:
             break
         if pkg.delivery_status != "At Hub":
             continue
         if truck.load_package(pkg.pkg_id,
                               self.destinations.get_location(pkg.address)):
             pkg.delivery_status = "In Route"
Beispiel #3
0
 def load_forced_group(self, truck: Truck):
     """
     Loads packages that must be delivered together.
     :param truck:Truck
     :return:None
     """
     for pkg in self.database.table:
         if truck.not_full() is False:
             break
         if pkg.delivery_status != "At Hub":
             continue
         if pkg.special_notes.endswith('Must', 0, 4):
             if truck.load_package(
                     pkg.pkg_id,
                     self.destinations.get_location(pkg.address)):
                 pkg.delivery_status = "In Route"
                 group = pkg.special_notes.strip(
                     'Must be delivered with ').split(',')
                 for pair in group:
                     pkg_match = self.database.look_up(int(pair))
                     destination = self.destinations.get_location(
                         pkg_match.address)
                     truck.load_package(int(pair), destination)
                     pkg_match.delivery_status = "In Route"
Beispiel #4
0
 def load_same_stop_truck(self, truck: Truck):
     """
     Loads packages with delivery addresses that the truck is already going to.
     :param truck:Truck
     :return:None
     """
     for pkg in self.database.table:
         if truck.not_full() is False:
             break
         if pkg.delivery_status != "At Hub":
             continue
         pkg_location = self.destinations.get_location(pkg.address)
         if pkg_location in truck.cargo.keys():
             if truck.load_package(pkg.pkg_id, pkg_location):
                 pkg.delivery_status = "In Route"
Beispiel #5
0
 def load_truck_2(self, truck: Truck):
     """
     Loads all packages that must be on truck 2.
     :param truck:Truck
     :return:None
     """
     for pkg in self.database.table:
         if truck.not_full() is False:
             break
         if pkg.delivery_status != "At Hub":
             continue
         if pkg.special_notes.endswith('truck 2'):
             if truck.load_package(
                     pkg.pkg_id,
                     self.destinations.get_location(pkg.address)):
                 pkg.delivery_status = "In Route"
Beispiel #6
0
 def load_zip_code_truck(self, truck: Truck):
     """
     Loads packages with similar zip_codes onto the given truck.
     :param truck:Truck
     :return:None
     """
     zip_code_locations = self.destinations.get_zip_code_matches(
         truck.cargo.keys())
     for pkg in self.database.table:
         if truck.not_full() is False:
             break
         if pkg.delivery_status != "At Hub":
             continue
         pkg_location = self.destinations.get_location(pkg.address)
         if pkg_location in zip_code_locations:
             if truck.load_package(pkg.pkg_id, pkg_location):
                 pkg.delivery_status = "In Route"
Beispiel #7
0
 def load_early_truck(self, truck: Truck):
     """
     Load truck with packages that have deadlines before 10:30 AM.
     :param truck:
     :return:
     """
     for pkg in self.database.table:
         if truck.not_full() is False:
             break
         if pkg.delivery_status != "At Hub":
             continue
         if len(pkg.special_notes) > 1:
             continue
         if pkg.calculate_deadline(pkg.deadline) <= 10.5:
             if truck.load_package(
                     pkg.pkg_id,
                     self.destinations.get_location(pkg.address)):
                 pkg.delivery_status = "In Route"
Beispiel #8
0
    # late packages will hit the hub at this time
    late_package_ready_time = datetime.strptime("09:05 AM", TIME_FORMAT)

    # What time the addresses will be expected to be fixed on the packages
    wrong_address_fix_time = datetime.strptime("10:20 AM", TIME_FORMAT)

    # Main Loop for package delivery
    truck_1.current_time = start_time
    truck_2.current_time = start_time

    # counts packages being delivered
    total_packages_delivered = 0

    # Load Packages onto truck
    for i in truck_1_packages:  # O(16)
        truck_1.load_package(i)
    for i in truck_2_packages:  # O(16)
        truck_2.load_package(i)
    # bool to check if the late packages have been picked up
    late_packages_picked_up = False

    # bool to check if all packages have been delivered to break out of the loop
    all_delivered = False

    while (
            not all_delivered
    ):  # SpaceTime Complexity: O(n^3) - This will deliver all packages throughout the while loop and subsequent for loops
        # for updating the wrong address listed packages and adding them to the avail
        #O(1) + O(1) + O(1)
        if wrong_packages and (truck_1.current_time >= wrong_address_fix_time
                               and