updateNext() and preemptReceiver() added to CoreObject

parent f9071603
...@@ -229,44 +229,64 @@ class CoreObject(Process): ...@@ -229,44 +229,64 @@ class CoreObject(Process):
# #get the entity from the previous object and put it in front of the activeQ # #get the entity from the previous object and put it in front of the activeQ
# activeObjectQueue.append(activeEntity) # activeObjectQueue.append(activeEntity)
#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([activeObject,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) activeObject.updateNext(activeEntity)
self.outputTrace(activeEntity.name, "got into "+self.objName)
# local variable to inform if the receiver is operated for Loading self.printTrace(activeEntity.name, "got into "+self.id)
receiverOperated=False return activeEntity
# perform preemption when required
# if the object is not Exit #===========================================================================
# TODO this has to be performed after updating the next list # updates the next list of the object
# TODO: create a method that should check if preemption should be performed #===========================================================================
# this should be done after the update of the next list def updateNext(self, entity=None):
if activeObject.receiver: pass
# if the receiver has an operatorPool and its operationType is Load
try: #===========================================================================
if activeObject.receiver.operatorPool\ # check whether there is a critical entity to be disposed
and (activeObject.receiver.type=='MachineJobShop'\ # and if preemption is required
or activeObject.receiver.type=='MachineManagedJob'): #===========================================================================
# and the operationType list contains Load, the receiver is operated def preemptReceiver(self):
if (activeObject.receiver.operatorPool!="None")\ self.printTrace(self.id, 'trying to preempt a receiver')
and any(type=="Load" for type in activeObject.receiver.multOperationTypeList): activeObject=self.getActiveObject()
receiverOperated=True activeObjectQueue=self.getActiveObjectQueue()
except:
pass # find a critical order if any
critical=False
for entity in activeObjectQueue:
if entity.isCritical:
activeEntity=entity
critical=True
break
if critical:
# pick a receiver
receiver=next(object for object in activeObject.next if object.isPreemptive and object.checkIfActive())
# if there is any receiver that can be preempted check if it is operated
if receiver:
receiverOperated=False # local variable to inform if the receiver is operated for Loading
try:
# TODO: implement preemption for simple machines
if receiver.operatorPool\
and (type(receiver) is MachineJobShop\
or type(receiver) is MachineManagedJob):
# and the operationType list contains Load, the receiver is operated
if (receiver.operatorPool!="None")\
and any(type=="Load" for type in receiver.multOperationTypeList):
receiverOperated=True
except:
pass
# 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 activeEntity.isCritical and activeObject.receiver.isPreemptive and activeObject.receiver.Up and not receiverOperated: if not receiverOperated:
#if the receiver is not empty #if the receiver is not empty
if len(self.receiver.getActiveObjectQueue())>0: if len(self.receiver.getActiveObjectQueue())>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
...@@ -275,18 +295,11 @@ class CoreObject(Process): ...@@ -275,18 +295,11 @@ class CoreObject(Process):
self.printTrace(self.id, 'preempting receiver'+self.receiver.id+'.. '*6) self.printTrace(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
self.outputTrace(activeEntity.name, "got into "+self.objName) # TODO: sort so that the critical entity is placed in front
self.printTrace(activeEntity.name, "got into "+self.id) activeObjectQueue.sort(key=lambda x: x==activeEntity, reverse=True)
# update wipStatList # update wipStatList
if self.gatherWipStat: if self.gatherWipStat:
self.wipStatList.append([now(), len(activeObjectQueue)]) self.wipStatList.append([now(), len(activeObjectQueue)])
return activeEntity
#===========================================================================
# updates the next list of the object
#===========================================================================
def updateNext(self, entity=None):
pass
#=========================================================================== #===========================================================================
# find possible receivers # find possible receivers
...@@ -302,7 +315,7 @@ class CoreObject(Process): ...@@ -302,7 +315,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):
# self.printTrace(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:
...@@ -314,6 +327,8 @@ class CoreObject(Process): ...@@ -314,6 +327,8 @@ class CoreObject(Process):
if not possibleReceivers: if not possibleReceivers:
receiversGiver=None receiversGiver=None
receiver=None receiver=None
# if no receiver can accept then try to preempt a receive if the stations holds a critical order
self.preemptReceiver()
return False return False
receiver=activeObject.selectReceiver(possibleReceivers) receiver=activeObject.selectReceiver(possibleReceivers)
receiversGiver=activeObject receiversGiver=activeObject
...@@ -330,6 +345,8 @@ class CoreObject(Process): ...@@ -330,6 +345,8 @@ class CoreObject(Process):
activeObject.receiver.assignEntryTo() activeObject.receiver.assignEntryTo()
activeObject.receiver.isRequested.signal(activeObject) activeObject.receiver.isRequested.signal(activeObject)
return True return True
# if no receiver can accept then try to preempt a receive if the stations holds a critical order
self.preemptReceiver()
return False return False
# ======================================================================= # =======================================================================
......
...@@ -113,10 +113,7 @@ class QueueManagedJob(QueueJobShop): ...@@ -113,10 +113,7 @@ class QueueManagedJob(QueueJobShop):
if receiver.identifyEntityToGet().manager.isAssignedTo()!=receiver: if receiver.identifyEntityToGet().manager.isAssignedTo()!=receiver:
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
......
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