diff --git a/reborn.py b/reborn.py index 04b04f7..6013a34 100755 --- a/reborn.py +++ b/reborn.py @@ -287,7 +287,14 @@ def newTurn(): #log("Drones", ", ".join(availableDrones), "("+str(len(availableDrones))+")", "are available") # Algorithm that only works for 1 warehouse -CLIENT_TRIES = 3 # Determined by trial and error. Not really reliable + +# Determined by trial and error. Not really reliable +CLIENT_TRIES = 3 +def efficiency(pack, time): + return Product.totalWeight(pack) / time + #return len(pack) / time + #return 1 / time + def route(roadmap): # 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']] @@ -299,15 +306,14 @@ def route(roadmap): if not pack: continue - # Efficiency of a travel = number of items carried / time of travel # Calcultes the efficiency of adding a stop routeTime = distance(roadmap['pos'], client.pos) + len(list(set(pack))) - routeEfficiency = len(pack) / routeTime + routeEfficiency = efficiency(pack, routeTime) if roadmap['stops']: # Calculates the efficiency of coming back to warehouse and to the client again backPack = client.pack() backTime = len(list(set(backPack))) + distance(roadmap['pos'], roadmap['warehouse'].pos) + distance(roadmap['warehouse'].pos, client.pos) - backEfficiency = len(backPack) / backTime + backEfficiency = efficiency(backPack, backTime) if backEfficiency > routeEfficiency: continue options.append({ @@ -319,7 +325,8 @@ def route(roadmap): if options: # Choose the best option (i.e. the max efficiency) - option = sorted(options, key=lambda c: c['efficiency'])[0] + #option = sorted(options, key=lambda c: c['efficiency'])[-1] + option = options[0] # Plan the delivery roadmap['warehouse'].plan(option['pack']) option['client'].plan(option['pack'])