Machine, new variable interruptedBy (holds the type of interruptions). ShiftScheduler update.

parent f52b2011
...@@ -542,8 +542,8 @@ class Machine(CoreObject): ...@@ -542,8 +542,8 @@ class Machine(CoreObject):
def interruptionActions(self): def interruptionActions(self):
activeObjectQueue=self.Res.users activeObjectQueue=self.Res.users
activeEntity=activeObjectQueue[0] activeEntity=activeObjectQueue[0]
# self.printTrace(activeEntity.name, interrupted=self.objName) self.printTrace(activeEntity.name, interrupted=self.objName)
# if the interrupt occured while processing an entity # if the interrupt occurred while processing an entity
if not self.waitToDispose: if not self.waitToDispose:
# output to trace that the Machine (self.objName) got interrupted # output to trace that the Machine (self.objName) got interrupted
try: try:
...@@ -817,8 +817,8 @@ class Machine(CoreObject): ...@@ -817,8 +817,8 @@ class Machine(CoreObject):
#calculate the offShift time for current entity #calculate the offShift time for current entity
offShiftTimeInCurrentEntity=0 offShiftTimeInCurrentEntity=0
if self.interruptCause: if self.interruptedBy:
if self.onShift==False and self.interruptCause.type=='ShiftScheduler': if self.onShift==False and self.interruptedBy=='ShiftScheduler':
offShiftTimeInCurrentEntity=self.env.now-activeObject.timeLastShiftEnded offShiftTimeInCurrentEntity=self.env.now-activeObject.timeLastShiftEnded
# if there is an entity that finished processing in a Machine but did not get to reach # if there is an entity that finished processing in a Machine but did not get to reach
...@@ -870,8 +870,8 @@ class Machine(CoreObject): ...@@ -870,8 +870,8 @@ class Machine(CoreObject):
# we also need to add the last blocking time to total blockage time # we also need to add the last blocking time to total blockage time
if activeObject.onShift==False: if activeObject.onShift==False:
#add the time only if the object is interrupted because of off-shift #add the time only if the object is interrupted because of off-shift
if self.interruptCause: if self.interruptedBy:
if self.interruptCause.type=='ShiftScheduler': if self.interruptedBy=='ShiftScheduler':
self.totalOffShiftTime+=self.env.now-self.timeLastShiftEnded self.totalOffShiftTime+=self.env.now-self.timeLastShiftEnded
elif len(self.getActiveObjectQueue())==0 or self.waitToDispose: elif len(self.getActiveObjectQueue())==0 or self.waitToDispose:
self.totalOffShiftTime+=self.env.now-self.timeLastShiftEnded self.totalOffShiftTime+=self.env.now-self.timeLastShiftEnded
......
...@@ -37,13 +37,11 @@ class ObjectInterruption(object): ...@@ -37,13 +37,11 @@ class ObjectInterruption(object):
def __init__(self, victim=None): def __init__(self, victim=None):
from Globals import G from Globals import G
self.env=G.env self.env=G.env
# Process.__init__(self)
self.victim=victim self.victim=victim
# variable used to hand in control to the objectInterruption # variable used to hand in control to the objectInterruption
self.call=False self.call=False
def initialize(self): def initialize(self):
# Process.__init__(self)
self.call=False self.call=False
#=========================================================================== #===========================================================================
...@@ -90,12 +88,9 @@ class ObjectInterruption(object): ...@@ -90,12 +88,9 @@ class ObjectInterruption(object):
# interrupts the victim # interrupts the victim
#=========================================================================== #===========================================================================
def interruptVictim(self): def interruptVictim(self):
# # if the victim is not in position to dispose an entity, then interrupt the processing # inform the victim by whom will it be interrupted
# if not self.victim.waitToDispose and self.victim.getActiveObjectQueue(): # TODO: reconsider what happens when failure and ShiftScheduler (e.g.) signal simultaneously
# self.interrupt(self.victim) self.victim.interruptedBy=self.type
# otherwise it waits for an interruption event
# else:
# self.victim.interruptionStart.signal(now())
self.victim.interruptionStart.succeed(self.env.now) self.victim.interruptionStart.succeed(self.env.now)
#=========================================================================== #===========================================================================
...@@ -105,6 +100,8 @@ class ObjectInterruption(object): ...@@ -105,6 +100,8 @@ class ObjectInterruption(object):
self.victim.interruptionEnd.succeed(self.env.now) self.victim.interruptionEnd.succeed(self.env.now)
#reset the interruptionStart event of the victim #reset the interruptionStart event of the victim
self.victim.interruptionStart=self.env.event() self.victim.interruptionStart=self.env.event()
# TODO: reconsider what happens when failure and ShiftScheduler (e.g.) signal simultaneously
self.victim.interruptedBy=None
#=========================================================================== #===========================================================================
# outputs message to the trace.xls. Format is (Simulation Time | Victim Name | message) # outputs message to the trace.xls. Format is (Simulation Time | Victim Name | message)
......
...@@ -26,7 +26,8 @@ Created on 3 Jan 2014 ...@@ -26,7 +26,8 @@ Created on 3 Jan 2014
schedules the availability of an object according to its shift pattern schedules the availability of an object according to its shift pattern
''' '''
from SimPy.Simulation import now, Process, hold, request, release, infinity # from SimPy.Simulation import now, Process, hold, request, release, infinity
import simpy
from RandomNumberGenerator import RandomNumberGenerator from RandomNumberGenerator import RandomNumberGenerator
from ObjectInterruption import ObjectInterruption from ObjectInterruption import ObjectInterruption
...@@ -58,26 +59,26 @@ class ShiftScheduler(ObjectInterruption): ...@@ -58,26 +59,26 @@ class ShiftScheduler(ObjectInterruption):
# ======================================================================= # =======================================================================
def run(self): def run(self):
self.victim.totalOffShiftTime=0 self.victim.totalOffShiftTime=0
self.victim.timeLastShiftEnded=now() self.victim.timeLastShiftEnded=self.env.now
self.victim.onShift=False self.victim.onShift=False
while 1: while 1:
yield hold,self,float(self.remainingShiftPattern[0][0]-now()) # wait for the onShift yield self.env.timeout(float(self.remainingShiftPattern[0][0]-self.env.now)) # wait for the onShift
if(len(self.getVictimQueue())>0 and self.victim.interruptCause and not(self.endUnfinished)): 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.reactivateVictim() # re-activate the victim in case it was interrupted
self.victim.totalOffShiftTime+=now()-self.victim.timeLastShiftEnded self.victim.totalOffShiftTime+=self.env.now-self.victim.timeLastShiftEnded
self.victim.onShift=True self.victim.onShift=True
self.victim.timeLastShiftStarted=now() self.victim.timeLastShiftStarted=self.env.now
self.outputTrace("is on shift") self.outputTrace("is on shift")
startShift=now() startShift=self.env.now
yield hold,self,float(self.remainingShiftPattern[0][1]-now()) # wait until the shift is over 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)): 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.onShift=False # get the victim off-shift
self.victim.timeLastShiftEnded=now() self.victim.timeLastShiftEnded=self.env.now
self.outputTrace("is off shift") self.outputTrace("is off shift")
self.remainingShiftPattern.pop(0) self.remainingShiftPattern.pop(0)
if len(self.remainingShiftPattern)==0: if len(self.remainingShiftPattern)==0:
......
...@@ -180,7 +180,7 @@ class Source(CoreObject): ...@@ -180,7 +180,7 @@ class Source(CoreObject):
# creates an Entity # creates an Entity
#============================================================================ #============================================================================
def createEntity(self): def createEntity(self):
# self.printTrace(self.id, create='') self.printTrace(self.id, create='')
return self.item(id = self.item.type+str(G.numberOfEntities), name = self.item.type+str(self.numberOfArrivals)) #return the newly created Entity return self.item(id = self.item.type+str(G.numberOfEntities), name = self.item.type+str(self.numberOfArrivals)) #return the newly created Entity
#============================================================================ #============================================================================
# calculates the processing time # calculates the processing time
......
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