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

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