CoreObject getActiveObject() used less to speed up

parent 2f71acc0
...@@ -157,7 +157,6 @@ class CoreObject(Process): ...@@ -157,7 +157,6 @@ class CoreObject(Process):
# and sends an event to initialize the simulation # and sends an event to initialize the simulation
# ======================================================================= # =======================================================================
def initialSignalReceiver(self): def initialSignalReceiver(self):
activeObject=self.getActiveObject()
if self.haveToDispose(): if self.haveToDispose():
self.signalReceiver() self.signalReceiver()
...@@ -168,7 +167,7 @@ class CoreObject(Process): ...@@ -168,7 +167,7 @@ class CoreObject(Process):
def removeEntity(self, entity=None): def removeEntity(self, entity=None):
self.addBlockage() self.addBlockage()
activeObjectQueue=self.getActiveObjectQueue() activeObjectQueue=self.Res.activeQ
activeObjectQueue.remove(entity) #remove the Entity from the queue activeObjectQueue.remove(entity) #remove the Entity from the queue
if self.receiver: if self.receiver:
self.receiver.appendEntity(entity) self.receiver.appendEntity(entity)
...@@ -189,8 +188,7 @@ class CoreObject(Process): ...@@ -189,8 +188,7 @@ class CoreObject(Process):
# this method is created to be overridden by the Assembly class in its getEntity where Frames are loaded # this method is created to be overridden by the Assembly class in its getEntity where Frames are loaded
#=========================================================================== #===========================================================================
def appendEntity(self,entity=None): def appendEntity(self,entity=None):
activeObject=self.getActiveObject() activeObjectQueue=self.Res.activeQ
activeObjectQueue=self.getActiveObjectQueue()
activeObjectQueue.append(entity) activeObjectQueue.append(entity)
# ======================================================================= # =======================================================================
...@@ -199,7 +197,7 @@ class CoreObject(Process): ...@@ -199,7 +197,7 @@ class CoreObject(Process):
# getEntity gives it to removeEntity as argument # getEntity gives it to removeEntity as argument
# ======================================================================= # =======================================================================
def identifyEntityToGet(self): def identifyEntityToGet(self):
giverObjectQueue=self.giver.getActiveObjectQueue() giverObjectQueue=self.getGiverObjectQueue()
return giverObjectQueue[0] return giverObjectQueue[0]
# ======================================================================= # =======================================================================
...@@ -220,19 +218,19 @@ class CoreObject(Process): ...@@ -220,19 +218,19 @@ class CoreObject(Process):
def getEntity(self): def getEntity(self):
# get active object and its queue, as well as the active (to be) entity # get active object and its queue, as well as the active (to be) entity
#(after the sorting of the entities in the queue of the giver object) #(after the sorting of the entities in the queue of the giver object)
activeObject=self.getActiveObject() # activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue() activeObjectQueue=self.Res.activeQ
# get giver object, its queue, and sort the entities according to this object priorities # get giver object, its queue, and sort the entities according to this object priorities
giverObject=self.getGiverObject() giverObject=self.giver
giverObject.sortEntities() #sort the Entities of the giver giverObject.sortEntities() #sort the Entities of the giver
#according to the scheduling rule if applied #according to the scheduling rule if applied
giverObjectQueue=self.getGiverObjectQueue() giverObjectQueue=giverObject.Res.activeQ
# if the giverObject is blocked then unBlock it # if the giverObject is blocked then unBlock it
if giverObject.exitIsAssignedTo(): if giverObject.exitIsAssignedTo():
giverObject.unAssignExit() giverObject.unAssignExit()
# if the activeObject entry is blocked then unBlock it # if the activeObject entry is blocked then unBlock it
if activeObject.entryIsAssignedTo(): if self.entryIsAssignedTo():
activeObject.unAssignEntry() self.unAssignEntry()
# remove entity from the giver # remove entity from the giver
activeEntity = giverObject.removeEntity(entity=self.identifyEntityToGet()) activeEntity = giverObject.removeEntity(entity=self.identifyEntityToGet())
...@@ -244,16 +242,16 @@ class CoreObject(Process): ...@@ -244,16 +242,16 @@ class CoreObject(Process):
#append the time to schedule so that it can be read in the result #append the time to schedule so that it can be read in the result
#remember that every entity has it's schedule which is supposed to be updated every time #remember that every entity has it's schedule which is supposed to be updated every time
# he entity enters a new object # he entity enters a new object
activeEntity.schedule.append([activeObject,now()]) activeEntity.schedule.append([self,now()])
#update variables #update variables
activeEntity.currentStation=self activeEntity.currentStation=self
self.timeLastEntityEntered=now() self.timeLastEntityEntered=now()
self.nameLastEntityEntered=activeEntity.name # this holds the name of the last entity that got into Machine self.nameLastEntityEntered=activeEntity.name # this holds the name of the last entity that got into Machine
self.downTimeProcessingCurrentEntity=0 self.downTimeProcessingCurrentEntity=0
# update the next list of the object # update the next list of the object
activeObject.updateNext(activeEntity) self.updateNext(activeEntity)
self.outputTrace(activeEntity.name, "got into "+self.objName) self.outputTrace(activeEntity.name, "got into "+self.objName)
self.printTrace(activeEntity.name, enter=self.id) # self.printTrace(activeEntity.name, enter=self.id)
return activeEntity return activeEntity
#=========================================================================== #===========================================================================
...@@ -267,8 +265,7 @@ class CoreObject(Process): ...@@ -267,8 +265,7 @@ class CoreObject(Process):
# and if preemption is required # and if preemption is required
#=========================================================================== #===========================================================================
def preemptReceiver(self): def preemptReceiver(self):
activeObject=self.getActiveObject() activeObjectQueue=self.Res.activeQ
activeObjectQueue=self.getActiveObjectQueue()
# find a critical order if any # find a critical order if any
critical=False critical=False
...@@ -279,7 +276,7 @@ class CoreObject(Process): ...@@ -279,7 +276,7 @@ class CoreObject(Process):
break break
if critical: if critical:
# pick a receiver # pick a receiver
receiver=next(object for object in activeObject.next if object.isPreemptive and object.checkIfActive()) receiver=next(object for object in self.next if object.isPreemptive and object.checkIfActive())
# if there is any receiver that can be preempted check if it is operated # if there is any receiver that can be preempted check if it is operated
if receiver: if receiver:
receiverOperated=False # local variable to inform if the receiver is operated for Loading receiverOperated=False # local variable to inform if the receiver is operated for Loading
...@@ -299,18 +296,18 @@ class CoreObject(Process): ...@@ -299,18 +296,18 @@ class CoreObject(Process):
# if the obtained Entity is critical and the receiver is preemptive and not operated # if the obtained Entity is critical and the receiver is preemptive and not operated
# in the case that the receiver is operated the preemption is performed by the operators # in the case that the receiver is operated the preemption is performed by the operators
# if the receiver is not Up then no preemption will be performed # if the receiver is not Up then no preemption will be performed
if not receiverOperated and len(receiver.getActiveObjectQueue())>0: if not receiverOperated and len(receiver.Res.activeQ)>0:
#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 receiver.getActiveObjectQueue()[0].isCritical: if not receiver.Res.activeQ[0].isCritical:
receiver.shouldPreempt=True receiver.shouldPreempt=True
self.printTrace(self.id, preempt=receiver.id) # self.printTrace(self.id, preempt=receiver.id)
receiver.preempt() receiver.preempt()
receiver.timeLastEntityEnded=now() #required to count blockage correctly in the preemptied station receiver.timeLastEntityEnded=now() #required to count blockage correctly in the preemptied station
# sort so that the critical entity is placed in front # sort so that the critical entity is placed in front
activeObjectQueue.sort(key=lambda x: x==activeEntity, reverse=True) activeObjectQueue.sort(key=lambda x: x==activeEntity, reverse=True)
# if there is a critical entity and the possible receivers are operated then signal the Router # if there is a critical entity and the possible receivers are operated then signal the Router
elif receiverOperated: elif receiverOperated:
activeObject.signalRouter(receiver) self.signalRouter(receiver)
activeObjectQueue.sort(key=lambda x: x==activeEntity, reverse=True) activeObjectQueue.sort(key=lambda x: x==activeEntity, reverse=True)
# update wipStatList # update wipStatList
if self.gatherWipStat: if self.gatherWipStat:
...@@ -341,11 +338,10 @@ class CoreObject(Process): ...@@ -341,11 +338,10 @@ 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):
activeObject=self.getActiveObject() possibleReceivers=self.findReceiversFor(self)
possibleReceivers=self.findReceiversFor(activeObject)
if possibleReceivers: if possibleReceivers:
receiver=activeObject.selectReceiver(possibleReceivers) receiver=self.selectReceiver(possibleReceivers)
receiversGiver=activeObject receiversGiver=self
# perform the checks that canAcceptAndIsRequested used to perform and update activeCallersList or assignExit and operatorPool # perform the checks that canAcceptAndIsRequested used to perform and update activeCallersList or assignExit and operatorPool
while not receiver.canAcceptAndIsRequested(receiversGiver): while not receiver.canAcceptAndIsRequested(receiversGiver):
possibleReceivers.remove(receiver) possibleReceivers.remove(receiver)
...@@ -355,20 +351,20 @@ class CoreObject(Process): ...@@ -355,20 +351,20 @@ class CoreObject(Process):
# if no receiver can accept then try to preempt a receive if the stations holds a critical order # if no receiver can accept then try to preempt a receive if the stations holds a critical order
self.preemptReceiver() self.preemptReceiver()
return False return False
receiver=activeObject.selectReceiver(possibleReceivers) receiver=self.selectReceiver(possibleReceivers)
receiversGiver=activeObject receiversGiver=self
# sorting the entities of the object for the receiver # sorting the entities of the object for the receiver
activeObject.sortEntitiesForReceiver(receiver) self.sortEntitiesForReceiver(receiver)
# signalling the Router if the receiver is operated and not assigned an operator # signalling the Router if the receiver is operated and not assigned an operator
if activeObject.signalRouter(receiver): if self.signalRouter(receiver):
return False return False
activeObject.receiver=receiver self.receiver=receiver
activeObject.receiver.giver=activeObject self.receiver.giver=self
self.printTrace(self.id, signalReceiver=self.receiver.id) # self.printTrace(self.id, signalReceiver=self.receiver.id)
# assign the entry of the receiver # assign the entry of the receiver
activeObject.receiver.assignEntryTo() self.receiver.assignEntryTo()
activeObject.receiver.isRequested.signal(activeObject) self.receiver.isRequested.signal(self)
return True return True
# if no receiver can accept then try to preempt a receive if the stations holds a critical order # if no receiver can accept then try to preempt a receive if the stations holds a critical order
self.preemptReceiver() self.preemptReceiver()
...@@ -398,7 +394,7 @@ class CoreObject(Process): ...@@ -398,7 +394,7 @@ class CoreObject(Process):
# if an operator is not assigned to the receiver then do not signal the receiver but the Router # if an operator is not assigned to the receiver then do not signal the receiver but the Router
try: try:
if not receiver.assignedOperator or\ if not receiver.assignedOperator or\
(receiver.isPreemptive and len(receiver.getActiveObjectQueue())>0): (receiver.isPreemptive and len(receiver.Res.activeQ)>0):
if receiver.isLoadRequested(): if receiver.isLoadRequested():
from Globals import G from Globals import G
if not G.Router.invoked: if not G.Router.invoked:
...@@ -444,22 +440,21 @@ class CoreObject(Process): ...@@ -444,22 +440,21 @@ 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):
activeObject=self.getActiveObject() possibleGivers=self.findGiversFor(self)
possibleGivers=self.findGiversFor(activeObject)
if possibleGivers: if possibleGivers:
giver=activeObject.selectGiver(possibleGivers) giver=self.selectGiver(possibleGivers)
giversReceiver=activeObject giversReceiver=self
# perform the checks that canAcceptAndIsRequested used to perform and update activeCallersList or assignExit and operatorPool # perform the checks that canAcceptAndIsRequested used to perform and update activeCallersList or assignExit and operatorPool
while not activeObject.canAcceptAndIsRequested(giver): while not self.canAcceptAndIsRequested(giver):
possibleGivers.remove(giver) possibleGivers.remove(giver)
if not possibleGivers: if not possibleGivers:
return False return False
giver=activeObject.selectGiver(possibleGivers) giver=self.selectGiver(possibleGivers)
giversReceiver=activeObject giversReceiver=self
activeObject.giver=giver self.giver=giver
activeObject.giver.receiver=activeObject self.giver.receiver=self
self.printTrace(self.id, signalGiver=self.giver.id) # self.printTrace(self.id, signalGiver=self.giver.id)
activeObject.giver.canDispose.signal(activeObject) self.giver.canDispose.signal(self)
return True return True
return False return False
...@@ -554,7 +549,7 @@ class CoreObject(Process): ...@@ -554,7 +549,7 @@ class CoreObject(Process):
# checks if the Object can dispose an entity to the following object # checks if the Object can dispose an entity to the following object
# ======================================================================= # =======================================================================
def haveToDispose(self, callerObject=None): def haveToDispose(self, callerObject=None):
activeObjectQueue=self.getActiveObjectQueue() activeObjectQueue=self.Res.activeQ
return len(activeObjectQueue)>0 return len(activeObjectQueue)>0
# ======================================================================= # =======================================================================
...@@ -598,7 +593,7 @@ class CoreObject(Process): ...@@ -598,7 +593,7 @@ class CoreObject(Process):
# get the giver object queue in a getEntity transaction. # get the giver object queue in a getEntity transaction.
# ======================================================================= # =======================================================================
def getGiverObjectQueue(self): def getGiverObjectQueue(self):
return self.getGiverObject().getActiveObjectQueue() return self.giver.Res.activeQ
# ======================================================================= # =======================================================================
# get the receiver object in a removeEntity transaction. # get the receiver object in a removeEntity transaction.
...@@ -610,7 +605,7 @@ class CoreObject(Process): ...@@ -610,7 +605,7 @@ class CoreObject(Process):
# get the receiver object queue in a removeEntity transaction. # get the receiver object queue in a removeEntity transaction.
# ======================================================================= # =======================================================================
def getReceiverObjectQueue(self): def getReceiverObjectQueue(self):
return self.getReceiverObject().getActiveObjectQueue() return self.receiver.Res.activeQ
# ======================================================================= # =======================================================================
# calculates the processing time # calculates the processing time
...@@ -691,5 +686,5 @@ class CoreObject(Process): ...@@ -691,5 +686,5 @@ class CoreObject(Process):
# check if an entity is in the internal Queue of the object # check if an entity is in the internal Queue of the object
#=========================================================================== #===========================================================================
def isInActiveQueue(self, entity=None): def isInActiveQueue(self, entity=None):
activeObjectQueue = self.getActiveObjectQueue() activeObjectQueue = self.Res.activeQ
return any(x==entity for x in activeObjectQueue) return any(x==entity for x in activeObjectQueue)
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