DEADLINE STRESS YOLO
This commit is contained in:
parent
128f6100b8
commit
d30396c471
53
main.py
53
main.py
|
@ -3,6 +3,9 @@
|
||||||
import math
|
import math
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
def print(*a):
|
||||||
|
return
|
||||||
|
|
||||||
print("#hashcode2016")
|
print("#hashcode2016")
|
||||||
|
|
||||||
X = 0 # Nb rows
|
X = 0 # Nb rows
|
||||||
|
@ -135,7 +138,7 @@ def load(d, w, p, q):
|
||||||
assert(Da[d])
|
assert(Da[d])
|
||||||
if (Dp[d] != Wp[w]):
|
if (Dp[d] != Wp[w]):
|
||||||
Dd[d] += distance(Dp[d], Wp[w])
|
Dd[d] += distance(Dp[d], Wp[w])
|
||||||
Dd[d] = Cw[c]
|
Dp[d] = Wp[w]
|
||||||
Wi[w][p] += -q
|
Wi[w][p] += -q
|
||||||
Di[d][p] += +q
|
Di[d][p] += +q
|
||||||
assert(Wi[w][p] >= 0)
|
assert(Wi[w][p] >= 0)
|
||||||
|
@ -149,7 +152,7 @@ def unload(d, w, p, q):
|
||||||
assert(Da[d])
|
assert(Da[d])
|
||||||
if (Dp[d] != Wp[w]):
|
if (Dp[d] != Wp[w]):
|
||||||
Dd[d] += distance(Dp[d], Wp[w])
|
Dd[d] += distance(Dp[d], Wp[w])
|
||||||
Dd[d] = Cw[c]
|
Dp[d] = Wp[w]
|
||||||
Wi[w][p] += +q
|
Wi[w][p] += +q
|
||||||
Di[d][p] += -q
|
Di[d][p] += -q
|
||||||
assert(Dd[d] <= T)
|
assert(Dd[d] <= T)
|
||||||
|
@ -161,7 +164,7 @@ 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])
|
||||||
Dd[d] = Cp[c]
|
Dp[d] = Cp[c]
|
||||||
Ci[c][p] += +q
|
Ci[c][p] += +q
|
||||||
Di[d][p] += -q
|
Di[d][p] += -q
|
||||||
Dd[d] += 1
|
Dd[d] += 1
|
||||||
|
@ -170,8 +173,8 @@ def deliver(d, c, p, q):
|
||||||
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])
|
|
||||||
global Dd, Da
|
global Dd, Da
|
||||||
|
assert(Da[d])
|
||||||
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])
|
||||||
|
@ -219,19 +222,43 @@ def listItems(d):
|
||||||
items.append(p)
|
items.append(p)
|
||||||
return items
|
return items
|
||||||
|
|
||||||
def listNeeds():
|
N = [] # Needs
|
||||||
N = []
|
# client, product
|
||||||
# client, product
|
for c in range(C):
|
||||||
for c in range(C):
|
|
||||||
for p in range(P):
|
for p in range(P):
|
||||||
for cp in range(abs(Ci[c][p])):
|
for cp in range(abs(Ci[c][p])):
|
||||||
N.append((c, p))
|
N.append((c, p))
|
||||||
return N
|
|
||||||
|
|
||||||
|
try:
|
||||||
while t < 10:
|
while t < T:
|
||||||
N = listNeeds()
|
for d in [d for d in range(D) if Da[d]]:
|
||||||
|
for tk in Dt[d]:
|
||||||
|
c, p = tk
|
||||||
|
deliver(d, c, p, 1)
|
||||||
|
Dt[d].remove(tk)
|
||||||
|
if len([d for d in range(D) if Da[d]]) > 1:
|
||||||
|
for n in N:
|
||||||
|
c, p = n
|
||||||
|
w = nearestW(p, Cp[c])
|
||||||
|
if w != None:
|
||||||
|
minDist = math.inf;
|
||||||
|
selD = None
|
||||||
|
for d in [d for d in range(D) if Da[d] and len(listItems(d)) < 1]:
|
||||||
|
dist = distance(Dp[d], Wp[w])
|
||||||
|
if dist < minDist:
|
||||||
|
minDist = dist
|
||||||
|
print(d)
|
||||||
|
selD = d
|
||||||
|
print(244, selD)
|
||||||
|
if selD != None:
|
||||||
|
load(selD, w, p, 1)
|
||||||
|
N.remove(n)
|
||||||
|
Dt[selD].append((c, p))
|
||||||
|
else:
|
||||||
|
break
|
||||||
newTurn()
|
newTurn()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
|
||||||
# Output
|
# Output
|
||||||
f = open(sys.argv[1] + 'o', 'w')
|
f = open(sys.argv[1] + 'o', 'w')
|
||||||
|
@ -245,7 +272,7 @@ def SortCustomer():
|
||||||
CpSort.sort(key=lambda tup: tup[2])
|
CpSort.sort(key=lambda tup: tup[2])
|
||||||
|
|
||||||
def WarehouseHasItems(w, items):
|
def WarehouseHasItems(w, items):
|
||||||
for i in range(0, len(items):
|
for i in range(0, len(items)):
|
||||||
if Wi[w][items[i][0]] < items[i][1]:
|
if Wi[w][items[i][0]] < items[i][1]:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
Reference in a new issue