Exit object has its own haveToDispose which always returns False. Other minor...

Exit object has its own haveToDispose which always returns False. Other minor corrections to Machines and OperatedPoolBroker
parent 363fd41b
...@@ -108,8 +108,14 @@ class Exit(CoreObject): ...@@ -108,8 +108,14 @@ class Exit(CoreObject):
self.totalNumberOfUnitsExited+=activeEntity.numberOfUnits # add the number of units that xited self.totalNumberOfUnitsExited+=activeEntity.numberOfUnits # add the number of units that xited
self.totalTaktTime+=now()-self.timeLastEntityLeft # add the takt time self.totalTaktTime+=now()-self.timeLastEntityLeft # add the takt time
self.timeLastEntityLeft=now() # update the time that the last entity left from the Exit self.timeLastEntityLeft=now() # update the time that the last entity left from the Exit
return activeEntity return activeEntity
#===========================================================================
# haveToDispose of an exit must always return False
#===========================================================================
def haveToDispose(self, callerObject=None):
return False
# ======================================================================= # =======================================================================
# actions to be taken after the simulation ends # actions to be taken after the simulation ends
# ======================================================================= # =======================================================================
......
...@@ -653,8 +653,7 @@ class Machine(CoreObject): ...@@ -653,8 +653,7 @@ class Machine(CoreObject):
# 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
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))):
or any(type=='Setup' for type in activeObject.multOperationTypeList))):
if giverObject.haveToDispose(activeObject): if giverObject.haveToDispose(activeObject):
#=============================================================== #===============================================================
# # TODO: check whether this entity is the one to be hand in # # TODO: check whether this entity is the one to be hand in
...@@ -718,6 +717,7 @@ class Machine(CoreObject): ...@@ -718,6 +717,7 @@ class Machine(CoreObject):
activeObject.waitToDispose=False # update the waitToDispose flag activeObject.waitToDispose=False # update the waitToDispose flag
# if the Machine canAccept then signal a giver # if the Machine canAccept then signal a giver
if activeObject.canAccept(): if activeObject.canAccept():
# print self.id, now(), 'will try signalling a giver from removeEntity'
activeObject.signalGiver() activeObject.signalGiver()
# if the Machine is operated then signal Broker that the internal queue is now empty # if the Machine is operated then signal Broker that the internal queue is now empty
if activeObject.currentOperator: if activeObject.currentOperator:
......
...@@ -164,8 +164,7 @@ class MachineJobShop(Machine): ...@@ -164,8 +164,7 @@ class MachineJobShop(Machine):
thecaller=callerObject thecaller=callerObject
#return according to the state of the Queue #return according to the state of the Queue
# also check if (if the machine is to be operated) there are available operators # also check if (if the machine is to be operated) there are available operators
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))):
or any(type=='Setup' for type in activeObject.multOperationTypeList))):
return activeObject.operatorPool.checkIfResourceIsAvailable()\ return activeObject.operatorPool.checkIfResourceIsAvailable()\
and len(activeObject.getActiveObjectQueue())<activeObject.capacity\ and len(activeObject.getActiveObjectQueue())<activeObject.capacity\
and activeObject.checkIfMachineIsUp()\ and activeObject.checkIfMachineIsUp()\
......
...@@ -48,6 +48,8 @@ class MachineManagedJob(MachineJobShop): ...@@ -48,6 +48,8 @@ class MachineManagedJob(MachineJobShop):
id = self.id+'_OP' id = self.id+'_OP'
name=self.objName+'_operatorPool' name=self.objName+'_operatorPool'
self.operatorPool=OperatorPool(id, name, operatorsList=[]) self.operatorPool=OperatorPool(id, name, operatorsList=[])
from Globals import G
G.OperatorPoolsList.append(self.operatorPool)
self.operatorPool.initialize() self.operatorPool.initialize()
self.operatorPool.operators=[] self.operatorPool.operators=[]
#create a Broker #create a Broker
...@@ -121,9 +123,11 @@ class MachineManagedJob(MachineJobShop): ...@@ -121,9 +123,11 @@ 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():
and not giverObject.exitIsAssignedTo(): if not giverObject.exitIsAssignedTo():
giverObject.assignExitTo() giverObject.assignExitTo()
elif giverObject.exitIsAssignedTo()!=activeObject:
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
if activeObject not in giverObjectQueue[0].manager.activeCallersList: if activeObject not in giverObjectQueue[0].manager.activeCallersList:
# append it to the activeCallerList of the manager of the entity to be received # append it to the activeCallerList of the manager of the entity to be received
......
...@@ -51,6 +51,7 @@ class Broker(ObjectInterruption): ...@@ -51,6 +51,7 @@ class Broker(ObjectInterruption):
self.brokerIsCalled=SimEvent('brokerIsCalled') self.brokerIsCalled=SimEvent('brokerIsCalled')
self.victimQueueIsEmpty=SimEvent('victimQueueIsEmpty') self.victimQueueIsEmpty=SimEvent('victimQueueIsEmpty')
self.resourceAvailable=SimEvent('resourceAvailable') self.resourceAvailable=SimEvent('resourceAvailable')
self.waitForOperator=False
#=========================================================================== #===========================================================================
# the initialize method # the initialize method
...@@ -60,6 +61,7 @@ class Broker(ObjectInterruption): ...@@ -60,6 +61,7 @@ class Broker(ObjectInterruption):
self.timeLastOperationEnded=0 self.timeLastOperationEnded=0
self.timeOperationStarted=0 self.timeOperationStarted=0
self.timeWaitForOperatorStarted=0 self.timeWaitForOperatorStarted=0
self.waitForOperator=False
# ======================================================================= # =======================================================================
# the run method # the run method
...@@ -74,11 +76,25 @@ class Broker(ObjectInterruption): ...@@ -74,11 +76,25 @@ class Broker(ObjectInterruption):
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):
# 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()
# TODO: cannot wait till the operatorPool has available resources. # if the resource is not available wait until a rousourceAvailable event
# They are supposed to be available for the Broker to be called
if not self.victim.operatorPool.checkIfResourceIsAvailable(): if not self.victim.operatorPool.checkIfResourceIsAvailable():
self.waitForOperator=True
print now(), self.victim.id, 'broker waits till resource is available'
yield waitevent, self, self.resourceAvailable yield waitevent, self, self.resourceAvailable
self.waitForOperator=False
# print self.victim.id, 'received resourceAvailable event'
# if there are machines waiting for the same resources (broker.waitForOperator==True) check if they wait for longer
# and if yes then wait also for the same event
else:
from Globals import G
for machine in [station for station in G.MachineList if station.operatorPool is self.victim.operatorPool]:
if machine.broker.waitForOperator:
self.waitForOperator=True
print now(), self.victim.id, 'broker waits till resource is available'
yield waitevent, self, self.resourceAvailable
self.waitForOperator=False
# print self.victim.id, 'received resourceAvailable event'
assert self.victim.operatorPool.checkIfResourceIsAvailable(), 'there is no available operator to request' assert self.victim.operatorPool.checkIfResourceIsAvailable(), 'there is no available operator to request'
# set the available resource as the currentOperator # set the available resource as the currentOperator
self.victim.currentOperator=self.victim.operatorPool.findAvailableOperator() self.victim.currentOperator=self.victim.operatorPool.findAvailableOperator()
...@@ -115,22 +131,49 @@ class Broker(ObjectInterruption): ...@@ -115,22 +131,49 @@ class Broker(ObjectInterruption):
# but now must have the option to proceed # but now must have the option to proceed
from Globals import G from Globals import G
candidateMachines=[] candidateMachines=[]
pendingMachines=[] loadPendingMachines=[]
# print ' have to signal machines that are waiting for operator', self.victim.id, 'broker'
# run through the operatorPools # run through the operatorPools
# TODO: MachineManagedJob operatorPool is not in the global OperatorPoolsList
for operatorpool in G.OperatorPoolsList: for operatorpool in G.OperatorPoolsList:
# print operatorpool.id
# and find the machines the share the currentOperator with the Broker.victim # and find the machines the share the currentOperator with the Broker.victim
# TODO: find the machineManagedJobs.entityToGet.managerers and search there
if self.victim.currentOperator in operatorpool.operators: if self.victim.currentOperator in operatorpool.operators:
# print ' current operator in other operatorPools', operatorpool.id
# print ' ', [str(x.id) for x in operatorpool.coreObjects]
for machine in operatorpool.coreObjects: for machine in operatorpool.coreObjects:
# if the machine waits to get an operator add it to the candidateMachines local list # if the machine waits to get an operator add it to the candidateMachines local list
if machine.broker.timeWaitForOperatorStarted: if machine.broker.waitForOperator:
candidateMachines.append(machine) candidateMachines.append(machine)
# cause an loadOperatorAvailable event if any of this machines can accept and has Load operation type defined # cause an loadOperatorAvailable event if any of this machines can accept and has Load operation type defined
if machine.canAccept() and any(type=='Load' for type in machine.multOperationTypeList): if machine.canAccept() and any(type=='Load' for type in machine.multOperationTypeList):
loadPendingMachines.append(machine)
#=============================================== #===============================================
# # TESTING # # TESTING
# print now(), self.victim.id, 'broker signalling', machine.id, 'loadOperatorAvailable' # print now(), self.victim.id, 'broker signalling', machine.id, 'loadOperatorAvailable'
#=============================================== #===============================================
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 # for the candidateMachines
if candidateMachines: if candidateMachines:
maxTimeWaiting=0 maxTimeWaiting=0
...@@ -150,7 +193,7 @@ class Broker(ObjectInterruption): ...@@ -150,7 +193,7 @@ class Broker(ObjectInterruption):
#=============================================================== #===============================================================
# # TESTING # # TESTING
# print now(), self.victim.currentOperator.objName, 'released', self.victim.id print now(), self.victim.currentOperator.objName, 'released', self.victim.id
#=============================================================== #===============================================================
# the victim current operator must be cleared after the operator is released # the victim current operator must be cleared after the operator is released
self.timeLastOperationEnded = now() self.timeLastOperationEnded = now()
......
...@@ -90,9 +90,11 @@ class Queue(CoreObject): ...@@ -90,9 +90,11 @@ class Queue(CoreObject):
activeObjectQueue=self.getActiveObjectQueue() activeObjectQueue=self.getActiveObjectQueue()
# check if there is WIP and signal receiver # check if there is WIP and signal receiver
self.initialSignalReceiver() self.initialSignalReceiver()
while 1: while 1:
# print self.id, 'will wait for event', now()
# wait until the Queue can accept an entity and one predecessor requests it # wait until the Queue can accept an entity and one predecessor requests it
yield waitevent, self, [self.isRequested,self.canDispose] yield waitevent, self, [self.isRequested,self.canDispose]
# print now(), self.id, 'just received an event'
# if the event that activated the thread is isRequested then getEntity # if the event that activated the thread is isRequested then getEntity
if self.isRequested.signalparam: if self.isRequested.signalparam:
# reset the isRequested signal parameter # reset the isRequested signal parameter
...@@ -102,7 +104,7 @@ class Queue(CoreObject): ...@@ -102,7 +104,7 @@ class Queue(CoreObject):
if self.isDummy: if self.isDummy:
activeObjectQueue[0].startTime=now() activeObjectQueue[0].startTime=now()
# 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 from', self.canDispose.signalparam.id
# 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():
# print now(), self.id, 'will try to signal a receiver from generator' # print now(), self.id, 'will try to signal a receiver from generator'
......
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