Cache unsatisfied clients
This commit is contained in:
parent
8f1970c127
commit
f7246fa3b7
16
reborn.py
16
reborn.py
|
@ -5,7 +5,7 @@ import math
|
|||
import copy
|
||||
import progressbar
|
||||
|
||||
DEBUG = False
|
||||
DEBUG = True
|
||||
|
||||
outLines = []
|
||||
|
||||
|
@ -75,10 +75,12 @@ class Warehouse:
|
|||
class Client:
|
||||
|
||||
ALL = []
|
||||
UNSATISFIED = []
|
||||
|
||||
def __init__(self, pos, needs):
|
||||
self.id = len(self.ALL)
|
||||
self.ALL.append(self)
|
||||
self.UNSATISFIED.append(self)
|
||||
|
||||
self.pos = pos
|
||||
self.needs = needs
|
||||
|
@ -121,7 +123,7 @@ class Client:
|
|||
# Set functions
|
||||
def near(pos):
|
||||
couples = []
|
||||
for el in __class__.ALL:
|
||||
for el in __class__.UNSATISFIED:
|
||||
couples.append([el, distance(el.pos, pos)])
|
||||
return [couple[0] for couple in sorted(couples, key=lambda c: c[1])]
|
||||
|
||||
|
@ -207,6 +209,7 @@ class Drone:
|
|||
if client.satisfied():
|
||||
global score
|
||||
score += math.ceil((T-(self.avail+1))/T*100)
|
||||
Client.UNSATISFIED.remove(client)
|
||||
log("Client", client.id, "satisfied!", "New score:", score)
|
||||
|
||||
def wait(self, turns=1):
|
||||
|
@ -366,8 +369,11 @@ def think():
|
|||
})
|
||||
|
||||
if not roadmap['stops']:
|
||||
global done
|
||||
done = True
|
||||
if len(Client.UNSATISFIED) == 0:
|
||||
done = False
|
||||
break
|
||||
if done:
|
||||
break
|
||||
|
||||
loadOcc = dict((i, roadmap['loads'].count(i)) for i in roadmap['loads'])
|
||||
|
@ -396,8 +402,8 @@ try:
|
|||
bar.update(turn)
|
||||
while turn < SIMULATION and [d for d in Drone.ALL if d.tasks]:
|
||||
newTurn()
|
||||
if not DEBUG:
|
||||
bar.update(turn)
|
||||
#if not DEBUG:
|
||||
# bar.update(turn)
|
||||
if not DEBUG:
|
||||
bar.finish()
|
||||
|
||||
|
|
Reference in a new issue