comments added to OperatorRouter

parent 12f0eb31
...@@ -64,10 +64,8 @@ class Router(ObjectInterruption): ...@@ -64,10 +64,8 @@ class Router(ObjectInterruption):
yield waituntil, self,self.entitiesFinishedMoving yield waituntil, self,self.entitiesFinishedMoving
# update the objects to be served list (pendingObjects) # update the objects to be served list (pendingObjects)
# self.pendingObjects=[object for object in G.MachineList if object.inPositionToGet] self.pendingObjects=[object for object in G.MachineList if object.inPositionToGet]
for object in G.MachineList:
if object.inPositionToGet:
self.pendingObjects.append(object)
#=================================================================== #===================================================================
# # TESTING # # TESTING
# print now(),' the pending objects are', # print now(),' the pending objects are',
...@@ -77,10 +75,8 @@ class Router(ObjectInterruption): ...@@ -77,10 +75,8 @@ class Router(ObjectInterruption):
#=================================================================== #===================================================================
# update the called operators list # update the called operators list
# self.calledOperators=[operator for operator in G.OperatorsList if len(operator.activeCallersList)] self.calledOperators=[operator for operator in G.OperatorsList if len(operator.activeCallersList)]
for operator in G.OperatorsList:
if len(operator.activeCallersList):
self.calledOperators.append(operator)
#=================================================================== #===================================================================
# # TESTING # # TESTING
# print ' the called operators are', # print ' the called operators are',
...@@ -193,12 +189,15 @@ class Router(ObjectInterruption): ...@@ -193,12 +189,15 @@ class Router(ObjectInterruption):
# TODO: if there is a critical entity, its manager should be served first # TODO: if there is a critical entity, its manager should be served first
# initialise local variables occupiedReceivers and entitiesWithOccupiedReceivers
occupiedReceivers=[] occupiedReceivers=[]
entitiesWithOccupiedReceivers=[] entitiesWithOccupiedReceivers=[]
# for the candidateOperators that do have candidateEntities pick a candidateEntity
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)
operator.noAvailableReceivers=False operator.noAvailableReceivers=False
# while not operator.noAvailableReceivers: # while not operator.noAvailableReceivers:
# find the first available entity that has no occupied receivers
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
...@@ -208,9 +207,10 @@ class Router(ObjectInterruption): ...@@ -208,9 +207,10 @@ class Router(ObjectInterruption):
# [str(x.id) for x in operator.candidateEntity.candidateReceivers], # [str(x.id) for x in operator.candidateEntity.candidateReceivers],
# print '' # print ''
#======================================================= #=======================================================
# initiate the local list variable available receivers
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]
# and pick the object that is waiting for the most time
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
...@@ -223,6 +223,7 @@ class Router(ObjectInterruption): ...@@ -223,6 +223,7 @@ class Router(ObjectInterruption):
operator.candidateEntity.candidateReceiver=availableReceiver operator.candidateEntity.candidateReceiver=availableReceiver
occupiedReceivers.append(availableReceiver) occupiedReceivers.append(availableReceiver)
operator.noAvailableReceivers=True operator.noAvailableReceivers=True
# if there is no available receiver add the entity to the entitiesWithOccupiedReceivers list
else: else:
entitiesWithOccupiedReceivers.append(availableEntity) entitiesWithOccupiedReceivers.append(availableEntity)
operator.candidateEntity.candidateReceiver=None operator.candidateEntity.candidateReceiver=None
...@@ -233,17 +234,20 @@ class Router(ObjectInterruption): ...@@ -233,17 +234,20 @@ class Router(ObjectInterruption):
# 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 and not x.candidateEntity in entitiesWithOccupiedReceivers] # print ' +{}+ with receivers :',[str(x.candidateEntity.candidateReceiver.id) for x in candidateOperators if x.candidateEntity and not x.candidateEntity in entitiesWithOccupiedReceivers]
#=================================================================== #===================================================================
# local variable used for testing
pendingObjectsMustBeSorted=False pendingObjectsMustBeSorted=False
# for those operators that do have candidateEntity
for operator in [x for x in candidateOperators if x.candidateEntity]: for operator in [x for x in candidateOperators if x.candidateEntity]:
# check whether are called by objects that require the resource
operator.called = (operator in self.calledOperators) operator.called = (operator in self.calledOperators)
# if they are not called or are not in the pendingObjects list sort the queues of the
# of the requesting the operator entities.
if not operator.called: if not operator.called:
operator.candidateEntity.currentStation.sortEntitiesForOperator(operator) operator.candidateEntity.currentStation.sortEntitiesForOperator(operator)
pendingObjectsMustBeSorted=True pendingObjectsMustBeSorted=True
# TODO: if the first candidate is not called then must run again # TODO: if the first candidate is not called then must run again
# if the first is called then this one must proceed with get entity # if the first is called then this one must proceed with get entity
elif not operator.candidateEntity.candidateReceiver in self.pendingObjects: elif not operator.candidateEntity.candidateReceiver in self.pendingObjects:
print '!!!!!!!!!!!!!!!!!!!!!!!!'
operator.candidateEntity.currentStation.sortEntitiesForOperator(operator) operator.candidateEntity.currentStation.sortEntitiesForOperator(operator)
pendingObjectsMustBeSorted=True pendingObjectsMustBeSorted=True
else: else:
...@@ -279,13 +283,13 @@ class Router(ObjectInterruption): ...@@ -279,13 +283,13 @@ class Router(ObjectInterruption):
# print ' pendingObjectsMustBeSorted', pendingObjectsMustBeSorted # print ' pendingObjectsMustBeSorted', pendingObjectsMustBeSorted
#=============================================================== #===============================================================
# check if the candidateReceivers are inPositionToGet or if they are already called # check if the candidateReceivers are inPositionToGet and if they are already called
try: try:
candidateEntityHasActiveReceiver=(operator.candidateEntity.candidateReceiver in operator.activeCallersList\ candidateEntityHasActiveReceiver=(operator.candidateEntity.candidateReceiver in operator.activeCallersList\
and operator.candidateEntity.candidateReceiver in self.pendingObjects ) and operator.candidateEntity.candidateReceiver in self.pendingObjects )
except: except:
candidateEntityHasActiveReceiver=True candidateEntityHasActiveReceiver=True
# check if they are available # check if the candidateOperators are available, if the are requested and reside in the pendingObjects list
if operator.checkIfResourceIsAvailable() and \ if operator.checkIfResourceIsAvailable() and \
candidateEntityHasActiveReceiver: candidateEntityHasActiveReceiver:
#=========================================================== #===========================================================
...@@ -324,6 +328,7 @@ class Router(ObjectInterruption): ...@@ -324,6 +328,7 @@ class Router(ObjectInterruption):
# and let it proceed withGetEntity # and let it proceed withGetEntity
priorityObject.canProceedWithGetEntity=True priorityObject.canProceedWithGetEntity=True
priorityObject.inPositionToGet=False priorityObject.inPositionToGet=False
# if the are not called and they are not in the pendingObjects list clear their activeCallersList
elif not candidateEntityHasActiveReceiver: elif not candidateEntityHasActiveReceiver:
operator.activeCallersList=[] operator.activeCallersList=[]
# 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
......
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