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

first version of ScheduledMaintenance added

parent c625e609
......@@ -26,7 +26,7 @@ Created on 18 Aug 2013
Class that acts as an abstract. It should have no instances. All object interruptions (eg failures, breaks) should inherit from it
'''
from SimPy.Simulation import Process, Resource, reactivate
from SimPy.Simulation import Process, Resource, reactivate, now
class ObjectInterruption(Process):
......@@ -61,4 +61,18 @@ class ObjectInterruption(Process):
def reactivateVictim(self):
reactivate(self.victim)
#outputs message to the trace.xls. Format is (Simulation Time | Victim Name | message)
def outputTrace(self, message):
from Globals import G
if(G.trace=="Yes"): #output only if the user has selected to
#handle the 3 columns
G.traceSheet.write(G.traceIndex,0,str(now()))
G.traceSheet.write(G.traceIndex,1, self.victim.objName)
G.traceSheet.write(G.traceIndex,2,message)
G.traceIndex+=1 #increment the row
#if we reach row 65536 we need to create a new sheet (excel limitation)
if(G.traceIndex==65536):
G.traceIndex=0
G.sheetIndex+=1
G.traceSheet=G.traceFile.add_sheet('sheet '+str(G.sheetIndex), cell_overwrite_ok=True)
\ No newline at end of file
# ===========================================================================
# 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
'''
'''
models an one time scheduled maintenance. It happens and stops at fixed times and it is also deterministic
'''
from SimPy.Simulation import now, Process, hold, request, release, infinity
from RandomNumberGenerator import RandomNumberGenerator
from ObjectInterruption import ObjectInterruption
class ScheduledMaintenance(ObjectInterruption):
def __init__(self, victim=None, start=0, duration=1):
ObjectInterruption.__init__(self,victim)
self.start=start
self.duration=duration
def run(self):
yield hold,self,self.start #wait until the start time
try:
if(len(self.getVictimQueue())>0): # when a Machine gets failure
self.interruptVictim() # while in process it is interrupted
self.victim.Up=False
self.victim.timeLastFailure=now()
self.outputTrace("is down")
except AttributeError:
print "AttributeError1"
yield hold,self,self.duration #wait until the start time
self.victim.totalFailureTime+=self.duration
try:
if(len(self.getVictimQueue())>0):
self.reactivateVictim() # since the maintenance is over, the victim is reactivated
self.victim.Up=True
self.outputTrace("is up")
except AttributeError:
print "AttributeError2"
\ No newline at end of file
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