DEADLINE STRESS YOLO

This commit is contained in:
Geoffrey Frogeye 2016-02-11 22:27:01 +01:00
parent 128f6100b8
commit d30396c471

61
main.py
View file

@ -3,6 +3,9 @@
import math
import sys
def print(*a):
return
print("#hashcode2016")
X = 0 # Nb rows
@ -135,7 +138,7 @@ def load(d, w, p, q):
assert(Da[d])
if (Dp[d] != Wp[w]):
Dd[d] += distance(Dp[d], Wp[w])
Dd[d] = Cw[c]
Dp[d] = Wp[w]
Wi[w][p] += -q
Di[d][p] += +q
assert(Wi[w][p] >= 0)
@ -149,7 +152,7 @@ def unload(d, w, p, q):
assert(Da[d])
if (Dp[d] != Wp[w]):
Dd[d] += distance(Dp[d], Wp[w])
Dd[d] = Cw[c]
Dp[d] = Wp[w]
Wi[w][p] += +q
Di[d][p] += -q
assert(Dd[d] <= T)
@ -161,7 +164,7 @@ def deliver(d, c, p, q):
assert(Da[d])
if (Dp[d] != Cp[c]):
Dd[d] += distance(Dp[d], Cp[c])
Dd[d] = Cp[c]
Dp[d] = Cp[c]
Ci[c][p] += +q
Di[d][p] += -q
Dd[d] += 1
@ -170,8 +173,8 @@ def deliver(d, c, p, q):
Out.append(str(d) + ' D ' + str(c) + ' ' + str(p) + ' ' + str(q))
def wait(d, w=1):
assert(Da[d])
global Dd, Da
assert(Da[d])
Dd[d] += w
Da[d] = False
print("Drone", d, "waits", w, "turn" + ('s' if w >= 2 else ''), "", Dd[d])
@ -219,19 +222,43 @@ def listItems(d):
items.append(p)
return items
def listNeeds():
N = []
# client, product
for c in range(C):
for p in range(P):
for cp in range(abs(Ci[c][p])):
N.append((c, p))
return N
N = [] # Needs
# client, product
for c in range(C):
for p in range(P):
for cp in range(abs(Ci[c][p])):
N.append((c, p))
while t < 10:
N = listNeeds()
newTurn()
try:
while t < T:
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()
except KeyboardInterrupt:
pass
# Output
f = open(sys.argv[1] + 'o', 'w')
@ -245,7 +272,7 @@ def SortCustomer():
CpSort.sort(key=lambda tup: tup[2])
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]:
return False
return True