OperatorPool will check if any operator can preempt when there no operators...

OperatorPool will check if any operator can preempt when there no operators available. checkIfResourceCanPreempt added to OperatorPool. checkIfResourceCanPreempt of OperatorPreemptive preemts the currentStation if there is such need
parent 659f024c
...@@ -110,12 +110,18 @@ class OperatorPool(ObjectResource): ...@@ -110,12 +110,18 @@ class OperatorPool(ObjectResource):
# if callerOjbect is None then the checkIfResourceIsAvailable performs the default behaviour # if callerOjbect is None then the checkIfResourceIsAvailable performs the default behaviour
# so initially it checks whether there is a free operator # so initially it checks whether there is a free operator
isAvailable = any(operator.checkIfResourceIsAvailable()==True for operator in self.operators) isAvailable = any(operator.checkIfResourceIsAvailable()==True for operator in self.operators)
# if isAvailable: if isAvailable:
# return True return True
return isAvailable return self.checkIfResourceCanPreempt()
# # if there is no free operator, then check if any of the operators can preempt # # 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) # 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
# ======================================================================= # =======================================================================
......
...@@ -31,6 +31,13 @@ that he is currently in. ...@@ -31,6 +31,13 @@ that he is currently in.
from SimPy.Simulation import Resource, now from SimPy.Simulation import Resource, now
from Operator import Operator from Operator import Operator
# ===========================================================================
# Error in the setting up of the WIP
# ===========================================================================
class NoCallerError(Exception):
def __init__(self, callerError):
Exception.__init__(self, callerError)
# =========================================================================== # ===========================================================================
# the resource that operates the machines # the resource that operates the machines
# =========================================================================== # ===========================================================================
...@@ -41,19 +48,23 @@ class OperatorPreemptive(Operator): ...@@ -41,19 +48,23 @@ class OperatorPreemptive(Operator):
# self.type="OperatorPreemptive" # self.type="OperatorPreemptive"
# ======================================================================= # =======================================================================
# checks if the worker is available # Check if Operator Can perform a preemption
# ======================================================================= # =======================================================================
def checkIfResourceIsAvailable(self,callerObject=None): def checkIfResourceCanPreempt(self,callerObject=None):
# TODO: to discuss with George about the use of callerObject # TODO: to discuss with George about the use of callerObject
activeResource= self.getResource() activeResource= self.getResource()
activeResourceQueue = activeResource.getResourceQueue() activeResourceQueue = activeResource.getResourceQueue()
# find out which station is requesting the operator? # find out which station is requesting the operator?
thecaller=callerObject thecaller=callerObject
# TODO: if the callerObject is None then # assert that the callerObject is not None
# perform then default behaviour. Used to find free operators try:
if thecaller==None: if callerObject:
# added for testing thecaller = callerObject
len(self.Res.activeQ)<self.capacity else:
raise NoCallerError('The caller of the MouldAssemblyBuffer must be defined')
except NoCallerError as noCaller:
print 'No caller error: {0}'.format(noCaller)
# Otherwise check the operator has a reason to preempt the machine he is currently working on # Otherwise check the operator has a reason to preempt the machine he is currently working on
# TODO: update the objects requesting the operator # TODO: update the objects requesting the operator
requestingObject=thecaller.requestingObject requestingObject=thecaller.requestingObject
...@@ -89,3 +100,14 @@ class OperatorPreemptive(Operator): ...@@ -89,3 +100,14 @@ class OperatorPreemptive(Operator):
except: except:
pass pass
return len(self.Res.activeQ)<self.capacity return len(self.Res.activeQ)<self.capacity
# =======================================================================
# checks if the worker is available
# =======================================================================
def checkIfResourceIsAvailable(self,callerObject=None):
# TODO: to discuss with George about the use of callerObject
activeResource= self.getResource()
activeResourceQueue = activeResource.getResourceQueue()
len(activeResourceQueue)<self.capacity
\ No newline at end of file
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