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

ShiftScheduler added and main script updated to read it

parent 8d2a4e35
......@@ -94,6 +94,7 @@ from ConditionalBuffer import ConditionalBuffer
from MouldAssemblyBuffer import MouldAssemblyBuffer
from MachineManagedJob import MachineManagedJob
from QueueManagedJob import QueueManagedJob
from ShiftScheduler import ShiftScheduler
import ExcelHandler
import time
......@@ -1260,6 +1261,7 @@ def createObjectInterruptions():
G.ObjectInterruptionList=[]
G.ScheduledMaintenanceList=[]
G.FailureList=[]
G.ShiftSchedulerList=[]
json_data = G.JSONData
#Read the json data
......@@ -1292,6 +1294,16 @@ def createObjectInterruptions():
F=Failure(victim, distributionType, MTTF, MTTR, availability, victim.id, victim.repairman)
G.ObjectInterruptionList.append(F)
G.FailureList.append(F)
# if there is a shift pattern defined
# initiate them
shift=element.get('shift', {})
if len(shift):
victim=Globals.findObjectById(element['id'])
shiftPattern=list(shift.get('shiftPattern', []))
endUnfinished=bool(int(shift.get('endUnfinished', 0)))
SS=ShiftScheduler(victim, shiftPattern, endUnfinished)
G.ObjectInterruptionList.append(SS)
G.ShiftSchedulerList.append(SS)
# ===========================================================================
# used to convert a string read from the input to object type
......
# ===========================================================================
# Copyright 2013 University of Limerick
#
# This file is part of DREAM.
#
# DREAM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DREAM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DREAM. If not, see <http://www.gnu.org/licenses/>.
# ===========================================================================
'''
Created on 3 Jan 2014
@author: George
'''
'''
schedules the availability of an object according to its shift pattern
'''
from SimPy.Simulation import now, Process, hold, request, release, infinity
from RandomNumberGenerator import RandomNumberGenerator
from ObjectInterruption import ObjectInterruption
# ===========================================================================
# the shift scheduler class
# ===========================================================================
class ShiftScheduler(ObjectInterruption):
# =======================================================================
# the __init__() method of the class
# =======================================================================
def __init__(self, victim=None, shiftPattern=[], endUnfinished=False):
ObjectInterruption.__init__(self,victim)
self.shiftPattern=shiftPattern
self.endUnfinished=endUnfinished #flag that shows if half processed Jobs should end after the shift ends
# =======================================================================
# initialize for every replications
# =======================================================================
def initialize(self):
ObjectInterruption.initialize(self)
self.remainingShiftPattern=self.shiftPattern
# =======================================================================
# The run method for the failure which has to served by a repairman
# =======================================================================
def run(self):
self.victim.totalOffShiftTime=0
offShiftTime=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)):
self.reactivateVictim() # re-activate the victim in case it was interrupted
#self.victim.totalFailureTime+=now()-offShiftTime
self.victim.onShift=True
self.victim.timeLastShiftStarted=now()
self.outputTrace("is on shift")
startShift=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)):
self.interruptVictim() # interrupt processing operations if any
self.victim.onShift=False # get the victim off-shift
offShiftTime=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