Fully functionnal I guess

This commit is contained in:
Geoffrey Frogeye 2016-02-11 21:24:25 +01:00
parent 3fc03d19c2
commit ae14fe0301

16
main.py
View file

@ -87,7 +87,7 @@ for i in range(0, C):
for k in range(0, P):
orderQ[k] = 0
for j in range(0, nbP):
orderQ[int(info[j])] += 1
orderQ[int(info[j])] += -1
Ci.append(orderQ)
f.close()
@ -124,10 +124,10 @@ def showGrid():
# Utilities
def distance(A, B):
return math.ceil(sqrt(pow((B[0] - A[0], 2) + pow(B[1] - A[1], 2))))
return math.ceil(math.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]])
return sum(Di[d][p]*Pw[p]for p in range(P))
# Actions
def load(d, w, p, q):
@ -137,7 +137,7 @@ def load(d, w, p, q):
Dd[d] += distance(Dp[d], Wp[w])
Wi[w][p] += -q
Di[d][p] += +q
assert(Wp[w][p] >= 0)
assert(Wi[w][p] >= 0)
assert(weight(d) <= M)
assert(Dd[d] <= T)
print("Drone", d, "loads", q, "of", p, "from warehouse", w, "", Dd[d])
@ -159,17 +159,16 @@ def deliver(d, c, p, q):
assert(Da[d])
if (Dp[d] != Cp[c]):
Dd[d] += distance(Dp[d], Cp[c])
Ci[w][p] += +q
Ci[c][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])
print("Drone", d, "delivers", q, "of", p, "to client", c, "", Dd[d])
Out.append(str(d) + ' D ' + str(c) + ' ' + str(p) + ' ' + str(q))
def wait(d, w=1):
assert(Da[d])
global Dd, Da
print(Da)
Dd[d] += w
Da[d] = False
print("Drone", d, "waits", w, "turn" + ('s' if w >= 2 else ''), "", Dd[d])
@ -196,7 +195,8 @@ def end():
print("--- End!")
# IA
newTurn()
while t < 10:
newTurn()
# Output
f = open(sys.argv[1] + 'o', 'w')