sorting of Operators and pendingEntities now optional

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