new process request yielding the broker to request an operator

parent 0c37bf3b
...@@ -409,22 +409,16 @@ class Machine(CoreObject): ...@@ -409,22 +409,16 @@ class Machine(CoreObject):
methodsNotRequired.append(tup) methodsNotRequired.append(tup)
required = True required = True
from Globals import getMethodFromName from Globals import getMethodFromName
# print ' '*20, 'Requested methods'
if methodsRequired: if methodsRequired:
for methodTup in methodsRequired: for methodTup in methodsRequired:
method, func = methodTup method, func = methodTup
# print ' '*20,method,
objMethod=getMethodFromName('Dream.Machine.'+method) objMethod=getMethodFromName('Dream.Machine.'+method)
# print objMethod(self)
required = required and (objMethod(self)) required = required and (objMethod(self))
notRequired = True notRequired = True
# print ' '*20, 'not Requested methods'
if methodsNotRequired: if methodsNotRequired:
for methodTup in methodsNotRequired: for methodTup in methodsNotRequired:
method, func = methodTup method, func = methodTup
# print ' '*20,method,
objMethod=getMethodFromName('Dream.Machine.'+method) objMethod=getMethodFromName('Dream.Machine.'+method)
# print objMethod(self)
notRequired = notRequired and (objMethod(self)) notRequired = notRequired and (objMethod(self))
else: else:
notRequired=False notRequired=False
...@@ -437,7 +431,7 @@ class Machine(CoreObject): ...@@ -437,7 +431,7 @@ class Machine(CoreObject):
return False return False
#=========================================================================== #===========================================================================
# yielding for the broker process # yielding the broker process for releasing the resource
#=========================================================================== #===========================================================================
def release(self): def release(self):
# after getting the entity release the operator # after getting the entity release the operator
...@@ -451,6 +445,22 @@ class Machine(CoreObject): ...@@ -451,6 +445,22 @@ class Machine(CoreObject):
assert transmitter==self.broker, 'brokerIsSet is not sent by the stations broker' assert transmitter==self.broker, 'brokerIsSet is not sent by the stations broker'
assert eventTime==self.env.now, 'brokerIsSet is not received on time' assert eventTime==self.env.now, 'brokerIsSet is not received on time'
self.brokerIsSet=self.env.event() self.brokerIsSet=self.env.event()
#===========================================================================
# yielding the broker process for requesting an operator
#===========================================================================
def request(self):
# when it's ready to accept (canAcceptAndIsRequested) then inform the broker
# machines waits to be operated (waits for the operator)
self.requestOperator()
# wait until the Broker has waited times equal to loadTime (if any)
self.expectedSignals['brokerIsSet']=1
yield self.brokerIsSet
self.expectedSignals['brokerIsSet']=0
transmitter, eventTime=self.brokerIsSet.value
assert transmitter==self.broker, 'brokerIsSet is not sent by the stations broker'
assert eventTime==self.env.now, 'brokerIsSet is not received on time'
self.brokerIsSet=self.env.event()
# ======================================================================= # =======================================================================
# the main process of the machine # the main process of the machine
...@@ -516,22 +526,12 @@ class Machine(CoreObject): ...@@ -516,22 +526,12 @@ class Machine(CoreObject):
self.loadTimeCurrentEntity = 0 self.loadTimeCurrentEntity = 0
self.setupTimeCurrentEntity = 0 self.setupTimeCurrentEntity = 0
# ======= request a resource #===================================================================
if(self.operatorPool!="None") and any(type=='Load' for type in self.multOperationTypeList): # # request a resource if there is a need for load operation
# when it's ready to accept (canAcceptAndIsRequested) then inform the broker #===================================================================
# machines waits to be operated (waits for the operator) if self.shouldYield(operationTypes={"Load":1}):
self.requestOperator()
self.timeWaitForLoadOperatorStarted = self.env.now self.timeWaitForLoadOperatorStarted = self.env.now
# wait until the Broker has waited times equal to loadTime (if any) yield self.env.process(self.request())
self.expectedSignals['brokerIsSet']=1
yield self.brokerIsSet
transmitter, eventTime=self.brokerIsSet.value
assert transmitter==self.broker, 'brokerIsSet is not sent by the stations broker'
assert eventTime==self.env.now, 'brokerIsSet is not received on time'
self.brokerIsSet=self.env.event()
self.timeWaitForLoadOperatorEnded = self.env.now self.timeWaitForLoadOperatorEnded = self.env.now
self.loadOperatorWaitTimeCurrentEntity += self.timeWaitForLoadOperatorEnded-self.timeWaitForLoadOperatorStarted self.loadOperatorWaitTimeCurrentEntity += self.timeWaitForLoadOperatorEnded-self.timeWaitForLoadOperatorStarted
self.totalTimeWaitingForLoadOperator += self.loadOperatorWaitTimeCurrentEntity self.totalTimeWaitingForLoadOperator += self.loadOperatorWaitTimeCurrentEntity
...@@ -545,30 +545,12 @@ class Machine(CoreObject): ...@@ -545,30 +545,12 @@ class Machine(CoreObject):
self.loadTimeCurrentEntity = self.timeLoadEnded-self.timeLoadStarted self.loadTimeCurrentEntity = self.timeLoadEnded-self.timeLoadStarted
self.totalLoadTime += self.loadTimeCurrentEntity self.totalLoadTime += self.loadTimeCurrentEntity
#===================================================================
# # release a resource if the only operation type is Load
#===================================================================
if self.shouldYield(operationTypes={"Load":1, "Processing":0,"Setup":0},methods={'isOperated':1}): if self.shouldYield(operationTypes={"Load":1, "Processing":0,"Setup":0},methods={'isOperated':1}):
yield self.env.process(self.release()) yield self.env.process(self.release())
# ======= release a resource if the only operation type is Load
# if (self.operatorPool!="None")\
# and any(type=="Load" for type in self.multOperationTypeList)\
# and not (any(type=="Processing" for type in self.multOperationTypeList)\
# or any(type=="Setup" for type in self.multOperationTypeList))\
# and self.isOperated():
# # after getting the entity release the operator
# # machine has to release the operator
# self.releaseOperator()
# # wait until the Broker has finished processing
#
# self.expectedSignals['brokerIsSet']=1
#
# yield self.brokerIsSet
#
# self.expectedSignals['brokerIsSet']=0
#
# transmitter, eventTime=self.brokerIsSet.value
# assert transmitter==self.broker, 'brokerIsSet is not sent by the stations broker'
# assert eventTime==self.env.now, 'brokerIsSet is not received on time'
# self.brokerIsSet=self.env.event()
#=================================================================== #===================================================================
#=================================================================== #===================================================================
...@@ -605,33 +587,15 @@ class Machine(CoreObject): ...@@ -605,33 +587,15 @@ class Machine(CoreObject):
#=================================================================== #===================================================================
#=================================================================== #===================================================================
#===================================================================
# # request a resource if it is not already assigned an Operator
#===================================================================
# ======= request a resource if it is not already assigned an Operator if self.shouldYield(operationTypes={"Setup":1,"Processing":1}, methods={"isOperated":0}):
if(self.operatorPool!="None")\
and (any(type=="Processing" for type in self.multOperationTypeList)\
or any(type=="Setup" for type in self.multOperationTypeList))\
and not self.isOperated():
# when it's ready to accept (canAcceptAndIsRequested) then inform the broker
# machines waits to be operated (waits for the operator)
self.requestOperator()
self.timeWaitForOperatorStarted = self.env.now self.timeWaitForOperatorStarted = self.env.now
# wait until the Broker has waited times equal to loadTime (if any) yield self.env.process(self.request())
self.expectedSignals['brokerIsSet']=1
yield self.brokerIsSet
transmitter, eventTime=self.brokerIsSet.value
assert transmitter==self.broker, 'brokerIsSet is not sent by the stations broker'
assert eventTime==self.env.now, 'brokerIsSet is not received on time'
self.brokerIsSet=self.env.event()
self.timeWaitForOperatorEnded = self.env.now self.timeWaitForOperatorEnded = self.env.now
self.operatorWaitTimeCurrentEntity += self.timeWaitForOperatorEnded-self.timeWaitForOperatorStarted self.operatorWaitTimeCurrentEntity += self.timeWaitForOperatorEnded-self.timeWaitForOperatorStarted
# ======= setup the machine if the Setup is defined as one of the Operators' operation types # ======= setup the machine if the Setup is defined as one of the Operators' operation types
# in plantSim the setup is performed when the machine has to process a new type of Entity and only once # in plantSim the setup is performed when the machine has to process a new type of Entity and only once
if any(type=="Setup" for type in self.multOperationTypeList) and self.isOperated(): if any(type=="Setup" for type in self.multOperationTypeList) and self.isOperated():
...@@ -656,34 +620,12 @@ class Machine(CoreObject): ...@@ -656,34 +620,12 @@ class Machine(CoreObject):
# except: # except:
# pass # pass
#===================================================================
# # release a resource if the only operation type is Setup
#===================================================================
if self.shouldYield(operationTypes={"Setup":1,"Load":1,"Processing":0},methods={'isOperated':1}): if self.shouldYield(operationTypes={"Setup":1,"Load":1,"Processing":0},methods={'isOperated':1}):
yield self.env.process(self.release()) yield self.env.process(self.release())
# ======= release a resource if the only operation type is Setup
# if (self.operatorPool!="None")\
# and self.isOperated()\
# and (any(type=="Setup" for type in self.multOperationTypeList)\
# or any(type=="Load" for type in self.multOperationTypeList))\
# and not any(type=="Processing" for type in self.multOperationTypeList):
# # after getting the entity release the operator
# # machine has to release the operator
# self.releaseOperator()
# # wait until the Broker has finished processing
#
# self.expectedSignals['brokerIsSet']=1
#
# yield self.brokerIsSet
#
# self.expectedSignals['brokerIsSet']=0
#
# transmitter, eventTime=self.brokerIsSet.value
# assert transmitter==self.broker, 'brokerIsSet is not sent by the stations broker'
# assert eventTime==self.env.now, 'brokerIsSet is not received on time'
# self.brokerIsSet=self.env.event()
#=================================================================== #===================================================================
#=================================================================== #===================================================================
#=================================================================== #===================================================================
...@@ -733,27 +675,12 @@ class Machine(CoreObject): ...@@ -733,27 +675,12 @@ class Machine(CoreObject):
self.interruptionStart=self.env.event() self.interruptionStart=self.env.event()
self.interruptionActions() # execute interruption actions self.interruptionActions() # execute interruption actions
#===========================================================
# # release the operator if there is interruption
#===========================================================
if self.shouldYield(operationTypes={"Processing":1},methods={'isOperated':1}): if self.shouldYield(operationTypes={"Processing":1},methods={'isOperated':1}):
yield self.env.process(self.release()) yield self.env.process(self.release())
# =============== release the operator if there is interruption
# if (self.operatorPool!="None")\
# and self.isOperated()\
# and any(type=="Processing" for type in self.multOperationTypeList):
# self.releaseOperator()
#
# self.expectedSignals['brokerIsSet']=1
#
# yield self.brokerIsSet
#
# self.expectedSignals['brokerIsSet']=0
#
# transmitter, eventTime=self.brokerIsSet.value
# assert transmitter==self.broker, 'brokerIsSet is not sent by the stations broker'
# assert eventTime==self.env.now, 'brokerIsSet is not received on time'
# self.brokerIsSet=self.env.event()
# loop until we reach at a state that there is no interruption # loop until we reach at a state that there is no interruption
while 1: while 1:
...@@ -767,23 +694,13 @@ class Machine(CoreObject): ...@@ -767,23 +694,13 @@ class Machine(CoreObject):
break break
self.postInterruptionActions() self.postInterruptionActions()
#===========================================================
# =============== request a resource after the repair # # request a resource after the repair
if (self.operatorPool!="None")\ #===========================================================
and any(type=="Processing" for type in self.multOperationTypeList)\ if self.shouldYield(operationTypes={"Processing":1}, methods={"isInterrupted":0}):
and not self.isInterrupted():
self.timeWaitForOperatorStarted = self.env.now self.timeWaitForOperatorStarted = self.env.now
self.requestOperator() yield self.env.process(self.request())
self.timeWaitForOperatorEnded = self.env.now
self.expectedSignals['brokerIsSet']=1
yield self.brokerIsSet
transmitter, eventTime=self.brokerIsSet.value
assert transmitter==self.broker, 'brokerIsSet is not sent by the stations broker'
assert eventTime==self.env.now, 'brokerIsSet is not received on time'
self.brokerIsSet=self.env.event()
self.timeWaitForOperatorEnded = self.env.now
self.operatorWaitTimeCurrentEntity += self.timeWaitForOperatorEnded-self.timeWaitForOperatorStarted self.operatorWaitTimeCurrentEntity += self.timeWaitForOperatorEnded-self.timeWaitForOperatorStarted
# if the processing operator left # if the processing operator left
elif self.processOperatorUnavailable in receivedEvent: elif self.processOperatorUnavailable in receivedEvent:
...@@ -817,26 +734,12 @@ class Machine(CoreObject): ...@@ -817,26 +734,12 @@ class Machine(CoreObject):
self.preemptQueue=self.env.event() self.preemptQueue=self.env.event()
self.interruptionActions() # execute interruption actions self.interruptionActions() # execute interruption actions
#===========================================================
# # release the operator if there is interruption
#===========================================================
if self.shouldYield(operationTypes={"Processing":1},methods={'isOperated':1}): if self.shouldYield(operationTypes={"Processing":1},methods={'isOperated':1}):
yield self.env.process(self.release()) yield self.env.process(self.release())
# =============== release the operator if there is interruption
# if (self.operatorPool!="None")\
# and self.isOperated()\
# and any(type=="Processing" for type in self.multOperationTypeList):
# self.releaseOperator()
#
# self.expectedSignals['brokerIsSet']=1
#
# yield self.brokerIsSet
#
# self.expectedSignals['brokerIsSet']=0
#
# transmitter, eventTime=self.brokerIsSet.value
# assert transmitter==self.broker, 'brokerIsSet is not sent by the stations broker'
# assert eventTime==self.env.now, 'brokerIsSet is not received on time'
# self.brokerIsSet=self.env.event()
self.postInterruptionActions() self.postInterruptionActions()
break break
...@@ -847,27 +750,12 @@ class Machine(CoreObject): ...@@ -847,27 +750,12 @@ class Machine(CoreObject):
# carry on actions that have to take place when an Entity ends its processing # carry on actions that have to take place when an Entity ends its processing
self.endProcessingActions() self.endProcessingActions()
#===================================================================
# # release resource after the end of processing
#===================================================================
if self.shouldYield(operationTypes={"Processing":1},methods={'isInterrupted':0, 'isOperated':1}): if self.shouldYield(operationTypes={"Processing":1},methods={'isInterrupted':0, 'isOperated':1}):
yield self.env.process(self.release()) yield self.env.process(self.release())
# =============== release resource after the end of processing
# if (self.operatorPool!='None')\
# and self.isOperated()\
# and any(type=="Processing" for type in self.multOperationTypeList)\
# and not self.isInterrupted():
# self.releaseOperator()
#
# self.expectedSignals['brokerIsSet']=1
#
# yield self.brokerIsSet
#
# self.expectedSignals['brokerIsSet']=0
#
# transmitter, eventTime=self.brokerIsSet.value
# assert transmitter==self.broker, 'brokerIsSet is not sent by the stations broker'
# assert eventTime==self.env.now, 'brokerIsSet is not received on time'
# self.brokerIsSet=self.env.event()
#=================================================================== #===================================================================
#=================================================================== #===================================================================
#=================================================================== #===================================================================
...@@ -876,9 +764,6 @@ class Machine(CoreObject): ...@@ -876,9 +764,6 @@ class Machine(CoreObject):
#=================================================================== #===================================================================
#=================================================================== #===================================================================
# signal the receiver that the activeObject has something to dispose of # signal the receiver that the activeObject has something to dispose of
if not self.signalReceiver(): if not self.signalReceiver():
# if there was no available receiver, get into blocking control # if there was no available receiver, get into blocking control
......
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