bug fix in Router

parent 4efc0af2
...@@ -186,46 +186,45 @@ class Router(ObjectInterruption): ...@@ -186,46 +186,45 @@ class Router(ObjectInterruption):
entitiesWithOccupiedReceivers=[] entitiesWithOccupiedReceivers=[]
for operator in [x for x in candidateOperators if x.candidateEntities]: for operator in [x for x in candidateOperators if x.candidateEntities]:
operator.sortCandidateEntities(operator.candidateEntities) operator.sortCandidateEntities(operator.candidateEntities)
noAvailableReceivers=False operator.noAvailableReceivers=False
while not noAvailableReceivers: # while not operator.noAvailableReceivers:
availableEntity=next(x for x in operator.candidateEntities if not x in entitiesWithOccupiedReceivers) availableEntity=next(x for x in operator.candidateEntities if not x in entitiesWithOccupiedReceivers)
if availableEntity: if availableEntity:
operator.candidateEntity=availableEntity operator.candidateEntity=availableEntity
#======================================================= #=======================================================
# # TESTING # # TESTING
# print ' the candidate receivers for', operator.candidateEntity.id, 'are',\ # print ' the candidate receivers for', operator.candidateEntity.id, 'are',\
# [str(x.id) for x in operator.candidateEntity.candidateReceivers] # [str(x.id) for x in operator.candidateEntity.candidateReceivers],
#======================================================= #=======================================================
availableReceivers=[x for x in operator.candidateEntity.candidateReceivers\ availableReceivers=[x for x in operator.candidateEntity.candidateReceivers\
if not x in occupiedReceivers] if not x in occupiedReceivers]
if availableReceivers: if availableReceivers:
# TODO: must find the receiver that waits the most # TODO: must find the receiver that waits the most
maxTimeWaiting=0 maxTimeWaiting=0
for object in availableReceivers: for object in availableReceivers:
timeWaiting=now()-object.timeLastEntityLeft timeWaiting=now()-object.timeLastEntityLeft
if(timeWaiting>maxTimeWaiting or maxTimeWaiting==0): if(timeWaiting>maxTimeWaiting or maxTimeWaiting==0):
maxTimeWaiting=timeWaiting maxTimeWaiting=timeWaiting
availableReceiver=object availableReceiver=object
# availableReceiver=availableReceivers[0]
# print ' after', operator.candidateEntity.candidateReceiver=availableReceiver
# print availableReceiver.id occupiedReceivers.append(availableReceiver)
operator.candidateEntity.candidateReceiver=availableReceiver operator.noAvailableReceivers=True
occupiedReceivers.append(availableReceiver) else:
noAvailableReceivers=True entitiesWithOccupiedReceivers.append(availableEntity)
else: operator.candidateEntity.candidateReceiver=None
entitiesWithOccupiedReceivers.append(availableEntity)
#=================================================================== #===================================================================
# # TESTING # # TESTING
# print ' +{}+ candidate operators :',[str(x.id) for x in candidateOperators if x.candidateEntity] # print ' +{}+ candidate operators :',[str(x.id) for x in candidateOperators if x.candidateEntity]
# print ' +{}+ have entities :',[str(x.candidateEntity.id) for x in candidateOperators if x.candidateEntity] # print ' +{}+ have entities :',[str(x.candidateEntity.id) for x in candidateOperators if x.candidateEntity]
# print ' +{}+ with receivers :',[str(x.candidateEntity.candidateReceiver.id) for x in candidateOperators if x.candidateEntity] # print ' +{}+ with receivers :',[str(x.candidateEntity.candidateReceiver.id) for x in candidateOperators if x.candidateEntity and not x.candidateEntity in entitiesWithOccupiedReceivers]
#=================================================================== #===================================================================
pendingObjectsMustBeSorted=False pendingObjectsMustBeSorted=False
for operator in [x for x in candidateOperators if x.candidateEntity]: for operator in [x for x in candidateOperators if x.candidateEntity]:
operator.called = (operator in self.calledOperators) operator.called = (operator in self.calledOperators)
# print operator.id, 'is called?', operator.called
if not operator.called: if not operator.called:
operator.candidateEntity.currentStation.sortEntitiesForOperator(operator) operator.candidateEntity.currentStation.sortEntitiesForOperator(operator)
pendingObjectsMustBeSorted=True pendingObjectsMustBeSorted=True
...@@ -310,7 +309,6 @@ class Router(ObjectInterruption): ...@@ -310,7 +309,6 @@ class Router(ObjectInterruption):
priorityObject.inPositionToGet=False priorityObject.inPositionToGet=False
elif not candidateEntityHasActiveReceiver: elif not candidateEntityHasActiveReceiver:
operator.activeCallersList=[] operator.activeCallersList=[]
# print ' activerCallersList of', operator.id, 'cleared'
# if an object cannot proceed with getEntity, unAssign the exit of its giver # if an object cannot proceed with getEntity, unAssign the exit of its giver
for object in self.pendingObjects: for object in self.pendingObjects:
if not object.canProceedWithGetEntity: if not object.canProceedWithGetEntity:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment