Check if it's better to return home
This commit is contained in:
parent
84e72a46c8
commit
13b0a4d054
14
reborn.py
14
reborn.py
|
@ -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)
|
||||
|
|
Reference in a new issue