Commit 484ce818 authored by Georgios Dagkakis's avatar Georgios Dagkakis Committed by Jérome Perrin

change in ShiftScheduler to correctly interrupt the victim. TODO topology53 and starting conditions

parent cd832a16
......@@ -92,6 +92,8 @@ class CoreObject(object):
self.processingTimeOfCurrentEntity=0 #holds the total processing time that the current entity required
# ============================== waiting flag ==============================================
self.waitToDispose=False #shows if the object waits to dispose an entity
self.isWorkingOnTheLastBeforeOffShift=False #shows if the object is performing the last processing before it goes offShift
# ============================== the below are currently used in Jobshop =======================
self.giver=None #the CoreObject that the activeObject will take an Entity from
......@@ -119,7 +121,7 @@ class CoreObject(object):
self.totalProcessingTimeInCurrentEntity=0
self.failureTimeInCurrentEntity=0
self.setupTimeCurrentEntity=0
self.shouldPreempt=False #flag that shows that the machine should preempt or not
self.lastGiver=None # variable that holds the last giver of the object, used by machine in case of preemption
......@@ -134,6 +136,7 @@ class CoreObject(object):
self.interruptionStart=self.env.event()
self.interruptedBy=None
self.entityRemoved=self.env.event()
# =======================================================================
# the main process of the core object
......
......@@ -527,7 +527,15 @@ class Machine(CoreObject):
self.nameLastEntityEnded=self.currentEntity.name # this holds the name of the last entity that ended processing in Machine
self.completedJobs+=1 # Machine completed one more Job
# reseting the shouldPreempt flag
self.shouldPreempt=False
self.shouldPreempt=False
if self.isWorkingOnTheLastBeforeOffShift:
mySS=None
for SS in G.ShiftSchedulerList:
if SS.victim==self:
mySS=SS
break
mySS.victimEndedLastProcessing.succeed()
self.isWorkingOnTheLastBeforeOffShift=False
# =======================================================================
# actions to be carried out when the processing of an Entity ends
......
......@@ -53,6 +53,7 @@ class ShiftScheduler(ObjectInterruption):
def initialize(self):
ObjectInterruption.initialize(self)
self.remainingShiftPattern=list(self.shiftPattern)
self.victimEndedLastProcessing=self.env.event()
# =======================================================================
# The run method for the failure which has to served by a repairman
......@@ -60,26 +61,38 @@ class ShiftScheduler(ObjectInterruption):
def run(self):
self.victim.totalOffShiftTime=0
self.victim.timeLastShiftEnded=self.env.now
self.victim.onShift=False
while 1:
yield self.env.timeout(float(self.remainingShiftPattern[0][0]-self.env.now)) # wait for the onShift
if(len(self.getVictimQueue())>0 and self.victim.interruptedBy==self.type and not(self.endUnfinished)):
self.reactivateVictim() # re-activate the victim in case it was interrupted
self.victim.totalOffShiftTime+=self.env.now-self.victim.timeLastShiftEnded
self.victim.onShift=True
self.victim.timeLastShiftStarted=self.env.now
self.outputTrace("is on shift")
startShift=self.env.now
# if in the beginning the victim is offShift
if float(self.remainingShiftPattern[0][0])!=self.env.now:
self.victim.onShift=False
yield self.env.timeout(float(self.remainingShiftPattern[0][1]-self.env.now)) # wait until the shift is over
if(len(self.getVictimQueue())>0 and not(self.endUnfinished)):
self.interruptVictim() # interrupt processing operations if any
self.interruptVictim() # interrupt processing operations if any
self.victim.onShift=False # get the victim off-shift
self.victim.timeLastShiftEnded=self.env.now
self.outputTrace("is off shift")
self.remainingShiftPattern.pop(0)
while 1:
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
self.victim.totalOffShiftTime+=self.env.now-self.victim.timeLastShiftEnded
self.victim.onShift=True
self.victim.timeLastShiftStarted=self.env.now
self.outputTrace("is on shift")
startShift=self.env.now
else:
yield self.env.timeout(float(self.remainingShiftPattern[0][1]-self.env.now)) # wait until the shift is over
if self.endUnfinished and len(self.victim.getActiveObjectQueue())==1 and (not self.victim.waitToDispose):
self.victim.isWorkingOnTheLastBeforeOffShift=True
yield self.victimEndedLastProcessing
self.interruptVictim() # interrupt processing operations if any
self.victim.onShift=False # get the victim off-shift
self.victim.timeLastShiftEnded=self.env.now
self.outputTrace("is off shift")
self.remainingShiftPattern.pop(0)
if len(self.remainingShiftPattern)==0:
break
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