minor changes in sorting of operators in Router

parent f78a1c17
...@@ -64,6 +64,7 @@ class Router(ObjectInterruption): ...@@ -64,6 +64,7 @@ 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]
for object in G.MachineList: for object in G.MachineList:
if object.inPositionToGet: if object.inPositionToGet:
self.pendingObjects.append(object) self.pendingObjects.append(object)
...@@ -76,6 +77,7 @@ class Router(ObjectInterruption): ...@@ -76,6 +77,7 @@ 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)]
for operator in G.OperatorsList: for operator in G.OperatorsList:
if len(operator.activeCallersList): if len(operator.activeCallersList):
self.calledOperators.append(operator) self.calledOperators.append(operator)
...@@ -157,27 +159,36 @@ class Router(ObjectInterruption): ...@@ -157,27 +159,36 @@ class Router(ObjectInterruption):
# initialise the operatorsWithOneOption # initialise the operatorsWithOneOption
operatorsWithOneOption=[] operatorsWithOneOption=[]
operatorsWithOneCandidateEntity=[]
# for all the candidateOperators # for all the candidateOperators
for operator in candidateOperators: for operator in candidateOperators:
# initialise the local candidateEntities list, candidateEntity and candidateReceiver of each operator # initialise the local candidateEntities list, candidateEntity and candidateReceiver of each operator
operator.candidateEntities=[] operator.candidateEntities=[]
operator.candidateEntity=None operator.candidateEntity=None
operator.candidateReceiver=None # operator.candidateReceiver=None
# find which pendingEntities that can move to machines is the operator managing # find which pendingEntities that can move to machines is the operator managing
for entity in [x for x in G.pendingEntities if x.canProceed and x.manager==operator]: for entity in [x for x in G.pendingEntities if x.canProceed and x.manager==operator]:
operator.candidateEntities.append(entity) # candidateOperator.candidateEntity operator.candidateEntities.append(entity) # candidateOperator.candidateEntity
# sort the candidate operators so that those who have only one option be served first # sort the candidate operators so that those who have only one option be served first
if len(operator.candidateEntities)==1: if len(operator.candidateEntities)==1:
operatorsWithOneOption.append(operator) operatorsWithOneCandidateEntity.append(operator)
if len(operator.candidateEntities[0].candidateReceivers)==1:
operatorsWithOneOption.append(operator)
# if there operators that have only one option then sort the candidateOperators according to the first one of these # if there operators that have only one option then sort the candidateOperators according to the first one of these
# TODO: find out what happens if there are many operators with one option # TODO: find out what happens if there are many operators with one option
if operatorsWithOneOption: if operatorsWithOneOption:
candidateOperators.sort(key=lambda x:x==operatorsWithOneOption[0],reverse=True) # candidateOperators.sort(key=lambda x:x==operatorsWithOneOption[0],reverse=True)
candidateOperators.sort(key=lambda x: x in operatorsWithOneOption, reverse=True)
#=================================================================== #===================================================================
# # TESTING # # TESTING
# if candidateOperators: # if candidateOperators:
# print ' {} the candidate operators after second sorting are: ', # print ' {} the candidate operators after second sorting are: ',
# print [str(candidate.id) for candidate in candidateOperators] # print [str(candidate.id) for candidate in candidateOperators]
# print ' operators with one Option ',
# print [str(operator.id) for operator in operatorsWithOneOption]
# for operator in candidateOperators:
# print ' operator', operator.id, 'has candidate entities'
# print [candidateEntity.id for candidateEntity in operator.candidateEntities]
#=================================================================== #===================================================================
# 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
...@@ -195,6 +206,7 @@ class Router(ObjectInterruption): ...@@ -195,6 +206,7 @@ class Router(ObjectInterruption):
# # 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],
# print ''
#======================================================= #=======================================================
availableReceivers=[x for x in operator.candidateEntity.candidateReceivers\ availableReceivers=[x for x in operator.candidateEntity.candidateReceivers\
...@@ -230,6 +242,10 @@ class Router(ObjectInterruption): ...@@ -230,6 +242,10 @@ class Router(ObjectInterruption):
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:
print '!!!!!!!!!!!!!!!!!!!!!!!!'
operator.candidateEntity.currentStation.sortEntitiesForOperator(operator)
pendingObjectsMustBeSorted=True
else: else:
break break
#=================================================================== #===================================================================
...@@ -263,19 +279,20 @@ class Router(ObjectInterruption): ...@@ -263,19 +279,20 @@ class Router(ObjectInterruption):
# print ' pendingObjectsMustBeSorted', pendingObjectsMustBeSorted # print ' pendingObjectsMustBeSorted', pendingObjectsMustBeSorted
#=============================================================== #===============================================================
# check if they are available # check if the candidateReceivers are inPositionToGet or 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 )
except: except:
candidateEntityHasActiveReceiver=True candidateEntityHasActiveReceiver=True
# check if they are available
if operator.checkIfResourceIsAvailable() and \ if operator.checkIfResourceIsAvailable() and \
candidateEntityHasActiveReceiver: candidateEntityHasActiveReceiver:
#=========================================================== #===========================================================
# TESTING # # TESTING
#print now(), 'the active callers of', operator.objName, 'before sorting are' # print now(), 'the active callers of', operator.objName, 'before sorting are'
#for caller in operator.activeCallersList: # for caller in operator.activeCallersList:
# print ' ', caller.id # print ' ', caller.id
#=========================================================== #===========================================================
# sort the activeCallersList of the operator # sort the activeCallersList of the operator
...@@ -290,8 +307,8 @@ class Router(ObjectInterruption): ...@@ -290,8 +307,8 @@ class Router(ObjectInterruption):
# find the activeCaller that has priority # find the activeCaller that has priority
priorityObject=next(x for x in operator.activeCallersList if x in self.pendingObjects) priorityObject=next(x for x in operator.activeCallersList if x in self.pendingObjects)
#=========================================================== #===========================================================
# TESTING # # TESTING
#print ' the PRIORITY object is', priorityObject.id # print ' the PRIORITY object is', priorityObject.id
#=========================================================== #===========================================================
# and if the priorityObject is indeed pending # and if the priorityObject is indeed pending
......
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