Example #1
0
 def find_a_way(self, truck: Truck):
     """
     finds the shortest route along the stops from truck in O(N^2) time
     :param truck: truck with stops to make
     :return: the list of locations and the total distance traveled by the truck
     """
     stops = list(truck.cargo.keys())
     current = self.center  # start at the Hub
     the_way = [current]
     distance = 0.0
     while stops:
         result = self.nearest_neighbor(stops, current)
         distance += result[1]
         the_way.append(result[0])
         current = stops.pop(0)
         packages = truck.unload_package(current)
         delivery_time = Package.get_delivery_time(distance, truck.speed,
                                                   truck.depart_at)
         for pkg_id in packages:
             pkg = self.database.look_up(pkg_id)
             pkg.delivery_status = "Delivered"
             pkg.delivery_time = delivery_time
     distance += self.destinations.get_distance(
         the_way[-1], self.center)  # return to the Hub
     truck.depart_at = Package.get_delivery_time(distance, truck.speed,
                                                 truck.depart_at)
     return the_way, distance
Example #2
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"