From 13b0a4d054021b684bad87cb136da210e368096f Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Sat, 13 Feb 2016 17:59:31 +0100 Subject: [PATCH] Check if it's better to return home --- reborn.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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)