Commit 04f6da24 authored by Ioannis Papagiannopoulos's avatar Ioannis Papagiannopoulos Committed by Georgios Dagkakis

default router clean-up. new method getReceivers that returns the stations...

default router clean-up. new method getReceivers that returns the stations that have been chosen by operators
parent 106651ba
...@@ -132,9 +132,9 @@ class Router(ObjectInterruption): ...@@ -132,9 +132,9 @@ class Router(ObjectInterruption):
self.findPendingEntities() self.findPendingEntities()
# find the operators that can start working now # find the operators that can start working now
self.findCandidateOperators() self.findCandidateOperators()
# sort the pendingEntities list # # sort the pendingEntities list
if self.sorting: # if self.sorting:
self.sortPendingEntities() # self.sortPendingEntities()
# find the operators candidateEntities # find the operators candidateEntities
self.sortCandidateEntities() self.sortCandidateEntities()
# find the entity that will occupy the resource, and the station that will receive it (if any available) # find the entity that will occupy the resource, and the station that will receive it (if any available)
...@@ -167,15 +167,13 @@ class Router(ObjectInterruption): ...@@ -167,15 +167,13 @@ class Router(ObjectInterruption):
for operator in self.candidateOperators: for operator in self.candidateOperators:
# check if the candidateOperators are available, if the are requested and reside in the pendingObjects list # check if the candidateOperators are available, if the are requested and reside in the pendingObjects list
if operator.checkIfResourceIsAvailable(): if operator.checkIfResourceIsAvailable():
# if the operator is not conflicting
if not operator in self.conflictingOperators:
# assign an operator to the priorityObject # assign an operator to the priorityObject
self.printTrace('router', 'will assign '+operator.id+' to '+operator.candidateStation.id) self.printTrace('router', 'will assign '+operator.id+' to '+operator.candidateStation.id)
operator.assignTo(operator.candidateStation) operator.assignTo(operator.candidateStation)
if not operator.candidateStation in self.toBeSignalled: if not operator.candidateStation in self.toBeSignalled:
self.toBeSignalled.append(operator.candidateStation) self.toBeSignalled.append(operator.candidateStation)
# if there must be preemption performed # if there must be preemption performed
elif operator in self.preemptiveOperators and not operator in self.conflictingOperators: elif operator in self.preemptiveOperators:
# if the operator is not currently working on the candidateStation then the entity he is # if the operator is not currently working on the candidateStation then the entity he is
# currently working on must be preempted, and he must be unassigned and assigned to the new station # currently working on must be preempted, and he must be unassigned and assigned to the new station
if operator.workingStation!=operator.candidateStation: if operator.workingStation!=operator.candidateStation:
...@@ -316,18 +314,30 @@ class Router(ObjectInterruption): ...@@ -316,18 +314,30 @@ class Router(ObjectInterruption):
# for each pendingMachine # for each pendingMachine
for object in self.pendingMachines: for object in self.pendingMachines:
# find candidateOperators for each object operator # find candidateOperators for each object operator
candidateOperator=object.findCandidateOperator() candidateOperators=object.operatorPool.availableOperators()
# append the station into its candidateStations
if candidateOperators: # if there was an operator found append the Machine on his candidateStations
for candidateOperator in candidateOperators:
if not object in candidateOperator.candidateStations:
candidateOperator.candidateStations.append(object)
# if there is candidateOperator that is not already in self.candidateOperators add him # if there is candidateOperator that is not already in self.candidateOperators add him
# TODO: this way no sorting is performed # TODO: this way no sorting is performed
if candidateOperator and (not candidateOperator in self.candidateOperators): if not candidateOperator in self.candidateOperators:
self.candidateOperators.append(candidateOperator) self.candidateOperators.append(candidateOperator)
# for each pendingQueue # for each pendingQueue
for object in self.pendingQueues: for object in self.pendingQueues:
# find available operator for then machines that follow # find available operator for then machines that follow
for nextobject in object.findReceiversFor(object): for nextobject in object.findReceiversFor(object):
candidateOperator=nextobject.findCandidateOperator() candidateOperators=nextobject.operatorPool.availableOperators()
# append the station into its candidateStations
if candidateOperators: # if there was an operator found append the Machine on his candidateStations
for candidateOperator in candidateOperators:
if not nextobject in candidateOperator.candidateStations:
candidateOperator.candidateStations.append(nextobject)
if not candidateOperator in self.candidateOperators: if not candidateOperator in self.candidateOperators:
self.candidateOperators.append(candidateOperator) self.candidateOperators.append(candidateOperator)
# check the option of preemption if there are critical entities and no available operators # check the option of preemption if there are critical entities and no available operators
if not object.findReceiversFor(object) and\ if not object.findReceiversFor(object) and\
any(entity for entity in object.getActiveObjectQueue() if entity.isCritical): any(entity for entity in object.getActiveObjectQueue() if entity.isCritical):
...@@ -345,15 +355,10 @@ class Router(ObjectInterruption): ...@@ -345,15 +355,10 @@ class Router(ObjectInterruption):
self.candidateOperators.append(preemptiveOperator) self.candidateOperators.append(preemptiveOperator)
self.preemptiveOperators.append(preemptiveOperator) self.preemptiveOperators.append(preemptiveOperator)
break break
# preemptiveOperator=next(operator for operator in nextObject.operatorPool.operators)
# preemptiveOperator.candidateStations.append(nextObject)
# if not preemptiveOperator in self.candidateOperators:
# self.candidateOperators.append(preemptiveOperator)
# self.preemptiveOperators.append(preemptiveOperator)
# update the schedulingRule/multipleCriterionList of the Router # # update the schedulingRule/multipleCriterionList of the Router
if self.sorting: # if self.sorting:
self.updateSchedulingRule() # self.updateSchedulingRule()
# if there are candidate operators # if there are candidate operators
if self.candidateOperators: if self.candidateOperators:
self.printTrace('router found candidate operators'+' '*3, self.printTrace('router found candidate operators'+' '*3,
...@@ -361,32 +366,32 @@ class Router(ObjectInterruption): ...@@ -361,32 +366,32 @@ class Router(ObjectInterruption):
else: else:
self.printTrace('router', 'found NO candidate operators') self.printTrace('router', 'found NO candidate operators')
#=========================================================================== # #===========================================================================
# find the candidate entities for each candidateOperator # # find the candidate entities for each candidateOperator
#=========================================================================== # #===========================================================================
def findCandidateEntities(self): # def findCandidateEntities(self):
for operator in self.candidateOperators: # for operator in self.candidateOperators:
# find which pendingEntities that can move to machines is the operator managing # # find which pendingEntities that can move to machines is the operator managing
operator.findCandidateEntities(self.pending) # operator.findCandidateEntities(self.pending)
#======================================================================= # #=======================================================================
# find the schedulingRules of the candidateOperators # # find the schedulingRules of the candidateOperators
#======================================================================= # #=======================================================================
def updateSchedulingRule(self): # def updateSchedulingRule(self):
if self.candidateOperators: # if self.candidateOperators:
for operator in self.candidateOperators: # for operator in self.candidateOperators:
if operator.multipleCriterionList: # if operator.multipleCriterionList:
for criterion in operator.multipleCriterionList: # for criterion in operator.multipleCriterionList:
if not criterion in self.multipleCriterionList: # if not criterion in self.multipleCriterionList:
self.multipleCriterionList.append(criterion) # self.multipleCriterionList.append(criterion)
else: # if operator has only simple scheduling Rule # else: # if operator has only simple scheduling Rule
if not operator.schedulingRule in self.multipleCriterionList: # if not operator.schedulingRule in self.multipleCriterionList:
self.multipleCriterionList.append(operator.schedulingRule) # self.multipleCriterionList.append(operator.schedulingRule)
# TODO: For the moment all operators should have only one scheduling rule and the same among them # # TODO: For the moment all operators should have only one scheduling rule and the same among them
# added for testing # # added for testing
assert len(self.multipleCriterionList)==1,'The operators must have the same (one) scheduling rule' # assert len(self.multipleCriterionList)==1,'The operators must have the same (one) scheduling rule'
if len(self.multipleCriterionList)==1: # if len(self.multipleCriterionList)==1:
self.schedulingRule=self.multipleCriterionList[0] # self.schedulingRule=self.multipleCriterionList[0]
#======================================================================= #=======================================================================
# Find the candidateEntities for each candidateOperator # Find the candidateEntities for each candidateOperator
...@@ -426,16 +431,16 @@ class Router(ObjectInterruption): ...@@ -426,16 +431,16 @@ class Router(ObjectInterruption):
if operatorsWithOneOption: if operatorsWithOneOption:
self.candidateOperators.sort(key=lambda x: x in operatorsWithOneOption, reverse=True) self.candidateOperators.sort(key=lambda x: x in operatorsWithOneOption, reverse=True)
#======================================================================= # #=======================================================================
# Sort pendingEntities # # Sort pendingEntities
# TODO: sorting them according to the operators schedulingRule # # TODO: sorting them according to the operators schedulingRule
#======================================================================= # #=======================================================================
def sortPendingEntities(self): # def sortPendingEntities(self):
if self.candidateOperators: # if self.candidateOperators:
from Globals import G # from Globals import G
candidateList=self.pending # candidateList=self.pending
self.activeQSorter(criterion=self.schedulingRule,candList=candidateList) # self.activeQSorter(criterion=self.schedulingRule,candList=candidateList)
self.printTrace('router', ' sorted pending entities') # self.printTrace('router', ' sorted pending entities')
#======================================================================= #=======================================================================
# Sort candidateOperators # Sort candidateOperators
...@@ -450,6 +455,17 @@ class Router(ObjectInterruption): ...@@ -450,6 +455,17 @@ class Router(ObjectInterruption):
candidateList=self.candidateOperators candidateList=self.candidateOperators
self.activeQSorter(criterion=self.schedulingRule,candList=candidateList) self.activeQSorter(criterion=self.schedulingRule,candList=candidateList)
#===========================================================================
# get all the candidate stations that have been chosen by an operator
#===========================================================================
def getReceivers(self):
candidateStations=[]
for operator in self.candidateOperators:
if operator.candidateStation:
if not operator.candidateStation in candidateStations:
candidateStations.append(operator.candidateStation)
return candidateStations
#======================================================================= #=======================================================================
# Find candidate entities and their receivers # Find candidate entities and their receivers
# 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
...@@ -472,6 +488,7 @@ class Router(ObjectInterruption): ...@@ -472,6 +488,7 @@ class Router(ObjectInterruption):
if operator.candidateStation in self.conflictingStations] if operator.candidateStation in self.conflictingStations]
# keep the sorting provided by the queues if there is conflict between operators # keep the sorting provided by the queues if there is conflict between operators
conflictingGroup=[] # list that holds the operators that have the same recipient conflictingGroup=[] # list that holds the operators that have the same recipient
removedOperators=[]
if self.conflictingOperators: if self.conflictingOperators:
# for each of the candidateReceivers # for each of the candidateReceivers
for station in self.conflictingStations: for station in self.conflictingStations:
...@@ -480,9 +497,10 @@ class Router(ObjectInterruption): ...@@ -480,9 +497,10 @@ class Router(ObjectInterruption):
# the operator that can proceed is the manager of the entity as sorted by the queue that holds them # the operator that can proceed is the manager of the entity as sorted by the queue that holds them
conflictingGroup.sort() conflictingGroup.sort()
# the operators that are not first in the list cannot proceed # the operators that are not first in the list cannot proceed
for operator in conflitingGroup: for operator in conflictingGroup:
if conflictingGroup.index(operator)!=0: if conflictingGroup.index(operator)!=0 and not operator in removedOperators:
self.candidateOperators.remove(operator) self.candidateOperators.remove(operator)
removedOperators.append(operator)
# ======================================================================= # =======================================================================
# sorts the Operators of the Queue according to the scheduling rule # sorts the Operators of the Queue according to the scheduling rule
......
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