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

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