From 1c42ca8ccbc2f654c9a54a838e5d18a7b95e65e3 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Thu, 11 Feb 2016 19:56:36 +0100 Subject: [PATCH] Actions and functions and stuff --- main.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/main.py b/main.py index 89bb472..1dae8a5 100644 --- a/main.py +++ b/main.py @@ -13,12 +13,16 @@ P = 0 # Nb products W = 0 # Nb warehouses C = 0 # Nb customers +t = 0 # Turn + Dp = []; # Positions of drones # (x, y) Di = []; # Items of drones # {product number: qt} Dd = []; # Turn avaibility of drone # int +Da = []; # Avaibles drones +# int Pw = []; # Weight of products # int @@ -33,7 +37,65 @@ Cp = []; # Positions of customers Ci = []; # Needs of customers # {product number: qt} +# Utilities def distance(A, B): return math.ceil(sqrt(pow((B[0] - A[0], 2) + pow(B[1] - A[1], 2)))) +def weight(d): + return sum([Pw[i] for i in Di[d]]) +# Actions +def load(d, w, p, q): + # drone number, warehouse, product, qt + assert(d in Da) + if (Dp[d] != Wp[w]): + Dd[d] += distance(Dp[d], Wp[w]) + Wi[w][p] += -q + Di[d][p] += +q + assert(Wp[w][p] >= 0) + assert(weight(d) <= M) + assert(Dd[d] <= T); + print("Drone", d, "loads", q, "of", p, "from warehouse", w, "→", Dd[d]) + +def unload(d, w, p, q): + # drone number, warehouse, product, qt + assert(d in Da) + if (Dp[d] != Wp[w]): + Dd[d] += distance(Dp[d], Wp[w]) + Wi[w][p] += +q + Di[d][p] += -q + assert(Dd[d] <= T); + print("Drone", d, "unloads", q, "of", p, "from warehouse", w, "→", Dd[d]) + +def deliver(d, c, p, q): + # drone number, customer, product, qt + assert(d in Da) + if (Dp[d] != Cp[c]): + Dd[d] += distance(Dp[d], Cp[c]) + Ci[w][p] += +q + Di[d][p] += -q + Dd[d] += 1 + assert(Dd[d] <= T); + print("Drone", d, "delivers", q, "of", p, "to client", w, "→", Dd[d]) + +def wait(d, w=1): + assert(d in Da) + Dd[d] += w + print("Drone", d, "waits", w, "turn" + ('s' if w >= 2 else ''), "→", Dd[d]) + +# Control +def newTurn(): + t += 1 + print("--- Turn", t) + for d in Da: + wait(d) + assert(Da.len == 0) + for d in range(D): + if Dd[d] <= t: + Da.push(d) + print("Drones", ", ".join(Da), "(", len(Da), ")", "are avaible") + +def end(): + print("--- End!") + +# IA