new method prinTrace for printing on console

parent b84a9fd4
...@@ -266,10 +266,7 @@ class CoreObject(Process): ...@@ -266,10 +266,7 @@ class CoreObject(Process):
#if the receiver does not hold an Entity that is also critical #if the receiver does not hold an Entity that is also critical
if not self.receiver.getActiveObjectQueue()[0].isCritical: if not self.receiver.getActiveObjectQueue()[0].isCritical:
self.receiver.shouldPreempt=True self.receiver.shouldPreempt=True
#======================================================= self.printTrace(self.id, 'preempting receiver'+self.receiver.id+'.. '*6)
# testing
# print now(), self.id, 'preempting receiver', self.receiver.id,'.. '*6
#=======================================================
self.receiver.preempt() self.receiver.preempt()
self.receiver.timeLastEntityEnded=now() #required to count blockage correctly in the preemptied station self.receiver.timeLastEntityEnded=now() #required to count blockage correctly in the preemptied station
...@@ -310,10 +307,7 @@ class CoreObject(Process): ...@@ -310,10 +307,7 @@ class CoreObject(Process):
# the hot flag should not be raised # the hot flag should not be raised
if successorsAreMachines: if successorsAreMachines:
activeEntity.hot = True activeEntity.hot = True
#======================================================================= self.printTrace(activeEntity.name, "got into "+self.id)
# # TESTING
# print now(), activeEntity.name, "got into "+self.id
#=======================================================================
# update wipStatList # update wipStatList
if self.gatherWipStat: if self.gatherWipStat:
self.wipStatList.append([now(), len(activeObjectQueue)]) self.wipStatList.append([now(), len(activeObjectQueue)])
...@@ -333,7 +327,7 @@ class CoreObject(Process): ...@@ -333,7 +327,7 @@ class CoreObject(Process):
# signal the successor that the object can dispose an entity # signal the successor that the object can dispose an entity
# ======================================================================= # =======================================================================
def signalReceiver(self): def signalReceiver(self):
# print now(), self.id, 'trying to signal receiver' # self.printTrace(self.id, 'trying to signal receiver')
activeObject=self.getActiveObject() activeObject=self.getActiveObject()
possibleReceivers=activeObject.findReceivers() possibleReceivers=activeObject.findReceivers()
if possibleReceivers: if possibleReceivers:
...@@ -356,10 +350,7 @@ class CoreObject(Process): ...@@ -356,10 +350,7 @@ class CoreObject(Process):
activeObject.receiver=receiver activeObject.receiver=receiver
activeObject.receiver.giver=activeObject activeObject.receiver.giver=activeObject
#=================================================================== self.printTrace(self.id, ' '*50+'signalling receiver '+self.receiver.id)
# # TESTING
# print now(), self.id,' '*50, 'signalling receiver', self.receiver.id
#===================================================================
# assign the entry of the receiver # assign the entry of the receiver
activeObject.receiver.assignEntryTo() activeObject.receiver.assignEntryTo()
activeObject.receiver.isRequested.signal(activeObject) activeObject.receiver.isRequested.signal(activeObject)
...@@ -392,10 +383,7 @@ class CoreObject(Process): ...@@ -392,10 +383,7 @@ class CoreObject(Process):
if receiver.isLoadRequested(): if receiver.isLoadRequested():
from Globals import G from Globals import G
if not G.Router.invoked: if not G.Router.invoked:
#=================================================================== self.printTrace(self.id, ' '*50+'signalling router')
# # TESTING
# print now(), self.id,' '*50, 'signalling router'
#===================================================================
G.Router.invoked=True G.Router.invoked=True
G.Router.isCalled.signal(now()) G.Router.isCalled.signal(now())
return True return True
...@@ -425,7 +413,7 @@ class CoreObject(Process): ...@@ -425,7 +413,7 @@ class CoreObject(Process):
# signal the giver that the entity is removed from its internalQueue # signal the giver that the entity is removed from its internalQueue
# ======================================================================= # =======================================================================
def signalGiver(self): def signalGiver(self):
# print now(), self.id, 'trying to signal giver' # self.printTrace(self.id, 'trying to signal giver')
activeObject=self.getActiveObject() activeObject=self.getActiveObject()
possibleGivers=activeObject.findGivers() possibleGivers=activeObject.findGivers()
if possibleGivers: if possibleGivers:
...@@ -440,10 +428,7 @@ class CoreObject(Process): ...@@ -440,10 +428,7 @@ class CoreObject(Process):
giversReceiver=activeObject giversReceiver=activeObject
activeObject.giver=giver activeObject.giver=giver
activeObject.giver.receiver=activeObject activeObject.giver.receiver=activeObject
#=================================================================== self.printTrace(self.id, ' '*50+'signalling giver '+self.giver.id)
# # TESTING
# print now(), self.id,' '*50, 'signalling giver', self.giver.id
#===================================================================
activeObject.giver.canDispose.signal(activeObject) activeObject.giver.canDispose.signal(activeObject)
return True return True
return False return False
...@@ -497,8 +482,17 @@ class CoreObject(Process): ...@@ -497,8 +482,17 @@ class CoreObject(Process):
if(G.traceIndex==65536): if(G.traceIndex==65536):
G.traceIndex=0 G.traceIndex=0
G.sheetIndex+=1 G.sheetIndex+=1
G.traceSheet=G.traceFile.add_sheet('sheet '+str(G.sheetIndex), cell_overwrite_ok=True) 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
# ======================================================================= # =======================================================================
# outputs data to "output.xls" # outputs data to "output.xls"
# ======================================================================= # =======================================================================
...@@ -604,15 +598,14 @@ class CoreObject(Process): ...@@ -604,15 +598,14 @@ class CoreObject(Process):
# assign Exit of the object # assign Exit of the object
# ======================================================================= # =======================================================================
def assignExitTo(self, callerObject=None): def assignExitTo(self, callerObject=None):
# print self.id, 'assignExit' # self.printTrace(self.id, 'assignExit')
# self.exitAssignedToReceiver = self.receiver
self.exitAssignedToReceiver=callerObject self.exitAssignedToReceiver=callerObject
# ======================================================================= # =======================================================================
# unblock the object # unblock the object
# ======================================================================= # =======================================================================
def unAssignExit(self): def unAssignExit(self):
# print now(),self.id, 'unassignExit' # self.printTrace(self.id, 'unassignExit')
self.exitAssignedToReceiver = None self.exitAssignedToReceiver = None
# ======================================================================= # =======================================================================
......
...@@ -50,6 +50,10 @@ class G: ...@@ -50,6 +50,10 @@ class G:
Base=1 #the Base time unit. Default =1 minute Base=1 #the Base time unit. Default =1 minute
maxSimTime=0 #the total simulation time maxSimTime=0 #the total simulation time
# flag for printing in console
# -----------------------------------------------------------------------
console=""
# data for the trace output in excel # data for the trace output in excel
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
trace="" #this is written from input. If it is "Yes" then you write to trace, else we do not trace="" #this is written from input. If it is "Yes" then you write to trace, else we do not
......
...@@ -103,6 +103,7 @@ def readGeneralInput(): ...@@ -103,6 +103,7 @@ def readGeneralInput():
G.numberOfReplications=int(general.get('numberOfReplications', '1')) # read the number of replications / default 1 G.numberOfReplications=int(general.get('numberOfReplications', '1')) # read the number of replications / default 1
G.maxSimTime=float(general.get('maxSimTime', '100')) # get the maxSimTime / default 100 G.maxSimTime=float(general.get('maxSimTime', '100')) # get the maxSimTime / default 100
G.trace=general.get('trace', 'No') # get trace in order to check if trace is requested G.trace=general.get('trace', 'No') # get trace in order to check if trace is requested
G.console=general.get('console', 'No') # get console flag in order to check if console print is requested
G.confidenceLevel=float(general.get('confidenceLevel', '0.95')) # get the confidence level G.confidenceLevel=float(general.get('confidenceLevel', '0.95')) # get the confidence level
G.seed = general.get('seed') G.seed = general.get('seed')
......
...@@ -226,12 +226,12 @@ class Machine(CoreObject): ...@@ -226,12 +226,12 @@ class Machine(CoreObject):
while 1: while 1:
# waitEvent isRequested /interruptionEnd/loadOperatorAvailable # waitEvent isRequested /interruptionEnd/loadOperatorAvailable
while 1: while 1:
# print now(), self.id, 'will wait for event' # self.printTrace(self.id, 'will wait for event')
yield waitevent, self, [self.isRequested, self.interruptionEnd, self.loadOperatorAvailable] yield waitevent, self, [self.isRequested, self.interruptionEnd, self.loadOperatorAvailable]
# print now(), self.id, 'received an event' # self.printTrace(self.id, 'received an event')
# if the machine can accept an entity and one predecessor requests it continue with receiving the entity # if the machine can accept an entity and one predecessor requests it continue with receiving the entity
if self.isRequested.signalparam: if self.isRequested.signalparam:
# print now(), self.id, 'received an isRequested event from', self.isRequested.signalparam.id # self.printTrace(self.id, 'received an isRequested event from'+self.isRequested.signalparam.id)
assert self.isRequested.signalparam==self.giver, 'the giver is not the requestingObject' 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' assert self.giver.receiver==self, 'the receiver of the signalling object in not the station'
# reset the signalparam of the isRequested event # reset the signalparam of the isRequested event
...@@ -241,9 +241,9 @@ class Machine(CoreObject): ...@@ -241,9 +241,9 @@ class Machine(CoreObject):
# if an operator was rendered available while it was needed by the machine to proceed with getEntity # 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() or self.loadOperatorAvailable.signalparam==now():
# if self.interruptionEnd.signalparam==now(): # if self.interruptionEnd.signalparam==now():
# print self.id, 'received an interruptionEnd event sent at ', self.interruptionEnd.signalparam # self.printTrace(self.id, 'received an interruptionEnd event sent at '+self.interruptionEnd.signalparam)
# elif self.loadOperatorAvailable.signalparam==now(): # elif self.loadOperatorAvailable.signalparam==now():
# print now(), self.id, 'received an loadOperatorAvailable event sent at ', self.loadOperatorAvailable.signalparam # self.printTrace(self.id, 'received an loadOperatorAvailable event sent at '+self.loadOperatorAvailable.signalparam)
# try to signal the Giver, otherwise wait until it is requested # try to signal the Giver, otherwise wait until it is requested
if self.signalGiver(): if self.signalGiver():
break break
...@@ -481,10 +481,7 @@ class Machine(CoreObject): ...@@ -481,10 +481,7 @@ class Machine(CoreObject):
activeObject=self.getActiveObject() activeObject=self.getActiveObject()
activeObjectQueue=activeObject.getActiveObjectQueue() activeObjectQueue=activeObject.getActiveObjectQueue()
activeEntity=activeObjectQueue[0] activeEntity=activeObjectQueue[0]
#======================================================================= self.printTrace(activeObject.getActiveObjectQueue()[0].name,"ended processing in "+activeObject.objName)
# # TESTING
# print activeObject.getActiveObjectQueue()[0].name,"ended processing in "+activeObject.objName
#=======================================================================
# reset the variables used to handle the interruptions timing # reset the variables used to handle the interruptions timing
self.timeRestartingProcessing=0 self.timeRestartingProcessing=0
self.breakTime=0 self.breakTime=0
...@@ -539,10 +536,7 @@ class Machine(CoreObject): ...@@ -539,10 +536,7 @@ class Machine(CoreObject):
activeObject=self.getActiveObject() activeObject=self.getActiveObject()
activeObjectQueue=activeObject.getActiveObjectQueue() activeObjectQueue=activeObject.getActiveObjectQueue()
activeEntity=activeObjectQueue[0] activeEntity=activeObjectQueue[0]
#======================================================================= self.printTrace(self.getActiveObjectQueue()[0].name, "Interrupted at "+self.objName+'. '*5)
# testing
# print self.getActiveObjectQueue()[0].name, "Interrupted at ",self.objName, '. '*5
#=======================================================================
# if the interrupt occured while processing an entity # if the interrupt occured while processing an entity
if not activeObject.waitToDispose: if not activeObject.waitToDispose:
# output to trace that the Machine (self.objName) got interrupted # output to trace that the Machine (self.objName) got interrupted
...@@ -747,7 +741,7 @@ class Machine(CoreObject): ...@@ -747,7 +741,7 @@ class Machine(CoreObject):
activeObject.waitToDispose=False # update the waitToDispose flag activeObject.waitToDispose=False # update the waitToDispose flag
# if the Machine canAccept then signal a giver # if the Machine canAccept then signal a giver
if activeObject.canAccept(): if activeObject.canAccept():
# print self.id, now(), 'will try signalling a giver from removeEntity' # self.printTrace(self.id, 'will try signalling a giver from removeEntity')
activeObject.signalGiver() activeObject.signalGiver()
return activeEntity return activeEntity
......
...@@ -137,4 +137,12 @@ class ObjectInterruption(Process): ...@@ -137,4 +137,12 @@ class ObjectInterruption(Process):
G.traceIndex=0 G.traceIndex=0
G.sheetIndex+=1 G.sheetIndex+=1
G.traceSheet=G.traceFile.add_sheet('sheet '+str(G.sheetIndex), cell_overwrite_ok=True) G.traceSheet=G.traceFile.add_sheet('sheet '+str(G.sheetIndex), cell_overwrite_ok=True)
\ No newline at end of file #===========================================================================
# 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
\ No newline at end of file
...@@ -49,7 +49,6 @@ class Broker(ObjectInterruption): ...@@ -49,7 +49,6 @@ class Broker(ObjectInterruption):
self.timeWaitForOperatorStarted=0 self.timeWaitForOperatorStarted=0
# Broker events # Broker events
self.isCalled=SimEvent('brokerIsCalled') self.isCalled=SimEvent('brokerIsCalled')
# self.victimQueueIsEmpty=SimEvent('victimQueueIsEmpty')
self.resourceAvailable=SimEvent('resourceAvailable') self.resourceAvailable=SimEvent('resourceAvailable')
self.waitForOperator=False self.waitForOperator=False
...@@ -76,7 +75,7 @@ class Broker(ObjectInterruption): ...@@ -76,7 +75,7 @@ class Broker(ObjectInterruption):
if self.victim.isOperated()\ if self.victim.isOperated()\
and any(type=='Load' or type=='Setup' or type=='Processing'\ and any(type=='Load' or type=='Setup' or type=='Processing'\
for type in self.victim.multOperationTypeList): for type in self.victim.multOperationTypeList):
# print now(), self.victim.id, 'broker is invoked' # self.printTrace(self.victim.id, 'broker is invoked')
# update the time that the station is waiting for the operator # update the time that the station is waiting for the operator
self.timeWaitForOperatorStarted=now() self.timeWaitForOperatorStarted=now()
#=============================================================== #===============================================================
...@@ -88,30 +87,24 @@ class Broker(ObjectInterruption): ...@@ -88,30 +87,24 @@ class Broker(ObjectInterruption):
if not self.victim.currentEntity in G.pendingEntities: if not self.victim.currentEntity in G.pendingEntities:
G.pendingEntities.append(self.victim.currentEntity) G.pendingEntities.append(self.victim.currentEntity)
if not G.Router.invoked: if not G.Router.invoked:
#=========================================================== self.printTrace(self.victim.id, 'broker'+' '*50+'signalling router')
# testing
# print now(), self.victim.id, 'broker', ' '*50, 'signalling router'
#===========================================================
G.Router.invoked=True G.Router.invoked=True
G.Router.isCalled.signal(now()) G.Router.isCalled.signal(now())
self.waitForOperator=True self.waitForOperator=True
# print now(), self.victim.id, 'broker waits till resource is available1' # self.printTrace(self.victim.id, 'broker waits till resource is available1')
yield waitevent, self, self.resourceAvailable yield waitevent, self, self.resourceAvailable
# remove the currentEntity from the pendingEntities # remove the currentEntity from the pendingEntities
if self.victim.currentEntity in G.pendingEntities: if self.victim.currentEntity in G.pendingEntities:
G.pendingEntities.remove(self.victim.currentEntity) G.pendingEntities.remove(self.victim.currentEntity)
self.waitForOperator=False self.waitForOperator=False
# print self.victim.id, 'received resourceAvailable event' # self.printTrace(self.victim.id, 'received resourceAvailable event')
#=============================================================== #===============================================================
assert self.victim.operatorPool.checkIfResourceIsAvailable(), 'there is no available operator to request' assert self.victim.operatorPool.checkIfResourceIsAvailable(), 'there is no available operator to request'
# set the available resource as the currentOperator # set the available resource as the currentOperator
self.victim.currentOperator=self.victim.operatorPool.findAvailableOperator() self.victim.currentOperator=self.victim.operatorPool.findAvailableOperator()
yield request, self, self.victim.operatorPool.getResource(self.victim.currentOperator) yield request, self, self.victim.operatorPool.getResource(self.victim.currentOperator)
#=============================================================== self.printTrace(self.victim.currentOperator.objName, 'started work in '+self.victim.id)
# # TESTING
# print now(), self.victim.currentOperator.objName, 'started work in ', self.victim.id
#===============================================================
# clear the timeWaitForOperatorStarted variable # clear the timeWaitForOperatorStarted variable
self.timeWaitForOperatorStarted = 0 self.timeWaitForOperatorStarted = 0
# update the time that the operation started # update the time that the operation started
...@@ -125,13 +118,11 @@ class Broker(ObjectInterruption): ...@@ -125,13 +118,11 @@ class Broker(ObjectInterruption):
yield release,self,self.victim.operatorPool.getResource(self.victim.currentOperator) yield release,self,self.victim.operatorPool.getResource(self.victim.currentOperator)
# signal the other brokers waiting for the same operators that they are now free # signal the other brokers waiting for the same operators that they are now free
# also signal the stations that were not requested to receive because the operator was occupied # also signal the stations that were not requested to receive because the operator was occupied
#===============================================================
# TESTING
# print now(), self.victim.id, 'broker signalling ROUTER'
#===============================================================
# TODO: signalling the router must be done more elegantly, router must be set as global variable # 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 the router is already invoked then do not signal it again
if not self.victim.router.invoked: if not self.victim.router.invoked:
self.printTrace(self.victim.id, 'broker'+' '*50+'signalling ROUTER')
self.victim.router.invoked=True self.victim.router.invoked=True
self.victim.router.isCalled.signal(now()) 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. # TODO: signalling the router will give the chance to it to take the control, but when will it eventually receive it.
...@@ -139,10 +130,7 @@ class Broker(ObjectInterruption): ...@@ -139,10 +130,7 @@ class Broker(ObjectInterruption):
# TODO: this wont work for the moment. The actions that follow must be performed by all operated brokers. # TODO: this wont work for the moment. The actions that follow must be performed by all operated brokers.
# self.signalLoadStations() # self.signalLoadStations()
#=============================================================== self.printTrace(self.victim.currentOperator.objName, 'released '+self.victim.id)
# # TESTING
# print now(), self.victim.currentOperator.objName, 'released', self.victim.id
#===============================================================
# the victim current operator must be cleared after the operator is released # the victim current operator must be cleared after the operator is released
self.timeLastOperationEnded = now() self.timeLastOperationEnded = now()
self.victim.currentOperator = None self.victim.currentOperator = None
......
...@@ -104,18 +104,17 @@ class Router(ObjectInterruption): ...@@ -104,18 +104,17 @@ class Router(ObjectInterruption):
while 1: while 1:
# wait until the router is called # wait until the router is called
yield waitevent, self, self.isCalled yield waitevent, self, self.isCalled
# print '=-'*15 self.printTrace('','=-'*15)
# print now(), 'router received event' self.printTrace('','router received event')
# wait till there are no more events, the machines must be blocked # wait till there are no more events, the machines must be blocked
while 1: while 1:
# print Simulation.allEventNotices(sim)
if now() in Simulation.allEventTimes(sim): if now() in Simulation.allEventTimes(sim):
# print 'there are MORE events for now' self.printTrace('', 'there are MORE events for now')
yield hold, self, 0 yield hold, self, 0
else: else:
# print 'there are NO more events for now' self.printTrace('','there are NO more events for now')
break break
# print '=-'*15 self.printTrace('','=-'*15)
# after the events are over, assign the operators to machines for loading or simple processing # after the events are over, assign the operators to machines for loading or simple processing
# read the pendingEntities currentStations, these are the stations (queues) that may be signalled # read the pendingEntities currentStations, these are the stations (queues) that may be signalled
# the activeCallers list is updated each time the canAcceptAndIsRequested returns true even if the machine is not signalled # the activeCallers list is updated each time the canAcceptAndIsRequested returns true even if the machine is not signalled
...@@ -160,11 +159,8 @@ class Router(ObjectInterruption): ...@@ -160,11 +159,8 @@ class Router(ObjectInterruption):
object.unAssignExit() object.unAssignExit()
# signal the stations that ought to be signalled # signal the stations that ought to be signalled
self.signalOperatedStations() self.signalOperatedStations()
#=================================================================== self.printTrace('', 'router exiting')
# # testing self.printTrace('','=-'*20)
# print 'router exiting'
# print '=-'*20
#===================================================================
self.exit() self.exit()
#=========================================================================== #===========================================================================
...@@ -182,10 +178,7 @@ class Router(ObjectInterruption): ...@@ -182,10 +178,7 @@ class Router(ObjectInterruption):
# if the operator is not conflicting # if the operator is not conflicting
if not operator in self.conflictingOperators: if not operator in self.conflictingOperators:
# assign an operator to the priorityObject # assign an operator to the priorityObject
#======================================================= self.printTrace('router', ' will assign'+operator.id+'to'+operator.candidateStation.id)
# # testing
# print 'router will assign', operator.id, 'to', operator.candidateStation.id
#=======================================================
operator.assignTo(operator.candidateStation) operator.assignTo(operator.candidateStation)
if not operator.candidateStation in self.toBeSignalled: if not operator.candidateStation in self.toBeSignalled:
self.toBeSignalled.append(operator.candidateStation) self.toBeSignalled.append(operator.candidateStation)
...@@ -197,18 +190,11 @@ class Router(ObjectInterruption): ...@@ -197,18 +190,11 @@ class Router(ObjectInterruption):
and (not operator in self.conflictingOperators)\ and (not operator in self.conflictingOperators)\
and operator.candidateEntity.candidateReceiver: and operator.candidateEntity.candidateReceiver:
# assign an operator to the priorityObject # assign an operator to the priorityObject
#======================================================= self.printTrace('router', 'will assign '+operator.id+' to --> '+operator.candidateEntity.candidateReceiver.id)
# # testing
# print 'router will assign', operator.id, 'to', operator.candidateEntity.candidateReceiver.id
#=======================================================
operator.assignTo(operator.candidateEntity.candidateReceiver) operator.assignTo(operator.candidateEntity.candidateReceiver)
if not operator.candidateEntity.currentStation in self.toBeSignalled: if not operator.candidateEntity.currentStation in self.toBeSignalled:
self.toBeSignalled.append(operator.candidateEntity.currentStation) self.toBeSignalled.append(operator.candidateEntity.currentStation)
#=================================================================== self.printTrace('objects to be signalled:'+' '*11, [str(object.id) for object in self.toBeSignalled])
# # testing
# print 'router found objects to be signalled'
# print [str(object.id) for object in self.toBeSignalled]
#===================================================================
# ======================================================================= # =======================================================================
# return control to the Machine.run # return control to the Machine.run
...@@ -251,29 +237,20 @@ class Router(ObjectInterruption): ...@@ -251,29 +237,20 @@ class Router(ObjectInterruption):
assert station in self.toBeSignalled, 'the station must be in toBeSignalled list' assert station in self.toBeSignalled, 'the station must be in toBeSignalled list'
if station.broker.waitForOperator: if station.broker.waitForOperator:
# signal this station's broker that the resource is available # signal this station's broker that the resource is available
#=========================================================== self.printTrace('router', 'signalling broker of'+' '*50+operator.isAssignedTo().id)
# # testing
# print now(), 'router signalling broker of ', operator.isAssignedTo().id
#===========================================================
station.broker.resourceAvailable.signal(now()) station.broker.resourceAvailable.signal(now())
else: else:
# signal the queue proceeding the station # signal the queue proceeding the station
if station.canAccept()\ if station.canAccept()\
and any(type=='Load' for type in station.multOperationTypeList): and any(type=='Load' for type in station.multOperationTypeList):
#======================================================= self.printTrace('router', 'signalling'+' '*50+operator.isAssignedTo().id)
# # testing
# print now(), 'router signalling ', operator.isAssignedTo().id
#=======================================================
station.loadOperatorAvailable.signal(now()) station.loadOperatorAvailable.signal(now())
# in case the router deals with managed entities # in case the router deals with managed entities
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
else: else:
if station in self.pendingMachines and station in self.toBeSignalled: if station in self.pendingMachines and station in self.toBeSignalled:
# signal this station's broker that the resource is available # signal this station's broker that the resource is available
#=========================================================== self.printTrace('router','signalling broker of'+' '*50+operator.isAssignedTo().id)
# # testing
# print now(), 'router signalling broker of', operator.isAssignedTo().id
#===========================================================
operator.isAssignedTo().broker.resourceAvailable.signal(now()) operator.isAssignedTo().broker.resourceAvailable.signal(now())
elif (not station in self.pendingMachines) or (not station in self.toBeSignalled): elif (not station in self.pendingMachines) or (not station in self.toBeSignalled):
# signal the queue proceeding the station # signal the queue proceeding the station
...@@ -281,10 +258,7 @@ class Router(ObjectInterruption): ...@@ -281,10 +258,7 @@ class Router(ObjectInterruption):
assert operator.candidateEntity.currentStation in G.QueueList, 'the candidateEntity currentStation to receive signal from Router is not a queue' assert operator.candidateEntity.currentStation in G.QueueList, 'the candidateEntity currentStation to receive signal from Router is not a queue'
if operator.candidateEntity.candidateReceiver.canAccept()\ if operator.candidateEntity.candidateReceiver.canAccept()\
and any(type=='Load' for type in operator.candidateEntity.candidateReceiver.multOperationTypeList): and any(type=='Load' for type in operator.candidateEntity.candidateReceiver.multOperationTypeList):
#======================================================= self.printTrace('router','signalling queue'+' '*50+operator.candidateEntity.currentStation.id)
# # testing
# print now(), 'router signalling queue', operator.candidateEntity.currentStation.id
#=======================================================
operator.candidateEntity.currentStation.loadOperatorAvailable.signal(now()) operator.candidateEntity.currentStation.loadOperatorAvailable.signal(now())
#=========================================================================== #===========================================================================
...@@ -314,12 +288,9 @@ class Router(ObjectInterruption): ...@@ -314,12 +288,9 @@ class Router(ObjectInterruption):
break break
# self.pendingMachines=[machine for machine in G.MachineList if machine.broker.waitForOperator] # self.pendingMachines=[machine for machine in G.MachineList if machine.broker.waitForOperator]
self.pendingObjects=self.pendingQueues+self.pendingMachines self.pendingObjects=self.pendingQueues+self.pendingMachines
#======================================================================= self.printTrace('router found pending objects'+'-'*6+'>', [str(object.id) for object in self.pendingObjects])
# # testing self.printTrace('pendingMachines'+'-'*19+'>', [str(object.id) for object in self.pendingMachines])
# print 'router found pending objects', '-'*6,'>', [str(object.id) for object in self.pendingObjects] self.printTrace('pendingQueues'+'-'*21+'>', [str(object.id) for object in self.pendingQueues])
# print 'pendingMachines', '-'*19,'>', [str(object.id) for object in self.pendingMachines]
# print 'pendingQueues', '-'*21,'>', [str(object.id) for object in self.pendingQueues]
#=======================================================================
#=========================================================================== #===========================================================================
# finding the entities that require manager now # finding the entities that require manager now
...@@ -339,10 +310,7 @@ class Router(ObjectInterruption): ...@@ -339,10 +310,7 @@ class Router(ObjectInterruption):
if self.pending: if self.pending:
if self.pending[0].manager: if self.pending[0].manager:
self.managed=True self.managed=True
#======================================================================= self.printTrace('found pending entities'+'-'*12+'>', [str(entity.id) for entity in self.pending if not entity.type=='Part'])
# # testing
# print 'found pending entities', '-'*12,'>', [str(entity.id) for entity in self.pending if not entity.type=='Part']
#=======================================================================
#======================================================================== #========================================================================
# Find candidate Operators # Find candidate Operators
...@@ -422,14 +390,11 @@ class Router(ObjectInterruption): ...@@ -422,14 +390,11 @@ class Router(ObjectInterruption):
self.updateSchedulingRule() self.updateSchedulingRule()
# find the candidateEntities for each operator # find the candidateEntities for each operator
self.findCandidateEntities() self.findCandidateEntities()
#======================================================================= if self.managed:
# # testing self.printTrace('router found candidate operators'+' '*3,[operator.id for operator in self.candidateOperators])
# print 'router found candidate operators' else:
# if self.managed: self.printTrace('router found candidate operators'+' '*3,
# print [operator.id for operator in self.candidateOperators] [(operator.id, [station.id for station in operator.candidateStations]) for operator in self.candidateOperators])
# else:
# print [(operator.id, [station.id for station in operator.candidateStations]) for operator in self.candidateOperators]
#=======================================================================
#=========================================================================== #===========================================================================
# find the candidate entities for each candidateOperator # find the candidate entities for each candidateOperator
...@@ -496,14 +461,10 @@ class Router(ObjectInterruption): ...@@ -496,14 +461,10 @@ class Router(ObjectInterruption):
if operatorsWithOneOption: if operatorsWithOneOption:
self.candidateOperators.sort(key=lambda x: x in operatorsWithOneOption, reverse=True) self.candidateOperators.sort(key=lambda x: x in operatorsWithOneOption, reverse=True)
#======================================================================= if self.managed:
# # testing self.printTrace('candidateEntities for each operator', [(str(operator.id),\
# if self.managed: [str(x.id) for x in operator.candidateEntities])
# print 'router found the candidate entities for each operator' for operator in self.candidateOperators])
# print [(str(operator.id),\
# [str(x.id) for x in operator.candidateEntities])
# for operator in self.candidateOperators]
#=======================================================================
#======================================================================= #=======================================================================
# Sort pendingEntities # Sort pendingEntities
...@@ -522,7 +483,7 @@ class Router(ObjectInterruption): ...@@ -522,7 +483,7 @@ class Router(ObjectInterruption):
self.activeQSorter(criterion=self.schedulingRule,candList=candidateList) self.activeQSorter(criterion=self.schedulingRule,candList=candidateList)
#======================================================================= #=======================================================================
# # testing # # testing
# print 'router sorted pending entities' # self.printTrace('router', ' sorted pending entities')
#======================================================================= #=======================================================================
#======================================================================= #=======================================================================
...@@ -698,14 +659,10 @@ class Router(ObjectInterruption): ...@@ -698,14 +659,10 @@ class Router(ObjectInterruption):
self.candidateOperators.remove(operator) self.candidateOperators.remove(operator)
self.calledOperators.remove(operator) self.calledOperators.remove(operator)
#======================================================================= if self.managed:
# # testing self.printTrace('candidateReceivers for each entity ',[(str(entity.id),\
# if self.managed: str(entity.candidateReceiver.id))
# print 'router found candidate receivers for each entity' for entity in self.pending if entity.candidateReceiver])
# print [(str(entity.id),\
# str(entity.candidateReceiver.id))
# for entity in self.pending if entity.candidateReceiver]
#=======================================================================
# ======================================================================= # =======================================================================
# sorts the Operators of the Queue according to the scheduling rule # sorts the Operators of the Queue according to the scheduling rule
......
...@@ -95,13 +95,13 @@ class Queue(CoreObject): ...@@ -95,13 +95,13 @@ class Queue(CoreObject):
# check if there is WIP and signal receiver # check if there is WIP and signal receiver
self.initialSignalReceiver() self.initialSignalReceiver()
while 1: while 1:
# print self.id, 'will wait for event', now() # self.printTrace(self.id, 'will wait for event')
# wait until the Queue can accept an entity and one predecessor requests it # wait until the Queue can accept an entity and one predecessor requests it
yield waitevent, self, [self.isRequested,self.canDispose, self.loadOperatorAvailable] yield waitevent, self, [self.isRequested,self.canDispose, self.loadOperatorAvailable]
# print now(), self.id, 'just received an event' # self.printTrace(self.id, 'just received an event')
# if the event that activated the thread is isRequested then getEntity # if the event that activated the thread is isRequested then getEntity
if self.isRequested.signalparam: if self.isRequested.signalparam:
# print now(), self.id, 'received a isRequested event from', self.isRequested.signalparam.id # self.printTrace(self.id, 'received a isRequested event from'+self.isRequested.signalparam.id)
# reset the isRequested signal parameter # reset the isRequested signal parameter
self.isRequested.signalparam=None self.isRequested.signalparam=None
self.getEntity() self.getEntity()
...@@ -110,15 +110,15 @@ class Queue(CoreObject): ...@@ -110,15 +110,15 @@ class Queue(CoreObject):
activeObjectQueue[0].startTime=now() activeObjectQueue[0].startTime=now()
# if the queue received an loadOperatorIsAvailable (from Router) with signalparam time # if the queue received an loadOperatorIsAvailable (from Router) with signalparam time
if self.loadOperatorAvailable.signalparam: if self.loadOperatorAvailable.signalparam:
# print now(), self.id, 'received a loadOperatorAvailable event' # self.printTrace(self.id, 'received a loadOperatorAvailable event')
self.loadOperatorAvailable.signalparam=None self.loadOperatorAvailable.signalparam=None
# if the queue received an canDispose with signalparam time, this means that the signals was sent from a MouldAssemblyBuffer # if the queue received an canDispose with signalparam time, this means that the signals was sent from a MouldAssemblyBuffer
if self.canDispose.signalparam: if self.canDispose.signalparam:
# print now(), self.id, 'received a canDispose event' # self.printTrace(self.id, 'received a canDispose event')
self.canDispose.signalparam=None self.canDispose.signalparam=None
# if the event that activated the thread is canDispose then signalReceiver # if the event that activated the thread is canDispose then signalReceiver
if self.haveToDispose(): if self.haveToDispose():
# print now(), self.id, 'will try to signal a receiver from generator' # self.printTrace(self.id, 'will try to signal a receiver from generator')
if self.receiver: if self.receiver:
if not self.receiver.entryIsAssignedTo(): if not self.receiver.entryIsAssignedTo():
self.signalReceiver() self.signalReceiver()
...@@ -171,7 +171,7 @@ class Queue(CoreObject): ...@@ -171,7 +171,7 @@ class Queue(CoreObject):
# TODO: disable that for the mouldAssemblyBuffer # TODO: disable that for the mouldAssemblyBuffer
if not self.__class__.__name__=='MouldAssemblyBuffer': if not self.__class__.__name__=='MouldAssemblyBuffer':
if self.haveToDispose(): if self.haveToDispose():
# print now(), self.id, 'will try to signal a receiver from removeEntity' # self.printTrace(self.id, 'will try to signal a receiver from removeEntity')
self.signalReceiver() self.signalReceiver()
return activeEntity return activeEntity
......
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