canAcceptAndIsRequested, readLoadTime, assignExitTo, and checkOperator methods now require caller

parent 89541c19
......@@ -219,12 +219,13 @@ class BatchDecomposition(CoreObject):
(thecaller in activeObject.next) and activeObjectQueue[0].type!="Batch" and activeObject.Up
# =======================================================================
# canAcceptAndIsRequested logc
# canAcceptAndIsRequested logic
# =======================================================================
def canAcceptAndIsRequested(self):
def canAcceptAndIsRequested(self,callerObject=None):
# get the active and the giver objects
activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue()
giverObject=self.getGiverObject()
# giverObject=self.getGiverObject()
giverObject=callerObject
assert giverObject, 'there must be a caller for canAcceptAndIsRequested'
return activeObject.Up and len(activeObjectQueue)==0 and giverObject.haveToDispose(activeObject)
......@@ -222,12 +222,14 @@ class BatchReassembly(CoreObject):
# which is of the same batchId as the ones that the assembler currently holds
# (if it holds any), and if doesn't hold any entities of type Batch
# =======================================================================
def canAcceptAndIsRequested(self):
def canAcceptAndIsRequested(self,callerObject=None):
# get the active and the giver objects
activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue()
giverObject=self.getGiverObject()
giverObjectQueue=self.getGiverObjectQueue()
# giverObject=self.getGiverObject()
giverObject=callerObject
assert giverObject, 'there must be a caller for canAcceptAndIsRequested'
giverObjectQueue=giverObject.getActiveObjectQueue()
if (len(activeObjectQueue)==0):
return activeObject.Up and giverObject.haveToDispose(activeObject)
......
......@@ -87,11 +87,13 @@ class Exit(CoreObject):
# checks if the Exit can accept an entity
# and there is an entity waiting for it
# =======================================================================
def canAcceptAndIsRequested(self):
def canAcceptAndIsRequested(self,callerObject=None):
# get the active object and its internal queue
activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue()
giverObject=activeObject.getGiverObject()
# giverObject=activeObject.getGiverObject()
giverObject=callerObject
assert giverObject, 'there must be a caller for canAcceptAndIsRequested'
return giverObject.haveToDispose(self)
# =======================================================================
......
......@@ -80,12 +80,14 @@ class LineClearance(Queue):
and giverObjectQueue[0].type == 'SubBatch'\
and giverObjectQueue[0].batchId == activeObjectQueue[0].batchId
def canAcceptAndIsRequested(self):
def canAcceptAndIsRequested(self,callerObject=None):
# get the active and the giver objects
activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue()
giverObject=self.getGiverObject()
giverObjectQueue = self.getGiverObjectQueue()
# giverObject=self.getGiverObject()
giverObject=callerObject
assert giverObject, 'there must be a caller for canAcceptAndIsRequested'
giverObjectQueue = giverObject.getActiveObjectQueue()
#if we have only one potential giver just check if there is a place available and the potential giver has an entity to dispose
if(len(activeObject.previous)==1):
......
......@@ -224,6 +224,7 @@ class Machine(CoreObject):
while 1:
# waitEvent isRequested /interruptionEnd/loadOperatorAvailable
while 1:
# print now(), self.id, 'will wait for event'
yield waitevent, self, [self.isRequested, self.interruptionEnd, self.loadOperatorAvailable]
# print now(), self.id, 'received an event'
# if the machine can accept an entity and one predecessor requests it continue with receiving the entity
......@@ -646,11 +647,13 @@ class Machine(CoreObject):
# some possible giver waiting for it
# also updates the giver to the one that is to be taken
# =======================================================================
def canAcceptAndIsRequested(self):
def canAcceptAndIsRequested(self,callerObject=None):
# get active and giver objects
activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue()
giverObject=self.getGiverObject()
# giverObject=self.getGiverObject()
giverObject=callerObject
assert giverObject, 'there must be a caller for canAcceptAndIsRequested'
# check if there is a place, the machine is up and the predecessor has an entity to dispose. if the machine has to compete
# for an Operator that loads the entities onto it check if the predecessor if blocked by an other Machine. if not then the machine
# has to block the predecessor giverObject to avoid conflicts with other competing machines
......@@ -668,7 +671,7 @@ class Machine(CoreObject):
if activeObject.operatorPool.checkIfResourceIsAvailable()\
and activeObject.checkIfActive() and len(activeObjectQueue)<activeObject.capacity:
if not giverObject.exitIsAssignedTo():
activeObject.giver.assignExitTo()
giverObject.assignExitTo(activeObject)
elif giverObject.exitIsAssignedTo()!=activeObject:
return False
# if the activeObject is not in operators' activeCallersList
......@@ -686,7 +689,7 @@ class Machine(CoreObject):
if activeObject.checkIfActive() and len(activeObjectQueue)<activeObject.capacity\
and giverObject.haveToDispose(activeObject):
if not giverObject.exitIsAssignedTo():
activeObject.giver.assignExitTo()
giverObject.assignExitTo(activeObject)
elif giverObject.exitIsAssignedTo()!=activeObject:
return False
return True
......
......@@ -262,12 +262,14 @@ class MachineJobShop(Machine):
# extend the default behaviour to check if whether the station
# is in the route of the entity to be received
#===========================================================================
def canAcceptAndIsRequested(self):
def canAcceptAndIsRequested(self,callerObject):
activeObject=self.getActiveObject()
giverObject=activeObject.getGiverObject()
# giverObject=activeObject.getGiverObject()
giverObject=callerObject
assert giverObject, 'there must be a caller for canAcceptAndIsRequested'
if activeObject.isInRoute(giverObject):
if Machine.canAcceptAndIsRequested(self):
activeObject.readLoadTime()
if Machine.canAcceptAndIsRequested(self,giverObject):
activeObject.readLoadTime(giverObject)
return True
return False
......@@ -275,10 +277,12 @@ class MachineJobShop(Machine):
# to be called by canAcceptAndIsRequested if it is to return True.
# the load timeof the Entity must be read
#===========================================================================
def readLoadTime(self):
def readLoadTime(self,callerObject=None):
assert callerObject!=None, 'the caller of readLoadTime cannot be None'
activeObject=self.getActiveObject()
activeObject.giver.sortEntities()
activeEntity=activeObject.giver.getActiveObjectQueue()[0]
thecaller=callerObject
thecaller.sortEntities()
activeEntity=thecaller.getActiveObjectQueue()[0]
loadTime=activeEntity.remainingRoute[0].get('loadTime',{})
activeObject.distType=loadTime.get('distributionType','Fixed')
activeObject.loadTime=float(loadTime.get('mean', 0))
......
......@@ -103,11 +103,13 @@ class MachineManagedJob(MachineJobShop):
# some possible giver waiting for it
# also updates the giver to the one that is to be taken
# =======================================================================
def canAcceptAndIsRequested(self):
def canAcceptAndIsRequested(self,callerObject=None):
# get active and giver objects
activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue()
giverObject=activeObject.getGiverObject()
# giverObject=activeObject.getGiverObject()
giverObject=callerObject
assert giverObject, 'there must be a caller for canAcceptAndIsRequested'
giverObjectQueue=giverObject.getActiveObjectQueue()
# if the multOperationTypeList of the machine contains Load or Setup
if (activeObject.operatorPool!='None' and (any(type=='Load' for type in activeObject.multOperationTypeList)\
......@@ -123,10 +125,10 @@ class MachineManagedJob(MachineJobShop):
# activeObject.operatorPool.receivingObject=activeObject
#===============================================================
if activeObject.checkIfActive() and len(activeObjectQueue)<activeObject.capacity\
and activeObject.checkOperator():
and activeObject.checkOperator(giverObject):
if not giverObject.exitIsAssignedTo():
# print self.id, 'assigning givers exit'
giverObject.assignExitTo()
giverObject.assignExitTo(activeObject)
elif giverObject.exitIsAssignedTo()!=activeObject:
return False
# if the activeObject is not in manager's activeCallersList of the entityToGet
......@@ -138,7 +140,7 @@ class MachineManagedJob(MachineJobShop):
#make the operators List so that it holds only the manager of the current order
activeObject.operatorPool.operators=[giverObjectQueue[0].manager]
# read the load time of the machine
activeObject.readLoadTime()
activeObject.readLoadTime(giverObject)
return True
else:
return False
......@@ -176,7 +178,7 @@ class MachineManagedJob(MachineJobShop):
#make the operators List so that it holds only the manager of the current order
activeObject.operatorPool.operators=[giverObjectQueue[0].manager]
# read the load time of the machine
activeObject.readLoadTime()
activeObject.readLoadTime(giverObject)
return True
else:
return False
......@@ -185,16 +187,18 @@ class MachineManagedJob(MachineJobShop):
# is not assigned to operators
if activeObject.checkIfActive() and len(activeObjectQueue)<activeObject.capacity and giverObject.haveToDispose(activeObject):
# update entityToGet
activeObject.entityToGet=self.giver.getActiveObjectQueue()[0]
activeObject.readLoadTime()
activeObject.entityToGet=giverObject.getActiveObjectQueue()[0]
activeObject.readLoadTime(giverObject)
return activeObject.checkIfActive() and len(activeObjectQueue)<activeObject.capacity and giverObject.haveToDispose(activeObject)
# =======================================================================
# to be called by canAcceptAndIsRequested and check for the operator
# =======================================================================
def checkOperator(self): #, candidateEntity=None):
def checkOperator(self,callerObject=None): #, candidateEntity=None):
assert callerObject!=None, 'checkOperator must have a caller for MachineManagedJob'
activeObject=self.getActiveObject()
giverObject=activeObject.getGiverObject()
# giverObject=activeObject.getGiverObject()
giverObject=callerObject
giverObjectQueue=giverObject.getActiveObjectQueue()
if giverObjectQueue[0].manager:
manager=giverObjectQueue[0].manager
......
......@@ -75,6 +75,7 @@ class Broker(ObjectInterruption):
if self.victim.isOperated()\
and any(type=='Load' or type=='Setup' or type=='Processing'\
for type in self.victim.multOperationTypeList):
# print now(), self.victim.id, 'broker is invoked'
# update the time that the station is waiting for the operator
self.timeWaitForOperatorStarted=now()
# if the resource is not available wait until a rousourceAvailable event
......@@ -252,28 +253,11 @@ class Broker(ObjectInterruption):
# # TESTING
# print now(), self.victim.id, 'broker signalling ', machine.id, 'loadOperatorAvailable2'
#===============================================
# machine.loadOperatorAvailable.signal(now())
machine.loadOperatorAvailable.signal(now())
# print 'machines waitingForLoadOperator',[str(x.id) for x in loadPendingMachines]
# print 'machines waitingForOperator',[str(x.id) for x in candidateMachines]
# # for the candidateMachines
# if loadPendingMachines:
# maxTimeWaiting=0
# receiver=None
# # choose the one that waits the most time and give it the chance to grasp the resource
# # TODO: failures after the end of processing are not considered here
# for machine in loadPendingMachines:
# timeWaiting=now()-machine.timeLastEntityEnded
# if(timeWaiting>maxTimeWaiting or maxTimeWaiting==0):
# maxTimeWaiting=timeWaiting
# receiver=machine
# #===============================================
# # # TESTING
# # print now(), self.victim.id, 'broker signalling', machine.id, 'loadOperatorAvailable'
# #===============================================
# # finally signal the machine to receive the operator
# receiver.loadOperatorAvailable.signal(now())
# for the candidateMachines
if candidateMachines:
......
......@@ -106,11 +106,13 @@ class OrderDecomposition(CoreObject):
# and there is an entity in some possible giver waiting for it
# also updates the giver to the one that is to be taken
# =======================================================================
def canAcceptAndIsRequested(self):
def canAcceptAndIsRequested(self,callerObject=None):
# get active and giver objects
activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue()
giverObject=self.getGiverObject()
# giverObject=self.getGiverObject()
giverObject=callerObject
assert giverObject, 'there must be a caller for canAcceptAndIsRequested'
# if we have only one possible giver just check if there is a place,
# the machine is up and the predecessor has an entity to dispose
# this is done to achieve better (cpu) processing time
......
......@@ -106,7 +106,7 @@ class Queue(CoreObject):
activeObjectQueue[0].startTime=now()
# if the queue received an canDispose with signalparam time, this means that the signals was sent from a MouldAssemblyBuffer
if self.canDispose.signalparam:
# print now(), self.id, 'received a canDispose event from', self.canDispose.signalparam
# print now(), self.id, 'received a canDispose event'
self.canDispose.signalparam=None
# if the event that activated the thread is canDispose then signalReceiver
if self.haveToDispose():
......@@ -173,11 +173,13 @@ class Queue(CoreObject):
# there is an entity in some predecessor waiting for it
# also updates the predecessorIndex to the one that is to be taken
# =======================================================================
def canAcceptAndIsRequested(self):
def canAcceptAndIsRequested(self,callerObject=None):
# get the active and the giver objects
activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue()
giverObject=self.getGiverObject()
# giverObject=self.getGiverObject()
giverObject=callerObject
assert giverObject, 'there must be a caller for canAcceptAndIsRequested'
return len(activeObjectQueue)<activeObject.capacity and giverObject.haveToDispose(activeObject)
......
......@@ -100,11 +100,13 @@ class QueueJobShop(Queue):
# extend the default behaviour to check if whether the station
# is in the route of the entity to be received
#===========================================================================
def canAcceptAndIsRequested(self):
def canAcceptAndIsRequested(self,callerObject=None):
activeObject=self.getActiveObject()
giverObject=activeObject.getGiverObject()
# giverObject=activeObject.getGiverObject()
giverObject=callerObject
assert giverObject, 'there must be a caller for canAcceptAndIsRequested'
if activeObject.isInRoute(giverObject):
return Queue.canAcceptAndIsRequested(self)
return Queue.canAcceptAndIsRequested(self,giverObject)
# =======================================================================
# gets an entity from the predecessor that the predecessor index points to
......
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