Commit 084645e4 authored by Georgios Dagkakis's avatar Georgios Dagkakis

added ObjectResource generic class. Repairman inherits from it

parent 8a3d8ac2
# ===========================================================================
# Copyright 2013 Georgios Dagkakis
#
# 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 18 Aug 2013
@author: George
'''
'''
Class that acts as an abstract. It should have no instances. All the Resources should inherit from it
'''
from SimPy.Simulation import Resource
#the resource that repairs the machines
class ObjectResource(object):
def initialize(self):
self.totalWorkingTime=0 #holds the total working time
self.totalWaitingTime=0 #holds the total waiting time
self.timeLastRepairStarted=0 #holds the time that the last repair was started
self.Res=Resource(self.capacity)
#checks if the worker is available
def checkIfResourceIsAvailable(self):
return len(self.W.activeQ)<self.capacity
#actions to be taken after the simulation ends
def postProcessing(self, MaxSimtime):
pass
#outputs message to the trace.xls
def outputTrace(self, message):
pass
#outputs data to "output.xls"
def outputResultsXL(self, MaxSimtime):
pass
#outputs results to JSON File
def outputResultsJSON(self):
pass
#takes the array and checks if all its values are identical (returns false) or not (returns true)
#needed because if somebody runs multiple runs in deterministic case it would crash!
def checkIfArrayHasDifValues(self, array):
difValuesFlag=False
for i in range(1, len(array)):
if(array[i]!=array[1]):
difValuesFlag=True
return difValuesFlag
\ No newline at end of file
......@@ -26,12 +26,13 @@ Created on 14 Nov 2012
models a repairman that can fix a machine when it gets failures
'''
from SimPy.Simulation import *
from SimPy.Simulation import Resource
import xlwt
import scipy.stats as stat
from ObjectResource import ObjectResource
#the resource that repairs the machines
class Repairman(object):
class Repairman(ObjectResource):
def __init__(self, id, name, capacity):
self.id=id
......@@ -45,16 +46,7 @@ class Repairman(object):
self.coreObjectIds=[] #list with the coreObjects that the repairman repairs
def initialize(self):
self.totalWorkingTime=0 #holds the total working time
self.totalWaitingTime=0 #holds the total waiting time
self.timeLastRepairStarted=0 #holds the time that the last repair was started
self.Res=Resource(self.capacity)
#checks if the worker is available
def checkIfWorkerIsAvailable(self):
return len(self.W.activeQ)<self.capacity
#actions to be taken after the simulation ends
def postProcessing(self, MaxSimtime):
#if the repairman is currently working we have to count the time of this work
......@@ -144,11 +136,3 @@ class Repairman(object):
G.outputJSON['elementList'].append(json)
#takes the array and checks if all its values are identical (returns false) or not (returns true)
#needed because if somebody runs multiple runs in deterministic case it would crash!
def checkIfArrayHasDifValues(self, array):
difValuesFlag=False
for i in range(1, len(array)):
if(array[i]!=array[1]):
difValuesFlag=True
return difValuesFlag
\ 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