Fixing more and less important things
This commit is contained in:
parent
e174125024
commit
5c716f0bd5
35
reborn.py
35
reborn.py
|
@ -8,6 +8,7 @@ import progressbar
|
|||
DEBUG = False
|
||||
|
||||
outLines = []
|
||||
differed = dict()
|
||||
|
||||
def log(*data):
|
||||
if DEBUG:
|
||||
|
@ -66,6 +67,7 @@ class Warehouse:
|
|||
|
||||
def planUnload(self, items):
|
||||
for i in items:
|
||||
self.plannedItems.remove(i)
|
||||
self.plannedExtra.remove(i)
|
||||
|
||||
def pack(self, payload=-1, rests=[]):
|
||||
|
@ -212,9 +214,17 @@ class Drone:
|
|||
if (self.pos != warehouse.pos):
|
||||
self.busyFor(distance(self.pos, warehouse.pos))
|
||||
self.pos = warehouse.pos
|
||||
|
||||
# Differed actions
|
||||
def diff():
|
||||
for q in range(qt):
|
||||
warehouse.items.remove(product.id)
|
||||
self.items.append(product.id)
|
||||
global differed
|
||||
if self.avail not in differed:
|
||||
differed[self.avail] = []
|
||||
differed[self.avail].append(diff)
|
||||
|
||||
self.busyFor(1)
|
||||
assert(self.weight() <= __class__.PAYLOAD)
|
||||
log("Drone", self.id, "loads", qt, "of", product.id, "from warehouse", warehouse.id, "→", self.avail)
|
||||
|
@ -225,9 +235,18 @@ class Drone:
|
|||
if (self.pos != warehouse.pos):
|
||||
self.busyFor(distance(self.pos, warehouse.pos))
|
||||
self.pos = warehouse.pos
|
||||
|
||||
# Differed actions
|
||||
def diff():
|
||||
for q in range(qt):
|
||||
self.items.remove(product.id)
|
||||
warehouse.items.append(product.id)
|
||||
warehouse.plannedItems.append(product.id)
|
||||
global differed
|
||||
if self.avail not in differed:
|
||||
differed[self.avail] = []
|
||||
differed[self.avail].append(diff)
|
||||
|
||||
self.busyFor(1)
|
||||
log("Drone", self.id, "unloads", qt, "of", product.id, "to warehouse", warehouse.id, "→", self.avail)
|
||||
output(self.id, 'U', warehouse.id, product.id, qt)
|
||||
|
@ -325,15 +344,17 @@ def readFile(filename):
|
|||
extra = warehouse.items.copy()
|
||||
for client in warehouse.clients:
|
||||
needs += client.needs
|
||||
warehouse.toDeliver = needs.copy()
|
||||
for item in needs:
|
||||
if item in extra:
|
||||
extra.remove(item)
|
||||
for item in warehouse.items:
|
||||
if item in needs:
|
||||
needs.remove(item)
|
||||
warehouse.needs = warehouse.plannedNeeds = needs
|
||||
warehouse.extra = warehouse.plannedExtra = extra
|
||||
|
||||
warehouse.needs = needs
|
||||
warehouse.extra = extra
|
||||
warehouse.plannedNeeds = warehouse.needs.copy()
|
||||
warehouse.plannedExtra = warehouse.extra.copy()
|
||||
readFile(sys.argv[1])
|
||||
|
||||
def newTurn():
|
||||
|
@ -341,6 +362,9 @@ def newTurn():
|
|||
# Finishing turn
|
||||
for drone in Drone.ALL:
|
||||
drone.executeTask()
|
||||
if turn in differed:
|
||||
for diff in differed[turn]:
|
||||
diff()
|
||||
# New turn
|
||||
turn += 1
|
||||
log("--- Turn", turn)
|
||||
|
@ -359,7 +383,7 @@ def efficiency(pack, time):
|
|||
|
||||
def route(roadmap):
|
||||
# Refill warehouse first
|
||||
# TODO Merge both (this is actually more for testin.idg)
|
||||
# TODO Merge both (this is actually more for testing)
|
||||
remainingWarehouses = [w for w in Warehouse.near(roadmap['pos']) if w.plannedNeeds and w not in roadmap['clients'] and w != roadmap['warehouse']]
|
||||
for warehouse in remainingWarehouses[:CLIENT_TRIES]:
|
||||
pack = warehouse.pack(Drone.PAYLOAD - Product.totalWeight(roadmap['loads']), roadmap['warehouse'].plannedExtra)
|
||||
|
@ -437,6 +461,7 @@ def think():
|
|||
})
|
||||
|
||||
if not roadmap['stops']:
|
||||
global done
|
||||
done = True
|
||||
#if len(Client.UNSATISFIED) == 0:
|
||||
# done = False
|
||||
|
@ -456,7 +481,7 @@ def think():
|
|||
|
||||
|
||||
if DEBUG:
|
||||
SIMULATION = 1000
|
||||
SIMULATION = 3000
|
||||
else:
|
||||
SIMULATION = 8*T/10
|
||||
|
||||
|
|
Reference in a new issue