new method isInActiveQueue added to coreObject. Machine run() updated to...

new method isInActiveQueue added to coreObject. Machine run() updated to incorporate the operatorRouter object
parent bfb2dd03
......@@ -173,15 +173,15 @@ class CoreObject(Process):
# gets an entity from the giver
# =======================================================================
def getEntity(self):
# 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)
activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue()
# get giver object, its queue, and sort the entities according to this object priorities
giverObject=self.getGiverObject()
giverObject.sortEntities() #sort the Entities of the giver
#according to the scheduling rule if applied
giverObjectQueue=self.getGiverObjectQueue()
# 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)
activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue()
# remove entity from the giver
activeEntity = giverObject.removeEntity(entity=self.identifyEntityToGet())
# variable that holds the last giver; used in case of preemption
......@@ -222,7 +222,7 @@ class CoreObject(Process):
activeEntity.manager.activeCallersList=[]
self.outputTrace(activeEntity.name, "got into "+self.objName)
# # TESTING
# print now(), self.id, 'just received', activeEntity.id
# print now(), activeEntity.id, "got into "+self.id
return activeEntity
# =======================================================================
......@@ -444,3 +444,10 @@ class CoreObject(Process):
# =======================================================================
def endProcessingActions(self):
pass
#===========================================================================
# check if an entity is in the internal Queue of the object
#===========================================================================
def isInActiveQueue(self, entity=None):
activeObjectQueue = self.getActiveObjectQueue()
return any(x==entity for x in activeObjectQueue)
\ No newline at end of file
......@@ -149,13 +149,14 @@ class Machine(CoreObject):
activate(self.broker,self.broker.run())
# if there is no router in G.RouterList
# initialise a new router
if len(G.RouterList)==0:
from Globals import G
if len(G.RoutersList)==0:
self.router=Router()
activate(self.router,self.router.run())
G.RouterList.append(self.router)
G.RoutersList.append(self.router)
# otherwise set the already existing router as the machines Router
else:
self.router=G.RouterList[0]
self.router=G.RoutersList[0]
for operator in self.operatorPool.operators:
operator.coreObjectIds.append(self.id)
operator.coreObjects.append(self)
......@@ -185,7 +186,8 @@ class Machine(CoreObject):
# flag that shows if the station is ready to proceed with the getEntity
# the router must set the flag to false if the station must not proceed with getEntity
# he must also assign the operator to the station that will proceed (operatorAssignedTo)
self.canProceedWithGetEntity=True
self.canProceedWithGetEntity=False
self.inPositionToGet=False
# =======================================================================
# the main process of the machine
......@@ -193,28 +195,23 @@ class Machine(CoreObject):
def run(self):
# execute all through simulation time
while 1:
# wait until the Router has picked the station to proceed with getEntity
while self.canProceedWithGetEntity:
# wait until the machine can accept an entity and one predecessor requests it
# canAcceptAndIsRequested is invoked to check when the machine requested to receive an entity
yield waituntil, self, self.canAcceptAndIsRequested
# TESTING
print self.id, 'will receive?'
# # wait until the Router has checked how many stations are requesting (if)
# # for operators at the same simulation time
# if (self.operatorPool!="None")\
# and any(type=="Load" for type in self.multOperationTypeList):
# self.requestRouter()
# yield waituntil, self, self.router.routerIsSet
# while 1:
# yield waituntil, self, self.canAcceptAndIsRequested
# if self.isReadyToGet():
# break
# # TODO check if the commented below is needed with operators shceduling rules
# else:
# yield hold,self,0
# wait until the machine can accept an entity and one predecessor requests it
# canAcceptAndIsRequested is invoked to check when the machine requested to receive an entity
yield waituntil, self, self.canAcceptAndIsRequested
# if the machine must be operated for the loading then the operators must be picked wisely for every machine
if (self.operatorPool!="None")\
and any(type=="Load" for type in self.multOperationTypeList):
# the machine informs the router that it can receive from a requesting object
self.requestRouter()
# the machine must wait until the router has decided which machine will operated by which operator
yield waituntil, self, self.router.routerIsSet
# # TESTING
# print now(), self.id, 'return from router'
# if the machine is not picked by the router the it should wait again
if not self.canProceedWithGetEntity:
break
# here or in the getEntity (apart from the loadTimeCurrentEntity)
# in case they are placed inside the getEntity then the initialize of
......@@ -400,6 +397,9 @@ class Machine(CoreObject):
except IndexError:
pass
# carry on actions that have to take place when an Entity ends its processing
self.endProcessingActions()
# set the variable that flags an Entity is ready to be disposed
self.waitToDispose=True
......@@ -614,6 +614,7 @@ class Machine(CoreObject):
# removes an entity from the Machine
# =======================================================================
def removeEntity(self, entity=None):
activeObject=self.getActiveObject()
activeEntity=CoreObject.removeEntity(self, entity) # run the default method
activeObject.waitToDispose=False # update the waitToDispose flag
return activeEntity
......@@ -665,6 +666,9 @@ class Machine(CoreObject):
# prepare the machine to be operated
# =======================================================================
def requestRouter(self):
# # TESTING
# print now(), self.id, 'requested router'
self.inPositionToGet=True
self.router.invokeRouter()
# =======================================================================
......
......@@ -93,6 +93,8 @@ class MachineManagedJob(MachineJobShop):
# also updates the giver to the one that is to be taken
# =======================================================================
def canAcceptAndIsRequested(self):
# # TESTING
# print now(), self.id, 'canA$iR'
# get active and giver objects
activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue()
......@@ -155,10 +157,6 @@ class MachineManagedJob(MachineJobShop):
# update entityToGet
self.entityToGet=self.giver.getActiveObjectQueue()[0]
return activeObject.Up and len(activeObjectQueue)<activeObject.capacity and isRequested
# while if the set up is performed before the (automatic) loading of the machine then the availability of the
# operator is requested
# return (activeObject.operatorPool=='None' or activeObject.operatorPool.checkIfResourceIsAvailable())\
# and activeObject.Up and len(activeObjectQueue)<activeObject.capacity and isRequested
# =======================================================================
# to be called by canAcceptAndIsRequested and check for the operator
......
......@@ -69,8 +69,8 @@ class Broker(ObjectInterruption):
# set the available resource as the currentOperator
self.victim.currentOperator=self.victim.operatorPool.findAvailableOperator()
yield request,self,self.victim.operatorPool.getResource(self.victim.currentOperator)
# TESTING
print now(), self.victim.currentOperator.objName, 'started work in ', self.victim.id
# # TESTING
# print now(), self.victim.currentOperator.objName, 'started work in ', self.victim.id
# self.victim.totalTimeWaitingForOperator+=now()-self.timeWaitForOperatorStarted
# clear the timeWaitForOperatorStarted variable
self.timeWaitForOperatorStarted = 0
......
......@@ -72,10 +72,6 @@ class QueueManagedJob(QueueJobShop):
activeObject.receiver=activeObject.next[0]
#sort the internal queue so that the Entities that have an available manager go in the front
activeObject.sortEntities()
# # TESTING
# if self.id=='QEDM':
# if len(activeObjectQueue)>0 and thecaller==activeObject.receiver:
# print ' ',self.id, 'has to dispose'
return len(activeObjectQueue)>0\
and thecaller==activeObject.receiver
......@@ -89,10 +85,6 @@ class QueueManagedJob(QueueJobShop):
self.receiver=object # and update the receiver
#sort the internal queue so that the Entities that have an available manager go in the front
activeObject.sortEntities()
# # TESTING
# if self.id=='QEDM':
# if len(activeObjectQueue)>0 and thecaller==activeObject.receiver:
# print ' ',self.id, 'has to dispose'
#return True if the Queue has Entities and the caller is the receiver
return len(activeObjectQueue)>0 and (thecaller is self.receiver)
......
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