Commit 6c01469b authored by Ioannis Papagiannopoulos's avatar Ioannis Papagiannopoulos Committed by Georgios Dagkakis

Machine clean-up

parent fa2ebbc1
...@@ -487,7 +487,7 @@ class Machine(CoreObject): ...@@ -487,7 +487,7 @@ class Machine(CoreObject):
transmitter, eventTime=self.interruptionStart.value transmitter, eventTime=self.interruptionStart.value
assert eventTime==self.env.now, 'the interruption has not been processed on the time of activation' assert eventTime==self.env.now, 'the interruption has not been processed on the time of activation'
self.interruptionStart=self.env.event() self.interruptionStart=self.env.event()
self.genInterruptionActions(type) # execute interruption actions self.interruptionActions(type) # execute interruption actions
#=========================================================== #===========================================================
# # release the operator if there is interruption # # release the operator if there is interruption
#=========================================================== #===========================================================
...@@ -517,7 +517,7 @@ class Machine(CoreObject): ...@@ -517,7 +517,7 @@ class Machine(CoreObject):
assert self.env.now==eventTime, 'the operator leaving has not been processed at the time it should' assert self.env.now==eventTime, 'the operator leaving has not been processed at the time it should'
self.processOperatorUnavailable=self.env.event() self.processOperatorUnavailable=self.env.event()
# carry interruption actions # carry interruption actions
self.genInterruptionActions(type) self.interruptionActions(type)
#=========================================================== #===========================================================
# # release the operator # # release the operator
#=========================================================== #===========================================================
...@@ -543,7 +543,7 @@ class Machine(CoreObject): ...@@ -543,7 +543,7 @@ class Machine(CoreObject):
transmitter, eventTime=self.preemptQueue.value transmitter, eventTime=self.preemptQueue.value
assert eventTime==self.env.now, 'the preemption must be performed on the time of request' assert eventTime==self.env.now, 'the preemption must be performed on the time of request'
self.preemptQueue=self.env.event() self.preemptQueue=self.env.event()
self.genInterruptionActions(type) # execute interruption actions self.interruptionActions(type) # execute interruption actions
#=========================================================== #===========================================================
# # release the operator if there is interruption # # release the operator if there is interruption
#=========================================================== #===========================================================
...@@ -555,116 +555,9 @@ class Machine(CoreObject): ...@@ -555,116 +555,9 @@ class Machine(CoreObject):
else: else:
operationNotFinished=False operationNotFinished=False
# =======================================================================
# actions to be carried out when the processing of an Entity ends
# =======================================================================
def genInterruptionActions(self, type='Processing'):
# if object was processing add the working time
# only if object is not preempting though
# in case of preemption endProcessingActions will be called
if self.isProcessing and not self.shouldPreempt:
self.totalOperationTime+=self.env.now-self.timeLastOperationStarted
if type=='Processing':
self.totalWorkingTime=self.totalOperationTime
elif type=='Setup':
self.totalSetupTime=self.totalOperationTime
# if object was blocked add the working time
if self.isBlocked:
self.addBlockage()
# the machine is currently performing nothing
self.currentlyPerforming=None
activeObjectQueue=self.Res.users
activeEntity=activeObjectQueue[0]
self.printTrace(activeEntity.name, interrupted=self.objName)
# if the interrupt occurred while processing an entity
if not self.waitToDispose:
# output to trace that the Machine (self.objName) got interrupted
try:
self.outputTrace(activeObjectQueue[0].name, "Interrupted at "+self.objName)
except IndexError:
pass
# recalculate the processing time left tinM
self.tinM=self.tinM-(self.env.now-self.timeLastOperationStarted)
if(self.tinM==0): # sometimes the failure may happen exactly at the time that the processing would finish
# this may produce disagreement with the simul8 because in both SimPy and Simul8
# it seems to be random which happens 1st
# this should not appear often to stochastic models though where times are random
self.interruption=True
# start counting the down time at breatTime dummy variable
self.breakTime=self.env.now # dummy variable that the interruption happened
# set isProcessing to False
self.isProcessing=False
# set isBlocked to False
self.isBlocked=False
#===========================================================================
# actions to be performed after an operation (setup or processing)
#===========================================================================
def endOperationActions(self,type):
activeObjectQueue=self.Res.users
activeEntity=activeObjectQueue[0]
# set isProcessing to False
self.isProcessing=False
# the machine is currently performing no operation
self.currentlyPerforming=None
# add working time
self.totalOperationTime+=self.env.now-self.timeLastOperationStarted
if type=='Processing':
self.totalWorkingTime=self.totalOperationTime
elif type=='Setup':
self.totalSetupTime=self.totalOperationTime
# reseting variables used by operation() process
self.totalOperationTime=None
self.timeLastOperationStarted=None
# reseting flags
self.shouldPreempt=False
# reset the variables used to handle the interruptions timing
self.breakTime=0
# if the station has just concluded a processing turn then
if type=='Processing':
# blocking starts
self.isBlocked=True
self.timeLastBlockageStarted=self.env.now
self.printTrace(self.getActiveObjectQueue()[0].name, processEnd=self.objName)
# output to trace that the processing in the Machine self.objName ended
try:
self.outputTrace(activeObjectQueue[0].name,"ended processing in "+self.objName)
except IndexError:
pass
from Globals import G
if G.Router:
# the just processed entity is added to the list of entities
# pending for the next processing
G.pendingEntities.append(activeObjectQueue[0])
# set the variable that flags an Entity is ready to be disposed
self.waitToDispose=True
# update the variables keeping track of Entity related attributes of the machine
self.timeLastEntityEnded=self.env.now # this holds the time that the last entity ended processing in Machine
self.nameLastEntityEnded=self.currentEntity.name # this holds the name of the last entity that ended processing in Machine
self.completedJobs+=1 # Machine completed one more Job# it will be used
self.isProcessingInitialWIP=False
# if there is a failure that depends on the working time of the Machine
# send it the victimEndsProcess signal
for oi in self.objectInterruptions:
if oi.type=='Failure':
if oi.deteriorationType=='working':
if oi.expectedSignals['victimEndsProcess']:
self.sendSignal(receiver=oi, signal=oi.victimEndsProcess)
# in case Machine just performed the last work before the scheduled maintenance signal the corresponding object
if self.isWorkingOnTheLast:
# for the scheduled Object interruptions
# XXX add the SkilledOperatorRouter to this list and perform the signalling only once
for interruption in (G.ObjectInterruptionList):
# if the objectInterruption is waiting for a a signal
if interruption.victim==self and interruption.waitingSignal:
# signal it and reset the flags
if interruption.expectedSignals['endedLastProcessing']:
self.sendSignal(receiver=self, signal=self.endedLastProcessing)
interruption.waitingSignal=False
self.isWorkingOnTheLast=False
# set timeLastShiftEnded attribute so that if it is overtime working it is not counted as off-shift time
if self.interruptedBy=='ShiftScheduler':
self.timeLastShiftEnded=self.env.now
# ======================================================================= # =======================================================================
# the main process of the machine # the main process of the machine
...@@ -875,7 +768,7 @@ class Machine(CoreObject): ...@@ -875,7 +768,7 @@ class Machine(CoreObject):
assert eventTime==self.env.now, 'the interruption has not been processed on the time of activation' assert eventTime==self.env.now, 'the interruption has not been processed on the time of activation'
self.interruptionStart=self.env.event() self.interruptionStart=self.env.event()
# wait for the end of the interruption # wait for the end of the interruption
self.genInterruptionActions() # 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:
...@@ -927,26 +820,35 @@ class Machine(CoreObject): ...@@ -927,26 +820,35 @@ class Machine(CoreObject):
if not self.haveToDispose(): if not self.haveToDispose():
break break
# ======================================================================= #===========================================================================
# actions to be carried out when the processing of an Entity ends # actions to be performed after an operation (setup or processing)
# ======================================================================= #===========================================================================
def endProcessingActions(self): def endOperationActions(self,type):
activeObjectQueue=self.Res.users
activeEntity=activeObjectQueue[0]
# set isProcessing to False # set isProcessing to False
self.isProcessing=False self.isProcessing=False
# the machine is currently performing no operation
self.currentlyPerforming=None self.currentlyPerforming=None
# add working time # add working time
self.totalWorkingTime+=self.env.now-self.timeLastProcessingStarted self.totalOperationTime+=self.env.now-self.timeLastOperationStarted
if type=='Processing':
self.totalWorkingTime=self.totalOperationTime
elif type=='Setup':
self.totalSetupTime=self.totalOperationTime
# reseting variables used by operation() process
self.totalOperationTime=None
self.timeLastOperationStarted=None
# reseting flags
self.shouldPreempt=False
# reset the variables used to handle the interruptions timing
self.breakTime=0
# if the station has just concluded a processing turn then
if type=='Processing':
# blocking starts # blocking starts
self.isBlocked=True self.isBlocked=True
self.timeLastBlockageStarted=self.env.now self.timeLastBlockageStarted=self.env.now
activeObjectQueue=self.Res.users
activeEntity=activeObjectQueue[0]
self.printTrace(self.getActiveObjectQueue()[0].name, processEnd=self.objName) self.printTrace(self.getActiveObjectQueue()[0].name, processEnd=self.objName)
# reset the variables used to handle the interruptions timing
# self.timeLastProcessingStarted=0
self.breakTime=0
# output to trace that the processing in the Machine self.objName ended # output to trace that the processing in the Machine self.objName ended
try: try:
self.outputTrace(activeObjectQueue[0].name,"ended processing in "+self.objName) self.outputTrace(activeObjectQueue[0].name,"ended processing in "+self.objName)
...@@ -959,15 +861,11 @@ class Machine(CoreObject): ...@@ -959,15 +861,11 @@ class Machine(CoreObject):
G.pendingEntities.append(activeObjectQueue[0]) G.pendingEntities.append(activeObjectQueue[0])
# set the variable that flags an Entity is ready to be disposed # set the variable that flags an Entity is ready to be disposed
self.waitToDispose=True self.waitToDispose=True
# update the variables keeping track of Entity related attributes of the machine # update the variables keeping track of Entity related attributes of the machine
self.timeLastEntityEnded=self.env.now # this holds the time that the last entity ended processing in Machine self.timeLastEntityEnded=self.env.now # this holds the time that the last entity ended processing in Machine
self.nameLastEntityEnded=self.currentEntity.name # this holds the name of the last entity that ended processing in Machine self.nameLastEntityEnded=self.currentEntity.name # this holds the name of the last entity that ended processing in Machine
self.completedJobs+=1 # Machine completed one more Job self.completedJobs+=1 # Machine completed one more Job# it will be used
# reseting flags
self.shouldPreempt=False
self.isProcessingInitialWIP=False self.isProcessingInitialWIP=False
# if there is a failure that depends on the working time of the Machine # if there is a failure that depends on the working time of the Machine
# send it the victimEndsProcess signal # send it the victimEndsProcess signal
for oi in self.objectInterruptions: for oi in self.objectInterruptions:
...@@ -975,7 +873,6 @@ class Machine(CoreObject): ...@@ -975,7 +873,6 @@ class Machine(CoreObject):
if oi.deteriorationType=='working': if oi.deteriorationType=='working':
if oi.expectedSignals['victimEndsProcess']: if oi.expectedSignals['victimEndsProcess']:
self.sendSignal(receiver=oi, signal=oi.victimEndsProcess) self.sendSignal(receiver=oi, signal=oi.victimEndsProcess)
# 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:
# for the scheduled Object interruptions # for the scheduled Object interruptions
...@@ -1000,29 +897,28 @@ class Machine(CoreObject): ...@@ -1000,29 +897,28 @@ class Machine(CoreObject):
# only if object is not preempting though # only if object is not preempting though
# in case of preemption endProcessingActions will be called # in case of preemption endProcessingActions will be called
if self.isProcessing and not self.shouldPreempt: if self.isProcessing and not self.shouldPreempt:
self.totalWorkingTime+=self.env.now-self.timeLastProcessingStarted self.totalOperationTime+=self.env.now-self.timeLastOperationStarted
# self.totalOperationTime+=self.env.now-self.timeLastOperationStarted if type=='Processing':
# if type=='Processing': self.totalWorkingTime=self.totalOperationTime
# self.totalWorkingTime=self.totalOperationTime elif type=='Setup':
# elif type=='Setup': self.totalSetupTime=self.totalOperationTime
# self.totalSetupTime=self.totalOperationTime
# if object was blocked add the working time # if object was blocked add the working time
if self.isBlocked: if self.isBlocked:
self.addBlockage() self.addBlockage()
# the machine is currently performing nothing
self.currentlyPerforming=None self.currentlyPerforming=None
activeObjectQueue=self.Res.users activeObjectQueue=self.Res.users
activeEntity=activeObjectQueue[0] activeEntity=activeObjectQueue[0]
self.printTrace(activeEntity.name, interrupted=self.objName) self.printTrace(activeEntity.name, interrupted=self.objName)
# if the interrupt occurred while processing an entity # if the interrupt occurred while processing an entity
if self.isProcessing: if not self.waitToDispose:
# output to trace that the Machine (self.objName) got interrupted # output to trace that the Machine (self.objName) got interrupted
try: try:
self.outputTrace(activeObjectQueue[0].name, "Interrupted at "+self.objName) self.outputTrace(activeObjectQueue[0].name, "Interrupted at "+self.objName)
except IndexError: except IndexError:
pass pass
# recalculate the processing time left tinM # recalculate the processing time left tinM
self.tinM=self.tinM-(self.env.now-self.timeLastProcessingStarted) self.tinM=self.tinM-(self.env.now-self.timeLastOperationStarted)
if(self.tinM==0): # sometimes the failure may happen exactly at the time that the processing would finish if(self.tinM==0): # sometimes the failure may happen exactly at the time that the processing would finish
# this may produce disagreement with the simul8 because in both SimPy and Simul8 # this may produce disagreement with the simul8 because in both SimPy and Simul8
# it seems to be random which happens 1st # it seems to be random which happens 1st
......
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