Now functionnal

This commit is contained in:
Geoffrey Frogeye 2016-02-11 21:00:42 +01:00
parent c56e442d29
commit f0de43a61d

35
main.py
View file

@ -14,7 +14,7 @@ P = 0 # Nb products
W = 0 # Nb warehouses
C = 0 # Nb customers
t = -1 # Turn
t = 0 # Turn
Dp = [] # Positions of drones
# (x, y)
@ -23,7 +23,7 @@ Di = [] # Items of drones
Dd = [] # Turn avaibility of drone
# int
Da = [] # Avaibles drones
# int
# bool
Pw = [] # Weight of products
# int
@ -97,12 +97,13 @@ for d in range(D):
Dp.append(Wp[0])
Di.append(dict((p, 0) for p in range(P)))
Dd.append(0)
Da.append(True)
Out = [] # Drones commands
# Debug
assert(len(Dp) == len(Di) == len(Dd) == D)
assert(len(Dp) == len(Di) == len(Dd) == len(Da) == D)
assert(len(Pw) == P)
assert(len(Wp) == len(Wi) == W)
assert(len(Cp) == len(Ci) == C)
@ -131,7 +132,7 @@ def weight(d):
# Actions
def load(d, w, p, q):
# drone number, warehouse, product, qt
assert(d in Da)
assert(Da[d])
if (Dp[d] != Wp[w]):
Dd[d] += distance(Dp[d], Wp[w])
Wi[w][p] += -q
@ -143,7 +144,7 @@ def load(d, w, p, q):
def unload(d, w, p, q):
# drone number, warehouse, product, qt
assert(d in Da)
assert(Da[d])
if (Dp[d] != Wp[w]):
Dd[d] += distance(Dp[d], Wp[w])
Wi[w][p] += +q
@ -153,7 +154,7 @@ def unload(d, w, p, q):
def deliver(d, c, p, q):
# drone number, customer, product, qt
assert(d in Da)
assert(Da[d])
if (Dp[d] != Cp[c]):
Dd[d] += distance(Dp[d], Cp[c])
Ci[w][p] += +q
@ -163,9 +164,11 @@ def deliver(d, c, p, q):
print("Drone", d, "delivers", q, "of", p, "to client", w, "", Dd[d])
def wait(d, w=1):
assert(d in Da)
assert(Da[d])
global Dd, Da
print(Da)
Dd[d] += w
Da.remove(d)
Da[d] = False
print("Drone", d, "waits", w, "turn" + ('s' if w >= 2 else ''), "", Dd[d])
Out.append(str(d) + ' W ' + str(w))
@ -173,24 +176,26 @@ def wait(d, w=1):
# Control
def newTurn():
global t
# Finishing turn
for d in [d for d in range(len(Da)) if Da[d]]:
print(d)
wait(d)
assert(sum(Da) == 0)
# New turn
t += 1
print("--- Turn", t)
for d in Da:
wait(d)
assert(len(Da) == 0)
for d in range(D):
if Dd[d] <= t:
Da.append(d)
print("Drones", ", ".join([str(d) for d in Da]), "(", len(Da), ")", "are avaible")
Da[d] = True
print("Drones", ", ".join([str(d) for d in range(len(Da)) if Da[d]]), "(", len(Da), ")", "are avaible")
def end():
print("--- End!")
# IA
newTurn()
newTurn()
# Output
f = open(sys.argv[1] + 'o', 'w')
f.write(str(len(Out)) + '\n' + '\n'.join(Out))
f.write(str(len(Out)) + '\n' + '\n'.join(Out) + '\n')
f.close()