Fix assignment

This commit is contained in:
2026-01-13 18:07:01 -08:00
parent 2301ac357e
commit 83b520d2e2
10 changed files with 55 additions and 22 deletions
+19 -11
View File
@@ -38,14 +38,17 @@ class Truck:
pkgMins = offsetMinutes % 60 # pull minutes back out
return datetime.time(pkgHours, pkgMins) # return the time of day
def deliverPkgs(self): # Delivers any packeges that match the current location
def deliverPkgs(self): # Delivers any packeges that match the current location
for i in range(len(self.packages) - 1, -1, -1): # Loop backwards so removals dont index shift
if self.packages[i].address in self.current_location: # Check if the package is at the correct address
self.packages[i].status = deliveryStatus.DELIVERED # Mark as delivered
self.packages[i].timeEnd = self.getTimeOfDay() # Mark the delivered time
self.deliveryCounter += 1 # Incriment the delivery counter
self.packages[i].deliveryNumber = self.deliveryCounter # Mark the package number
self.packages.remove(self.packages[i]) # Remove the package from the truck
pkg = self.packages[i]
if pkg.address in self.current_location: # Check if the package is at the correct address
if ("Wrong address listed" not in pkg.notes or
self.getTimeOfDay() >= datetime.time(10, 30)): # Wait for corrected shipping address
pkg.status = deliveryStatus.DELIVERED # Mark as delivered
pkg.timeEnd = self.getTimeOfDay() # Mark the delivered time
self.deliveryCounter += 1 # Incriment the delivery counter
pkg.deliveryNumber = self.deliveryCounter # Mark the package number
self.packages.pop(i)
def getMatrixIndex(self, address_string: str) -> int: # Helper function to get x or y offset in the distance table
for i, full_name in enumerate(AssignmentData.xyNames2): # Loop through the names in the list
@@ -57,19 +60,25 @@ class Truck:
print(f"Address {address_string} is not in Full List") # Report items not found in the list
return 0 # Default to Hub if not found
def driveNextClosest(self, priority: DerekHashTable) -> int: # The bread and butter of the algorithm
def driveNextClosest(self, priority: DerekHashTable) -> datetime.time: # The bread and butter of the algorithm
# deal with priority
priorityPkgs = [] # set the packages we currently want to look for
for cur in self.packages: # loop thorugh looking for priority matches
if priority.getItem(cur.id):
priorityPkgs.append(cur) # if a priority matches add it to the list
if not priorityPkgs: # if no priority matches just use the normal
priorityPkgs = self.packages
for v in self.packages:
if ("Wrong address listed" not in v.notes or # If the package is marked wrong address
self.getTimeOfDay() >= datetime.time(10, 30)): # Wait for corrected shipping address
priorityPkgs.append(v) # add to the list
# get the next closest
shortest_dist = float('inf') # Start with a very long distance to work backwards from
next_pkg = None # Keep track of the closest pkg
if len(priorityPkgs) == 0:
priorityPkgs.append(DeliveryObject(-1, "HUB", "", "", 0, "10:30 AM", 21),) # Add a blank package in order to get the truck to drive back to HUB
current_idx = self.getMatrixIndex(self.current_location) # Get the trucks xyIndex
for pkg in priorityPkgs: # Loop through the packages
dest_idx = self.getMatrixIndex(pkg.address) # Get the package xyIndex
@@ -87,5 +96,4 @@ class Truck:
self.current_location = next_pkg.address # update the location
self.deliverPkgs() # deliver packages at this location
if len(self.packages) == 0: # if there is no packages
self.hasLoad = False # Set the load to empty
return len(self.packages) # return packages left to deliver
self.hasLoad = False # Set the load to empty