Fixed regressions

But not better.

Note to myself: when sorting different options by efficiency,
don't take the WORST one...
This commit is contained in:
Geoffrey Frogeye 2016-02-13 18:51:47 +01:00
parent 3509d21856
commit 9b5920eedb

View file

@ -287,7 +287,14 @@ 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
# 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): 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']]
@ -299,15 +306,14 @@ def route(roadmap):
if not pack: if not pack:
continue continue
# Efficiency of a travel = number of items carried / time of travel
# Calcultes the efficiency of adding a stop # Calcultes the efficiency of adding a stop
routeTime = distance(roadmap['pos'], client.pos) + len(list(set(pack))) routeTime = distance(roadmap['pos'], client.pos) + len(list(set(pack)))
routeEfficiency = len(pack) / routeTime routeEfficiency = efficiency(pack, routeTime)
if roadmap['stops']: if roadmap['stops']:
# Calculates the efficiency of coming back to warehouse and to the client again # Calculates the efficiency of coming back to warehouse and to the client again
backPack = client.pack() backPack = client.pack()
backTime = len(list(set(backPack))) + distance(roadmap['pos'], roadmap['warehouse'].pos) + distance(roadmap['warehouse'].pos, client.pos) 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: if backEfficiency > routeEfficiency:
continue continue
options.append({ options.append({
@ -319,7 +325,8 @@ def route(roadmap):
if options: if options:
# Choose the best option (i.e. the max efficiency) # 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 # Plan the delivery
roadmap['warehouse'].plan(option['pack']) roadmap['warehouse'].plan(option['pack'])
option['client'].plan(option['pack']) option['client'].plan(option['pack'])