printTrace method changed. Clean-up

parent 6ddc3dae
......@@ -123,26 +123,22 @@ class Assembly(CoreObject):
# check if there is WIP and signal receiver
self.initialSignalReceiver()
while 1:
# self.printTrace(self.id, 'will wait for frame event')
self.printTrace1(self.id, waitEvent='')
self.printTrace(self.id, waitEvent='')
# wait until the Queue can accept an entity and one predecessor requests it
yield waitevent, self, self.isRequested #[self.isRequested,self.canDispose, self.loadOperatorAvailable]
if self.isRequested.signalparam:
# self.printTrace(self.id, 'received a isRequested event from '+self.isRequested.signalparam.id)
self.printTrace1(self.id, isRequested=self.isRequested.signalparam.id)
self.printTrace(self.id, isRequested=self.isRequested.signalparam.id)
# reset the isRequested signal parameter
self.isRequested.signalparam=None
self.getEntity("Frame") #get the Frame
for i in range(self.getActiveObjectQueue()[0].capacity): #this loop will be carried until the Frame is full with the parts
self.printTrace1(self.id, waitEvent='(to load parts)')
# self.printTrace(self.id, 'will wait for part event')
self.printTrace(self.id, waitEvent='(to load parts)')
yield waitevent, self, self.isRequested
if self.isRequested.signalparam:
# self.printTrace(self.id, 'received a isRequested event from '+self.isRequested.signalparam.id)
self.printTrace1(self.id, isRequested=self.isRequested.signalparam.id)
self.printTrace(self.id, isRequested=self.isRequested.signalparam.id)
# reset the isRequested signal parameter
self.isRequested.signalparam=None
# TODO: fix the getEntity 'Part' case
......@@ -166,8 +162,7 @@ class Assembly(CoreObject):
self.completedJobs+=1 #Assembly completed a job
self.waitToDispose=True #since all the frame is full
# self.printTrace(self.id, 'will try to signal a receiver from generator')
self.printTrace1(self.id, attemptSignalReceiver='(generator')
self.printTrace(self.id, attemptSignalReceiver='(generator')
# signal the receiver that the activeObject has something to dispose of
if not self.signalReceiver():
# if there was no available receiver, get into blocking control
......@@ -250,8 +245,7 @@ class Assembly(CoreObject):
activeEntity=CoreObject.removeEntity(self, entity) #run the default method
self.waitToDispose=False
if self.canAccept():
# self.printTrace(self.id, 'will try signalling a giver from removeEntity')
self.printTrace1(self.id, attemptSignalGiver='(removeEntity)')
self.printTrace(self.id, attemptSignalGiver='(removeEntity)')
self.signalGiver()
return activeEntity
......@@ -276,8 +270,7 @@ class Assembly(CoreObject):
assert activeEntity.type==type, 'the type of the entity to get must be of type '+type+' while it is '+activeEntity.type
#remove the entity from the previews object
giverObject.removeEntity(activeEntity)
# self.printTrace(activeEntity.name, "got into "+self.id)
self.printTrace1(activeEntity.name, enter=self.id)
self.printTrace(activeEntity.name, enter=self.id)
self.outputTrace(activeEntity.name, "got into "+ self.objName)
# if the type is Frame
if(activeEntity.type=="Frame"):
......@@ -287,8 +280,7 @@ class Assembly(CoreObject):
# if the frame is not fully loaded then signal a giver
if len(activeObjectQueue[0].getFrameQueue())<activeObjectQueue[0].capacity:
# self.printTrace(self.id, 'will try signalling a giver from getEntity')
self.printTrace1(self.id, attemptSignalGiver='(getEntity)')
self.printTrace(self.id, attemptSignalGiver='(getEntity)')
self.signalGiver()
return activeEntity
......
......@@ -100,13 +100,11 @@ class Conveyer(CoreObject):
# print self.id, 'time to move', self.conveyerMover.timeToWait
self.conveyerMover.canMove.signal(now())
# self.printTrace(self.id, 'will wait for event')
self.printTrace1(self.id, waitEvent='')
self.printTrace(self.id, waitEvent='')
yield waitevent, self, [self.isRequested,self.canDispose, self.moveEnd] # , self.loadOperatorAvailable]
# if the event that activated the thread is isRequested then getEntity
if self.isRequested.signalparam:
# self.printTrace(self.id, 'received an is requested event')
self.printTrace1(self.id, isRequested='')
self.printTrace(self.id, isRequested='')
# reset the isRequested signal parameter
self.isRequested.signalparam=None
# get the entity
......@@ -119,32 +117,26 @@ class Conveyer(CoreObject):
# self.loadOperatorAvailable.signalparam=None
# if the queue received an canDispose with signalparam time, this means that the signals was sent from a MouldAssemblyBuffer
if self.canDispose.signalparam:
# self.printTrace(self.id, 'received a canDispose event')
self.printTrace1(self.id, canDispose='')
self.printTrace(self.id, canDispose='')
self.canDispose.signalparam=None
# if the object received a moveEnd signal from the ConveyerMover
if self.moveEnd.signalparam:
# self.printTrace(self.id, 'received a moveEnd event')
self.printTrace1(self.id, moveEnd='')
self.printTrace(self.id, moveEnd='')
self.moveEnd.signalparam=None
# check if there is a possibility to accept and signal a giver
if self.canAccept():
# self.printTrace(self.id, 'will try to signal Giver from removeEntity')
self.printTrace1(self.id, attemptSignalGiver='(removeEntity)')
self.printTrace(self.id, attemptSignalGiver='(removeEntity)')
self.signalGiver()
# if the event that activated the thread is canDispose then signalReceiver
if self.haveToDispose():
# self.printTrace(self.id, 'will try to signal a receiver from generator')
self.printTrace1(self.id, attemptSignalReceiver='(generator)')
self.printTrace(self.id, attemptSignalReceiver='(generator)')
if self.receiver:
if not self.receiver.entryIsAssignedTo():
# self.printTrace(self.id, 'will try to signal receiver from generator1')
self.printTrace1(self.id, attemptSignalReceiver='(generator1)')
self.printTrace(self.id, attemptSignalReceiver='(generator1)')
self.signalReceiver()
continue
# self.printTrace(self.id, 'will try to signal receiver from generator2')
self.printTrace1(self.id, attemptSignalReceiver='(generator2)')
self.printTrace(self.id, attemptSignalReceiver='(generator2)')
self.signalReceiver()
#===========================================================================
......@@ -203,8 +195,7 @@ class Conveyer(CoreObject):
if(self.length-self.position[0]<0.000001) and (not self.entityLastReachedEnd==self.getActiveObjectQueue()[0]):
self.waitToDispose=True
self.entityLastReachedEnd=self.getActiveObjectQueue()[0]
# self.printTrace(self.getActiveObjectQueue()[0].name, 'has reached the end'+' !! . !! .'*7)
self.printTrace1(self.getActiveObjectQueue()[0].name, conveyerEnd='')
self.printTrace(self.getActiveObjectQueue()[0].name, conveyerEnd='')
return True
return False
......@@ -343,8 +334,7 @@ class Conveyer(CoreObject):
if self.isFull():
self.timeBlockageStarted=now()
self.wasFull=True
# self.printTrace(self.id, 'is now Full '+str(len(self.getActiveObjectQueue()))+' (*) '*20)
self.printTrace1(self.id, conveyerFull=str(len(self.getActiveObjectQueue())))
self.printTrace(self.id, conveyerFull=str(len(self.getActiveObjectQueue())))
return activeEntity
#===========================================================================
......@@ -367,8 +357,7 @@ class Conveyer(CoreObject):
self.conveyerMover.canMove.signal(now())
# if there is anything to dispose of then signal a receiver
if self.haveToDispose():
# self.printTrace(self.id, 'will try to signal a receiver from removeEntity')
self.printTrace1(self.id, attemptSingalReceiver='(removeEntity)')
self.printTrace(self.id, attemptSingalReceiver='(removeEntity)')
self.signalReceiver()
return activeEntity
......@@ -521,18 +510,13 @@ class ConveyerMover(Process):
#===========================================================================
def run(self):
while 1:
# self.conveyer.printTrace(self.conveyer.id, 'mover will wait for canMove event')
self.conveyer.printTrace1(self.conveyer.id, waitEvent='(canMove)')
self.conveyer.printTrace(self.conveyer.id, waitEvent='(canMove)')
yield waitevent,self,self.canMove #wait until the conveyer triggers the mover
# self.conveyer.printTrace(self.conveyer.id, 'mover received canMove event')
self.conveyer.printTrace1(self.conveyer.id, received='(canMove)')
self.conveyer.printTrace(self.conveyer.id, received='(canMove)')
yield hold,self,self.timeToWait #wait for the time that the conveyer calculated
# print '. .'*40
# print 'conveyer moving entities'
# continue if interrupted
self.conveyer.moveEntities() #move the entities of the conveyer
# self.conveyer.call=False #reset call so it will be triggered only when it is needed again
self.conveyer.moveEnd.signal(now())
......
......@@ -253,8 +253,7 @@ class CoreObject(Process):
# update the next list of the object
activeObject.updateNext(activeEntity)
self.outputTrace(activeEntity.name, "got into "+self.objName)
# self.printTrace(activeEntity.name, "got into "+self.id)
self.printTrace1(activeEntity.name, enter=self.id)
self.printTrace(activeEntity.name, enter=self.id)
return activeEntity
#===========================================================================
......@@ -268,7 +267,6 @@ class CoreObject(Process):
# and if preemption is required
#===========================================================================
def preemptReceiver(self):
# self.printTrace(self.id, 'trying to preempt a receiver')
activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue()
......@@ -305,8 +303,7 @@ class CoreObject(Process):
#if the receiver does not hold an Entity that is also critical
if not receiver.getActiveObjectQueue()[0].isCritical:
receiver.shouldPreempt=True
# activeObject.printTrace(self.id, 'preempting receiver '+receiver.id+'.. '*6)
self.printTrace1(self.id, preempt=receiver.id)
self.printTrace(self.id, preempt=receiver.id)
receiver.preempt()
receiver.timeLastEntityEnded=now() #required to count blockage correctly in the preemptied station
# sort so that the critical entity is placed in front
......@@ -319,23 +316,33 @@ class CoreObject(Process):
if self.gatherWipStat:
self.wipStatList.append([now(), len(activeObjectQueue)])
#===========================================================================
# find possible receivers
#===========================================================================
def findReceivers(self):
activeObject=self.getActiveObject()
@staticmethod
def findReceiversFor(activeObject):
receivers=[]
for object in [x for x in self.next if x.canAccept(activeObject)]:
for object in [x for x in activeObject.next if x.canAccept(activeObject)]:
receivers.append(object)
return receivers
# #===========================================================================
# # find possible receivers
# #===========================================================================
# def findReceivers(self):
# activeObject=self.getActiveObject()
# receivers=[]
# for object in [x for x in self.next if x.canAccept(activeObject)]:
# receivers.append(object)
# return receivers
# =======================================================================
# signal the successor that the object can dispose an entity
# =======================================================================
def signalReceiver(self):
# self.printTrace(self.id, 'trying to signal receiver')
activeObject=self.getActiveObject()
possibleReceivers=activeObject.findReceivers()
possibleReceivers=self.findReceiversFor(activeObject)
if possibleReceivers:
receiver=activeObject.selectReceiver(possibleReceivers)
receiversGiver=activeObject
......@@ -358,8 +365,7 @@ class CoreObject(Process):
activeObject.receiver=receiver
activeObject.receiver.giver=activeObject
# self.printTrace(self.id, ' '*50+'signalling receiver '+self.receiver.id)
self.printTrace1(self.id, signalReceiver=self.receiver.id)
self.printTrace(self.id, signalReceiver=self.receiver.id)
# assign the entry of the receiver
activeObject.receiver.assignEntryTo()
activeObject.receiver.isRequested.signal(activeObject)
......@@ -371,8 +377,8 @@ class CoreObject(Process):
# =======================================================================
# select a receiver Object
# =======================================================================
def selectReceiver(self,possibleReceivers=[]):
activeObject=self.getActiveObject()
@staticmethod
def selectReceiver(possibleReceivers=[]):
candidates=possibleReceivers
# dummy variables that help prioritize the objects requesting to give objects to the Machine (activeObject)
maxTimeWaiting=0 # dummy variable counting the time a successor is waiting
......@@ -387,7 +393,8 @@ class CoreObject(Process):
#===========================================================================
# signalRouter method
#===========================================================================
def signalRouter(self, receiver=None):
@staticmethod
def signalRouter(receiver=None):
# if an operator is not assigned to the receiver then do not signal the receiver but the Router
try:
if not receiver.assignedOperator or\
......@@ -395,8 +402,7 @@ class CoreObject(Process):
if receiver.isLoadRequested():
from Globals import G
if not G.Router.invoked:
# self.printTrace(self.id, ' '*50+'signalling router')
self.printTrace1(self.id, signal='router')
# self.printTrace(self.id, signal='router')
G.Router.invoked=True
G.Router.isCalled.signal(now())
return True
......@@ -414,21 +420,32 @@ class CoreObject(Process):
#===========================================================================
# find possible givers
#===========================================================================
def findGivers(self):
activeObject=self.getActiveObject()
@staticmethod
def findGiversFor(activeObject):
givers=[]
for object in [x for x in activeObject.previous if(not x is activeObject)]:
if object.haveToDispose(activeObject):
givers.append(object)
return givers
# #===========================================================================
# # find possible givers
# #===========================================================================
# def findGivers(self):
# activeObject=self.getActiveObject()
# givers=[]
# for object in [x for x in activeObject.previous if(not x is activeObject)]:
# if object.haveToDispose(activeObject):
# givers.append(object)
# return givers
# =======================================================================
# signal the giver that the entity is removed from its internalQueue
# =======================================================================
def signalGiver(self):
# self.printTrace(self.id, 'trying to signal giver')
activeObject=self.getActiveObject()
possibleGivers=activeObject.findGivers()
possibleGivers=self.findGiversFor(activeObject)
if possibleGivers:
giver=activeObject.selectGiver(possibleGivers)
giversReceiver=activeObject
......@@ -441,8 +458,7 @@ class CoreObject(Process):
giversReceiver=activeObject
activeObject.giver=giver
activeObject.giver.receiver=activeObject
# self.printTrace(self.id, ' '*50+'signalling giver '+self.giver.id)
self.printTrace1(self.id, signalGiver=self.giver.id)
self.printTrace(self.id, signalGiver=self.giver.id)
activeObject.giver.canDispose.signal(activeObject)
return True
return False
......@@ -450,8 +466,8 @@ class CoreObject(Process):
# =======================================================================
# select a giver Object
# =======================================================================
def selectGiver(self,possibleGivers=[]):
activeObject=self.getActiveObject()
@staticmethod
def selectGiver(possibleGivers=[]):
candidates=possibleGivers
# dummy variables that help prioritize the objects requesting to give objects to the Machine (activeObject)
maxTimeWaiting=0 # dummy variable counting the time a predecessor is blocked
......@@ -498,27 +514,21 @@ class CoreObject(Process):
G.sheetIndex+=1
G.traceSheet=G.traceFile.add_sheet('sheet '+str(G.sheetIndex), cell_overwrite_ok=True)
#===========================================================================
# prints message to the console
#===========================================================================
#print message in the console. Format is (Simulation Time | Entity or Frame Name | message)
def printTrace(self, entityName, message):
from Globals import G
if(G.console=="Yes"): #output only if the user has selected to
print now(), entityName, message
def printTrace1(self,entity='', **kw):
@staticmethod
def printTrace(entity='', **kw):
assert len(kw)==1, 'only one phrase per printTrace supported for the moment'
from Globals import G
import Globals
time=now()
charLimit=60
remainingChar=charLimit-len(entity)-len(str(time))
if(G.console=='Yes'):
print time,entity,
for key in kw:
if key not in self.getSupportedPrintKwrds():
raise ValueError("Unsupported phrase %s for %s" % (key, self.id))
element=self.getPhrase()[key]
if key not in Globals.getSupportedPrintKwrds():
raise ValueError("Unsupported phrase %s for %s" % (key, entity.name))
element=Globals.getPhrase()[key]
phrase=element['phrase']
prefix=element.get('prefix',None)
suffix=element.get('suffix',None)
......@@ -533,40 +543,6 @@ class CoreObject(Process):
print phrase,arg,suffix
else:
print phrase,arg
@staticmethod
def getSupportedPrintKwrds():
return ("signal", "signalReceiver", "signalGiver","attemptSignal",
"attemptSignalGiver", "attemptSignalReceiver",
"preempt", "preempted","startWork", "finishWork", "processEnd", "interrupted",
"enter", "waitEvent", "received",
"isRequested","canDispose","interruptionEnd", "loadOperatorAvailable", 'resourceAvailable',
'conveyerEnd', 'conveyerFull','moveEnd')
@staticmethod
def getPhrase():
printKwrds={'signal':{'phrase':'signalling'},
'signalGiver':{'phrase':'signalling giver', 'prefix':'_'},
'signalReceiver':{'phrase':'signalling receiver','prefix':'_'},
'attemptSignal':{'phrase':'will try to signal'},
'attemptSignalGiver':{'phrase':'will try to signal a giver'},
'attemptSignalReceiver':{'phrase':'will try to signal a receiver'},
'preempt': {'phrase':'preempts','suffix':' .'},
'preempted': {'phrase':'is being preempted','suffix':'. '},
'startWork':{'phrase':'started working in'},
'finishWork':{'phrase':'finished working in'},
'processEnd':{'phrase':'ended processing in'},
'interrupted':{'phrase':'interrupted at','suffix':' .'},
'enter':{'phrase':'got into','suffix':'='},
'waitEvent':{'phrase':'will wait for event'},
'received':{'phrase':'received event'},
'isRequested':{'phrase':'received an isRequested event from'},
'canDispose':{'phrase':'received an canDispose event'},
'interruptionEnd':{'phrase':'received an interruptionEnd event at'},
"loadOperatorAvailable":{'phrase':'received a loadOperatorAvailable event at'},
"resourceAvailable":{'phrase':'received a resourceAvailable event'},
'moveEnd':{'phrase':'received a moveEnd event'},
"conveyerEnd":{'phrase':'has reached conveyer End', 'suffix':'.!'},
'conveyerFull':{'phrase':'is now Full, No of units:', 'suffix':'(*)'}}
return printKwrds
# =======================================================================
# outputs data to "output.xls"
......@@ -587,15 +563,6 @@ class CoreObject(Process):
activeObjectQueue=self.getActiveObjectQueue()
return len(activeObjectQueue)>0
#========================================================================
# checks if the object can dispose an entity
# and returns the entity that it will dispose
# To be used as self.canAcceptEntity(giver.haveToDisposeEntity(self))
#========================================================================
def haveToDisposeEntity(self, callerObject=None):
activeObjectQueue=self.getActiveObjectQueue()
if self.haveToDispose(callerObject):
return activeObjectQueue[0]
# =======================================================================
# checks if the Object can accept an entity and there is an entity
# in some possible giver waiting for it
......@@ -609,12 +576,6 @@ class CoreObject(Process):
def canAccept(self, callerObject=None):
pass
# =======================================================================
# checks if the object can accept an specific Entity
# =======================================================================
def canAcceptEntity(self, callerEntity=None):
return True
# =======================================================================
# sorts the Entities in the activeQ of the objects
# =======================================================================
......@@ -673,14 +634,12 @@ class CoreObject(Process):
# assign Exit of the object
# =======================================================================
def assignExitTo(self, callerObject=None):
# self.printTrace(self.id, 'assignExit')
self.exitAssignedToReceiver=callerObject
# =======================================================================
# unblock the object
# =======================================================================
def unAssignExit(self):
# self.printTrace(self.id, 'unassignExit')
self.exitAssignedToReceiver = None
# =======================================================================
......
......@@ -117,14 +117,12 @@ class Dismantle(CoreObject):
# check if there is WIP and signal receiver
self.initialSignalReceiver()
while 1:
# self.printTrace(self.id, 'will wait for frame event')
self.printTrace1(self.id, waitEvent='(frame)')
self.printTrace(self.id, waitEvent='(frame)')
# wait until the Queue can accept an entity and one predecessor requests it
yield waitevent, self, self.isRequested #[self.isRequested,self.canDispose, self.loadOperatorAvailable]
if self.isRequested.signalparam:
# self.printTrace(self.id, 'received a isRequested event from '+self.isRequested.signalparam.id)
self.printTrace1(self.id, isRequested=self.isRequested.signalparam.id)
self.printTrace(self.id, isRequested=self.isRequested.signalparam.id)
# reset the isRequested signal parameter
self.isRequested.signalparam=None
......@@ -277,8 +275,7 @@ class Dismantle(CoreObject):
activeObject.waitToDisposePart=False
# if the internal queue is empty then try to signal the giver that the object can now receive
if activeObject.canAccept():
# activeObject.printTrace(self.id, 'will try signalling a giver from removeEntity')
activeObject.printTrace1(self.id, attemptSingalGiver='(removeEntity)')
activeObject.printTrace(self.id, attemptSingalGiver='(removeEntity)')
activeObject.signalGiver()
return activeEntity
......
......@@ -279,3 +279,78 @@ def getConfidenceIntervals(value_list):
'ub': ub,
'avg': numpy.mean(value_list) }
# #===========================================================================
# # printTrace
# #===========================================================================
# def printTrace(entity='',station='', **kw):
# assert len(kw)==1, 'only one phrase per printTrace supported for the moment'
# from Globals import G
# time=now()
# charLimit=60
# remainingChar=charLimit-len(entity)-len(str(time))
# if(G.console=='Yes'):
# print time,entity,
# for key in kw:
# if key not in getSupportedPrintKwrds():
# raise ValueError("Unsupported phrase %s for %s" % (key, station.id))
# element=getPhrase()[key]
# phrase=element['phrase']
# prefix=element.get('prefix',None)
# suffix=element.get('suffix',None)
# arg=kw[key]
# if prefix:
# print prefix*remainingChar,phrase,arg
# elif suffix:
# remainingChar-=len(phrase)+len(arg)
# suffix*=remainingChar
# if key=='enter':
# suffix=suffix+'>'
# print phrase,arg,suffix
# else:
# print phrase,arg
#===========================================================================
# get the supported print Keywords
#===========================================================================
def getSupportedPrintKwrds():
return ("create",
"signal", "signalReceiver", "signalGiver",
"attemptSignal","attemptSignalGiver", "attemptSignalReceiver",
"preempt", "preempted",
"startWork", "finishWork",
"processEnd", "interrupted",
"enter",
"waitEvent", "received", "isRequested","canDispose",
"interruptionEnd", "loadOperatorAvailable", 'resourceAvailable',
'conveyerEnd', 'conveyerFull','moveEnd')
#===========================================================================
# get the phrase to print from the keyword
#===========================================================================
def getPhrase():
printKwrds={'create':{'phrase':'created an entity'},
'signal':{'phrase':'signalling'},
'signalGiver':{'phrase':'signalling giver', 'prefix':'_'},
'signalReceiver':{'phrase':'signalling receiver','prefix':'_'},
'attemptSignal':{'phrase':'will try to signal'},
'attemptSignalGiver':{'phrase':'will try to signal a giver'},
'attemptSignalReceiver':{'phrase':'will try to signal a receiver'},
'preempt': {'phrase':'preempts','suffix':' .'},
'preempted': {'phrase':'is being preempted','suffix':'. '},
'startWork':{'phrase':'started working in'},
'finishWork':{'phrase':'finished working in'},
'processEnd':{'phrase':'ended processing in'},
'interrupted':{'phrase':'interrupted at','suffix':' .'},
'enter':{'phrase':'got into','suffix':'='},
'waitEvent':{'phrase':'will wait for event'},
'received':{'phrase':'received event'},
'isRequested':{'phrase':'received an isRequested event from'},
'canDispose':{'phrase':'received an canDispose event'},
'interruptionEnd':{'phrase':'received an interruptionEnd event at'},
"loadOperatorAvailable":{'phrase':'received a loadOperatorAvailable event at'},
"resourceAvailable":{'phrase':'received a resourceAvailable event'},
'moveEnd':{'phrase':'received a moveEnd event'},
"conveyerEnd":{'phrase':'has reached conveyer End', 'suffix':'.!'},
'conveyerFull':{'phrase':'is now Full, No of units:', 'suffix':'(*)'}}
return printKwrds
......@@ -228,15 +228,12 @@ class Machine(CoreObject):
while 1:
# waitEvent isRequested /interruptionEnd/loadOperatorAvailable
while 1:
# self.printTrace(self.id, 'will wait for event')
self.printTrace1(self.id, waitEvent='')
self.printTrace(self.id, waitEvent='')
yield waitevent, self, [self.isRequested, self.interruptionEnd, self.loadOperatorAvailable]
# self.printTrace(self.id, 'received an event')
self.printTrace1(self.id, received='')
self.printTrace(self.id, received='')
# if the machine can accept an entity and one predecessor requests it continue with receiving the entity
if self.isRequested.signalparam:
# self.printTrace(self.id, 'received an isRequested event from'+self.isRequested.signalparam.id)
self.printTrace1(self.id, isRequested=self.isRequested.signalparam.id)
self.printTrace(self.id, isRequested=self.isRequested.signalparam.id)
assert self.isRequested.signalparam==self.giver, 'the giver is not the requestingObject'
assert self.giver.receiver==self, 'the receiver of the signalling object in not the station'
# reset the signalparam of the isRequested event
......@@ -246,11 +243,9 @@ class Machine(CoreObject):
# if an operator was rendered available while it was needed by the machine to proceed with getEntity
if self.interruptionEnd.signalparam==now() or self.loadOperatorAvailable.signalparam==now():
if self.interruptionEnd.signalparam==now():
# self.printTrace(self.id, 'received an interruptionEnd event sent at '+str(self.interruptionEnd.signalparam))
self.printTrace1(self.id, interruptionEnd=str(self.interruptionEnd.signalparam))
self.printTrace(self.id, interruptionEnd=str(self.interruptionEnd.signalparam))
elif self.loadOperatorAvailable.signalparam==now():
# self.printTrace(self.id, 'received an loadOperatorAvailable event sent at '+str(self.loadOperatorAvailable.signalparam))
self.printTrace1(self.id,loadOperatorAvailable=str(self.loadOperatorAvailable.signalparam))
self.printTrace(self.id,loadOperatorAvailable=str(self.loadOperatorAvailable.signalparam))
# try to signal the Giver, otherwise wait until it is requested
if self.signalGiver():
break
......@@ -475,8 +470,7 @@ class Machine(CoreObject):
activeObject=self.getActiveObject()
activeObjectQueue=activeObject.getActiveObjectQueue()
activeEntity=activeObjectQueue[0]
# self.printTrace(activeObject.getActiveObjectQueue()[0].name,"ended processing in "+activeObject.objName)
self.printTrace1(activeObject.getActiveObjectQueue()[0].name, processEnd=activeObject.objName)
self.printTrace(activeObject.getActiveObjectQueue()[0].name, processEnd=activeObject.objName)
# reset the variables used to handle the interruptions timing
self.timeRestartingProcessing=0
self.breakTime=0
......@@ -526,8 +520,7 @@ class Machine(CoreObject):
activeObject=self.getActiveObject()
activeObjectQueue=activeObject.getActiveObjectQueue()
activeEntity=activeObjectQueue[0]
# self.printTrace(self.getActiveObjectQueue()[0].name, "Interrupted at "+self.objName+'. '*5)
self.printTrace1(self.getActiveObjectQueue()[0].name, interrupted=self.objName)
self.printTrace(self.getActiveObjectQueue()[0].name, interrupted=self.objName)
# if the interrupt occured while processing an entity
if not activeObject.waitToDispose:
# output to trace that the Machine (self.objName) got interrupted
......@@ -712,8 +705,7 @@ class Machine(CoreObject):
activeObject.waitToDispose=False # update the waitToDispose flag
# if the Machine canAccept then signal a giver
if activeObject.canAccept():
# self.printTrace(self.id, 'will try signalling a giver from removeEntity')
self.printTrace1(self.id, attemptSignalGiver='(removeEntity)')
self.printTrace(self.id, attemptSignalGiver='(removeEntity)')
activeObject.signalGiver()
return activeEntity
......@@ -744,12 +736,6 @@ class Machine(CoreObject):
def calculateLoadTime(self):
return self.loadRng.generateNumber()
# =======================================================================
# prepare the machine to be operated
# =======================================================================
def requestRouter(self):
if not self.router.isCalled():
self.router.invoke()
#===========================================================================
# find candidate operators within the free operators
......@@ -803,18 +789,6 @@ class Machine(CoreObject):
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
# =======================================================================
......
......@@ -49,8 +49,7 @@ class MachineJobShop(Machine):
activeObject=self.getActiveObject()
activeObjectQueue=activeObject.getActiveObjectQueue()
activeEntity=activeObjectQueue[0]
# self.printTrace(activeObject.getActiveObjectQueue()[0].name,"ended processing in "+activeObject.objName)
self.printTrace1(activeObject.getActiveObjectQueue()[0].name,processEnd=activeObject.objName)
self.printTrace(activeObject.getActiveObjectQueue()[0].name,processEnd=activeObject.objName)
# reset the variables used to handle the interruptions timing
self.timeRestartingProcessing=0
self.breakTime=0
......@@ -231,8 +230,7 @@ class MachineJobShop(Machine):
# method to execute preemption
# =======================================================================
def preempt(self):
# self.printTrace(self.id,'preempting'+' .'*7)
self.printTrace1(self.id,preempted='')
self.printTrace(self.id,preempted='')
activeObject=self.getActiveObject()
activeEntity=self.getActiveObjectQueue()[0] #get the active Entity
#calculate the remaining processing time
......
......@@ -71,7 +71,7 @@ class Broker(ObjectInterruption):
# TODO: add new broker event - brokerIsCalled
yield waitevent, self, self.isCalled
assert self.isCalled.signalparam==now(), 'the broker should be granted control instantly'
self.victim.printTrace1(self.victim.id, received='(broker)')
self.victim.printTrace(self.victim.id, received='(broker)')
# ======= request a resource
if self.victim.isOperated()\
and any(type=='Load' or type=='Setup' or type=='Processing'\
......@@ -87,28 +87,24 @@ class Broker(ObjectInterruption):
if not self.victim.currentEntity in G.pendingEntities:
G.pendingEntities.append(self.victim.currentEntity)
if not G.Router.invoked:
# self.printTrace(self.victim.id, 'broker'+' '*50+'signalling router')
self.victim.printTrace1(self.victim.id, signal='router (broker)')
self.victim.printTrace(self.victim.id, signal='router (broker)')
G.Router.invoked=True
G.Router.isCalled.signal(now())
self.waitForOperator=True
# self.printTrace(self.victim.id, 'broker waits till resource is available1')
self.victim.printTrace1(self.victim.id, waitEvent='(resourceIsAvailable broker)')
self.victim.printTrace(self.victim.id, waitEvent='(resourceIsAvailable broker)')
yield waitevent, self, self.resourceAvailable
# remove the currentEntity from the pendingEntities
if self.victim.currentEntity in G.pendingEntities:
G.pendingEntities.remove(self.victim.currentEntity)
self.waitForOperator=False
# self.printTrace(self.victim.id, 'received resourceAvailable event')
self.victim.printTrace1(self.victim.id, resourceAvailable='(broker)')
self.victim.printTrace(self.victim.id, resourceAvailable='(broker)')
#===============================================================
assert self.victim.operatorPool.checkIfResourceIsAvailable(), 'there is no available operator to request'
# set the available resource as the currentOperator
self.victim.currentOperator=self.victim.operatorPool.findAvailableOperator()
yield request, self, self.victim.operatorPool.getResource(self.victim.currentOperator)
# self.printTrace(self.victim.currentOperator.objName, 'started work in '+self.victim.id)
self.victim.printTrace1(self.victim.currentOperator.objName, startWork=self.victim.id)
self.victim.printTrace(self.victim.currentOperator.objName, startWork=self.victim.id)
# clear the timeWaitForOperatorStarted variable
self.timeWaitForOperatorStarted = 0
# update the time that the operation started
......@@ -125,16 +121,14 @@ class Broker(ObjectInterruption):
# TODO: signalling the router must be done more elegantly, router must be set as global variable
# if the router is already invoked then do not signal it again
if not self.victim.router.invoked:
# self.printTrace(self.victim.id, 'broker'+' '*50+'signalling ROUTER')
self.victim.printTrace1(self.victim.id, signal='router (broker)')
self.victim.printTrace(self.victim.id, signal='router (broker)')
self.victim.router.invoked=True
self.victim.router.isCalled.signal(now())
# TODO: signalling the router will give the chance to it to take the control, but when will it eventually receive it.
# after signalling the broker will signal it's victim that it has finished it's processes
# TODO: this wont work for the moment. The actions that follow must be performed by all operated brokers.
self.printTrace(self.victim.currentOperator.objName, 'released '+self.victim.id)
self.victim.printTrace1(self.victim.currentOperator.objName, finishWork=self.victim.id)
self.victim.printTrace(self.victim.currentOperator.objName, finishWork=self.victim.id)
# the victim current operator must be cleared after the operator is released
self.timeLastOperationEnded = now()
self.victim.currentOperator = None
......
......@@ -386,13 +386,13 @@ class Router(ObjectInterruption):
# for each pendingQueue
for object in self.pendingQueues:
# find available operator for then machines that follow
for nextobject in object.findReceivers():
for nextobject in object.findReceiversFor(object):
candidateOperator=nextobject.findCandidateOperator()
if not candidateOperator in self.candidateOperators:
self.candidateOperators.append(candidateOperator)
# check the option of preemption if there are critical entities and no available operators
#------------------------------------------------------------------------------
if not object.findReceivers() and\
if not object.findReceiversFor(object) and\
any(entity for entity in object.getActiveObjectQueue() if entity.isCritical):
# for each of the following objects
for nextObject in object.next:
......@@ -533,6 +533,25 @@ class Router(ObjectInterruption):
candidateList=self.candidateOperators
self.activeQSorter(criterion=self.schedulingRule,candList=candidateList)
def findCandidateReceiverFor(self, entity):
# initiate the local list variable available receivers
availableReceivers=[x for x in entity.candidateReceivers\
if not x in self.occupiedReceivers]
# and pick the object that is waiting for the most time
if availableReceivers:
# find the receiver that waits the most
availableReceiver=entity.currentStation.selectReceiver(availableReceivers)
self.occupiedReceivers.append(availableReceiver)
# if there is no available receiver add the entity to the entitiesWithOccupiedReceivers list
else:
self.entitiesWithOccupiedReceivers.append(entity)
availableReceiver=None
# if the sorting flag is not set then the sorting of each queue must prevail in case of operators conflict
if not self.sorting and not availableReceiver and bool(availableReceivers):
availableReceiver=entity.currentStation.selectReceiver(self.candidateReceivers)
if not entity in self.conflictingEntities:
self.conflictingEntities.append(entity)
return availableReceiver
#=======================================================================
# Find candidate entities and their receivers
......
......@@ -96,16 +96,13 @@ class Queue(CoreObject):
# check if there is WIP and signal receiver
self.initialSignalReceiver()
while 1:
# self.printTrace(self.id, 'will wait for event')
self.printTrace1(self.id, waitEvent='')
self.printTrace(self.id, waitEvent='')
# wait until the Queue can accept an entity and one predecessor requests it
yield waitevent, self, [self.isRequested,self.canDispose, self.loadOperatorAvailable]
# self.printTrace(self.id, 'just received an event')
self.printTrace1(self.id, received='')
self.printTrace(self.id, received='')
# if the event that activated the thread is isRequested then getEntity
if self.isRequested.signalparam:
# self.printTrace(self.id, 'received a isRequested event from'+self.isRequested.signalparam.id)
self.printTrace1(self.id, isRequested=self.isRequested.signalparam.id)
self.printTrace(self.id, isRequested=self.isRequested.signalparam.id)
# reset the isRequested signal parameter
self.isRequested.signalparam=None
self.getEntity()
......@@ -114,18 +111,15 @@ class Queue(CoreObject):
activeObjectQueue[0].startTime=now()
# if the queue received an loadOperatorIsAvailable (from Router) with signalparam time
if self.loadOperatorAvailable.signalparam:
# self.printTrace(self.id, 'received a loadOperatorAvailable event')
# self.printTrace1(self.id, loadOperatorAvailable=str(self.loadOperatorAvailable.signalparam))
# self.printTrace(self.id, loadOperatorAvailable=str(self.loadOperatorAvailable.signalparam))
self.loadOperatorAvailable.signalparam=None
# if the queue received an canDispose with signalparam time, this means that the signals was sent from a MouldAssemblyBuffer
if self.canDispose.signalparam:
# self.printTrace(self.id, 'received a canDispose event')
self.printTrace1(self.id, canDispose='')
self.printTrace(self.id, canDispose='')
self.canDispose.signalparam=None
# if the event that activated the thread is canDispose then signalReceiver
if self.haveToDispose():
# self.printTrace(self.id, 'will try to signal a receiver from generator')
self.printTrace1(self.id, attemptSignalReceiver='(generator)')
self.printTrace(self.id, attemptSignalReceiver='(generator)')
if self.receiver:
if not self.receiver.entryIsAssignedTo():
self.signalReceiver()
......@@ -178,8 +172,7 @@ class Queue(CoreObject):
# TODO: disable that for the mouldAssemblyBuffer
if not self.__class__.__name__=='MouldAssemblyBuffer':
if self.haveToDispose():
self.printTrace(self.id, 'will try to signal a receiver from removeEntity')
self.printTrace1(self.id, attemptSignalReceiver='(removeEntity)')
self.printTrace(self.id, attemptSignalReceiver='(removeEntity)')
self.signalReceiver()
return activeEntity
......
......@@ -104,7 +104,8 @@ class QueueManagedJob(QueueJobShop):
#===========================================================================
# signalRouter method
#===========================================================================
def signalRouter(self, receiver=None):
@staticmethod
def signalRouter(receiver=None):
# if an operator is not assigned to the receiver then do not signal the receiver but the Router
# TODO: identifyEntityToGet needs giver defined but here is not yet defined for Machines and machineJobShops
try:
......@@ -113,8 +114,7 @@ class QueueManagedJob(QueueJobShop):
if receiver.identifyEntityToGet().manager.isAssignedTo()!=receiver:
from Globals import G
if not G.Router.invoked:
# self.printTrace(self.id,' '*50+'signalling router')
self.printTrace1(self.id, signal='router')
# self.printTrace(self.id, signal='router')
G.Router.invoked=True
G.Router.isCalled.signal(now())
return True
......
......@@ -171,7 +171,7 @@ class Source(CoreObject):
# creates an Entity
#============================================================================
def createEntity(self):
self.printTrace(self.id, 'created an entity')
# self.printTrace(self.id, create='')
return self.item(id = self.item.type+str(G.numberOfEntities), name = self.item.type+str(self.numberOfArrivals)) #return the newly created Entity
#============================================================================
# calculates the processing time
......
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