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
......@@ -110,6 +110,12 @@ class Exit(CoreObject):
self.timeLastEntityLeft=now() # update the time that the last entity left from the Exit
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
# =======================================================================
......
......@@ -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
# 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
if (activeObject.operatorPool!='None' and (any(type=='Load' for type in activeObject.multOperationTypeList)\
or any(type=='Setup' for type in activeObject.multOperationTypeList))):
if (activeObject.operatorPool!='None' and (any(type=='Load' for type in activeObject.multOperationTypeList))):
if giverObject.haveToDispose(activeObject):
#===============================================================
# # TODO: check whether this entity is the one to be hand in
......@@ -718,6 +717,7 @@ class Machine(CoreObject):
activeObject.waitToDispose=False # update the waitToDispose flag
# if the Machine canAccept then signal a giver
if activeObject.canAccept():
# print self.id, now(), 'will try signalling a giver from removeEntity'
activeObject.signalGiver()
# if the Machine is operated then signal Broker that the internal queue is now empty
if activeObject.currentOperator:
......
......@@ -164,8 +164,7 @@ class MachineJobShop(Machine):
thecaller=callerObject
#return according to the state of the Queue
# 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)\
or any(type=='Setup' for type in activeObject.multOperationTypeList))):
if (activeObject.operatorPool!='None' and (any(type=='Load' for type in activeObject.multOperationTypeList))):
return activeObject.operatorPool.checkIfResourceIsAvailable()\
and len(activeObject.getActiveObjectQueue())<activeObject.capacity\
and activeObject.checkIfMachineIsUp()\
......
......@@ -48,6 +48,8 @@ class MachineManagedJob(MachineJobShop):
id = self.id+'_OP'
name=self.objName+'_operatorPool'
self.operatorPool=OperatorPool(id, name, operatorsList=[])
from Globals import G
G.OperatorPoolsList.append(self.operatorPool)
self.operatorPool.initialize()
self.operatorPool.operators=[]
#create a Broker
......@@ -121,9 +123,11 @@ class MachineManagedJob(MachineJobShop):
# activeObject.operatorPool.receivingObject=activeObject
#===============================================================
if activeObject.checkIfActive() and len(activeObjectQueue)<activeObject.capacity\
and activeObject.checkOperator()\
and not giverObject.exitIsAssignedTo():
and activeObject.checkOperator():
if not giverObject.exitIsAssignedTo():
giverObject.assignExitTo()
elif giverObject.exitIsAssignedTo()!=activeObject:
return False
# if the activeObject is not in manager's activeCallersList of the entityToGet
if activeObject not in giverObjectQueue[0].manager.activeCallersList:
# append it to the activeCallerList of the manager of the entity to be received
......
......@@ -51,6 +51,7 @@ class Broker(ObjectInterruption):
self.brokerIsCalled=SimEvent('brokerIsCalled')
self.victimQueueIsEmpty=SimEvent('victimQueueIsEmpty')
self.resourceAvailable=SimEvent('resourceAvailable')
self.waitForOperator=False
#===========================================================================
# the initialize method
......@@ -60,6 +61,7 @@ class Broker(ObjectInterruption):
self.timeLastOperationEnded=0
self.timeOperationStarted=0
self.timeWaitForOperatorStarted=0
self.waitForOperator=False
# =======================================================================
# the run method
......@@ -75,10 +77,24 @@ class Broker(ObjectInterruption):
for type in self.victim.multOperationTypeList):
# update the time that the station is waiting for the operator
self.timeWaitForOperatorStarted=now()
# TODO: cannot wait till the operatorPool has available resources.
# They are supposed to be available for the Broker to be called
# if the resource is not available wait until a rousourceAvailable event
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
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'
# set the available resource as the currentOperator
self.victim.currentOperator=self.victim.operatorPool.findAvailableOperator()
......@@ -115,22 +131,49 @@ class Broker(ObjectInterruption):
# but now must have the option to proceed
from Globals import G
candidateMachines=[]
pendingMachines=[]
loadPendingMachines=[]
# print ' have to signal machines that are waiting for operator', self.victim.id, 'broker'
# run through the operatorPools
# TODO: MachineManagedJob operatorPool is not in the global OperatorPoolsList
for operatorpool in G.OperatorPoolsList:
# print operatorpool.id
# 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:
# print ' current operator in other operatorPools', operatorpool.id
# print ' ', [str(x.id) for x in operatorpool.coreObjects]
for machine in operatorpool.coreObjects:
# 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)
# 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):
loadPendingMachines.append(machine)
#===============================================
# # TESTING
# print now(), self.victim.id, 'broker signalling', machine.id, 'loadOperatorAvailable'
#===============================================
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:
maxTimeWaiting=0
......@@ -150,7 +193,7 @@ class Broker(ObjectInterruption):
#===============================================================
# # 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
self.timeLastOperationEnded = now()
......
......@@ -91,8 +91,10 @@ class Queue(CoreObject):
# check if there is WIP and signal receiver
self.initialSignalReceiver()
while 1:
# print self.id, 'will wait for event', now()
# wait until the Queue can accept an entity and one predecessor requests it
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 self.isRequested.signalparam:
# reset the isRequested signal parameter
......@@ -102,7 +104,7 @@ class Queue(CoreObject):
if self.isDummy:
activeObjectQueue[0].startTime=now()
# 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 self.haveToDispose():
# 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