Tries 3 different clients
This commit is contained in:
parent
6bd43ed2ad
commit
0d8cd171bb
|
@ -287,15 +287,16 @@ def newTurn():
|
||||||
#log("Drones", ", ".join(availableDrones), "("+str(len(availableDrones))+")", "are available")
|
#log("Drones", ", ".join(availableDrones), "("+str(len(availableDrones))+")", "are available")
|
||||||
|
|
||||||
# Algorithm that only works for 1 warehouse
|
# Algorithm that only works for 1 warehouse
|
||||||
|
CLIENT_TRIES = 3 # Determined by trial and error. Not really reliable
|
||||||
def route(roadmap):
|
def route(roadmap):
|
||||||
# Find the nearest client that still has things to be delivered
|
# Find the nearest client that still has things to be delivered
|
||||||
remainingClients = [c for c in Client.near(roadmap['pos']) if c.plannedNeeds and c not in roadmap['clients']]
|
remainingClients = [c for c in Client.near(roadmap['pos']) if c.plannedNeeds and c not in roadmap['clients']]
|
||||||
if remainingClients:
|
#for client in remainingClients:
|
||||||
client = remainingClients[0]
|
for client in remainingClients[:CLIENT_TRIES]:
|
||||||
# Create a pack to deliver
|
# Create a pack to deliver
|
||||||
pack = client.pack(Drone.PAYLOAD - Product.totalWeight(roadmap['loads']))
|
pack = client.pack(Drone.PAYLOAD - Product.totalWeight(roadmap['loads']))
|
||||||
if not pack:
|
if not pack:
|
||||||
return roadmap
|
continue
|
||||||
# Plan the delivery
|
# Plan the delivery
|
||||||
roadmap['warehouse'].plan(pack)
|
roadmap['warehouse'].plan(pack)
|
||||||
client.plan(pack)
|
client.plan(pack)
|
||||||
|
@ -305,7 +306,6 @@ def route(roadmap):
|
||||||
roadmap['clients'].append(client)
|
roadmap['clients'].append(client)
|
||||||
roadmap['stops'].append((client, pack))
|
roadmap['stops'].append((client, pack))
|
||||||
return route(roadmap)
|
return route(roadmap)
|
||||||
else:
|
|
||||||
return roadmap
|
return roadmap
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue