Commit b3ed30f2 authored by Ioannis Papagiannopoulos's avatar Ioannis Papagiannopoulos Committed by Jérome Perrin

OperatedMachine collapsed to Machine

parent b98f8a3c
...@@ -260,17 +260,53 @@ def createObjects(): ...@@ -260,17 +260,53 @@ def createObjects():
failureDistribution=failures.get('failureDistribution', 'not found') failureDistribution=failures.get('failureDistribution', 'not found')
MTTF=float(failures.get('MTTF', '0')) MTTF=float(failures.get('MTTF', '0'))
MTTR=float(failures.get('MTTR', '0')) MTTR=float(failures.get('MTTR', '0'))
availability=float(failures.get('availability', '0')) availability=float(failures.get('availability', '0'))
# type of operation and related times
operationType=element.get('operationType','not found')
setupTime = element.get('setupTime',{})
setupDistribution = setupTime.get('setupDistribution','not found')
setupMean = float(setupTime.get('setupMean','0'))
setupStdev=float(setupTime.get('setupStdev', '0'))
setupMin=float(setupTime.get('setupMin', '0'))
setupMax=float(setupTime.get('setupMax', '0'))
loadTime = element.get('loadTime',{})
loadDistribution = loadTime.get('loadDistribution','not found')
loadMean = float(loadTime.get('loadMean','0'))
loadStdev = float(loadTime.get('loadStdev', '0'))
loadMin=float(loadTime.get('loadMin', '0'))
loadMax=float(loadTime.get('loadMax', '0'))
if len(G.OperatorPoolsList)>0:
for operatorPool in G.OperatorPoolsList: # find the operatorPool assigned to the machine
if(id in operatorPool.coreObjectIds): # and add it to the machine's operatorPool
machineOperatorPoolList=operatorPool # there must only one operator pool assigned to the machine,
# otherwise only one of them will be taken into account
else:
machineOperatorPoolList=[] # if there is no operatorPool assigned to the machine
else: # then machineOperatorPoolList/operatorPool is a list
machineOperatorPoolList=[] # if there are no operatorsPool created then the
# then machineOperatorPoolList/operatorPool is a list
if (type(machineOperatorPoolList) is list): # if the machineOperatorPoolList is a list
# find the operators assigned to it and add them to the list
for operator in G.OperatorsList: # check which operator in the G.OperatorsList
if(id in operator.coreObjectIds): # (if any) is assigned to operate
machineOperatorPoolList.append(operator) # the machine with ID equal to id
# if there is no operator assigned then the list will be empty
r='None' r='None'
for repairman in G.RepairmanList: # check which repairman in the G.RepairmanList for repairman in G.RepairmanList: # check which repairman in the G.RepairmanList
if(id in repairman.coreObjectIds): # (if any) is assigned to repair if(id in repairman.coreObjectIds): # (if any) is assigned to repair
r=repairman # the machine with ID equal to id r=repairman # the machine with ID equal to id
M=Machine(id, name, 1, distribution=distributionType, failureDistribution=failureDistribution, M=Machine(id, name, 1, distribution=distributionType, failureDistribution=failureDistribution,
MTTF=MTTF, MTTR=MTTR, availability=availability, repairman=r, MTTF=MTTF, MTTR=MTTR, availability=availability, #repairman=r,
mean=mean,stdev=stdev,min=min,max=max) mean=mean,stdev=stdev,min=min,max=max,
operatorPool=machineOperatorPoolList, operationType=operationType,
loadDistribution=loadDistribution, setupDistribution=setupDistribution,
setupMean=setupMean,setupStdev=setupStdev,setupMin=setupMin,setupMax=setupMax,
loadMean=loadMean,loadStdev=loadStdev,loadMin=loadMin,loadMax=loadMax,
repairman=r)
M.nextIds=getSuccessorList(id) # update the nextIDs list of the machine M.nextIds=getSuccessorList(id) # update the nextIDs list of the machine
G.MachineList.append(M) # add machine to global MachineList G.MachineList.append(M) # add machine to global MachineList
G.OperatedMachineList.append(M) # add the machine to the operatedMachines List
G.ObjList.append(M) # add machine to ObjList G.ObjList.append(M) # add machine to ObjList
elif objClass=='Dream.BatchScrapMachine': elif objClass=='Dream.BatchScrapMachine':
......
...@@ -26,11 +26,14 @@ Models a machine that can also have failures ...@@ -26,11 +26,14 @@ Models a machine that can also have failures
''' '''
from SimPy.Simulation import Process, Resource from SimPy.Simulation import Process, Resource
from SimPy.Simulation import activate, passivate, waituntil, now, hold from SimPy.Simulation import activate, passivate, waituntil, now, hold, request, release
from Failure import Failure from Failure import Failure
from CoreObject import CoreObject from CoreObject import CoreObject
from OperatedPoolBroker import Broker
from OperatorPool import OperatorPool
from RandomNumberGenerator import RandomNumberGenerator from RandomNumberGenerator import RandomNumberGenerator
import scipy.stats as stat import scipy.stats as stat
...@@ -38,11 +41,14 @@ import scipy.stats as stat ...@@ -38,11 +41,14 @@ import scipy.stats as stat
# the Machine object # the Machine object
# =========================================================================== # ===========================================================================
class Machine(CoreObject): class Machine(CoreObject):
# =======================================================================
#initialize the id the capacity, of the resource and the distribution # initialise the id the capacity, of the resource and the distribution
# =======================================================================
def __init__(self, id, name, capacity=1, distribution='Fixed', mean=1, stdev=0, min=0, max=10,\ def __init__(self, id, name, capacity=1, distribution='Fixed', mean=1, stdev=0, min=0, max=10,\
failureDistribution='No', MTTF=0, MTTR=0, availability=0, repairman='None'): failureDistribution='No', MTTF=0, MTTR=0, availability=0, repairman='None',\
# Process.__init__(self) operatorPool='None',operationType='None',\
loadDistribution="No",loadMean=0, loadStdev=0, loadMin=0, loadMax=10,
setupDistribution="No",setupMean=0, setupStdev=0, setupMin=0, setupMax=10):
CoreObject.__init__(self) CoreObject.__init__(self)
# hold the id, name, and type of the Machine instance # hold the id, name, and type of the Machine instance
self.id=id self.id=id
...@@ -63,35 +69,202 @@ class Machine(CoreObject): ...@@ -63,35 +69,202 @@ class Machine(CoreObject):
self.rng.max=max self.rng.max=max
self.MTTF=MTTF self.MTTF=MTTF
self.MTTR=MTTR self.MTTR=MTTR
self.availability=availability self.availability=availability
''' sets the operator resource of the Machine
check if the operatorPool is a List or a OperatorPool type Object
if it is a list then initiate a OperatorPool type object containing
the list of operators provided
if the list is empty create operator pool with empty list
'''
if (type(operatorPool) is list): #and len(operatorPool)>0:
id = id+'_OP'
name=self.objName+'_operatorPool'
self.operatorPool=OperatorPool(id, name, operatorsList=operatorPool)
else:
self.operatorPool=operatorPool
# update the operatorPool coreObjects list
if self.operatorPool!='None':
self.operatorPool.coreObjectIds.append(self.id)
self.operatorPool.coreObjects.append(self)
# holds the Operator currently processing the Machine
self.currentOperator=None
# define if load/setup/removal/processing are performed by the operator
self.operationType=operationType
# boolean to check weather the machine is being operated
self.toBeOperated = False
# define the load times
self.loadDistType=loadDistribution
self.loadRng=RandomNumberGenerator(self, self.loadDistType)
self.loadRng.avg=loadMean
self.loadRng.stdev=loadStdev
self.loadRng.min=loadMin
self.loadRng.max=loadMax
# variable that informs on the need for setup
self.setUp=True
# define the setup times
self.setupDistType=setupDistribution
self.stpRng=RandomNumberGenerator(self, self.setupDistType)
self.stpRng.avg=setupMean
self.stpRng.stdev=setupStdev
self.stpRng.min=setupMin
self.stpRng.max=setupMax
# examine if there are multiple operation types performed by the operator
# there can be Setup/Processing operationType
# or the combination of both (MT-Load-Setup-Processing)
self.multOperationTypeList=[]
if self.operationType.startswith("MT"):
OTlist = operationType.split('-')
self.operationType=OTlist.pop(0)
self.multOperationTypeList = OTlist
else:
self.multOperationTypeList.append(self.operationType)
# lists to hold statistics of multiple runs
self.WaitingForOperator=[]
self.WaitingForLoadOperator=[]
self.Loading = []
self.SettingUp =[]
# ======================================================================= # =======================================================================
# initialize the Machine object # initialize the machine
# ======================================================================= # =======================================================================
def initialize(self): def initialize(self):
# using the Process __init__ and not the CoreObject __init__ # using the Process __init__ and not the CoreObject __init__
CoreObject.initialize(self) CoreObject.initialize(self)
# initialize the internal Queue (type Resource) of the Machine # initialize the internal Queue (type Resource) of the Machine
self.Res=Resource(self.capacity) self.Res=Resource(self.capacity)
# initiate the Broker responsible to control the request/release
# initialize the operator pool if any
if (self.operatorPool!="None"):
self.operatorPool.initialize()
self.broker = Broker(self)
activate(self.broker,self.broker.run())
for operator in self.operatorPool.operators:
operator.coreObjectIds.append(self.id)
operator.coreObjects.append(self)
# the time that the machine started/ended its wait for the operator
self.timeWaitForOperatorStarted=0
self.timeWaitForOperatorEnded=0
self.totalTimeWaitingForOperator=0
# the time that the machine started/ended its wait for the operator
self.timeWaitForLoadOperatorStarted=0
self.timeWaitForLoadOperatorEnded=0
self.totalTimeWaitingForLoadOperator=0
# the time that the operator started/ended loading the machine
self.timeLoadStarted=0
self.timeLoadEnded=0
self.totalLoadTime=0
# the time that the operator started/ended setting-up the machine
self.timeSetupStarted=0
self.timeSetupEnded=0
self.totalSetupTime=0
# Current entity load/setup/loadOperatorwait/operatorWait related times
self.operatorWaitTimeCurrentEntity=0 # holds the time that the machine was waiting for the operator
self.loadOperatorWaitTimeCurrentEntity = 0 # holds the time that the machine waits for operator to load the it
self.loadTimeCurrentEntity = 0 # holds the time to load the current entity
self.setupTimeCurrentEntity = 0 # holds the time to setup the machine before processing the current entity
# ======================================================================= # =======================================================================
# the main process of the machine # the main process of the machine
# ======================================================================= # =======================================================================
def run(self): def run(self):
#execute all through simulation time # execute all through simulation time
while 1: while 1:
# wait until the machine can accept an entity and one predecessor requests it # wait until the machine can accept an entity and one predecessor requests it
# canAcceptAndIsRequested is invoked to check when the machine requested to receive an entity # canAcceptAndIsRequested is invoked to check when the machine requested to receive an entity
yield waituntil, self, self.canAcceptAndIsRequested yield waituntil, self, self.canAcceptAndIsRequested
# get the entity from the predecessor
self.currentEntity=self.getEntity() # here or in the get entity (apart from the loatTimeCurrentEntity)
# in case they are placed inside the getEntity then the initialize of
# the corresponding variables should be moved to the initialize() of the CoreObject
self.operatorWaitTimeCurrentEntity = 0
self.loadOperatorWaitTimeCurrentEntity = 0
self.loadTimeCurrentEntity = 0
self.setupTimeCurrentEntity = 0
# ++++++++++++++++++++++++++++++ New ++++++++++++++++++++++++++++++++++++
# ======= 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 = now()
# wait until the Broker has waited times equal to loadTime (if any)
yield waituntil, self, self.broker.brokerIsSet
self.timeWaitForLoadOperatorEnded = 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 = now()
yield hold,self,self.calculateLoadTime()
# if self.interrupted(): There is the issue of failure during the Loading
self.timeLoadEnded = 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" or 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
yield waituntil, self, self.broker.brokerIsSet
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# get the 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
# may fall in failure mode (assignExit()?)
self.currentEntity=self.getEntity()
# ++++++++++++++++++++++++++++++ New ++++++++++++++++++++++++++++++++++++
# ======= request a resource if it is not already assigned an Operator
if(self.operatorPool!="None")\
and any(type=="Processing" or 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 = now()
# wait until the Broker has waited times equal to loadTime (if any)
yield waituntil, self, self.broker.brokerIsSet
self.timeWaitForOperatorEnded = now()
self.operatorWaitTimeCurrentEntity += self.timeWaitForOperatorEnded-self.timeWaitForOperatorStarted
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# variables dedicated to hold the processing times, the time when the Entity entered, # variables dedicated to hold the processing times, the time when the Entity entered,
# and the processing time left # and the processing time left
self.totalProcessingTimeInCurrentEntity=self.calculateProcessingTime() # get the processing time, tinMStarts holds the processing time of the machine self.totalProcessingTimeInCurrentEntity=self.calculateProcessingTime() # get the processing time, tinMStarts holds the processing time of the machine
tinM=self.totalProcessingTimeInCurrentEntity # timer to hold the processing time left tinM=self.totalProcessingTimeInCurrentEntity # timer to hold the processing time left
# ++++++++++++++++++++++++++++++ New ++++++++++++++++++++++++++++++++++++
# ======= 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
if any(type=="Setup" for type in self.multOperationTypeList) and self.isOperated():
self.timeSetupStarted = now()
yield hold,self,self.calculateSetupTime()
# if self.interrupted(): There is the issue of failure during the setup
self.timeSetupEnded = now()
self.setupTimeCurrentEntity = self.timeSetupEnded-self.timeSetupStarted
self.totalSetupTime += self.setupTimeCurrentEntity
# ======= release a resource if the only operation type is Setup
if (self.operatorPool!="None")\
and self.isOperated()\
and any(type=="Setup" or 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()
# print self.objName, 'operator released', now()
# wait until the Broker has finished processing
yield waituntil, self, self.broker.brokerIsSet
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# variables used to flag any interruptions and the end of the processing # variables used to flag any interruptions and the end of the processing
interruption=False interruption=False
processingNotFinished=True processingNotFinished=True
...@@ -110,7 +283,7 @@ class Machine(CoreObject): ...@@ -110,7 +283,7 @@ class Machine(CoreObject):
# processingEndedFlag and exit loop, # processingEndedFlag and exit loop,
# else (if interrupted()) set interruption flag to true (only if tinM==0), # else (if interrupted()) set interruption flag to true (only if tinM==0),
# and recalculate the processing time left tinM, # and recalculate the processing time left tinM,
# passivate while waiting for repair. # passivate while waiting for repair.
yield hold,self,tinM # getting processed for remaining processing time tinM yield hold,self,tinM # getting processed for remaining processing time tinM
if self.interrupted(): # if a failure occurs while processing the machine is interrupted. if self.interrupted(): # if a failure occurs while processing the machine is interrupted.
#self.interruptionActions() # execute interruption actions #self.interruptionActions() # execute interruption actions
...@@ -129,7 +302,17 @@ class Machine(CoreObject): ...@@ -129,7 +302,17 @@ class Machine(CoreObject):
# passivate the Machine for as long as there is no repair # passivate the Machine for as long as there is no repair
# start counting the down time at breatTime dummy variable # start counting the down time at breatTime dummy variable
breakTime=now() # dummy variable that the interruption happened breakTime=now() # dummy variable that the interruption happened
yield passivate,self # if there is a failure in the machine it is passivated # ++++++++++++++++++++++++++++++ New ++++++++++++++++++++++++++++++++++++
# =============== 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()
# print self.objName, 'operator released due to failure', now()
yield waituntil,self,self.broker.brokerIsSet
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# if there is a failure in the machine it is passivated
yield passivate,self
# use the timers to count the time that Machine is down and related # use the timers to count the time that Machine is down and related
self.downTimeProcessingCurrentEntity+=now()-breakTime # count the time that Machine is down while processing this Entity self.downTimeProcessingCurrentEntity+=now()-breakTime # count the time that Machine is down while processing this Entity
self.downTimeInCurrentEntity+=now()-breakTime # count the time that Machine is down while on currentEntity self.downTimeInCurrentEntity+=now()-breakTime # count the time that Machine is down while on currentEntity
...@@ -137,10 +320,23 @@ class Machine(CoreObject): ...@@ -137,10 +320,23 @@ class Machine(CoreObject):
self.failureTimeInCurrentEntity+=now()-breakTime # dummy variable keeping track of the failure time self.failureTimeInCurrentEntity+=now()-breakTime # dummy variable keeping track of the failure time
# output to trace that the Machine self.objName was passivated for the current failure time # output to trace that the Machine self.objName was passivated for the current failure time
self.outputTrace(self.getActiveObjectQueue()[0].name, "passivated in "+self.objName+" for "+str(now()-breakTime)) self.outputTrace(self.getActiveObjectQueue()[0].name, "passivated in "+self.objName+" for "+str(now()-breakTime))
#if during the interruption the object became empty break #if during the interruption the object became empty break
if (len(self.getActiveObjectQueue())==0 and self.shouldPreempt): if (len(self.getActiveObjectQueue())==0 and self.shouldPreempt):
break break
# ++++++++++++++++++++++++++++++ New ++++++++++++++++++++++++++++++++++++
# =============== request a resource after the repair
if (self.operatorPool!="None")\
and any(type=="Processing" for type in self.multOperationTypeList)\
and not interruption:
self.timeWaitForOperatorStarted = now()
self.requestOperator()
yield waituntil,self,self.broker.brokerIsSet
self.timeWaitForOperatorEnded = now()
self.operatorWaitTimeCurrentEntity += self.timeWaitForOperatorEnded-self.timeWaitForOperatorStarted
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# if no interruption occurred the processing in M1 is ended # if no interruption occurred the processing in M1 is ended
else: else:
processingNotFinished=False processingNotFinished=False
...@@ -156,20 +352,31 @@ class Machine(CoreObject): ...@@ -156,20 +352,31 @@ class Machine(CoreObject):
self.outputTrace(self.getActiveObjectQueue()[0].name,"ended processing in "+self.objName) self.outputTrace(self.getActiveObjectQueue()[0].name,"ended processing in "+self.objName)
except IndexError: except IndexError:
pass pass
# ++++++++++++++++++++++++++++++ New ++++++++++++++++++++++++++++++++++++
# =============== release resource after the end of processing
if (self.operatorPool!='None')\
and any(type=="Processing" for type in self.multOperationTypeList)\
and not interruption:
self.releaseOperator()
yield waituntil,self,self.broker.brokerIsSet
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# 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 total working time # update the total working time
self.totalWorkingTime+=self.totalProcessingTimeInCurrentEntity # the total processing time for this entity self.totalWorkingTime+=self.totalProcessingTimeInCurrentEntity # the total processing time for this entity
# is what the distribution initially gave # is what the distribution initially gave
# 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=now() # this holds the time that the last entity ended processing in Machine self.timeLastEntityEnded=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
while 1: while 1:
# wait until the next Object is available or machine has failure # wait until the next Object is available or machine has failure
yield waituntil, self, self.ifCanDisposeOrHaveFailure yield waituntil, self, self.ifCanDisposeOrHaveFailure
# if Next object available break # if Next object available break
if self.Up: if self.Up:
...@@ -186,7 +393,7 @@ class Machine(CoreObject): ...@@ -186,7 +393,7 @@ class Machine(CoreObject):
self.downTimeInTryingToReleaseCurrentEntity+=now()-failTime self.downTimeInTryingToReleaseCurrentEntity+=now()-failTime
self.downTimeInCurrentEntity+=now()-failTime # already updated from failures during processing self.downTimeInCurrentEntity+=now()-failTime # already updated from failures during processing
# update the timeLastFailureEnded # update the timeLastFailureEnded
self.timeLastFailureEnded=now() self.timeLastFailureEnded=now()
#if during the interruption the object became empty break #if during the interruption the object became empty break
if (len(self.getActiveObjectQueue())==0 and self.shouldPreempt): if (len(self.getActiveObjectQueue())==0 and self.shouldPreempt):
...@@ -201,7 +408,7 @@ class Machine(CoreObject): ...@@ -201,7 +408,7 @@ class Machine(CoreObject):
return self.Up return self.Up
# ======================================================================= # =======================================================================
# checks if the Machine can accept an entity # checks if the Machine can accept an entity
# it checks also who called it and returns TRUE only to the predecessor # it checks also who called it and returns TRUE only to the predecessor
# that will give the entity. # that will give the entity.
# ======================================================================= # =======================================================================
...@@ -214,17 +421,33 @@ class Machine(CoreObject): ...@@ -214,17 +421,33 @@ class Machine(CoreObject):
# if we have only one predecessor just check if there is a place and the machine is up # if we have only one predecessor just check if there is a place and the machine is up
# this is done to achieve better (cpu) processing time # this is done to achieve better (cpu) processing time
# then we can also use it as a filter for a yield method # then we can also use it as a filter for a yield method
if(len(activeObject.previous)==1 or callerObject==None): if(len(activeObject.previous)==1 or callerObject==None):
return activeObject.Up and len(activeObjectQueue)<activeObject.capacity if (activeObject.operatorPool!='None' and any(type=='Load' for type in activeObject.multOperationTypeList)):
return activeObject.operatorPool.checkIfResourceIsAvailable()\
and activeObject.Up\
and len(activeObjectQueue)<activeObject.capacity
else:
return activeObject.Up and len(activeObjectQueue)<activeObject.capacity\
thecaller=callerObject thecaller=callerObject
# return True ONLY if the length of the activeOjbectQue is smaller than # return True ONLY if the length of the activeOjbectQue is smaller than
# the object capacity, and the callerObject is not None but the giverObject # the object capacity, and the callerObject is not None but the giverObject
return len(activeObjectQueue)<activeObject.capacity and (thecaller is giverObject) and self.Up if (activeObject.operatorPool!='None' and any(type=='Load' for type in activeObject.multOperationTypeList)):
return activeObject.operatorPool.checkIfResourceIsAvailable()\
and activeObject.Up\
and len(activeObjectQueue)<activeObject.capacity
else:
# the operator doesn't have to be present for the loading of the machine as the load operation
# is not assigned to operators
return activeObject.Up and len(activeObjectQueue)<activeObject.capacity and (thecaller is giverObject)
# while if the set up is performed before the (automatic) loading of the machine then the availability of the
# operator is requested
# return (activeObject.operatorPool=='None' or activeObject.operatorPool.checkIfResourceIsAvailable())\
# and activeObject.Up and len(activeObjectQueue)<activeObject.capacity
# ======================================================================= # =======================================================================
# checks if the Machine can accept an entity and there is an entity in # checks if the Machine can accept an entity and there is an entity in
# some predecessor waiting for it # some possible giver waiting for it
# also updates the giver to the one that is to be taken # also updates the giver to the one that is to be taken
# ======================================================================= # =======================================================================
def canAcceptAndIsRequested(self): def canAcceptAndIsRequested(self):
...@@ -232,33 +455,69 @@ class Machine(CoreObject): ...@@ -232,33 +455,69 @@ class Machine(CoreObject):
activeObject=self.getActiveObject() activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue() activeObjectQueue=self.getActiveObjectQueue()
giverObject=self.getGiverObject() giverObject=self.getGiverObject()
# if we have only one predecessor just check if there is a place,
# if we have only one possible giver just check if there is a place,
# the machine is up and the predecessor has an entity to dispose # the machine is up and the predecessor has an entity to dispose
# this is done to achieve better (cpu) processing time # if the machine has to compete for an Operator that loads the entities onto it
# check if the predecessor if blocked by an other Machine
# if not then the machine has to block the predecessor giverObject to avoid conflicts
# with other competing machines
if(len(activeObject.previous)==1): if(len(activeObject.previous)==1):
return activeObject.Up and len(activeObjectQueue)<activeObject.capacity\ if (activeObject.operatorPool!='None' and any(type=='Load' for type in activeObject.multOperationTypeList)):
and giverObject.haveToDispose(activeObject) if activeObject.operatorPool.checkIfResourceIsAvailable()\
and activeObject.Up and len(activeObjectQueue)<activeObject.capacity\
and giverObject.haveToDispose(activeObject) and not giverObject.exitIsAssigned():
activeObject.giver.assignExit()
return True
else:
return False
else:
# the operator performs no load and the entity is received by the machine while there is
# no need for operators presence. The operator needs to be present only where the load Type
# operation is assigned
return activeObject.Up and len(activeObjectQueue)<activeObject.capacity\
and giverObject.haveToDispose(activeObject)
# if the set-up performance needs be first performed before the transfer of the entity to
# the machine then the presence of an operator to setup the machine before the getEntity()
# is requested
# return (activeObject.operatorPool=='None'\
# or activeObject.operatorPool.checkIfResourceIsAvailable())\
# and activeObject.Up and len(activeObjectQueue)<activeObject.capacity\
# and giverObject.haveToDispose()
# dummy variables that help prioritize the objects requesting to give objects to the Machine (activeObject) # dummy variables that help prioritise the objects requesting to give objects to the Machine (activeObject)
isRequested=False # is requested is dummyVariable checking if it is requested to accept an item isRequested=False # is requested is dummyVariable checking if it is requested to accept an item
maxTimeWaiting=0 # dummy variable counting the time a predecessor is blocked maxTimeWaiting=0 # dummy variable counting the time a predecessor is blocked
# loop through the possible givers to see which have to dispose and which is the one blocked for longer # loop through the possible givers to see which have to dispose and which is the one blocked for longer
for object in activeObject.previous: for object in activeObject.previous:
if(object.haveToDispose(activeObject) and object.receiver==self): if(object.haveToDispose(activeObject) and object.receiver==self):# and not object.exitIsAssigned()):
isRequested=True # if the predecessor objects have entities to dispose of isRequested=True # if the possible giver has entities to dispose of
if(object.downTimeInTryingToReleaseCurrentEntity>0):# and the predecessor has been down while trying to give away the Entity if(object.downTimeInTryingToReleaseCurrentEntity>0):# and the possible giver has been down while trying to give away the Entity
timeWaiting=now()-object.timeLastFailureEnded # the timeWaiting dummy variable counts the time end of the last failure of the giver object timeWaiting=now()-object.timeLastFailureEnded # the timeWaiting dummy variable counts the time end of the last failure of the giver object
else: else:
timeWaiting=now()-object.timeLastEntityEnded # in any other case, it holds the time since the end of the Entity processing timeWaiting=now()-object.timeLastEntityEnded # in any other case, it holds the time since the end of the Entity processing
#if more than one predecessor have to dispose take the part from the one that is blocked longer #if more than one possible givers have to dispose take the part from the one that is blocked longer
if(timeWaiting>=maxTimeWaiting): if(timeWaiting>=maxTimeWaiting):
activeObject.giver=object # the object to deliver the Entity to the activeObject is set to the ith member of the previous list activeObject.giver=object # set the giver
maxTimeWaiting=timeWaiting maxTimeWaiting=timeWaiting
# in the next loops, check the other predecessors in the previous list
return activeObject.Up and len(activeObjectQueue)<activeObject.capacity and isRequested if (activeObject.operatorPool!='None' and any(type=='Load' for type in activeObject.multOperationTypeList)):
if activeObject.operatorPool.checkIfResourceIsAvailable()\
and activeObject.Up and len(activeObjectQueue)<activeObject.capacity\
and isRequested and not activeObject.giver.exitIsAssigned():
activeObject.giver.assignExit()
return True
else:
return False
else:
# the operator doesn't have to be present for the loading of the machine as the load operation
# is not assigned to operators
return activeObject.Up and len(activeObjectQueue)<activeObject.capacity and isRequested
# while if the set up is performed before the (automatic) loading of the machine then the availability of the
# operator is requested
# return (activeObject.operatorPool=='None' or activeObject.operatorPool.checkIfResourceIsAvailable())\
# and activeObject.Up and len(activeObjectQueue)<activeObject.capacity and isRequested
# ======================================================================= # =======================================================================
# checks if the machine down or it can dispose the object # checks if the machine down or it can dispose the object
...@@ -306,10 +565,54 @@ class Machine(CoreObject): ...@@ -306,10 +565,54 @@ class Machine(CoreObject):
# in the next loops, check the other successors in the previous list # in the next loops, check the other successors in the previous list
return len(activeObjectQueue)>0 and activeObject.waitToDispose\ return len(activeObjectQueue)>0 and activeObject.waitToDispose\
and activeObject.Up and (thecaller is self.receiver) and activeObject.Up and (thecaller is self.receiver)
# =======================================================================
# calculates the setup time
# =======================================================================
def calculateSetupTime(self):
return self.stpRng.generateNumber()
# =======================================================================
# calculates the Load time
# =======================================================================
def calculateLoadTime(self):
return self.loadRng.generateNumber()
# =======================================================================
# prepare the machine to be operated
# =======================================================================
def requestOperator(self):
self.broker.invokeBroker()
self.toBeOperated = True
# =======================================================================
# prepare the machine to be released
# =======================================================================
def releaseOperator(self):
self.broker.invokeBroker()
self.toBeOperated = False
# =======================================================================
# check if the machine is currently operated by an operator
# =======================================================================
def isOperated(self):
return self.toBeOperated
# =======================================================================
# check if the machine is already set-up
# =======================================================================
def isSetUp(self):
return self.setUp
# =======================================================================
# request that the machine is set-up by an operator
# =======================================================================
def requestSetup(self):
self.setUp=False
# ======================================================================= # =======================================================================
# actions to be taken after the simulation ends # actions to be taken after the simulation ends
# ======================================================================= # =======================================================================
def postProcessing(self, MaxSimtime=None): def postProcessing(self, MaxSimtime=None):
if MaxSimtime==None: if MaxSimtime==None:
from Globals import G from Globals import G
...@@ -325,28 +628,42 @@ class Machine(CoreObject): ...@@ -325,28 +628,42 @@ class Machine(CoreObject):
for nextObject in self.next: for nextObject in self.next:
if nextObject.canAccept(): if nextObject.canAccept():
mightBeBlocked=False mightBeBlocked=False
# if there is an entity that finished processing in a Machine but did not get to reach # if there is an entity that finished processing in a Machine but did not get to reach
# the following Object till the end of simulation, # the following Object till the end of simulation,
# we have to add this blockage to the percentage of blockage in Machine # we have to add this blockage to the percentage of blockage in Machine
# we should exclude the failure time in current entity though! # we should exclude the failure time in current entity though!
# if (len(self.Res.activeQ)>0) and (len(self.next[0].Res.activeQ)>0) and ((self.nameLastEntityEntered == self.nameLastEntityEnded)): # if (len(self.Res.activeQ)>0) and (len(self.next[0].Res.activeQ)>0) and ((self.nameLastEntityEntered == self.nameLastEntityEnded)):
if (len(activeObjectQueue)>0) and (mightBeBlocked)\ if (len(activeObjectQueue)>0) and (mightBeBlocked)\
and ((activeObject.nameLastEntityEntered == activeObject.nameLastEntityEnded)): and ((activeObject.nameLastEntityEntered == activeObject.nameLastEntityEnded)):
# be carefull here, might have to reconsider # be careful here, might have to reconsider
activeObject.totalBlockageTime+=now()-(activeObject.timeLastEntityEnded+activeObject.downTimeInTryingToReleaseCurrentEntity) activeObject.totalBlockageTime+=now()-(activeObject.timeLastEntityEnded+activeObject.downTimeInTryingToReleaseCurrentEntity)
if activeObject.Up==False: if activeObject.Up==False:
activeObject.totalBlockageTime-=now()-activeObject.timeLastFailure activeObject.totalBlockageTime-=now()-activeObject.timeLastFailure
alreadyAdded=True alreadyAdded=True
#if Machine is currently processing an entity we should count this working time #if Machine is currently processing an entity we should count this working time
if(len(activeObject.Res.activeQ)>0) and (not (activeObject.nameLastEntityEnded==activeObject.nameLastEntityEntered)): if(len(activeObject.getActiveObjectQueue())>0)\
and (not (activeObject.nameLastEntityEnded==activeObject.nameLastEntityEntered))\
and (not (activeObject.operationType=='Processing' and (activeObject.currentOperator==None))):
#if Machine is down we should add this last failure time to the time that it has been down in current entity #if Machine is down we should add this last failure time to the time that it has been down in current entity
if self.Up==False: if self.Up==False:
# if(len(activeObjectQueue)>0) and (self.Up==False): # if(len(activeObjectQueue)>0) and (self.Up==False):
activeObject.downTimeProcessingCurrentEntity+=now()-activeObject.timeLastFailure activeObject.downTimeProcessingCurrentEntity+=now()-activeObject.timeLastFailure
activeObject.totalWorkingTime+=now()-activeObject.timeLastEntityEntered-activeObject.downTimeProcessingCurrentEntity activeObject.totalWorkingTime+=now()-activeObject.timeLastEntityEntered\
-activeObject.downTimeProcessingCurrentEntity\
-activeObject.operatorWaitTimeCurrentEntity\
-activeObject.setupTimeCurrentEntity
activeObject.totalTimeWaitingForOperator+=activeObject.operatorWaitTimeCurrentEntity
elif(len(activeObject.getActiveObjectQueue())>0)\
and (not (activeObject.nameLastEntityEnded==activeObject.nameLastEntityEntered))\
and (activeObject.currentOperator==None):
# TODO: needs further research as the time of failure while waiting for operator is not counted yet
if self.Up==False:
activeObject.downTimeProcessingCurrentEntity+=now()-activeObject.timeLastFailure
activeObject.totalTimeWaitingForOperator+=now()-activeObject.timeWaitForOperatorStarted\
-activeObject.downTimeProcessingCurrentEntity
# if Machine is down we have to add this failure time to its total failure time # if Machine is down we have to add this failure time to its total failure time
# we also need to add the last blocking time to total blockage time # we also need to add the last blocking time to total blockage time
if(activeObject.Up==False): if(activeObject.Up==False):
...@@ -357,7 +674,7 @@ class Machine(CoreObject): ...@@ -357,7 +674,7 @@ class Machine(CoreObject):
activeObject.totalBlockageTime+=(now()-activeObject.timeLastEntityEnded)-(now()-activeObject.timeLastFailure)-activeObject.downTimeInTryingToReleaseCurrentEntity activeObject.totalBlockageTime+=(now()-activeObject.timeLastEntityEnded)-(now()-activeObject.timeLastFailure)-activeObject.downTimeInTryingToReleaseCurrentEntity
#Machine was idle when it was not in any other state #Machine was idle when it was not in any other state
activeObject.totalWaitingTime=MaxSimtime-activeObject.totalWorkingTime-activeObject.totalBlockageTime-activeObject.totalFailureTime activeObject.totalWaitingTime=MaxSimtime-activeObject.totalWorkingTime-activeObject.totalBlockageTime-activeObject.totalFailureTime
if activeObject.totalBlockageTime<0 and activeObject.totalBlockageTime>-0.00001: #to avoid some effects of getting negative cause of rounding precision if activeObject.totalBlockageTime<0 and activeObject.totalBlockageTime>-0.00001: #to avoid some effects of getting negative cause of rounding precision
self.totalBlockageTime=0 self.totalBlockageTime=0
...@@ -368,7 +685,11 @@ class Machine(CoreObject): ...@@ -368,7 +685,11 @@ class Machine(CoreObject):
activeObject.Failure.append(100*self.totalFailureTime/MaxSimtime) activeObject.Failure.append(100*self.totalFailureTime/MaxSimtime)
activeObject.Blockage.append(100*self.totalBlockageTime/MaxSimtime) activeObject.Blockage.append(100*self.totalBlockageTime/MaxSimtime)
activeObject.Waiting.append(100*self.totalWaitingTime/MaxSimtime) activeObject.Waiting.append(100*self.totalWaitingTime/MaxSimtime)
activeObject.Working.append(100*self.totalWorkingTime/MaxSimtime) activeObject.Working.append(100*self.totalWorkingTime/MaxSimtime)
activeObject.WaitingForOperator.append(100*self.totalTimeWaitingForOperator/MaxSimtime)
activeObject.WaitingForLoadOperator.append(100*self.totalTimeWaitingForLoadOperator/MaxSimtime)
activeObject.Loading.append(100*self.totalLoadTime/MaxSimtime)
activeObject.SettingUp.append(100*self.totalSetupTime/MaxSimtime)
# ======================================================================= # =======================================================================
# outputs the the "output.xls" # outputs the the "output.xls"
......
...@@ -39,13 +39,12 @@ from RandomNumberGenerator import RandomNumberGenerator ...@@ -39,13 +39,12 @@ from RandomNumberGenerator import RandomNumberGenerator
import scipy.stats as stat import scipy.stats as stat
# =========================================================================== # ===========================================================================
# the Machine object # the Machine object
# =========================================================================== # ===========================================================================
# class Machine(CoreObject):
class OperatedMachine(Machine): class OperatedMachine(Machine):
# ======================================================================= # =======================================================================
# initialize the id the capacity, of the resource and the distribution # initialise the id the capacity, of the resource and the distribution
# ======================================================================= # =======================================================================
def __init__(self, id, name, capacity=1, distribution='Fixed', mean=1, stdev=0, min=0, max=10,\ def __init__(self, id, name, capacity=1, distribution='Fixed', mean=1, stdev=0, min=0, max=10,\
failureDistribution='No', MTTF=0, MTTR=0, availability=0, repairman='None',\ failureDistribution='No', MTTF=0, MTTR=0, availability=0, repairman='None',\
operatorPool='None',operationType='None',\ operatorPool='None',operationType='None',\
...@@ -69,8 +68,9 @@ class OperatedMachine(Machine): ...@@ -69,8 +68,9 @@ class OperatedMachine(Machine):
else: else:
self.operatorPool=operatorPool self.operatorPool=operatorPool
# update the operatorPool coreObjects list # update the operatorPool coreObjects list
self.operatorPool.coreObjectIds.append(self.id) if self.operatorPool!='None':
self.operatorPool.coreObjects.append(self) self.operatorPool.coreObjectIds.append(self.id)
self.operatorPool.coreObjects.append(self)
# holds the Operator currently processing the Machine # holds the Operator currently processing the Machine
self.currentOperator=None self.currentOperator=None
# define if load/setup/removal/processing are performed by the operator # define if load/setup/removal/processing are performed by the operator
...@@ -108,9 +108,9 @@ class OperatedMachine(Machine): ...@@ -108,9 +108,9 @@ class OperatedMachine(Machine):
self.WaitingForLoadOperator=[] self.WaitingForLoadOperator=[]
self.Loading = [] self.Loading = []
self.SettingUp =[] self.SettingUp =[]
# ======================================================================= # =======================================================================
# initialize the machine # initialize the machine
# ======================================================================= # =======================================================================
def initialize(self): def initialize(self):
Machine.initialize(self) Machine.initialize(self)
...@@ -144,9 +144,9 @@ class OperatedMachine(Machine): ...@@ -144,9 +144,9 @@ class OperatedMachine(Machine):
self.loadOperatorWaitTimeCurrentEntity = 0 # holds the time that the machine waits for operator to load the it self.loadOperatorWaitTimeCurrentEntity = 0 # holds the time that the machine waits for operator to load the it
self.loadTimeCurrentEntity = 0 # holds the time to load the current entity self.loadTimeCurrentEntity = 0 # holds the time to load the current entity
self.setupTimeCurrentEntity = 0 # holds the time to setup the machine before processing the current entity self.setupTimeCurrentEntity = 0 # holds the time to setup the machine before processing the current entity
# ======================================================================= # =======================================================================
# the main process of the machine # the main process of the machine
# ======================================================================= # =======================================================================
def run(self): def run(self):
# execute all through simulation time # execute all through simulation time
...@@ -200,10 +200,8 @@ class OperatedMachine(Machine): ...@@ -200,10 +200,8 @@ class OperatedMachine(Machine):
# 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
# may fall in failure mode # may fall in failure mode
self.currentEntity=self.getEntity() self.currentEntity=self.getEntity()
# print self.objName, 'part received', now()
# set the currentEntity as the Entity just received and initialize the timer timeLastEntityEntered # set the currentEntity as the Entity just received and initialize the timer timeLastEntityEntered
# self.currentEntity=self.getActiveObjectQueue()[0] # entity is the current entity processed in Machine
self.nameLastEntityEntered=self.currentEntity.name # this holds the name of the last entity that got into Machine self.nameLastEntityEntered=self.currentEntity.name # this holds the name of the last entity that got into Machine
self.timeLastEntityEntered=now() #this holds the last time that an entity got into Machine self.timeLastEntityEntered=now() #this holds the last time that an entity got into Machine
# variables dedicated to hold the processing times, the time when the Entity entered, # variables dedicated to hold the processing times, the time when the Entity entered,
...@@ -222,13 +220,10 @@ class OperatedMachine(Machine): ...@@ -222,13 +220,10 @@ class OperatedMachine(Machine):
yield waituntil, self, self.broker.brokerIsSet yield waituntil, self, self.broker.brokerIsSet
self.timeWaitForOperatorEnded = now() self.timeWaitForOperatorEnded = now()
self.operatorWaitTimeCurrentEntity += self.timeWaitForOperatorEnded-self.timeWaitForOperatorStarted self.operatorWaitTimeCurrentEntity += self.timeWaitForOperatorEnded-self.timeWaitForOperatorStarted
# self.totalTimeWaitingForOperator += self.operatorWaitTimeCurrentEntity
# print self.objName, 'operator assigned', now()
self.totalProcessingTimeInCurrentEntity=self.calculateProcessingTime() # get the processing time, tinMStarts holds the processing time of the machine self.totalProcessingTimeInCurrentEntity=self.calculateProcessingTime() # get the processing time, tinMStarts holds the processing time of the machine
tinM=self.totalProcessingTimeInCurrentEntity # timer to hold the processing time left tinM=self.totalProcessingTimeInCurrentEntity # timer to hold the processing time left
#self.processingTimeOfCurrentEntity=tinMStart # processing time of the machine
# ======= 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
...@@ -252,7 +247,6 @@ class OperatedMachine(Machine): ...@@ -252,7 +247,6 @@ class OperatedMachine(Machine):
# wait until the Broker has finished processing # wait until the Broker has finished processing
yield waituntil, self, self.broker.brokerIsSet yield waituntil, self, self.broker.brokerIsSet
# variables used to flag any interruptions and the end of the processing # variables used to flag any interruptions and the end of the processing
interruption=False interruption=False
processingEndedFlag=True processingEndedFlag=True
...@@ -272,7 +266,6 @@ class OperatedMachine(Machine): ...@@ -272,7 +266,6 @@ class OperatedMachine(Machine):
# else (if interrupted()) set interruption flag to true (only if tinM==0), # else (if interrupted()) set interruption flag to true (only if tinM==0),
# and recalculate the processing time left tinM, # and recalculate the processing time left tinM,
# passivate while waiting for repair. # passivate while waiting for repair.
# print self.objName, 'processing started', now()
yield hold,self,tinM # getting processed for remaining processing time tinM yield hold,self,tinM # getting processed for remaining processing time tinM
if self.interrupted(): # if a failure occurs while processing the machine is interrupted. if self.interrupted(): # if a failure occurs while processing the machine is interrupted.
# output to trace that the Machine (self.objName) got interrupted # output to trace that the Machine (self.objName) got interrupted
...@@ -296,8 +289,8 @@ class OperatedMachine(Machine): ...@@ -296,8 +289,8 @@ class OperatedMachine(Machine):
# print self.objName, 'operator released due to failure', now() # print self.objName, 'operator released due to failure', now()
yield waituntil,self,self.broker.brokerIsSet yield waituntil,self,self.broker.brokerIsSet
# if there is a failure in the machine it is passivated # if there is a failure in the machine it is passivated
yield passivate,self yield passivate,self
# use the timers to count the time that Machine is down and related # use the timers to count the time that Machine is down and related
self.downTimeProcessingCurrentEntity+=now()-breakTime # count the time that Machine is down while processing this Entity self.downTimeProcessingCurrentEntity+=now()-breakTime # count the time that Machine is down while processing this Entity
self.downTimeInCurrentEntity+=now()-breakTime # count the time that Machine is down while on currentEntity self.downTimeInCurrentEntity+=now()-breakTime # count the time that Machine is down while on currentEntity
...@@ -315,13 +308,11 @@ class OperatedMachine(Machine): ...@@ -315,13 +308,11 @@ class OperatedMachine(Machine):
yield waituntil,self,self.broker.brokerIsSet yield waituntil,self,self.broker.brokerIsSet
self.timeWaitForOperatorEnded = now() self.timeWaitForOperatorEnded = now()
self.operatorWaitTimeCurrentEntity += self.timeWaitForOperatorEnded-self.timeWaitForOperatorStarted self.operatorWaitTimeCurrentEntity += self.timeWaitForOperatorEnded-self.timeWaitForOperatorStarted
# self.totalTimeWaitingForOperator += self.operatorWaitTimeCurrentEntity
# if no interruption occurred the processing in M1 is ended # if no interruption occurred the processing in M1 is ended
else: else:
processingEndedFlag=False processingEndedFlag=False
# output to trace that the processing in the Machine self.objName ended # output to trace that the processing in the Machine self.objName ended
# print self.objName, 'processing ended', now()
self.outputTrace(self.getActiveObjectQueue()[0].name,"ended processing in "+self.objName) self.outputTrace(self.getActiveObjectQueue()[0].name,"ended processing in "+self.objName)
# =============== release resource after the end of processing # =============== release resource after the end of processing
...@@ -330,15 +321,14 @@ class OperatedMachine(Machine): ...@@ -330,15 +321,14 @@ class OperatedMachine(Machine):
and not interruption: and not interruption:
self.releaseOperator() self.releaseOperator()
yield waituntil,self,self.broker.brokerIsSet yield waituntil,self,self.broker.brokerIsSet
# print self.objName, 'operator released after processing', now()
# 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 total working time # update the total working time
self.totalWorkingTime+=self.totalProcessingTimeInCurrentEntity # the total processing time for this entity self.totalWorkingTime+=self.totalProcessingTimeInCurrentEntity # the total processing time for this entity
# is what the distribution initially gave # is what the distribution initially gave
# 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=now() # this holds the time that the last entity ended processing in Machine self.timeLastEntityEnded=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
...@@ -352,11 +342,10 @@ class OperatedMachine(Machine): ...@@ -352,11 +342,10 @@ class OperatedMachine(Machine):
# initialize the timer downTimeInTryingToReleaseCurrentEntity, we have to count how much time # initialize the timer downTimeInTryingToReleaseCurrentEntity, we have to count how much time
# the Entity will wait for the next successor to be able to accept (canAccept) # the Entity will wait for the next successor to be able to accept (canAccept)
self.downTimeInTryingToReleaseCurrentEntity=0 self.downTimeInTryingToReleaseCurrentEntity=0
while 1: while 1:
# wait until the next Object is available or machine has failure # wait until the next Object is available or machine has failure
yield waituntil, self, self.ifCanDisposeOrHaveFailure yield waituntil, self, self.ifCanDisposeOrHaveFailure
# if Next object available break # if Next object available break
if self.Up: if self.Up:
...@@ -372,39 +361,17 @@ class OperatedMachine(Machine): ...@@ -372,39 +361,17 @@ class OperatedMachine(Machine):
self.downTimeInTryingToReleaseCurrentEntity+=now()-failTime self.downTimeInTryingToReleaseCurrentEntity+=now()-failTime
self.downTimeInCurrentEntity+=now()-failTime # already updated from failures during processing self.downTimeInCurrentEntity+=now()-failTime # already updated from failures during processing
# update the timeLastFailureEnded # update the timeLastFailureEnded
self.timeLastFailureEnded=now() self.timeLastFailureEnded=now()
# dummy variable holding the total time the Entity spent in the Machine # dummy variable holding the total time the Entity spent in the Machine
# count the time the Machine was blocked subtracting the failureTime # count the time the Machine was blocked subtracting the failureTime
# and the processing time from the totalTime spent in the Machine # and the processing time from the totalTime spent in the Machine
self.totalTimeInCurrentEntity=now()-timeEntered self.totalTimeInCurrentEntity=now()-timeEntered
# update the total time waiting for the operator of the machine
# self.totalTimeWaitingForOperator += self.operatorWaitTimeCurrentEntity
# blockageTime=totalTime-(tinMStart\
# +failureTime\
# +self.operatorWaitTimeCurrentEntity\
# +self.setupTimeCurrentEntity)
# might be possible to avoid using blockageTime
# the time of blockage is derived from
# the whole time in the machine minus the processing time and the failure time
# self.totalBlockageTime+=totalTime-(tinMStart\
# +failureTime\
# +self.operatorWaitTimeCurrentEntity\
# +self.setupTimeCurrentEntity)
# print 'totalTime:',totalTime
# print 'tinMstart:',tinMStart
# print 'failureTime',failureTime
# print 'blockageTime',blockageTime
# print "machineId:", self.id,"|"\
# "the total blockage time up to now is:", self.totalBlockageTime,"|"\
# "SimulationTime:",now()
# ======================================================================= # =======================================================================
# checks if the Machine can accept an entity # checks if the Machine can accept an entity
# it checks also who called it and returns TRUE only to the predecessor # it checks also who called it and returns TRUE only to the predecessor
# that will give the entity. # that will give the entity.
# ======================================================================= # =======================================================================
def canAccept(self, callerObject=None): def canAccept(self, callerObject=None):
# get active and giver objects # get active and giver objects
...@@ -426,7 +393,6 @@ class OperatedMachine(Machine): ...@@ -426,7 +393,6 @@ class OperatedMachine(Machine):
thecaller=callerObject thecaller=callerObject
# return True ONLY if the length of the activeOjbectQue is smaller than # return True ONLY if the length of the activeOjbectQue is smaller than
# the object capacity, and the callerObject is not None but the giverObject # the object capacity, and the callerObject is not None but the giverObject
if (activeObject.operatorPool!='None' and any(type=='Load' for type in activeObject.multOperationTypeList)): if (activeObject.operatorPool!='None' and any(type=='Load' for type in activeObject.multOperationTypeList)):
return activeObject.operatorPool.checkIfResourceIsAvailable()\ return activeObject.operatorPool.checkIfResourceIsAvailable()\
and activeObject.Up\ and activeObject.Up\
...@@ -486,7 +452,7 @@ class OperatedMachine(Machine): ...@@ -486,7 +452,7 @@ class OperatedMachine(Machine):
# loop through the possible givers to see which have to dispose and which is the one blocked for longer # loop through the possible givers to see which have to dispose and which is the one blocked for longer
for object in activeObject.previous: for object in activeObject.previous:
if(object.haveToDispose(activeObject)):# and not object.exitIsAssigned()): if(object.haveToDispose(activeObject)):# and not object.exitIsAssigned()):
isRequested=True # if the possible giver have entities to dispose of isRequested=True # if the possible giver has entities to dispose of
if(object.downTimeInTryingToReleaseCurrentEntity>0):# and the possible giver has been down while trying to give away the Entity if(object.downTimeInTryingToReleaseCurrentEntity>0):# and the possible giver has been down while trying to give away the Entity
timeWaiting=now()-object.timeLastFailureEnded # the timeWaiting dummy variable counts the time end of the last failure of the giver object timeWaiting=now()-object.timeLastFailureEnded # the timeWaiting dummy variable counts the time end of the last failure of the giver object
else: else:
...@@ -512,50 +478,8 @@ class OperatedMachine(Machine): ...@@ -512,50 +478,8 @@ class OperatedMachine(Machine):
# while if the set up is performed before the (automatic) loading of the machine then the availability of the # while if the set up is performed before the (automatic) loading of the machine then the availability of the
# operator is requested # operator is requested
# return (activeObject.operatorPool=='None' or activeObject.operatorPool.checkIfResourceIsAvailable())\ # return (activeObject.operatorPool=='None' or activeObject.operatorPool.checkIfResourceIsAvailable())\
# and activeObject.Up and len(activeObjectQueue)<activeObject.capacity and isRequested # and activeObject.Up and len(activeObjectQueue)<activeObject.capacity and isRequested
# # =======================================================================
# # checks if the Machine can dispose an entity to the following object
# # =======================================================================
# def haveToDispose(self, callerObject=None):
# # get active and the receiver object
# activeObject=self.getActiveObject()
# activeObjectQueue=self.getActiveObjectQueue()
# receiverObject=activeObject.getReceiverObject()
# #if we have only one successor just check if machine waits to dispose and also is up
# # this is done to achieve better (cpu) processing time
# if(len(activeObject.next)==1 or callerObject==None):
# return len(activeObjectQueue)>0\
# and activeObject.waitToDispose\
# and activeObject.Up#\
# #and not receiverObject.exitIsAssigned() # this change has to be implemented on every object
#
# # # if the Machine is empty it returns false right away
# # if(len(activeObjectQueue)==0):
# # return False
#
# thecaller=callerObject
# # give the entity to the successor that is waiting for the most time.
# # (plant simulation does not do this in every occasion!)
# maxTimeWaiting=0 # dummy variable counting the time a successor is waiting
# i=0 # index used to set the successorIndex to the giver waiting the most
# for object in activeObject.next:
# if(object.canAccept(activeObject)): # if a successor can accept an object
# timeWaiting=now()-object.timeLastEntityLeft # the time it has been waiting is updated and stored in dummy variable timeWaiting
# if(timeWaiting>maxTimeWaiting or maxTimeWaiting==0):# if the timeWaiting is the maximum among the ones of the successors
# maxTimeWaiting=timeWaiting
# activeObject.successorIndex=i # set the successorIndex equal to the index of the longest waiting successor
# i+=1 # in the next loops, check the other successors in the previous list
# return len(activeObjectQueue)>0\
# and activeObject.waitToDispose\
# and activeObject.Up\
# and (thecaller is receiverObject)#\
# #and not receiverObject.exitIsAssigned
# ======================================================================= # =======================================================================
# calculates the setup time # calculates the setup time
# ======================================================================= # =======================================================================
...@@ -599,21 +523,17 @@ class OperatedMachine(Machine): ...@@ -599,21 +523,17 @@ class OperatedMachine(Machine):
# ======================================================================= # =======================================================================
def requestSetup(self): def requestSetup(self):
self.setUp=False self.setUp=False
# ======================================================================= # =======================================================================
# actions to be taken after the simulation ends # actions to be taken after the simulation ends
# ======================================================================= # =======================================================================
def postProcessing(self, MaxSimtime=None): def postProcessing(self, MaxSimtime=None):
if MaxSimtime==None: if MaxSimtime==None:
from Globals import G from Globals import G
MaxSimtime=G.maxSimTime MaxSimtime=G.maxSimTime
# print 'maxSimTime:',G.maxSimTime
activeObject=self.getActiveObject() activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue() activeObjectQueue=self.getActiveObjectQueue()
# print activeObject.objName
# print 'the last entity that entered the machine is', activeObject.nameLastEntityEntered, 'at', activeObject.timeLastEntityEntered
# print 'the current entity in the machine is',activeObject.currentEntity.name
alreadyAdded=False # a flag that shows if the blockage time has already been added alreadyAdded=False # a flag that shows if the blockage time has already been added
...@@ -630,22 +550,16 @@ class OperatedMachine(Machine): ...@@ -630,22 +550,16 @@ class OperatedMachine(Machine):
# if (len(self.Res.activeQ)>0) and (len(self.next[0].Res.activeQ)>0) and ((self.nameLastEntityEntered == self.nameLastEntityEnded)): # if (len(self.Res.activeQ)>0) and (len(self.next[0].Res.activeQ)>0) and ((self.nameLastEntityEntered == self.nameLastEntityEnded)):
if (len(activeObjectQueue)>0) and (mightBeBlocked)\ if (len(activeObjectQueue)>0) and (mightBeBlocked)\
and ((activeObject.nameLastEntityEntered == activeObject.nameLastEntityEnded)): and ((activeObject.nameLastEntityEntered == activeObject.nameLastEntityEnded)):
# be carefull here, might have to reconsider # be careful here, might have to reconsider
# print 'the machine', activeObject.objName, 'was blocked at', now()
activeObject.totalBlockageTime+=now()-(activeObject.timeLastEntityEnded+activeObject.downTimeInTryingToReleaseCurrentEntity) activeObject.totalBlockageTime+=now()-(activeObject.timeLastEntityEnded+activeObject.downTimeInTryingToReleaseCurrentEntity)
# print 'the machine', activeObject.objName,'was trying to release last entity for', activeObject.downTimeInTryingToReleaseCurrentEntity
# print 'the last entity', activeObject.nameLastEntityEnded ,'ended processing at', activeObject.timeLastEntityEnded
# print 'the current Entity in the machine is', activeObject.currentEntity.name
if activeObject.Up==False: if activeObject.Up==False:
activeObject.totalBlockageTime-=now()-activeObject.timeLastFailure activeObject.totalBlockageTime-=now()-activeObject.timeLastFailure
alreadyAdded=True alreadyAdded=True
# print activeObject.objName,'total Block time:',activeObject.totalBlockageTime#/G.maxSimTime
#if Machine is currently processing an entity we should count this working time #if Machine is currently processing an entity we should count this working time
if(len(activeObject.getActiveObjectQueue())>0)\ if(len(activeObject.getActiveObjectQueue())>0)\
and (not (activeObject.nameLastEntityEnded==activeObject.nameLastEntityEntered))\ and (not (activeObject.nameLastEntityEnded==activeObject.nameLastEntityEntered))\
and (not (activeObject.operationType=='Processing' and (activeObject.currentOperator==None))): and (not (activeObject.operationType=='Processing' and (activeObject.currentOperator==None))):
# print 'pre-total working time:',activeObject.totalWorkingTime#/G.maxSimTime
#if Machine is down we should add this last failure time to the time that it has been down in current entity #if Machine is down we should add this last failure time to the time that it has been down in current entity
if self.Up==False: if self.Up==False:
# if(len(activeObjectQueue)>0) and (self.Up==False): # if(len(activeObjectQueue)>0) and (self.Up==False):
...@@ -655,9 +569,6 @@ class OperatedMachine(Machine): ...@@ -655,9 +569,6 @@ class OperatedMachine(Machine):
-activeObject.operatorWaitTimeCurrentEntity\ -activeObject.operatorWaitTimeCurrentEntity\
-activeObject.setupTimeCurrentEntity -activeObject.setupTimeCurrentEntity
activeObject.totalTimeWaitingForOperator+=activeObject.operatorWaitTimeCurrentEntity activeObject.totalTimeWaitingForOperator+=activeObject.operatorWaitTimeCurrentEntity
# print "downTimeProcessingCurrentEntity", activeObject.downTimeProcessingCurrentEntity
# print "operatorWaitTimeCurrentEntity", activeObject.operatorWaitTimeCurrentEntity
# print "setupTimeCurrentEntity",activeObject.setupTimeCurrentEntity
elif(len(activeObject.getActiveObjectQueue())>0)\ elif(len(activeObject.getActiveObjectQueue())>0)\
and (not (activeObject.nameLastEntityEnded==activeObject.nameLastEntityEntered))\ and (not (activeObject.nameLastEntityEnded==activeObject.nameLastEntityEntered))\
and (activeObject.currentOperator==None): and (activeObject.currentOperator==None):
...@@ -667,8 +578,6 @@ class OperatedMachine(Machine): ...@@ -667,8 +578,6 @@ class OperatedMachine(Machine):
activeObject.totalTimeWaitingForOperator+=now()-activeObject.timeWaitForOperatorStarted\ activeObject.totalTimeWaitingForOperator+=now()-activeObject.timeWaitForOperatorStarted\
-activeObject.downTimeProcessingCurrentEntity -activeObject.downTimeProcessingCurrentEntity
# print activeObject.objName,'total working time:',activeObject.totalWorkingTime#/G.maxSimTime
# if Machine is down we have to add this failure time to its total failure time # if Machine is down we have to add this failure time to its total failure time
# we also need to add the last blocking time to total blockage time # we also need to add the last blocking time to total blockage time
if(activeObject.Up==False): if(activeObject.Up==False):
...@@ -677,10 +586,10 @@ class OperatedMachine(Machine): ...@@ -677,10 +586,10 @@ class OperatedMachine(Machine):
#if((len(self.next[0].Res.activeQ)>0) and (self.nameLastEntityEnded==self.nameLastEntityEntered) and (not alreadyAdded)): #if((len(self.next[0].Res.activeQ)>0) and (self.nameLastEntityEnded==self.nameLastEntityEntered) and (not alreadyAdded)):
if((mightBeBlocked) and (activeObject.nameLastEntityEnded==activeObject.nameLastEntityEntered) and (not alreadyAdded)): if((mightBeBlocked) and (activeObject.nameLastEntityEnded==activeObject.nameLastEntityEntered) and (not alreadyAdded)):
activeObject.totalBlockageTime+=(now()-activeObject.timeLastEntityEnded)-(now()-activeObject.timeLastFailure)-activeObject.downTimeInTryingToReleaseCurrentEntity activeObject.totalBlockageTime+=(now()-activeObject.timeLastEntityEnded)-(now()-activeObject.timeLastFailure)-activeObject.downTimeInTryingToReleaseCurrentEntity
# print activeObject.objName,'total Block time:',activeObject.totalBlockageTime#/G.maxSimTime
#Machine was idle when it was not in any other state #Machine was idle when it was not in any other state
activeObject.totalWaitingTime=MaxSimtime-activeObject.totalWorkingTime-activeObject.totalBlockageTime-activeObject.totalFailureTime
activeObject.totalWaitingTime=MaxSimtime-activeObject.totalWorkingTime-activeObject.totalBlockageTime-activeObject.totalFailureTime
if activeObject.totalBlockageTime<0 and activeObject.totalBlockageTime>-0.00001: #to avoid some effects of getting negative cause of rounding precision if activeObject.totalBlockageTime<0 and activeObject.totalBlockageTime>-0.00001: #to avoid some effects of getting negative cause of rounding precision
self.totalBlockageTime=0 self.totalBlockageTime=0
......
...@@ -96,7 +96,14 @@ class OperatorPool(ObjectResource): ...@@ -96,7 +96,14 @@ class OperatorPool(ObjectResource):
# timeWaiting = now()-machine.broker.timeWaitForOperatorStarted # timeWaiting = now()-machine.broker.timeWaitForOperatorStarted
# if (timeWaiting>=maxTimeWaiting): # if (timeWaiting>=maxTimeWaiting):
# maxTimeWaiting=timeWaiting # maxTimeWaiting=timeWaiting
# TODO: to discuss with George if using a callerObject is the proper way to inform the OperatorPreemptive
# about the object that is requesting to know about its availability
thecaller=callerObject thecaller=callerObject
# requestingEntity=thecaller.getActiveObjectQueue()[0]
# requestedOperator=requestingEntity.manager
# isAvailable=requestedOperator.checkIfResourceIsAvailable(callerObject)
return any(operator.checkIfResourceIsAvailable(callerObject=thecaller)==True for operator in self.operators) return any(operator.checkIfResourceIsAvailable(callerObject=thecaller)==True for operator in self.operators)
# ======================================================================= # =======================================================================
......
...@@ -44,6 +44,7 @@ class OperatorPreemptive(Operator): ...@@ -44,6 +44,7 @@ class OperatorPreemptive(Operator):
# checks if the worker is available # checks if the worker is available
# ======================================================================= # =======================================================================
def checkIfResourceIsAvailable(self,callerObject=None): def checkIfResourceIsAvailable(self,callerObject=None):
# 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?
......
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