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