Check if it's better to return home

master
Geoffrey Frogeye 2016-02-13 17:59:31 +01:00
parent 84e72a46c8
commit 13b0a4d054
1 changed files with 13 additions and 1 deletions

View File

@ -297,10 +297,22 @@ def route(roadmap):
pack = client.pack(Drone.PAYLOAD - Product.totalWeight(roadmap['loads']))
if not pack:
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
roadmap['warehouse'].plan(pack)
client.plan(pack)
roadmap['deliverTime'] += distance(roadmap['pos'], client.pos) + len(list(set(pack)))
roadmap['deliverTime'] += routeTime
roadmap['pos'] = client.pos
roadmap['loads'] += pack
roadmap['clients'].append(client)