Commit 7323512c authored by Ioannis Papagiannopoulos's avatar Ioannis Papagiannopoulos Committed by Georgios Dagkakis

Machine updated to use the expectedSignals dict. New process method introduced - yet still not used

parent c3943b8e
...@@ -156,8 +156,6 @@ class Machine(CoreObject): ...@@ -156,8 +156,6 @@ class Machine(CoreObject):
# initialise the router if not initialized already # initialise the router if not initialized already
self.initializeRouter() self.initializeRouter()
# TODO: check whether the requestingEntity variable can be used in OperatorPreemptive
self.requestingEntity=None
# variables used for interruptions # variables used for interruptions
self.tinM=0 self.tinM=0
self.timeLastProcessingStarted=0 self.timeLastProcessingStarted=0
...@@ -176,6 +174,11 @@ class Machine(CoreObject): ...@@ -176,6 +174,11 @@ class Machine(CoreObject):
self.preemptQueue=self.env.event() self.preemptQueue=self.env.event()
# signal used for informing objectInterruption objects that the current entity processed has finished processnig # signal used for informing objectInterruption objects that the current entity processed has finished processnig
self.endedLastProcessing=self.env.event() self.endedLastProcessing=self.env.event()
self.expectedSignals['isRequested']=1
self.expectedSignals['interruptionEnd']=1
self.expectedSignals['loadOperatorAvailable']=1
self.expectedSignals['initialWIP']=1
@staticmethod @staticmethod
def getProcessingTime(processingTime): def getProcessingTime(processingTime):
...@@ -310,7 +313,62 @@ class Machine(CoreObject): ...@@ -310,7 +313,62 @@ class Machine(CoreObject):
if not self.router.isActivated: if not self.router.isActivated:
self.env.process(self.router.run()) self.env.process(self.router.run())
self.router.isActivated=True self.router.isActivated=True
def loading(self):
# ======= request a resource
if(self.operatorPool!="None") and any(type=='Load' for type in self.multOperationTypeList):
# when it's ready to accept (canAcceptAndIsRequested) then inform the broker
# machines waits to be operated (waits for the operator)
self.requestOperator()
self.timeWaitForLoadOperatorStarted = self.env.now
# 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()
self.timeWaitForLoadOperatorEnded = self.env.now
self.loadOperatorWaitTimeCurrentEntity += self.timeWaitForLoadOperatorEnded-self.timeWaitForLoadOperatorStarted
self.totalTimeWaitingForLoadOperator += self.loadOperatorWaitTimeCurrentEntity
# ======= Load the machine if the Load is defined as one of the Operators' operation types
if any(type=="Load" for type in self.multOperationTypeList) and self.isOperated():
self.timeLoadStarted = self.env.now
yield self.env.timeout(self.calculateLoadTime())
# TODO: if self.interrupted(): There is the issue of failure during the Loading
self.timeLoadEnded = self.env.now
self.loadTimeCurrentEntity = self.timeLoadEnded-self.timeLoadStarted
self.totalLoadTime += self.loadTimeCurrentEntity
# ======= 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()
# ======================================================================= # =======================================================================
# the main process of the machine # the main process of the machine
# ======================================================================= # =======================================================================
...@@ -322,6 +380,12 @@ class Machine(CoreObject): ...@@ -322,6 +380,12 @@ class Machine(CoreObject):
# waitEvent isRequested /interruptionEnd/loadOperatorAvailable # waitEvent isRequested /interruptionEnd/loadOperatorAvailable
while 1: while 1:
self.printTrace(self.id, waitEvent='') self.printTrace(self.id, waitEvent='')
self.expectedSignals['isRequested']=1
self.expectedSignals['interruptionEnd']=1
self.expectedSignals['loadOperatorAvailable']=1
self.expectedSignals['initialWIP']=1
receivedEvent = yield self.env.any_of([self.isRequested, self.interruptionEnd, receivedEvent = yield self.env.any_of([self.isRequested, self.interruptionEnd,
self.loadOperatorAvailable, self.initialWIP]) self.loadOperatorAvailable, self.initialWIP])
self.printTrace(self.id, received='') self.printTrace(self.id, received='')
...@@ -369,6 +433,11 @@ class Machine(CoreObject): ...@@ -369,6 +433,11 @@ class Machine(CoreObject):
self.loadTimeCurrentEntity = 0 self.loadTimeCurrentEntity = 0
self.setupTimeCurrentEntity = 0 self.setupTimeCurrentEntity = 0
self.expectedSignals['isRequested']=0
self.expectedSignals['interruptionEnd']=0
self.expectedSignals['loadOperatorAvailable']=0
self.expectedSignals['initialWIP']=0
# ======= request a resource # ======= request a resource
if(self.operatorPool!="None") and any(type=='Load' for type in self.multOperationTypeList): if(self.operatorPool!="None") and any(type=='Load' for type in self.multOperationTypeList):
# when it's ready to accept (canAcceptAndIsRequested) then inform the broker # when it's ready to accept (canAcceptAndIsRequested) then inform the broker
...@@ -376,7 +445,13 @@ class Machine(CoreObject): ...@@ -376,7 +445,13 @@ class Machine(CoreObject):
self.requestOperator() self.requestOperator()
self.timeWaitForLoadOperatorStarted = self.env.now self.timeWaitForLoadOperatorStarted = self.env.now
# wait until the Broker has waited times equal to loadTime (if any) # wait until the Broker has waited times equal to loadTime (if any)
self.expectedSignals['brokerIsSet']=1
yield self.brokerIsSet yield self.brokerIsSet
self.expectedSignals['brokerIsSet']=0
transmitter, eventTime=self.brokerIsSet.value transmitter, eventTime=self.brokerIsSet.value
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'
...@@ -384,7 +459,7 @@ class Machine(CoreObject): ...@@ -384,7 +459,7 @@ class Machine(CoreObject):
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
# ======= Load the machine if the Load is defined as one of the Operators' operation types # ======= Load the machine if the Load is defined as one of the Operators' operation types
if any(type=="Load" for type in self.multOperationTypeList) and self.isOperated(): if any(type=="Load" for type in self.multOperationTypeList) and self.isOperated():
self.timeLoadStarted = self.env.now self.timeLoadStarted = self.env.now
...@@ -393,7 +468,7 @@ class Machine(CoreObject): ...@@ -393,7 +468,7 @@ class Machine(CoreObject):
self.timeLoadEnded = self.env.now self.timeLoadEnded = self.env.now
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 # ======= release a resource if the only operation type is Load
if (self.operatorPool!="None")\ if (self.operatorPool!="None")\
and any(type=="Load" for type in self.multOperationTypeList)\ and any(type=="Load" for type in self.multOperationTypeList)\
...@@ -404,14 +479,20 @@ class Machine(CoreObject): ...@@ -404,14 +479,20 @@ class Machine(CoreObject):
# machine has to release the operator # machine has to release the operator
self.releaseOperator() self.releaseOperator()
# wait until the Broker has finished processing # wait until the Broker has finished processing
self.expectedSignals['brokerIsSet']=1
yield self.brokerIsSet yield self.brokerIsSet
self.expectedSignals['brokerIsSet']=0
transmitter, eventTime=self.brokerIsSet.value transmitter, eventTime=self.brokerIsSet.value
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()
# TODO: reset the requestinEntity before receiving the currentEntity # yield self.env.process(self.loading())
self.requestingEntity=None
# get the entity # get the entity
# TODO: if there was loading time then we must solve the problem of getting an entity # TODO: if there was loading time then we must solve the problem of getting an entity
# from an unidentified giver or not getting an entity at all as the giver # from an unidentified giver or not getting an entity at all as the giver
...@@ -431,7 +512,13 @@ class Machine(CoreObject): ...@@ -431,7 +512,13 @@ class Machine(CoreObject):
self.requestOperator() self.requestOperator()
self.timeWaitForOperatorStarted = self.env.now self.timeWaitForOperatorStarted = self.env.now
# wait until the Broker has waited times equal to loadTime (if any) # wait until the Broker has waited times equal to loadTime (if any)
self.expectedSignals['brokerIsSet']=1
yield self.brokerIsSet yield self.brokerIsSet
self.expectedSignals['brokerIsSet']=0
transmitter, eventTime=self.brokerIsSet.value transmitter, eventTime=self.brokerIsSet.value
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'
...@@ -478,7 +565,13 @@ class Machine(CoreObject): ...@@ -478,7 +565,13 @@ class Machine(CoreObject):
# machine has to release the operator # machine has to release the operator
self.releaseOperator() self.releaseOperator()
# wait until the Broker has finished processing # wait until the Broker has finished processing
self.expectedSignals['brokerIsSet']=1
yield self.brokerIsSet yield self.brokerIsSet
self.expectedSignals['brokerIsSet']=0
transmitter, eventTime=self.brokerIsSet.value transmitter, eventTime=self.brokerIsSet.value
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'
...@@ -496,11 +589,17 @@ class Machine(CoreObject): ...@@ -496,11 +589,17 @@ class Machine(CoreObject):
for oi in self.objectInterruptions: for oi in self.objectInterruptions:
if oi.type=='Failure': if oi.type=='Failure':
if oi.deteriorationType=='working': if oi.deteriorationType=='working':
succeedTuple=(self,self.env.now) if oi.expectedSignals['victimStartsProcess']:
oi.victimStartsProcess.succeed(succeedTuple) succeedTuple=(self,self.env.now)
oi.victimStartsProcess.succeed(succeedTuple)
# this loop is repeated until the processing time is expired with no failure # this loop is repeated until the processing time is expired with no failure
# check when the processingEndedFlag switched to false # check when the processingEndedFlag switched to false
self.expectedSignals['interruptionStart']=1
self.expectedSignals['preemptQueue']=1
while processingNotFinished: while processingNotFinished:
# timeLastProcessingStarted : dummy variable to keep track of the time that the processing starts after # timeLastProcessingStarted : dummy variable to keep track of the time that the processing starts after
# every interruption # every interruption
...@@ -524,7 +623,13 @@ class Machine(CoreObject): ...@@ -524,7 +623,13 @@ class Machine(CoreObject):
and self.isOperated()\ and self.isOperated()\
and any(type=="Processing" for type in self.multOperationTypeList): and any(type=="Processing" for type in self.multOperationTypeList):
self.releaseOperator() self.releaseOperator()
self.expectedSignals['brokerIsSet']=1
yield self.brokerIsSet yield self.brokerIsSet
self.expectedSignals['brokerIsSet']=0
transmitter, eventTime=self.brokerIsSet.value transmitter, eventTime=self.brokerIsSet.value
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'
...@@ -532,7 +637,13 @@ class Machine(CoreObject): ...@@ -532,7 +637,13 @@ class Machine(CoreObject):
# 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:
self.expectedSignals['interruptionEnd']=1
yield self.interruptionEnd # interruptionEnd to be triggered by ObjectInterruption yield self.interruptionEnd # interruptionEnd to be triggered by ObjectInterruption
self.expectedSignals['interruptionEnd']=0
transmitter, eventTime=self.interruptionEnd.value transmitter, eventTime=self.interruptionEnd.value
assert eventTime==self.env.now, 'the interruptionEnd was received later than anticipated' assert eventTime==self.env.now, 'the interruptionEnd was received later than anticipated'
self.interruptionEnd=self.env.event() self.interruptionEnd=self.env.event()
...@@ -547,7 +658,13 @@ class Machine(CoreObject): ...@@ -547,7 +658,13 @@ class Machine(CoreObject):
and not self.interruption: and not self.interruption:
self.timeWaitForOperatorStarted = self.env.now self.timeWaitForOperatorStarted = self.env.now
self.requestOperator() self.requestOperator()
self.expectedSignals['brokerIsSet']=1
yield self.brokerIsSet yield self.brokerIsSet
self.expectedSignals['brokerIsSet']=0
transmitter, eventTime=self.brokerIsSet.value transmitter, eventTime=self.brokerIsSet.value
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'
...@@ -567,7 +684,13 @@ class Machine(CoreObject): ...@@ -567,7 +684,13 @@ class Machine(CoreObject):
and self.isOperated()\ and self.isOperated()\
and any(type=="Processing" for type in self.multOperationTypeList): and any(type=="Processing" for type in self.multOperationTypeList):
self.releaseOperator() self.releaseOperator()
self.expectedSignals['brokerIsSet']=1
yield self.brokerIsSet yield self.brokerIsSet
self.expectedSignals['brokerIsSet']=0
transmitter, eventTime=self.brokerIsSet.value transmitter, eventTime=self.brokerIsSet.value
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'
...@@ -580,6 +703,10 @@ class Machine(CoreObject): ...@@ -580,6 +703,10 @@ class Machine(CoreObject):
else: else:
processingNotFinished=False processingNotFinished=False
self.expectedSignals['interruptionStart']=0
self.expectedSignals['preemptQueue']=0
# 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 # =============== release resource after the end of processing
...@@ -588,7 +715,13 @@ class Machine(CoreObject): ...@@ -588,7 +715,13 @@ class Machine(CoreObject):
and any(type=="Processing" for type in self.multOperationTypeList)\ and any(type=="Processing" for type in self.multOperationTypeList)\
and not self.interruption: and not self.interruption:
self.releaseOperator() self.releaseOperator()
self.expectedSignals['brokerIsSet']=1
yield self.brokerIsSet yield self.brokerIsSet
self.expectedSignals['brokerIsSet']=0
transmitter, eventTime=self.brokerIsSet.value transmitter, eventTime=self.brokerIsSet.value
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'
...@@ -596,10 +729,17 @@ class Machine(CoreObject): ...@@ -596,10 +729,17 @@ 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
self.expectedSignals['interruptionStart']=1
self.expectedSignals['canDispose']=1
while 1: while 1:
self.timeLastBlockageStarted=self.env.now # blockage is starting self.timeLastBlockageStarted=self.env.now # blockage is starting
# wait the event canDispose, this means that the station can deliver the item to successor # wait the event canDispose, this means that the station can deliver the item to successor
self.printTrace(self.id, waitEvent='(canDispose or interruption start)') self.printTrace(self.id, waitEvent='(canDispose or interruption start)')
receivedEvent=yield self.env.any_of([self.canDispose , self.interruptionStart]) receivedEvent=yield self.env.any_of([self.canDispose , self.interruptionStart])
# if there was interruption # if there was interruption
# TODO not good implementation # TODO not good implementation
...@@ -611,7 +751,13 @@ class Machine(CoreObject): ...@@ -611,7 +751,13 @@ class Machine(CoreObject):
self.interruptionActions() # execute interruption actions self.interruptionActions() # execute interruption actions
# 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:
self.expectedSignals['interruptionEnd']=1
yield self.interruptionEnd # interruptionEnd to be triggered by ObjectInterruption yield self.interruptionEnd # interruptionEnd to be triggered by ObjectInterruption
self.expectedSignals['interruptionEnd']=0
transmitter, eventTime=self.interruptionEnd.value transmitter, eventTime=self.interruptionEnd.value
assert eventTime==self.env.now, 'the victim of the failure is not the object that received it' assert eventTime==self.env.now, 'the victim of the failure is not the object that received it'
self.interruptionEnd=self.env.event() self.interruptionEnd=self.env.event()
...@@ -641,7 +787,13 @@ class Machine(CoreObject): ...@@ -641,7 +787,13 @@ class Machine(CoreObject):
# notify that the station waits the entity to be removed # notify that the station waits the entity to be removed
self.waitEntityRemoval=True self.waitEntityRemoval=True
self.printTrace(self.id, waitEvent='(entityRemoved)') self.printTrace(self.id, waitEvent='(entityRemoved)')
self.expectedSignals['entityRemoved']=1
yield self.entityRemoved yield self.entityRemoved
self.expectedSignals['entityRemoved']=0
transmitter, eventTime=self.entityRemoved.value transmitter, eventTime=self.entityRemoved.value
self.printTrace(self.id, entityRemoved=eventTime) self.printTrace(self.id, entityRemoved=eventTime)
assert eventTime==self.env.now,'entityRemoved event activated earlier than received' assert eventTime==self.env.now,'entityRemoved event activated earlier than received'
...@@ -650,6 +802,9 @@ class Machine(CoreObject): ...@@ -650,6 +802,9 @@ class Machine(CoreObject):
# if while waiting (for a canDispose event) became free as the machines that follows emptied it, then proceed # if while waiting (for a canDispose event) became free as the machines that follows emptied it, then proceed
if not self.haveToDispose(): if not self.haveToDispose():
break break
self.expectedSignals['interruptionStart']=0
self.expectedSignals['canDispose']=0
# ======================================================================= # =======================================================================
# actions to be carried out when the processing of an Entity ends # actions to be carried out when the processing of an Entity ends
...@@ -707,8 +862,9 @@ class Machine(CoreObject): ...@@ -707,8 +862,9 @@ class Machine(CoreObject):
for oi in self.objectInterruptions: for oi in self.objectInterruptions:
if oi.type=='Failure': if oi.type=='Failure':
if oi.deteriorationType=='working': if oi.deteriorationType=='working':
succeedTuple=(self,self.env.now) if oi.expectedSignals['victimEndsProcess']:
oi.victimEndsProcess.succeed(succeedTuple) succeedTuple=(self,self.env.now)
oi.victimEndsProcess.succeed(succeedTuple)
# in case Machine just performed the last work before the scheduled maintenance signal the corresponding object # in case Machine just performed the last work before the scheduled maintenance signal the corresponding object
if self.isWorkingOnTheLast: if self.isWorkingOnTheLast:
...@@ -718,10 +874,11 @@ class Machine(CoreObject): ...@@ -718,10 +874,11 @@ class Machine(CoreObject):
# if the objectInterruption is waiting for a a signal # if the objectInterruption is waiting for a a signal
if interruption.victim==self and interruption.waitingSignal: if interruption.victim==self and interruption.waitingSignal:
# signal it and reset the flags # signal it and reset the flags
succeedTuple=(self,self.env.now) if interruption.expectedSignals['endedLastProcessing']:
self.endedLastProcessing.succeed(succeedTuple) succeedTuple=(self,self.env.now)
interruption.waitinSignal=False self.endedLastProcessing.succeed(succeedTuple)
self.isWorkingOnTheLast=False interruption.waitinSignal=False
self.isWorkingOnTheLast=False
# set timeLastShiftEnded attribute so that if it is overtime working it is not counted as off-shift time # set timeLastShiftEnded attribute so that if it is overtime working it is not counted as off-shift time
if self.interruptedBy=='ShiftScheduler': if self.interruptedBy=='ShiftScheduler':
self.timeLastShiftEnded=self.env.now self.timeLastShiftEnded=self.env.now
......
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