Fully functionnal I guess
This commit is contained in:
parent
3fc03d19c2
commit
ae14fe0301
16
main.py
16
main.py
|
@ -87,7 +87,7 @@ for i in range(0, C):
|
||||||
for k in range(0, P):
|
for k in range(0, P):
|
||||||
orderQ[k] = 0
|
orderQ[k] = 0
|
||||||
for j in range(0, nbP):
|
for j in range(0, nbP):
|
||||||
orderQ[int(info[j])] += 1
|
orderQ[int(info[j])] += -1
|
||||||
Ci.append(orderQ)
|
Ci.append(orderQ)
|
||||||
|
|
||||||
f.close()
|
f.close()
|
||||||
|
@ -124,10 +124,10 @@ def showGrid():
|
||||||
|
|
||||||
# Utilities
|
# Utilities
|
||||||
def distance(A, B):
|
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):
|
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
|
# Actions
|
||||||
def load(d, w, p, q):
|
def load(d, w, p, q):
|
||||||
|
@ -137,7 +137,7 @@ def load(d, w, p, q):
|
||||||
Dd[d] += distance(Dp[d], Wp[w])
|
Dd[d] += distance(Dp[d], Wp[w])
|
||||||
Wi[w][p] += -q
|
Wi[w][p] += -q
|
||||||
Di[d][p] += +q
|
Di[d][p] += +q
|
||||||
assert(Wp[w][p] >= 0)
|
assert(Wi[w][p] >= 0)
|
||||||
assert(weight(d) <= M)
|
assert(weight(d) <= M)
|
||||||
assert(Dd[d] <= T)
|
assert(Dd[d] <= T)
|
||||||
print("Drone", d, "loads", q, "of", p, "from warehouse", w, "→", Dd[d])
|
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])
|
assert(Da[d])
|
||||||
if (Dp[d] != Cp[c]):
|
if (Dp[d] != Cp[c]):
|
||||||
Dd[d] += distance(Dp[d], Cp[c])
|
Dd[d] += distance(Dp[d], Cp[c])
|
||||||
Ci[w][p] += +q
|
Ci[c][p] += +q
|
||||||
Di[d][p] += -q
|
Di[d][p] += -q
|
||||||
Dd[d] += 1
|
Dd[d] += 1
|
||||||
assert(Dd[d] <= T)
|
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))
|
Out.append(str(d) + ' D ' + str(c) + ' ' + str(p) + ' ' + str(q))
|
||||||
|
|
||||||
def wait(d, w=1):
|
def wait(d, w=1):
|
||||||
assert(Da[d])
|
assert(Da[d])
|
||||||
global Dd, Da
|
global Dd, Da
|
||||||
print(Da)
|
|
||||||
Dd[d] += w
|
Dd[d] += w
|
||||||
Da[d] = False
|
Da[d] = False
|
||||||
print("Drone", d, "waits", w, "turn" + ('s' if w >= 2 else ''), "→", Dd[d])
|
print("Drone", d, "waits", w, "turn" + ('s' if w >= 2 else ''), "→", Dd[d])
|
||||||
|
@ -196,7 +195,8 @@ def end():
|
||||||
print("--- End!")
|
print("--- End!")
|
||||||
|
|
||||||
# IA
|
# IA
|
||||||
newTurn()
|
while t < 10:
|
||||||
|
newTurn()
|
||||||
|
|
||||||
# Output
|
# Output
|
||||||
f = open(sys.argv[1] + 'o', 'w')
|
f = open(sys.argv[1] + 'o', 'w')
|
||||||
|
|
Reference in a new issue