Commit 8062b153 authored by Georgios Dagkakis's avatar Georgios Dagkakis

Failure not to wait for the same event that the victim does. If the victim...

Failure not to wait for the same event that the victim does. If the victim happened to take it first and reset it then it would lead to unexpected behaviour
parent 404facb4
......@@ -113,19 +113,21 @@ class Failure(ObjectInterruption):
elif self.deteriorationType=='onShift':
while failureNotTriggered:
timeRestartedCounting=self.env.now
# TODO: can also wait for interruptionStart signal of the victim and check whether the interruption is caused by a shiftScheduler
receivedEvent=yield self.env.timeout(remainingTimeToFailure) | self.victim.interruptionStart
self.isWaitingForVictimOffShift=True
receivedEvent=yield self.env.timeout(remainingTimeToFailure) | self.victimOffShift
# the failure should receive a signal if there is a shift-off triggered
if self.victim.interruptionStart in receivedEvent:
# TODO: the signal interruptionStart is reset by the time it is received by the victim. not sure if will be still triggered when it is checked here
if self.victimOffShift in receivedEvent:
assert self.victim.onShift==False, 'shiftFailure cannot recalculate TTF if the victim is onShift'
remainingTimeToFailure=remainingTimeToFailure-(self.env.now-timeRestartedCounting)
self.victimOffShift=self.env.event()
remainingTimeToFailure=remainingTimeToFailure-(self.env.now-timeRestartedCounting)
# wait for the shift to start again
self.isWaitingForVictimonShift=True
yield self.victim.interruptionEnd
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'
# TODO: the signal interruptionStart is reset by the time it is received by the victim. not sure if will be still triggered when it is checked here
else:
self.isWaitingForVictimOffShift=False
failureNotTriggered=False
# if time to failure counts only in working time
elif self.deteriorationType=='working':
......
......@@ -43,6 +43,12 @@ class ObjectInterruption(object):
from Globals import G
self.env=G.env
self.call=False
# events that are send by the ShiftScheduler to all the other interruptions that might wait for them
self.victimOffShift=self.env.event()
self.victimOnShift=self.env.event()
# flags that show if the interruption waits for the event
self.isWaitingForVictimOffShift=False
self.isWaitingForVictimOnShift=False
#===========================================================================
# the main process of the core object
......
......@@ -74,6 +74,12 @@ class ShiftScheduler(ObjectInterruption):
if not self.victim.onShift:
yield self.env.timeout(float(self.remainingShiftPattern[0][0]-self.env.now)) # wait for the onShift
self.reactivateVictim() # re-activate the victim in case it was interrupted
# 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:
oi.victimOnShift.succeed()
self.victim.totalOffShiftTime+=self.env.now-self.victim.timeLastShiftEnded
self.victim.onShift=True
self.victim.timeLastShiftStarted=self.env.now
......@@ -93,6 +99,11 @@ class ShiftScheduler(ObjectInterruption):
yield self.victim.endedLastProcessing
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:
oi.victimOffShift.succeed()
# interrupt the victim only if it was not previously interrupted
if not self.victim.interruptionStart.triggered:
self.interruptVictim() # interrupt the victim
......
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