checkIfResourceCanPreempt() removed as not used any more

parent 7ea60245
...@@ -52,13 +52,6 @@ class ObjectResource(object): ...@@ -52,13 +52,6 @@ class ObjectResource(object):
def checkIfResourceIsAvailable(self,callerObject=None): def checkIfResourceIsAvailable(self,callerObject=None):
return len(self.Res.activeQ)<self.capacity return len(self.Res.activeQ)<self.capacity
# =======================================================================
# Check if Operator Can perform a preemption
# =======================================================================
def checkIfResourceCanPreempt(self,callerObject=None):
# TODO: each resource will return according to its availability for preemption
return False
# ======================================================================= # =======================================================================
# actions to be taken after the simulation ends # actions to be taken after the simulation ends
# ======================================================================= # =======================================================================
......
...@@ -95,24 +95,8 @@ class OperatorPool(ObjectResource): ...@@ -95,24 +95,8 @@ class OperatorPool(ObjectResource):
# ======================================================================= # =======================================================================
# checks if there are operators available # checks if there are operators available
# ======================================================================= # =======================================================================
def checkIfResourceIsAvailable(self): def checkIfResourceIsAvailable(self):
# TODO: to discuss with George if using a callerObject is the proper way to inform the OperatorPreemptive return any(operator.checkIfResourceIsAvailable()==True for operator in self.operators)
# about the object that is requesting to know about its availability
# TODO: first check if there is any free operator, then check if the requesting entity is critical and preempt
# if callerOjbect is None then the checkIfResourceIsAvailable performs the default behaviour
# so initially it checks whether there is a free operator
isAvailable = any(operator.checkIfResourceIsAvailable()==True for operator in self.operators)
if isAvailable:
return True
return self.checkIfResourceCanPreempt()
# # if there is no free operator, then check if any of the operators can preempt
# return any(operator.checkIfResourceIsAvailable(callerObject=self)==True for operator in self.operators)
# =======================================================================
# checks if there are operators that can preempt
# =======================================================================
def checkIfResourceCanPreempt(self):
return any(x for x in self.operators if x.checkIfResourceCanPreempt(callerObject=self))
# ======================================================================= # =======================================================================
# find the first available operator and return it # find the first available operator and return it
...@@ -120,11 +104,7 @@ class OperatorPool(ObjectResource): ...@@ -120,11 +104,7 @@ class OperatorPool(ObjectResource):
def findAvailableOperator(self): # may need to implement different sorting of the operators def findAvailableOperator(self): # may need to implement different sorting of the operators
# find the free operator if any # find the free operator if any
freeOperator = next(x for x in self.operators if x.checkIfResourceIsAvailable()) freeOperator = next(x for x in self.operators if x.checkIfResourceIsAvailable())
# if freeOperator:
# return freeOperator
return freeOperator return freeOperator
# # if there is no free operator, return the operator that can preempt
# return next(x for x in self.operators if x.checkIfResourceIsAvailable(callerObject=self))
# ======================================================================= # =======================================================================
# returns the resource # returns the resource
......
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