Commit 85a340ff authored by Ioannis Papagiannopoulos's avatar Ioannis Papagiannopoulos Committed by Georgios Dagkakis

interruptions updated and make use of expectedSignals dict

parent 623ed13b
......@@ -112,7 +112,10 @@ class Failure(ObjectInterruption):
elif self.deteriorationType=='onShift':
while failureNotTriggered:
timeRestartedCounting=self.env.now
self.isWaitingForVictimOffShift=True
self.isWaitingForVictimOffShift=True
self.expectedSignals['victimOffShift']=1
receivedEvent=yield self.env.timeout(remainingTimeToFailure) | self.victimOffShift
# the failure should receive a signal if there is a shift-off triggered
if self.victimOffShift in receivedEvent:
......@@ -121,31 +124,57 @@ class Failure(ObjectInterruption):
remainingTimeToFailure=remainingTimeToFailure-(self.env.now-timeRestartedCounting)
# wait for the shift to start again
self.isWaitingForVictimOnShift=True
self.expectedSignals['victimOnShift']=1
yield self.victimOnShift
self.expectedSignals['victimOnShift']=0
self.isWaitingForVictimOnShift=False
self.victimOnShift=self.env.event()
assert self.victim.onShift==True, 'the victim of shiftFailure must be onShift to continue counting the TTF'
else:
self.isWaitingForVictimOffShift=False
failureNotTriggered=False
self.expectedSignals['victimOffShift']=0
# if time to failure counts only in working time
elif self.deteriorationType=='working':
# wait for victim to start process
self.expectedSignals['victimStartsProcess']=1
yield self.victimStartsProcess
self.expectedSignals['victimStartsProcess']=0
self.victimStartsProcess=self.env.event()
while failureNotTriggered:
timeRestartedCounting=self.env.now
self.expectedSignals['victimEndsProcess']=1
# wait either for the failure or end of process
receivedEvent=yield self.env.timeout(remainingTimeToFailure) | self.victimEndsProcess
if self.victimEndsProcess in receivedEvent:
self.victimEndsProcess=self.env.event()
remainingTimeToFailure=remainingTimeToFailure-(self.env.now-timeRestartedCounting)
self.expectedSignals['victimStartsProcess']=1
yield self.victimStartsProcess
self.expectedSignals['victimStartsProcess']=0
# wait for victim to start again processing
self.victimStartsProcess=self.env.event()
else:
failureNotTriggered=False
self.expectedSignals['victimEndsProcess']=0
# interrupt the victim only if it was not previously interrupted
if not self.victim.interruptionStart.triggered:
self.interruptVictim() # interrupt the victim
......
......@@ -71,7 +71,13 @@ class Broker(ObjectInterruption):
def run(self):
while 1:
# TODO: add new broker event - brokerIsCalled
self.expectedSignals['isCalled']=1
yield self.isCalled
self.expectedSignals['isCalled']=0
transmitter, eventTime=self.isCalled.value
assert eventTime==self.env.now, 'the broker should be granted control instantly'
self.isCalled=self.env.event()
......@@ -92,7 +98,7 @@ class Broker(ObjectInterruption):
# add the currentEntity to the pendingEntities
if not self.victim.currentEntity in G.pendingEntities:
G.pendingEntities.append(self.victim.currentEntity)
if not G.Router.invoked:
if not G.Router.invoked and G.Router.expectedSignals['isCalled']:
self.victim.printTrace(self.victim.id, signal='router (broker)')
G.Router.invoked=True
succeedTuple=(self,self.env.now)
......@@ -100,7 +106,13 @@ class Broker(ObjectInterruption):
self.waitForOperator=True
self.victim.printTrace(self.victim.id, waitEvent='(resourceIsAvailable broker)')
self.expectedSignals['resourceAvailable']=1
yield self.resourceAvailable
self.expectedSignals['resourceAvailable']=0
transmitter, eventTime=self.resourceAvailable.value
self.resourceAvailable=self.env.event()
# remove the currentEntity from the pendingEntities
......@@ -112,7 +124,13 @@ class Broker(ObjectInterruption):
elif G.Router.invoked and G.Router.allocation:
self.waitForOperator=True
self.victim.printTrace(self.victim.id, waitEvent='(resourceIsAvailable broker)')
self.expectedSignals['resourceAvailable']=1
yield self.resourceAvailable
self.expectedSignals['resourceAvailable']=0
transmitter, eventTime=self.resourceAvailable.value
self.resourceAvailable=self.env.event()
self.waitForOperator=False
......@@ -136,13 +154,18 @@ class Broker(ObjectInterruption):
self.victim.outputTrace(self.victim.currentOperator.objName, "started work in "+ self.victim.objName)
self.victim.currentOperator.timeLastOperationStarted=self.env.now#()
# signal the machine that an operator is reserved
succeedTuple=(self,self.env.now)
self.victim.brokerIsSet.succeed(succeedTuple)
if self.victim.expectedSignals['brokerIsSet']:
succeedTuple=(self,self.env.now)
self.victim.brokerIsSet.succeed(succeedTuple)
# update the schedule of the operator
self.victim.currentOperator.schedule.append([self.victim, self.env.now])
# wait till the processing is over
self.expectedSignals['isCalled']=1
yield self.isCalled
self.expectedSignals['isCalled']=0
transmitter, eventTime=self.isCalled.value
assert eventTime==self.env.now, 'the broker should be granted control instantly'
self.isCalled=self.env.event()
......@@ -156,11 +179,11 @@ class Broker(ObjectInterruption):
# TODO: signalling the router must be done more elegantly, router must be set as global variable
# if the router is already invoked then do not signal it again
if not self.victim.router.invoked:
if not G.Router.invoked and G.Router.expectedSignals['isCalled']:
self.victim.printTrace(self.victim.id, signal='router (broker)')
self.victim.router.invoked=True
G.Router.invoked=True
succeedTuple=(self,self.env.now)
self.victim.router.isCalled.succeed(succeedTuple)
G.Router.isCalled.succeed(succeedTuple)
# TODO: signalling the router will give the chance to it to take the control, but when will it eventually receive it.
# after signalling the broker will signal it's victim that it has finished it's processes
# TODO: this wont work for the moment. The actions that follow must be performed by all operated brokers.
......@@ -175,6 +198,7 @@ class Broker(ObjectInterruption):
else:
pass
# return the control to the victim
succeedTuple=(self,self.env.now)
self.victim.brokerIsSet.succeed(succeedTuple)
if self.victim.expectedSignals['brokerIsSet']:
succeedTuple=(self,self.env.now)
self.victim.brokerIsSet.succeed(succeedTuple)
......@@ -106,7 +106,13 @@ class Router(ObjectInterruption):
def run(self):
while 1:
# wait until the router is called
self.expectedSignals['isCalled']=1
yield self.isCalled
self.expectedSignals['isCalled']=0
transmitter, eventTime=self.isCalled.value
self.isCalled=self.env.event()
self.printTrace('','=-'*15)
......@@ -238,16 +244,18 @@ class Router(ObjectInterruption):
station.timeLastEntityEnded=self.env.now #required to count blockage correctly in the preemptied station
elif station.broker.waitForOperator:
# signal this station's broker that the resource is available
self.printTrace('router', 'signalling broker of'+' '*50+operator.isAssignedTo().id)
succeedTuple=(self,self.env.now)
station.broker.resourceAvailable.succeed(succeedTuple)
if station.broker.expectedSignals['resourceAvailable']:
self.printTrace('router', 'signalling broker of'+' '*50+operator.isAssignedTo().id)
succeedTuple=(self,self.env.now)
station.broker.resourceAvailable.succeed(succeedTuple)
else:
# signal the queue proceeding the station
if station.canAccept()\
and any(type=='Load' for type in station.multOperationTypeList):
self.printTrace('router', 'signalling'+' '*50+operator.isAssignedTo().id)
succeedTuple=(self,self.env.now)
station.loadOperatorAvailable.succeed(succeedTuple)
if station.expectedSignals['loadOperatorAvailable']:
self.printTrace('router', 'signalling'+' '*50+operator.isAssignedTo().id)
succeedTuple=(self,self.env.now)
station.loadOperatorAvailable.succeed(succeedTuple)
#===========================================================================
# clear the pending lists of the router
......
......@@ -78,7 +78,13 @@ class RouterManaged(Router):
def run(self):
while 1:
# wait until the router is called
self.expectedSignals['isCalled']=1
yield self.isCalled
self.expectedSignals['isCalled']=0
transmitter, eventTime=self.isCalled.value
self.isCalled=self.env.event()
self.printTrace('','=-'*15)
......@@ -193,8 +199,9 @@ class RouterManaged(Router):
if station in self.pendingMachines and station in self.toBeSignalled:
# signal this station's broker that the resource is available
self.printTrace('router','signalling broker of'+' '*50+operator.isAssignedTo().id)
succeedTuple=(self,self.env.now)
operator.isAssignedTo().broker.resourceAvailable.succeed(succeedTuple)
if operator.isAssignedTo().broker.expectedSignals['resourceAvailable']:
succeedTuple=(self,self.env.now)
operator.isAssignedTo().broker.resourceAvailable.succeed(succeedTuple)
elif (not station in self.pendingMachines) or (not station in self.toBeSignalled):
# signal the queue proceeding the station
assert operator.candidateEntity.currentStation in self.toBeSignalled, 'the candidateEntity currentStation is not picked by the Router'
......@@ -204,8 +211,9 @@ class RouterManaged(Router):
# if the station is already is already signalled then do not send event
if not operator.candidateEntity.currentStation.loadOperatorAvailable.triggered:
self.printTrace('router','signalling queue'+' '*50+operator.candidateEntity.currentStation.id)
succeedTuple=(self,self.env.now)
operator.candidateEntity.currentStation.loadOperatorAvailable.succeed(succeedTuple)
if operator.candidateEntity.currentStation.expectedSignals['loadOperatorAvailable']:
succeedTuple=(self,self.env.now)
operator.candidateEntity.currentStation.loadOperatorAvailable.succeed(succeedTuple)
#===========================================================================
# clear the pending lists of the router
......
......@@ -82,7 +82,13 @@ class ScheduledMaintenance(ObjectInterruption):
self.victim.isWorkingOnTheLast=True
self.waitingSignal=True
# TODO: signal to be triggered by postProcessingActions of Machines
self.expectedSignals['endedLastProcessing']=1
yield self.victim.endedLastProcessing # there is no signal yet that signals the change of such state (an object getting empty)
self.expectedSignals['endedLastProcessing']=0
transmitter, eventTime=self.victim.endedLastProcessing.value
assert eventTime==self.env.now, 'the processing end signal is not received by maintenance on time'
self.victim.endedLastProcessing=self.env.event()
......@@ -93,7 +99,13 @@ class ScheduledMaintenance(ObjectInterruption):
waitStartTime=self.env.now
self.waitingSignal=True
# TODO: signal to be triggered by removeEntity of Machines
self.expectedSignals['victimIsEmptyBeforeMaintenance']=1
yield self.victimIsEmptyBeforeMaintenance # there is no signal yet that signals the change of such state (an object getting empty)
self.expectedSignals['victimIsEmptyBeforeMaintenance']=0
transmitter, eventTime=self.victimIsEmptyBeforeMaintenance.value
assert eventTime==self.env.now, 'the processing end signal is not received by maintenance on time'
self.victimIsEmptyBeforeMaintenance=self.env.event()
......
......@@ -78,8 +78,9 @@ class ShiftScheduler(ObjectInterruption):
# if the victim has interruptions that measure only the on-shift time, they have to be notified
for oi in self.victim.objectInterruptions:
if oi.isWaitingForVictimOnShift:
succeedTuple=(self,self.env.now)
oi.victimOnShift.succeed(succeedTuple)
if oi.expectedSignals['victimOnShift']:
succeedTuple=(self,self.env.now)
oi.victimOnShift.succeed(succeedTuple)
self.victim.totalOffShiftTime+=self.env.now-self.victim.timeLastShiftEnded
self.victim.onShift=True
......@@ -97,15 +98,22 @@ class ShiftScheduler(ObjectInterruption):
if self.endUnfinished and len(self.victim.getActiveObjectQueue())==1 and (not self.victim.waitToDispose):
self.victim.isWorkingOnTheLast=True
self.waitingSignal=True
self.expectedSignals['endedLastProcessing']=1
yield self.victim.endedLastProcessing
self.expectedSignals['endedLastProcessing']=0
transmitter, eventTime=self.victim.endedLastProcessing.value
self.victim.endedLastProcessing=self.env.event()
# if the victim has interruptions that measure only the on-shift time, they have to be notified
for oi in self.victim.objectInterruptions:
if oi.isWaitingForVictimOffShift:
succeedTuple=(self, self.env.now)
oi.victimOffShift.succeed(succeedTuple)
if oi.expectedSignals['victimOffShift']:
succeedTuple=(self, self.env.now)
oi.victimOffShift.succeed(succeedTuple)
# interrupt the victim only if it was not previously interrupted
if not self.victim.interruptionStart.triggered:
......
......@@ -70,7 +70,13 @@ class SkilledRouter(Router):
def run(self):
while 1:
# wait until the router is called
self.expectedSignals['isCalled']=1
yield self.isCalled
self.expectedSignals['isCalled']=0
transmitter, eventTime=self.isCalled.value
self.isCalled=self.env.event()
self.printTrace('','=-'*15)
......@@ -126,7 +132,13 @@ class SkilledRouter(Router):
# # XXX wait till all the stations have finished their current WIP
#===================================================================
# TODO: fix that, add flags, reset the signals
self.expectedSignals['endedLastProcessing']=1
receivedEvent=yield self.env.all_of(self.endProcessingSignals)
self.expectedSignals['endedLastProcessing']=0
for station in self.busyStations:
if station.endedLastProcessing in receivedEvent:
transmitter, eventTime=station.endedLastProcessing.value
......@@ -241,16 +253,18 @@ class SkilledRouter(Router):
for station in self.toBeSignalled:
if station.broker.waitForOperator:
# signal this station's broker that the resource is available
self.printTrace('router', 'signalling broker of'+' '*50+station.id)
succeedTuple=(self,self.env.now)
station.broker.resourceAvailable.succeed(succeedTuple)
if station.broker.expectedSignals['resourceAvailable']:
self.printTrace('router', 'signalling broker of'+' '*50+station.id)
succeedTuple=(self,self.env.now)
station.broker.resourceAvailable.succeed(succeedTuple)
else:
# signal the queue proceeding the station
if station.canAccept()\
and any(type=='Load' for type in station.multOperationTypeList):
self.printTrace('router', 'signalling'+' '*50+station.id)
succeedTuple=(self,self.env.now)
station.loadOperatorAvailable.succeed(succeedTuple)
if station.expectedSignals['loadOperatorAvailable']:
self.printTrace('router', 'signalling'+' '*50+station.id)
succeedTuple=(self,self.env.now)
station.loadOperatorAvailable.succeed(succeedTuple)
#===================================================================
# default behaviour
......
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