Check if it's better to return home

This commit is contained in:
Geoffrey Frogeye 2016-02-13 17:59:31 +01:00
parent 84e72a46c8
commit 13b0a4d054

View file

@ -297,10 +297,22 @@ def route(roadmap):
pack = client.pack(Drone.PAYLOAD - Product.totalWeight(roadmap['loads'])) pack = client.pack(Drone.PAYLOAD - Product.totalWeight(roadmap['loads']))
if not pack: if not pack:
continue continue
routeTime = distance(roadmap['pos'], client.pos) + len(list(set(pack)))
if roadmap['stops']:
# Efficiency of a travel = number of items carried / time of travel
# Calcultes the efficiency of adding a stop
routeEfficiency = Product.totalWeight(pack) / routeTime
# Calculates the efficiency of coming back to warehouse and to the client again
backTime = distance(roadmap['pos'], roadmap['warehouse'].pos) + distance(roadmap['warehouse'].pos, client.pos)
backEfficiency = Product.totalWeight(client.pack()) / backTime
if backEfficiency > routeEfficiency:
continue
# Plan the delivery # Plan the delivery
roadmap['warehouse'].plan(pack) roadmap['warehouse'].plan(pack)
client.plan(pack) client.plan(pack)
roadmap['deliverTime'] += distance(roadmap['pos'], client.pos) + len(list(set(pack))) roadmap['deliverTime'] += routeTime
roadmap['pos'] = client.pos roadmap['pos'] = client.pos
roadmap['loads'] += pack roadmap['loads'] += pack
roadmap['clients'].append(client) roadmap['clients'].append(client)