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):
# 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 isAvailable
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
# =======================================================================
......
......@@ -31,6 +31,13 @@ that he is currently in.
from SimPy.Simulation import Resource, now
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
# ===========================================================================
......@@ -41,19 +48,23 @@ class OperatorPreemptive(Operator):
# self.type="OperatorPreemptive"
# =======================================================================
# checks if the worker is available
# =======================================================================
def checkIfResourceIsAvailable(self,callerObject=None):
# Check if Operator Can perform a preemption
# =======================================================================
def checkIfResourceCanPreempt(self,callerObject=None):
# TODO: to discuss with George about the use of callerObject
activeResource= self.getResource()
activeResourceQueue = activeResource.getResourceQueue()
# find out which station is requesting the operator?
thecaller=callerObject
# TODO: if the callerObject is None then
# perform then default behaviour. Used to find free operators
if thecaller==None:
# added for testing
len(self.Res.activeQ)<self.capacity
# assert that the callerObject is not None
try:
if callerObject:
thecaller = callerObject
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
# TODO: update the objects requesting the operator
requestingObject=thecaller.requestingObject
......@@ -89,3 +100,14 @@ class OperatorPreemptive(Operator):
except:
pass
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