diff --git a/reborn.py b/reborn.py index 10286b2..b783a0f 100755 --- a/reborn.py +++ b/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)