Commit 8a765025 authored by Georgios Dagkakis's avatar Georgios Dagkakis

invokeType flag added to broker

parent 1ebd69f7
...@@ -1156,6 +1156,7 @@ class Machine(CoreObject): ...@@ -1156,6 +1156,7 @@ class Machine(CoreObject):
# prepare the machine to be operated # prepare the machine to be operated
# ======================================================================= # =======================================================================
def requestOperator(self): def requestOperator(self):
self.broker.invokeType='request'
self.broker.invoke() self.broker.invoke()
self.toBeOperated = True self.toBeOperated = True
...@@ -1177,6 +1178,7 @@ class Machine(CoreObject): ...@@ -1177,6 +1178,7 @@ class Machine(CoreObject):
operator.timeLastShiftEnded=self.env.now operator.timeLastShiftEnded=self.env.now
operator.unAssign() # set the flag operatorAssignedTo to None operator.unAssign() # set the flag operatorAssignedTo to None
operator.workingStation=None operator.workingStation=None
self.toBeOperated = False
self.outputTrace(operator.name, "released from "+ self.objName) self.outputTrace(operator.name, "released from "+ self.objName)
# XXX in case of skilled operators which stay at the same station should that change # XXX in case of skilled operators which stay at the same station should that change
elif not operator.operatorDedicatedTo==self: elif not operator.operatorDedicatedTo==self:
...@@ -1186,13 +1188,14 @@ class Machine(CoreObject): ...@@ -1186,13 +1188,14 @@ class Machine(CoreObject):
# if the Router is expecting for signal send it # if the Router is expecting for signal send it
from Globals import G from Globals import G
from SkilledOperatorRouter import SkilledRouter from SkilledOperatorRouter import SkilledRouter
self.toBeOperated = False
if G.RouterList[0].__class__ is SkilledRouter: if G.RouterList[0].__class__ is SkilledRouter:
if G.RouterList[0].expectedFinishSignals: if G.RouterList[0].expectedFinishSignals:
if self.id in G.RouterList[0].expectedFinishSignalsDict: if self.id in G.RouterList[0].expectedFinishSignalsDict:
signal=G.RouterList[0].expectedFinishSignalsDict[self.id] signal=G.RouterList[0].expectedFinishSignalsDict[self.id]
self.sendSignal(receiver=G.RouterList[0], signal=signal) self.sendSignal(receiver=G.RouterList[0], signal=signal)
self.broker.invokeType='release'
self.broker.invoke() self.broker.invoke()
self.toBeOperated = False
# ======================================================================= # =======================================================================
# check if the machine is currently operated by an operator # check if the machine is currently operated by an operator
......
...@@ -49,6 +49,9 @@ class Broker(ObjectInterruption): ...@@ -49,6 +49,9 @@ class Broker(ObjectInterruption):
self.timeLastOperationEnded = 0 self.timeLastOperationEnded = 0
self.timeWaitForOperatorStarted=0 self.timeWaitForOperatorStarted=0
self.waitForOperator=False self.waitForOperator=False
# flag that shows if broker was called to request or release operator.
# Machine updates this before calling the broker
self.invokeType='request'
#=========================================================================== #===========================================================================
# the initialize method # the initialize method
...@@ -75,117 +78,129 @@ class Broker(ObjectInterruption): ...@@ -75,117 +78,129 @@ class Broker(ObjectInterruption):
self.expectedSignals['isCalled']=1 self.expectedSignals['isCalled']=1
yield self.isCalled yield self.isCalled
# if self.victim.id=='St2M0':
# print self.env.now, self.victim.id, 'Broker Called',self.invokeType
transmitter, eventTime=self.isCalled.value transmitter, eventTime=self.isCalled.value
assert eventTime==self.env.now, 'the broker should be granted control instantly' assert eventTime==self.env.now, 'the broker should be granted control instantly'
self.isCalled=self.env.event() self.isCalled=self.env.event()
self.victim.printTrace(self.victim.id, received='(broker)') self.victim.printTrace(self.victim.id, received='(broker)')
# ======= request a resource if self.invokeType=='request':
if self.victim.isOperated()\ # ======= request a resource
and any(type=='Load' or type=='Setup' or type=='Processing'\ if self.victim.isOperated()\
for type in self.victim.multOperationTypeList): and any(type=='Load' or type=='Setup' or type=='Processing'\
# update the time that the station is waiting for the operator for type in self.victim.multOperationTypeList):
self.timeWaitForOperatorStarted=self.env.now # update the time that the station is waiting for the operator
#=============================================================== self.timeWaitForOperatorStarted=self.env.now
from Globals import G #===============================================================
# if the victim does not have a dedicated operator from Globals import G
if not self.victim.checkForDedicatedOperators(): # if the victim does not have a dedicated operator
# if the victim already holds an entity that means that the machine's operation type if not self.victim.checkForDedicatedOperators():
# is no Load or setup, in that case the router is already invoked and the machine is already assigned an operator # if the victim already holds an entity that means that the machine's operation type
if not self.victimQueueIsEmpty(): # is no Load or setup, in that case the router is already invoked and the machine is already assigned an operator
# add the currentEntity to the pendingEntities if not self.victimQueueIsEmpty():
if not self.victim.currentEntity in G.pendingEntities: # add the currentEntity to the pendingEntities
G.pendingEntities.append(self.victim.currentEntity) if not self.victim.currentEntity in G.pendingEntities:
if not G.RouterList[0].invoked and G.RouterList[0].expectedSignals['isCalled']: G.pendingEntities.append(self.victim.currentEntity)
self.victim.printTrace(self.victim.id, signal='router (broker)') if not G.RouterList[0].invoked and G.RouterList[0].expectedSignals['isCalled']:
self.sendSignal(receiver=G.RouterList[0], signal=G.RouterList[0].isCalled) self.victim.printTrace(self.victim.id, signal='router (broker)')
G.RouterList[0].invoked=True self.sendSignal(receiver=G.RouterList[0], signal=G.RouterList[0].isCalled)
G.RouterList[0].invoked=True
self.waitForOperator=True
self.victim.printTrace(self.victim.id, waitEvent='(resourceIsAvailable broker)')
self.expectedSignals['resourceAvailable']=1
yield self.resourceAvailable
transmitter, eventTime=self.resourceAvailable.value
self.resourceAvailable=self.env.event()
# remove the currentEntity from the pendingEntities
if self.victim.currentEntity in G.pendingEntities:
G.pendingEntities.remove(self.victim.currentEntity)
self.waitForOperator=False
self.victim.printTrace(self.victim.id, resourceAvailable='(broker)')
# else if the Router is already invoked for allocating purposes wait until a resource is allocated to the victim's operatorPool
# wait only if there is no current operator
# XXX discuss this
elif G.RouterList[0].invoked and G.RouterList[0].allocation and not self.victim.currentOperator:
self.waitForOperator=True self.waitForOperator=True
self.victim.printTrace(self.victim.id, waitEvent='(resourceIsAvailable broker)') self.victim.printTrace(self.victim.id, waitEvent='(resourceIsAvailable broker)')
self.expectedSignals['resourceAvailable']=1
yield self.resourceAvailable if not self.victim.operatorPool.checkIfResourceIsAvailable():
self.expectedSignals['resourceAvailable']=1
transmitter, eventTime=self.resourceAvailable.value yield self.resourceAvailable
self.resourceAvailable=self.env.event() transmitter, eventTime=self.resourceAvailable.value
# remove the currentEntity from the pendingEntities self.resourceAvailable=self.env.event()
if self.victim.currentEntity in G.pendingEntities: self.waitForOperator=False
G.pendingEntities.remove(self.victim.currentEntity) #===============================================================
self.waitForOperator=False
self.victim.printTrace(self.victim.id, resourceAvailable='(broker)')
# else if the Router is already invoked for allocating purposes wait until a resource is allocated to the victim's operatorPool
# wait only if there is no current operator
# XXX discuss this
elif G.RouterList[0].invoked and G.RouterList[0].allocation and not self.victim.currentOperator:
self.waitForOperator=True
self.victim.printTrace(self.victim.id, waitEvent='(resourceIsAvailable broker)')
if not self.victim.operatorPool.checkIfResourceIsAvailable():
self.expectedSignals['resourceAvailable']=1
yield self.resourceAvailable
transmitter, eventTime=self.resourceAvailable.value
self.resourceAvailable=self.env.event()
self.waitForOperator=False
#===============================================================
assert self.victim.operatorPool.checkIfResourceIsAvailable(), 'there is no available operator to request'
# set the available resource as the currentOperator
currentOperator=None
for operator in self.victim.operatorPool.operators:
if operator.isAssignedTo()==self.victim:
currentOperator=operator
break
self.victim.currentOperator=currentOperator
if not currentOperator:
self.victim.currentOperator=self.victim.operatorPool.findAvailableOperator()
with self.victim.operatorPool.getResource(self.victim.currentOperator).request() as request:
yield request
# update the operator workingStation
self.victim.currentOperator.workingStation=self.victim
self.victim.printTrace(self.victim.currentOperator.objName, startWork=self.victim.id)
# clear the timeWaitForOperatorStarted variable
self.timeWaitForOperatorStarted = 0
# update the time that the operation started
self.timeOperationStarted = self.env.now
self.victim.outputTrace(self.victim.currentOperator.name, "started work in "+ self.victim.objName)
self.victim.currentOperator.timeLastOperationStarted=self.env.now#()
# signal the machine that an operator is reserved
if self.victim.expectedSignals['brokerIsSet']:
self.sendSignal(receiver=self.victim, signal=self.victim.brokerIsSet)
# update the schedule of the operator
self.victim.currentOperator.schedule.append({"station": self.victim,
"entranceTime": self.env.now})
# if the victim holds an entity (load is already performed)
if self.victim.getActiveObjectQueue():
activeEntity = self.victim.getActiveObjectQueue()[0]
# update the entity value of the schedule current step dict
if self.victim.currentOperator.schedule[-1].get("entity", None) == None:
self.victim.currentOperator.schedule[-1]["entity"] = activeEntity
# if the entity held by the station has a currentStep
try:
if activeEntity.currentStep:
if activeEntity.currentStep.get("task_id", None):
self.victim.currentOperator.schedule[-1]["task_id"] = activeEntity.currentStep["task_id"]
except AttributeError:
pass
# wait till the processing is over assert self.victim.operatorPool.checkIfResourceIsAvailable(), 'there is no available operator to request'
self.expectedSignals['isCalled']=1 # set the available resource as the currentOperator
currentOperator=None
yield self.isCalled for operator in self.victim.operatorPool.operators:
if operator.isAssignedTo()==self.victim:
transmitter, eventTime=self.isCalled.value currentOperator=operator
assert eventTime==self.env.now, 'the broker should be granted control instantly' break
self.isCalled=self.env.event() self.victim.currentOperator=currentOperator
if not currentOperator:
self.victim.currentOperator=self.victim.operatorPool.findAvailableOperator()
with self.victim.operatorPool.getResource(self.victim.currentOperator).request() as request:
yield request
if self.victim.id=='St2M0':
print 1
# update the operator workingStation
self.victim.currentOperator.workingStation=self.victim
self.victim.printTrace(self.victim.currentOperator.objName, startWork=self.victim.id)
# clear the timeWaitForOperatorStarted variable
self.timeWaitForOperatorStarted = 0
# update the time that the operation started
self.timeOperationStarted = self.env.now
self.victim.outputTrace(self.victim.currentOperator.name, "started work in "+ self.victim.objName)
self.victim.currentOperator.timeLastOperationStarted=self.env.now#()
# signal the machine that an operator is reserved
if self.victim.expectedSignals['brokerIsSet']:
self.sendSignal(receiver=self.victim, signal=self.victim.brokerIsSet)
# update the schedule of the operator
self.victim.currentOperator.schedule.append({"station": self.victim,
"entranceTime": self.env.now})
# if the victim holds an entity (load is already performed)
if self.victim.getActiveObjectQueue():
activeEntity = self.victim.getActiveObjectQueue()[0]
# update the entity value of the schedule current step dict
if self.victim.currentOperator.schedule[-1].get("entity", None) == None:
self.victim.currentOperator.schedule[-1]["entity"] = activeEntity
# if the entity held by the station has a currentStep
try:
if activeEntity.currentStep:
if activeEntity.currentStep.get("task_id", None):
self.victim.currentOperator.schedule[-1]["task_id"] = activeEntity.currentStep["task_id"]
except AttributeError:
pass
# wait till the processing is over
self.expectedSignals['isCalled']=1
yield self.isCalled
# if self.victim.id=='St2M0':
# print self.env.now, self.victim.id, 'Broker Called 2', self.invokeType
transmitter, eventTime=self.isCalled.value
assert eventTime==self.env.now, 'the broker should be granted control instantly'
self.isCalled=self.env.event()
# The operator is released (the router is not called in the case of skilled ops that work constantly on the same machine) if self.invokeType=='release':
# if self.victim.id=='St2M0':
# print 2
# The operator is released (the router is not called in the case of skilled
# ops that work constantly on the same machine)
if not self.victim.currentOperator.operatorDedicatedTo==self.victim: if not self.victim.currentOperator.operatorDedicatedTo==self.victim:
if not self.victim.isOperated(): if not self.victim.isOperated():
# if self.victim.id=='St2M0':
# print 3
# signal the other brokers waiting for the same operators that they are now free # signal the other brokers waiting for the same operators that they are now free
# also signal the stations that were not requested to receive because the operator was occupied # also signal the stations that were not requested to receive because the operator was occupied
......
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