sorting of Operators and pendingEntities now optional

parent 3513d0af
...@@ -43,7 +43,7 @@ class Router(ObjectInterruption): ...@@ -43,7 +43,7 @@ class Router(ObjectInterruption):
# TODO: we should maybe define a global schedulingRule criterion that will be # TODO: we should maybe define a global schedulingRule criterion that will be
# chosen in case of multiple criteria for different Operators # chosen in case of multiple criteria for different Operators
# ======================================================================= # =======================================================================
def __init__(self): def __init__(self,sorting=False):
ObjectInterruption.__init__(self) ObjectInterruption.__init__(self)
self.type = "Router" self.type = "Router"
# signal used to initiate the generator of the Router # signal used to initiate the generator of the Router
...@@ -52,7 +52,8 @@ class Router(ObjectInterruption): ...@@ -52,7 +52,8 @@ class Router(ObjectInterruption):
self.candidateOperators=[] self.candidateOperators=[]
self.multipleCriterionList=[] self.multipleCriterionList=[]
self.schedulingRule='WT' self.schedulingRule='WT'
self.sorting=False # boolean flag to check whether the Router should perform sorting on operators and on pendingEntities
self.sorting=sorting
#=========================================================================== #===========================================================================
# the initialize method # the initialize method
...@@ -70,8 +71,6 @@ class Router(ObjectInterruption): ...@@ -70,8 +71,6 @@ class Router(ObjectInterruption):
self.schedulingRule='WT' self.schedulingRule='WT'
# flag used to check if the Router is initialised # flag used to check if the Router is initialised
self.isInitialized=True self.isInitialized=True
# boolean flag to check whether the Router should perform sorting on operators and on pendingEntities
self.sorting=False
# ======================================================================= # =======================================================================
# the run method # the run method
...@@ -124,7 +123,8 @@ class Router(ObjectInterruption): ...@@ -124,7 +123,8 @@ class Router(ObjectInterruption):
#=================================================================== #===================================================================
# sort the pendingEntities list # sort the pendingEntities list
self.sortPendingEntities() if self.sorting:
self.sortPendingEntities()
#=================================================================== #===================================================================
# # TESTING # # TESTING
...@@ -346,7 +346,8 @@ class Router(ObjectInterruption): ...@@ -346,7 +346,8 @@ class Router(ObjectInterruption):
if entity.canProceed and not entity.manager in self.candidateOperators: if entity.canProceed and not entity.manager in self.candidateOperators:
self.candidateOperators.append(entity.manager) self.candidateOperators.append(entity.manager)
# update the schedulingRule/multipleCriterionList of the Router # update the schedulingRule/multipleCriterionList of the Router
self.updateSchedulingRule() if self.sorting:
self.updateSchedulingRule()
#======================================================================= #=======================================================================
...@@ -401,13 +402,14 @@ class Router(ObjectInterruption): ...@@ -401,13 +402,14 @@ class Router(ObjectInterruption):
# 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
# TODO: incorporate that to # TODO: incorporate that to
# self.sortOperators() # self.sortOperators()
# sort the operators according to their waiting time if self.sorting:
self.candidateOperators.sort(key=lambda x: x.totalWorkingTime) # sort the operators according to their waiting time
# sort according to the number of options self.candidateOperators.sort(key=lambda x: x.totalWorkingTime)
if operatorsWithOneOption: # sort according to the number of options
self.candidateOperators.sort(key=lambda x: x in operatorsWithOneOption, reverse=True) if operatorsWithOneOption:
self.candidateOperators.sort(key=lambda x: x in operatorsWithOneOption, reverse=True)
#======================================================================= #=======================================================================
# Find candidate entities and their receivers # Find candidate entities and their receivers
...@@ -448,11 +450,12 @@ class Router(ObjectInterruption): ...@@ -448,11 +450,12 @@ class Router(ObjectInterruption):
# operator.candidateEntity.candidateReceiver=None # operator.candidateEntity.candidateReceiver=None
return availableReceiver return availableReceiver
for operator in [x for x in self.candidateOperators if x.candidateEntities]: # for operator in [x for x in self.candidateOperators if x.candidateEntities]:
operator.candidateEntity=operator.candidateEntities[0] # operator.candidateEntity=operator.candidateEntities[0]
# TODO: sorting again after choosing candidateEntity # TODO: sorting again after choosing candidateEntity
self.sortOperators() if self.sorting:
self.sortOperators()
# for the candidateOperators that do have candidateEntities pick a candidateEntity # for the candidateOperators that do have candidateEntities pick a candidateEntity
for operator in [x for x in self.candidateOperators if x.candidateEntities]: for operator in [x for x in self.candidateOperators if x.candidateEntities]:
......
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