Fixing more and less important things

This commit is contained in:
Geoffrey Frogeye 2016-02-17 22:11:24 +01:00
parent e174125024
commit 5c716f0bd5

View file

@ -8,6 +8,7 @@ import progressbar
DEBUG = False DEBUG = False
outLines = [] outLines = []
differed = dict()
def log(*data): def log(*data):
if DEBUG: if DEBUG:
@ -66,6 +67,7 @@ class Warehouse:
def planUnload(self, items): def planUnload(self, items):
for i in items: for i in items:
self.plannedItems.remove(i)
self.plannedExtra.remove(i) self.plannedExtra.remove(i)
def pack(self, payload=-1, rests=[]): def pack(self, payload=-1, rests=[]):
@ -212,9 +214,17 @@ class Drone:
if (self.pos != warehouse.pos): if (self.pos != warehouse.pos):
self.busyFor(distance(self.pos, warehouse.pos)) self.busyFor(distance(self.pos, warehouse.pos))
self.pos = warehouse.pos self.pos = warehouse.pos
for q in range(qt):
warehouse.items.remove(product.id) # Differed actions
self.items.append(product.id) 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) self.busyFor(1)
assert(self.weight() <= __class__.PAYLOAD) assert(self.weight() <= __class__.PAYLOAD)
log("Drone", self.id, "loads", qt, "of", product.id, "from warehouse", warehouse.id, "", self.avail) 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): if (self.pos != warehouse.pos):
self.busyFor(distance(self.pos, warehouse.pos)) self.busyFor(distance(self.pos, warehouse.pos))
self.pos = warehouse.pos self.pos = warehouse.pos
for q in range(qt):
self.items.remove(product.id) # Differed actions
warehouse.items.append(product.id) 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) self.busyFor(1)
log("Drone", self.id, "unloads", qt, "of", product.id, "to warehouse", warehouse.id, "", self.avail) log("Drone", self.id, "unloads", qt, "of", product.id, "to warehouse", warehouse.id, "", self.avail)
output(self.id, 'U', warehouse.id, product.id, qt) output(self.id, 'U', warehouse.id, product.id, qt)
@ -325,15 +344,17 @@ def readFile(filename):
extra = warehouse.items.copy() extra = warehouse.items.copy()
for client in warehouse.clients: for client in warehouse.clients:
needs += client.needs needs += client.needs
warehouse.toDeliver = needs.copy()
for item in needs: for item in needs:
if item in extra: if item in extra:
extra.remove(item) extra.remove(item)
for item in warehouse.items: for item in warehouse.items:
if item in needs: if item in needs:
needs.remove(item) needs.remove(item)
warehouse.needs = warehouse.plannedNeeds = needs warehouse.needs = needs
warehouse.extra = warehouse.plannedExtra = extra warehouse.extra = extra
warehouse.plannedNeeds = warehouse.needs.copy()
warehouse.plannedExtra = warehouse.extra.copy()
readFile(sys.argv[1]) readFile(sys.argv[1])
def newTurn(): def newTurn():
@ -341,6 +362,9 @@ def newTurn():
# Finishing turn # Finishing turn
for drone in Drone.ALL: for drone in Drone.ALL:
drone.executeTask() drone.executeTask()
if turn in differed:
for diff in differed[turn]:
diff()
# New turn # New turn
turn += 1 turn += 1
log("--- Turn", turn) log("--- Turn", turn)
@ -359,7 +383,7 @@ def efficiency(pack, time):
def route(roadmap): def route(roadmap):
# Refill warehouse first # 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']] 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]: for warehouse in remainingWarehouses[:CLIENT_TRIES]:
pack = warehouse.pack(Drone.PAYLOAD - Product.totalWeight(roadmap['loads']), roadmap['warehouse'].plannedExtra) pack = warehouse.pack(Drone.PAYLOAD - Product.totalWeight(roadmap['loads']), roadmap['warehouse'].plannedExtra)
@ -437,6 +461,7 @@ def think():
}) })
if not roadmap['stops']: if not roadmap['stops']:
global done
done = True done = True
#if len(Client.UNSATISFIED) == 0: #if len(Client.UNSATISFIED) == 0:
# done = False # done = False
@ -456,7 +481,7 @@ def think():
if DEBUG: if DEBUG:
SIMULATION = 1000 SIMULATION = 3000
else: else:
SIMULATION = 8*T/10 SIMULATION = 8*T/10