Commit 47a49af9 authored by Jérome Perrin's avatar Jérome Perrin

Factorize some code to calculate confidence intervals

parent a4fd40f7
...@@ -35,7 +35,7 @@ from CoreObject import CoreObject ...@@ -35,7 +35,7 @@ from CoreObject import CoreObject
#the Assembly object #the Assembly object
class Assembly(CoreObject): class Assembly(CoreObject):
class_name = 'Dream.Assembly'
#initialize the object #initialize the object
def __init__(self, id, name, processingTime=None): def __init__(self, id, name, processingTime=None):
if not processingTime: if not processingTime:
...@@ -257,90 +257,42 @@ class Assembly(CoreObject): ...@@ -257,90 +257,42 @@ class Assembly(CoreObject):
G.outputSheet.write(G.outputIndex,0, "The percentage of Waiting of "+self.objName +" is:") G.outputSheet.write(G.outputIndex,0, "The percentage of Waiting of "+self.objName +" is:")
G.outputSheet.write(G.outputIndex,1,100*self.totalWaitingTime/MaxSimtime) G.outputSheet.write(G.outputIndex,1,100*self.totalWaitingTime/MaxSimtime)
G.outputIndex+=1 G.outputIndex+=1
else: #if we had multiple replications we output confidence intervals to excel
#for some outputs the results may be the same for each run (eg model is stochastic but failures fixed
#so failurePortion will be exactly the same in each run). That will give 0 variability and errors.
#so for each output value we check if there was difference in the runs' results
#if yes we output the Confidence Intervals. if not we output just the fix value
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Working of "+self.objName +" is:")
if self.checkIfArrayHasDifValues(self.Working):
G.outputSheet.write(G.outputIndex,1,stat.bayes_mvs(self.Working, G.confidenceLevel)[0][1][0])
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.Working, G.confidenceLevel)[0][0])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.Working, G.confidenceLevel)[0][1][1])
else: else:
G.outputSheet.write(G.outputIndex,1,self.Working[0]) G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Working of "+ self.objName+" is:")
G.outputSheet.write(G.outputIndex,2,self.Working[0]) working_ci = self.getConfidenceIntervals(self.Working)
G.outputSheet.write(G.outputIndex,3,self.Working[0]) G.outputSheet.write(G.outputIndex, 1, working_ci['min'])
G.outputSheet.write(G.outputIndex, 2, working_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, working_ci['max'])
G.outputIndex+=1 G.outputIndex+=1
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Blockage of "+self.objName +" is:")
if self.checkIfArrayHasDifValues(self.Blockage): G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Blockage of "+ self.objName+" is:")
G.outputSheet.write(G.outputIndex,1,stat.bayes_mvs(self.Blockage, G.confidenceLevel)[0][1][0]) blockage_ci = self.getConfidenceIntervals(self.Blockage)
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.Blockage, G.confidenceLevel)[0][0]) G.outputSheet.write(G.outputIndex, 1, blockage_ci['min'])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.Blockage, G.confidenceLevel)[0][1][1]) G.outputSheet.write(G.outputIndex, 2, blockage_ci['avg'])
else: G.outputSheet.write(G.outputIndex, 3, blockage_ci['max'])
G.outputSheet.write(G.outputIndex,1,self.Blockage[0])
G.outputSheet.write(G.outputIndex,2,self.Blockage[0])
G.outputSheet.write(G.outputIndex,3,self.Blockage[0])
G.outputIndex+=1 G.outputIndex+=1
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Waiting of "+self.objName +" is:")
if self.checkIfArrayHasDifValues(self.Waiting): G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Waiting of "+ self.objName+" is:")
G.outputSheet.write(G.outputIndex,1,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][1][0]) waiting_ci = self.getConfidenceIntervals(self.Waiting)
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][0]) G.outputSheet.write(G.outputIndex, 1, waiting_ci['min'])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][1][1]) G.outputSheet.write(G.outputIndex, 2, waiting_ci['avg'])
else: G.outputSheet.write(G.outputIndex, 3, waiting_ci['max'])
G.outputSheet.write(G.outputIndex,1,self.Waiting[0])
G.outputSheet.write(G.outputIndex,2,self.Waiting[0])
G.outputSheet.write(G.outputIndex,3,self.Waiting[0])
G.outputIndex+=1 G.outputIndex+=1
G.outputIndex+=1 G.outputIndex+=1
#outputs results to JSON File #outputs results to JSON File
def outputResultsJSON(self): def outputResultsJSON(self):
from Globals import G from Globals import G
if(G.numberOfReplications==1): #if we had just one replication output the results to excel json = {'_class': self.class_name,
json={} 'id': self.id,
json['_class'] = 'Dream.Assembly'; 'results': {}}
json['id'] = str(self.id) if(G.numberOfReplications==1):
json['results'] = {}
json['results']['working_ratio']=100*self.totalWorkingTime/G.maxSimTime json['results']['working_ratio']=100*self.totalWorkingTime/G.maxSimTime
json['results']['blockage_ratio']=100*self.totalBlockageTime/G.maxSimTime json['results']['blockage_ratio']=100*self.totalBlockageTime/G.maxSimTime
json['results']['waiting_ratio']=100*self.totalWaitingTime/G.maxSimTime json['results']['waiting_ratio']=100*self.totalWaitingTime/G.maxSimTime
else: #if we had multiple replications we output confidence intervals to excel
#for some outputs the results may be the same for each run (eg model is stochastic but failures fixed
#so failurePortion will be exactly the same in each run). That will give 0 variability and errors.
#so for each output value we check if there was difference in the runs' results
#if yes we output the Confidence Intervals. if not we output just the fix value
json={}
json['_class'] = 'Dream.Assembly'; # TODO: this is the only diff with Machine implementation of this method
json['id'] = str(self.id)
json['results'] = {}
json['results']['working_ratio']={}
if self.checkIfArrayHasDifValues(self.Working):
json['results']['working_ratio']['min']=stat.bayes_mvs(self.Working, G.confidenceLevel)[0][1][0]
json['results']['working_ratio']['avg']=stat.bayes_mvs(self.Working, G.confidenceLevel)[0][0]
json['results']['working_ratio']['max']=stat.bayes_mvs(self.Working, G.confidenceLevel)[0][1][1]
else:
json['results']['working_ratio']['min']=self.Working[0]
json['results']['working_ratio']['avg']=self.Working[0]
json['results']['working_ratio']['max']=self.Working[0]
json['results']['blockage_ratio']={}
if self.checkIfArrayHasDifValues(self.Blockage):
json['results']['blockage_ratio']['min']=stat.bayes_mvs(self.Blockage, G.confidenceLevel)[0][1][0]
json['results']['blockage_ratio']['avg']=stat.bayes_mvs(self.Blockage, G.confidenceLevel)[0][0]
json['results']['blockage_ratio']['max']=stat.bayes_mvs(self.Blockage, G.confidenceLevel)[0][1][1]
else: else:
json['results']['blockage_ratio']['min']=self.Blockage[0] json['results']['working_ratio'] = self.getConfidenceIntervals(self.Working)
json['results']['blockage_ratio']['avg']=self.Blockage[0] json['results']['blockage_ratio'] = self.getConfidenceIntervals(self.Blockage)
json['results']['blockage_ratio']['max']=self.Blockage[0] json['results']['waiting_ratio'] = self.getConfidenceIntervals(self.Waiting)
json['results']['waiting_ratio']={}
if self.checkIfArrayHasDifValues(self.Waiting):
json['results']['waiting_ratio']['min']=stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][1][0]
json['results']['waiting_ratio']['avg']=stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][0]
json['results']['waiting_ratio']['max']=stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][1][1]
else:
json['results']['waiting_ratio']['min']=self.Waiting[0]
json['results']['waiting_ratio']['avg']=self.Waiting[0]
json['results']['waiting_ratio']['max']=self.Waiting[0]
G.outputJSON['elementList'].append(json) G.outputJSON['elementList'].append(json)
...@@ -34,7 +34,7 @@ from CoreObject import CoreObject ...@@ -34,7 +34,7 @@ from CoreObject import CoreObject
#The conveyer object #The conveyer object
class Conveyer(CoreObject): class Conveyer(CoreObject):
class_name = 'Dream.Conveyer'
def __init__(self, id, name, length, speed): def __init__(self, id, name, length, speed):
CoreObject.__init__(self, id, name) CoreObject.__init__(self, id, name)
self.type="Conveyer" self.type="Conveyer"
...@@ -314,73 +314,46 @@ class Conveyer(CoreObject): ...@@ -314,73 +314,46 @@ class Conveyer(CoreObject):
#so for each output value we check if there was difference in the runs' results #so for each output value we check if there was difference in the runs' results
#if yes we output the Confidence Intervals. if not we output just the fix value #if yes we output the Confidence Intervals. if not we output just the fix value
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Working of "+self.objName +" is:") G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Working of "+self.objName +" is:")
if self.checkIfArrayHasDifValues(self.Working): working_ci = self.getConfidenceIntervals(self.Working)
G.outputSheet.write(G.outputIndex,1,stat.bayes_mvs(self.Working, G.confidenceLevel)[0][1][0]) G.outputSheet.write(G.outputIndex, 1, working_ci['min'])
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.Working, G.confidenceLevel)[0][0]) G.outputSheet.write(G.outputIndex, 2, working_ci['avg'])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.Working, G.confidenceLevel)[0][1][1]) G.outputSheet.write(G.outputIndex, 3, working_ci['max'])
else:
G.outputSheet.write(G.outputIndex,1,self.Working[0])
G.outputSheet.write(G.outputIndex,2,self.Working[0])
G.outputSheet.write(G.outputIndex,3,self.Working[0])
G.outputIndex+=1 G.outputIndex+=1
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Blockage of "+self.objName +" is:")
if self.checkIfArrayHasDifValues(self.Blockage): G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Blockage of "+ self.objName+" is:")
G.outputSheet.write(G.outputIndex,1,stat.bayes_mvs(self.Blockage, G.confidenceLevel)[0][1][0]) blockage_ci = self.getConfidenceIntervals(self.Blockage)
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.Blockage, G.confidenceLevel)[0][0]) G.outputSheet.write(G.outputIndex, 1, blockage_ci['min'])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.Blockage, G.confidenceLevel)[0][1][1]) G.outputSheet.write(G.outputIndex, 2, blockage_ci['avg'])
else: G.outputSheet.write(G.outputIndex, 3, blockage_ci['max'])
G.outputSheet.write(G.outputIndex,1,self.Blockage[0])
G.outputSheet.write(G.outputIndex,2,self.Blockage[0])
G.outputSheet.write(G.outputIndex,3,self.Blockage[0])
G.outputIndex+=1 G.outputIndex+=1
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Waiting of "+self.objName +" is:")
if self.checkIfArrayHasDifValues(self.Waiting): G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Waiting of "+ self.objName+" is:")
G.outputSheet.write(G.outputIndex,1,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][1][0]) waiting_ci = self.getConfidenceIntervals(self.Waiting)
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][0]) G.outputSheet.write(G.outputIndex, 1, waiting_ci['min'])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][1][1]) G.outputSheet.write(G.outputIndex, 2, waiting_ci['avg'])
else: G.outputSheet.write(G.outputIndex, 3, waiting_ci['max'])
G.outputSheet.write(G.outputIndex,1,self.Waiting[0])
G.outputSheet.write(G.outputIndex,2,self.Waiting[0])
G.outputSheet.write(G.outputIndex,3,self.Waiting[0])
G.outputIndex+=1 G.outputIndex+=1
G.outputIndex+=1 G.outputIndex+=1
#outputs results to JSON File #outputs results to JSON File
def outputResultsJSON(self): def outputResultsJSON(self):
from Globals import G from Globals import G
json={} json = {'_class': self.class_name,
json['_class'] = 'Dream.Conveyer'; 'id': self.id,
json['id'] = str(self.id) 'results': {}}
json['results'] = {} if (G.numberOfReplications == 1):
if(G.numberOfReplications==1): #if we had just one replication output the results to excel # if we had just one replication output the results as numbers
json['results']['working_ratio']=100*self.totalWorkingTime/G.maxSimTime json['results']['working_ratio']=100*self.totalWorkingTime/G.maxSimTime
json['results']['blockage_ratio']=100*self.totalBlockageTime/G.maxSimTime json['results']['blockage_ratio']=100*self.totalBlockageTime/G.maxSimTime
json['results']['waiting_ratio']=100*self.totalWaitingTime/G.maxSimTime json['results']['waiting_ratio']=100*self.totalWaitingTime/G.maxSimTime
else: #if we had multiple replications we output confidence intervals to excel
#for some outputs the results may be the same for each run (eg model is stochastic but failures fixed
#so failurePortion will be exactly the same in each run). That will give 0 variability and errors.
#so for each output value we check if there was difference in the runs' results
#if yes we output the Confidence Intervals. if not we output just the fix value
for ratio, measureList in (
('failure_ratio', self.Failure),
('working_ratio', self.Working),
('blockage_ratio', self.Blockage),
('waiting_ratio', self.Waiting), ):
json['results'][ratio] = {}
if self.checkIfArrayHasDifValues(measureList):
json['results'][ratio]['min'] = stat.bayes_mvs(
measureList, G.confidenceLevel)[0][1][0]
json['results'][ratio]['avg'] = stat.bayes_mvs(
measureList, G.confidenceLevel)[0][0]
json['results'][ratio]['max'] = stat.bayes_mvs(
measureList, G.confidenceLevel)[0][1][1]
else: else:
json['results'][ratio]['min'] = \ json['results']['working_ratio'] = self.getConfidenceIntervals(self.Working)
json['results'][ratio]['avg'] = \ json['results']['blockage_ratio'] = self.getConfidenceIntervals(self.Blockage)
json['results'][ratio]['max'] = measureList[0] json['results']['waiting_ratio'] = self.getConfidenceIntervals(self.Waiting)
G.outputJSON['elementList'].append(json) G.outputJSON['elementList'].append(json)
#Process that handles the moves of the conveyer #Process that handles the moves of the conveyer
class ConveyerMover(Process): class ConveyerMover(Process):
def __init__(self, conveyer): def __init__(self, conveyer):
......
...@@ -26,6 +26,7 @@ Class that acts as an abstract. It should have no instances. All the core-object ...@@ -26,6 +26,7 @@ Class that acts as an abstract. It should have no instances. All the core-object
''' '''
from SimPy.Simulation import Process, Resource, now from SimPy.Simulation import Process, Resource, now
import scipy.stats as stat
# =========================================================================== # ===========================================================================
# the core object # the core object
...@@ -310,16 +311,19 @@ class CoreObject(Process): ...@@ -310,16 +311,19 @@ class CoreObject(Process):
pass pass
# ======================================================================= # =======================================================================
# takes the array and checks if all its values are identical # Helper method to calculate the min, max and average values of a serie
# (returns false) or not (returns true)needed because if somebody runs
# multiple runs in deterministic case it would crash!
# ======================================================================= # =======================================================================
def checkIfArrayHasDifValues(self, array): def getConfidenceIntervals(self, value_list):
difValuesFlag=False from Globals import G
for i in range(1, len(array)): if len(set(value_list)) == 1:
if(array[i]!=array[1]): # All values are same, no need to perform statistical analysis
difValuesFlag=True return { 'min': value_list[0],
return difValuesFlag 'max': value_list[0],
'avg': value_list[0], }
bayes_mvs = stat.bayes_mvs(value_list, G.confidenceLevel)
return { 'min': bayes_mvs[0][1][0],
'max': bayes_mvs[0][1][1],
'avg': bayes_mvs[0][0], }
# ======================================================================= # =======================================================================
# get the active object. This always returns self # get the active object. This always returns self
......
...@@ -38,6 +38,7 @@ from CoreObject import CoreObject ...@@ -38,6 +38,7 @@ from CoreObject import CoreObject
# the Dismantle object # the Dismantle object
# =========================================================================== # ===========================================================================
class Dismantle(CoreObject): class Dismantle(CoreObject):
class_name = 'Dream.Dismantle'
# ======================================================================= # =======================================================================
# initialize the object # initialize the object
# ======================================================================= # =======================================================================
...@@ -292,40 +293,26 @@ class Dismantle(CoreObject): ...@@ -292,40 +293,26 @@ class Dismantle(CoreObject):
G.outputSheet.write(G.outputIndex,0, "The percentage of Waiting of "+self.objName +" is:") G.outputSheet.write(G.outputIndex,0, "The percentage of Waiting of "+self.objName +" is:")
G.outputSheet.write(G.outputIndex,1,100*self.totalWaitingTime/MaxSimtime) G.outputSheet.write(G.outputIndex,1,100*self.totalWaitingTime/MaxSimtime)
G.outputIndex+=1 G.outputIndex+=1
else: #if we had multiple replications we output confidence intervals to excel
#for some outputs the results may be the same for each run (eg model is stochastic but failures fixed
#so failurePortion will be exactly the same in each run). That will give 0 variability and errors.
#so for each output value we check if there was difference in the runs' results
#if yes we output the Confidence Intervals. if not we output just the fix value
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Working of "+self.objName +" is:")
if self.checkIfArrayHasDifValues(self.Working):
G.outputSheet.write(G.outputIndex,1,stat.bayes_mvs(self.Working, G.confidenceLevel)[0][1][0])
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.Working, G.confidenceLevel)[0][0])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.Working, G.confidenceLevel)[0][1][1])
else: else:
G.outputSheet.write(G.outputIndex,1,self.Working[0]) G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Working of "+ self.objName+" is:")
G.outputSheet.write(G.outputIndex,2,self.Working[0]) working_ci = self.getConfidenceIntervals(self.Working)
G.outputSheet.write(G.outputIndex,3,self.Working[0]) G.outputSheet.write(G.outputIndex, 1, working_ci['min'])
G.outputSheet.write(G.outputIndex, 2, working_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, working_ci['max'])
G.outputIndex+=1 G.outputIndex+=1
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Blockage of "+self.objName +" is:")
if self.checkIfArrayHasDifValues(self.Blockage): G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Blockage of "+ self.objName+" is:")
G.outputSheet.write(G.outputIndex,1,stat.bayes_mvs(self.Blockage, G.confidenceLevel)[0][1][0]) blockage_ci = self.getConfidenceIntervals(self.Blockage)
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.Blockage, G.confidenceLevel)[0][0]) G.outputSheet.write(G.outputIndex, 1, blockage_ci['min'])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.Blockage, G.confidenceLevel)[0][1][1]) G.outputSheet.write(G.outputIndex, 2, blockage_ci['avg'])
else: G.outputSheet.write(G.outputIndex, 3, blockage_ci['max'])
G.outputSheet.write(G.outputIndex,1,self.Blockage[0])
G.outputSheet.write(G.outputIndex,2,self.Blockage[0])
G.outputSheet.write(G.outputIndex,3,self.Blockage[0])
G.outputIndex+=1 G.outputIndex+=1
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Waiting of "+self.objName +" is:")
if self.checkIfArrayHasDifValues(self.Waiting): G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Waiting of "+ self.objName+" is:")
G.outputSheet.write(G.outputIndex,1,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][1][0]) waiting_ci = self.getConfidenceIntervals(self.Waiting)
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][0]) G.outputSheet.write(G.outputIndex, 1, waiting_ci['min'])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][1][1]) G.outputSheet.write(G.outputIndex, 2, waiting_ci['avg'])
else: G.outputSheet.write(G.outputIndex, 3, waiting_ci['max'])
G.outputSheet.write(G.outputIndex,1,self.Waiting[0])
G.outputSheet.write(G.outputIndex,2,self.Waiting[0])
G.outputSheet.write(G.outputIndex,3,self.Waiting[0])
G.outputIndex+=1 G.outputIndex+=1
G.outputIndex+=1 G.outputIndex+=1
...@@ -334,51 +321,15 @@ class Dismantle(CoreObject): ...@@ -334,51 +321,15 @@ class Dismantle(CoreObject):
# ======================================================================= # =======================================================================
def outputResultsJSON(self): def outputResultsJSON(self):
from Globals import G from Globals import G
if(G.numberOfReplications==1): #if we had just one replication output the results to excel json = {'_class': self.class_name,
json={} 'id': self.id,
json['_class'] = 'Dream.Dismantle'; 'results': {}}
json['id'] = str(self.id) if(G.numberOfReplications==1):
json['results'] = {}
json['results']['working_ratio']=100*self.totalWorkingTime/G.maxSimTime json['results']['working_ratio']=100*self.totalWorkingTime/G.maxSimTime
json['results']['blockage_ratio']=100*self.totalBlockageTime/G.maxSimTime json['results']['blockage_ratio']=100*self.totalBlockageTime/G.maxSimTime
json['results']['waiting_ratio']=100*self.totalWaitingTime/G.maxSimTime json['results']['waiting_ratio']=100*self.totalWaitingTime/G.maxSimTime
else: #if we had multiple replications we output confidence intervals to excel
#for some outputs the results may be the same for each run (eg model is stochastic but failures fixed
#so failurePortion will be exactly the same in each run). That will give 0 variability and errors.
#so for each output value we check if there was difference in the runs' results
#if yes we output the Confidence Intervals. if not we output just the fix value
json={}
json['_class'] = 'Dream.Dismantle';
json['id'] = str(self.id)
json['results'] = {}
json['results']['working_ratio']={}
if self.checkIfArrayHasDifValues(self.Working):
json['results']['working_ratio']['min']=stat.bayes_mvs(self.Working, G.confidenceLevel)[0][1][0]
json['results']['working_ratio']['avg']=stat.bayes_mvs(self.Working, G.confidenceLevel)[0][0]
json['results']['working_ratio']['max']=stat.bayes_mvs(self.Working, G.confidenceLevel)[0][1][1]
else: else:
json['results']['working_ratio']['min']=self.Working[0] json['results']['working_ratio'] = self.getConfidenceIntervals(self.Working)
json['results']['working_ratio']['avg']=self.Working[0] json['results']['blockage_ratio'] = self.getConfidenceIntervals(self.Blockage)
json['results']['working_ratio']['max']=self.Working[0] json['results']['waiting_ratio'] = self.getConfidenceIntervals(self.Waiting)
json['results']['blockage_ratio']={}
if self.checkIfArrayHasDifValues(self.Blockage):
json['results']['blockage_ratio']['min']=stat.bayes_mvs(self.Blockage, G.confidenceLevel)[0][1][0]
json['results']['blockage_ratio']['avg']=stat.bayes_mvs(self.Blockage, G.confidenceLevel)[0][0]
json['results']['blockage_ratio']['max']=stat.bayes_mvs(self.Blockage, G.confidenceLevel)[0][1][1]
else:
json['results']['blockage_ratio']['min']=self.Blockage[0]
json['results']['blockage_ratio']['avg']=self.Blockage[0]
json['results']['blockage_ratio']['max']=self.Blockage[0]
json['results']['waiting_ratio']={}
if self.checkIfArrayHasDifValues(self.Waiting):
json['results']['waiting_ratio']['min']=stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][1][0]
json['results']['waiting_ratio']['avg']=stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][0]
json['results']['waiting_ratio']['max']=stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][1][1]
else:
json['results']['waiting_ratio']['min']=self.Waiting[0]
json['results']['waiting_ratio']['avg']=self.Waiting[0]
json['results']['waiting_ratio']['max']=self.Waiting[0]
G.outputJSON['elementList'].append(json) G.outputJSON['elementList'].append(json)
...@@ -33,7 +33,7 @@ from CoreObject import CoreObject ...@@ -33,7 +33,7 @@ from CoreObject import CoreObject
# The exit object # The exit object
# =========================================================================== # ===========================================================================
class Exit(CoreObject): class Exit(CoreObject):
class_name = 'Dream.Exit'
def __init__(self, id, name=None): def __init__(self, id, name=None):
if not name: if not name:
name = id name = id
...@@ -172,35 +172,24 @@ class Exit(CoreObject): ...@@ -172,35 +172,24 @@ class Exit(CoreObject):
#so for each output value we check if there was difference in the runs' results #so for each output value we check if there was difference in the runs' results
#if yes we output the Confidence Intervals. if not we output just the fix value #if yes we output the Confidence Intervals. if not we output just the fix value
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean Throughput in " +self.objName + " is:") G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean Throughput in " +self.objName + " is:")
if self.checkIfArrayHasDifValues(self.Exits): throughput_ci = self.getConfidenceIntervals(self.Exits)
G.outputSheet.write(G.outputIndex,1,stat.bayes_mvs(self.Exits, G.confidenceLevel)[0][1][0]) G.outputSheet.write(G.outputIndex, 1, throughput_ci['min'])
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.Exits, G.confidenceLevel)[0][0]) G.outputSheet.write(G.outputIndex, 2, throughput_ci['avg'])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.Exits, G.confidenceLevel)[0][1][1]) G.outputSheet.write(G.outputIndex, 3, throughput_ci['max'])
else:
G.outputSheet.write(G.outputIndex,1,self.Exits[0])
G.outputSheet.write(G.outputIndex,2,self.Exits[0])
G.outputSheet.write(G.outputIndex,3,self.Exits[0])
G.outputIndex+=1 G.outputIndex+=1
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean Lifespan of an entity that exited from "+ self.objName + " is:") G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean Lifespan of an entity that exited from "+ self.objName + " is:")
if self.checkIfArrayHasDifValues(self.Lifespan): lifespan_ci = self.getConfidenceIntervals(self.Lifespan)
G.outputSheet.write(G.outputIndex,1,stat.bayes_mvs(self.Lifespan, G.confidenceLevel)[0][1][0]) G.outputSheet.write(G.outputIndex, 1, lifespan_ci['min'])
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.Lifespan, G.confidenceLevel)[0][0]) G.outputSheet.write(G.outputIndex, 2, lifespan_ci['avg'])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.Lifespan, G.confidenceLevel)[0][1][1]) G.outputSheet.write(G.outputIndex, 3, lifespan_ci['max'])
else:
G.outputSheet.write(G.outputIndex,1,self.Lifespan[0])
G.outputSheet.write(G.outputIndex,2,self.Lifespan[0])
G.outputSheet.write(G.outputIndex,3,self.Lifespan[0])
G.outputIndex+=1 G.outputIndex+=1
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the avg takt time in "+ self.objName + " is:") G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the avg takt time in "+ self.objName + " is:")
if self.checkIfArrayHasDifValues(self.TaktTime): takt_time_ci = self.getConfidenceIntervals(self.TaktTime)
G.outputSheet.write(G.outputIndex,1,stat.bayes_mvs(self.TaktTime, G.confidenceLevel)[0][1][0]) G.outputSheet.write(G.outputIndex, 1, takt_time_ci['min'])
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.TaktTime, G.confidenceLevel)[0][0]) G.outputSheet.write(G.outputIndex, 2, takt_time_ci['avg'])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.TaktTime, G.confidenceLevel)[0][1][1]) G.outputSheet.write(G.outputIndex, 3, takt_time_ci['max'])
else:
G.outputSheet.write(G.outputIndex,1,self.TaktTime[0])
G.outputSheet.write(G.outputIndex,2,self.TaktTime[0])
G.outputSheet.write(G.outputIndex,3,self.TaktTime[0])
G.outputIndex+=1 G.outputIndex+=1
G.outputIndex+=1 G.outputIndex+=1
# ======================================================================= # =======================================================================
...@@ -208,11 +197,10 @@ class Exit(CoreObject): ...@@ -208,11 +197,10 @@ class Exit(CoreObject):
# ======================================================================= # =======================================================================
def outputResultsJSON(self): def outputResultsJSON(self):
from Globals import G from Globals import G
if(G.numberOfReplications==1): #if we had just one replication output the results to excel json = { '_class': self.class_name,
json={} 'id': self.id,
json['_class'] = 'Dream.Exit'; 'results': {} }
json['id'] = str(self.id) if(G.numberOfReplications==1):
json['results'] = {}
json['results']['throughput']=self.numOfExits json['results']['throughput']=self.numOfExits
if self.totalNumberOfUnitsExited!=self.numOfExits: #output this only if there was variability in units if self.totalNumberOfUnitsExited!=self.numOfExits: #output this only if there was variability in units
json['results']['unitsThroughput']=self.totalNumberOfUnitsExited json['results']['unitsThroughput']=self.totalNumberOfUnitsExited
...@@ -221,51 +209,11 @@ class Exit(CoreObject): ...@@ -221,51 +209,11 @@ class Exit(CoreObject):
json['results']['intervalThroughputList']=self.intervalThroughPutList json['results']['intervalThroughputList']=self.intervalThroughPutList
json['results']['lifespan']=self.Lifespan[0] json['results']['lifespan']=self.Lifespan[0]
json['results']['takt_time']=self.TaktTime[0] json['results']['takt_time']=self.TaktTime[0]
else: #if we had multiple replications we output confidence intervals to excel
#for some outputs the results may be the same for each run (eg model is stochastic but failures fixed
#so failurePortion will be exactly the same in each run). That will give 0 variability and errors.
#so for each output value we check if there was difference in the runs' results
#if yes we output the Confidence Intervals. if not we output just the fix value
json={}
json['_class'] = 'Dream.Exit';
json['id'] = str(self.id)
json['results'] = {}
json['results']['throughput']={}
if self.checkIfArrayHasDifValues(self.Exits):
json['results']['throughput']['min']=stat.bayes_mvs(self.Exits, G.confidenceLevel)[0][1][0]
json['results']['throughput']['avg']=stat.bayes_mvs(self.Exits, G.confidenceLevel)[0][0]
json['results']['throughput']['max']=stat.bayes_mvs(self.Exits, G.confidenceLevel)[0][1][1]
else: else:
json['results']['throughput']['min']=self.Exits[0] json['results']['throughput'] = self.getConfidenceIntervals(self.Exits)
json['results']['throughput']['avg']=self.Exits[0] json['results']['lifespan'] = self.getConfidenceIntervals(self.Lifespan)
json['results']['throughput']['max']=self.Exits[0] json['results']['takt_time'] = self.getConfidenceIntervals(self.TaktTime)
if self.Exits!=self.UnitExits: #output this only if there was variability in units if self.Exits!=self.UnitExits: #output this only if there was variability in units
json['results']['unitsThroughput']={} json['results']['unitsThroughput'] = self.getConfidenceIntervals(self.UnitExits)
if self.checkIfArrayHasDifValues(self.UnitExits):
json['results']['unitsThroughput']['min']=stat.bayes_mvs(self.UnitExits, G.confidenceLevel)[0][1][0]
json['results']['unitsThroughput']['avg']=stat.bayes_mvs(self.UnitExits, G.confidenceLevel)[0][0]
json['results']['unitsThroughput']['max']=stat.bayes_mvs(self.UnitExits, G.confidenceLevel)[0][1][1]
else:
json['results']['unitsThroughput']['min']=self.UnitExits[0]
json['results']['unitsThroughput']['avg']=self.UnitExits[0]
json['results']['unitsThroughput']['max']=self.UnitExits[0]
json['results']['lifespan']={}
if self.checkIfArrayHasDifValues(self.Lifespan):
json['results']['lifespan']['min']=stat.bayes_mvs(self.Lifespan, G.confidenceLevel)[0][1][0]
json['results']['lifespan']['avg']=stat.bayes_mvs(self.Lifespan, G.confidenceLevel)[0][0]
json['results']['lifespan']['max']=stat.bayes_mvs(self.Lifespan, G.confidenceLevel)[0][1][1]
else:
json['results']['lifespan']['min']=self.Lifespan[0]
json['results']['lifespan']['avg']=self.Lifespan[0]
json['results']['lifespan']['max']=self.Lifespan[0]
json['results']['taktTime']={}
if self.checkIfArrayHasDifValues(self.TaktTime):
json['results']['taktTime']['min']=stat.bayes_mvs(self.TaktTime, G.confidenceLevel)[0][1][0]
json['results']['taktTime']['avg']=stat.bayes_mvs(self.TaktTime, G.confidenceLevel)[0][0]
json['results']['taktTime']['max']=stat.bayes_mvs(self.TaktTime, G.confidenceLevel)[0][1][1]
else:
json['results']['taktTime']['min']=self.TaktTime[0]
json['results']['taktTime']['avg']=self.TaktTime[0]
json['results']['taktTime']['max']=self.TaktTime[0]
G.outputJSON['elementList'].append(json) G.outputJSON['elementList'].append(json)
...@@ -43,6 +43,7 @@ import scipy.stats as stat ...@@ -43,6 +43,7 @@ import scipy.stats as stat
# the Machine object # the Machine object
# =========================================================================== # ===========================================================================
class Machine(CoreObject): class Machine(CoreObject):
class_name = 'Dream.Machine'
# ======================================================================= # =======================================================================
# initialise the id the capacity, of the resource and the distribution # initialise the id the capacity, of the resource and the distribution
# ======================================================================= # =======================================================================
...@@ -880,47 +881,31 @@ class Machine(CoreObject): ...@@ -880,47 +881,31 @@ class Machine(CoreObject):
#if yes we output the Confidence Intervals. if not we output just the fix value #if yes we output the Confidence Intervals. if not we output just the fix value
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Failure of "+ self.objName+" is:") G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Failure of "+ self.objName+" is:")
if self.checkIfArrayHasDifValues(self.Failure): failure_ci = self.getConfidenceIntervals(self.Failure)
G.outputSheet.write(G.outputIndex,1,stat.bayes_mvs(self.Failure, G.confidenceLevel)[0][1][0]) G.outputSheet.write(G.outputIndex, 1, failure_ci['min'])
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.Failure, G.confidenceLevel)[0][0]) G.outputSheet.write(G.outputIndex, 2, failure_ci['avg'])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.Failure, G.confidenceLevel)[0][1][1]) G.outputSheet.write(G.outputIndex, 3, failure_ci['max'])
else:
G.outputSheet.write(G.outputIndex,1,self.Failure[0])
G.outputSheet.write(G.outputIndex,2,self.Failure[0])
G.outputSheet.write(G.outputIndex,3,self.Failure[0])
G.outputIndex+=1 G.outputIndex+=1
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Working of "+ self.objName+" is:")
if self.checkIfArrayHasDifValues(self.Working):
G.outputSheet.write(G.outputIndex,1,stat.bayes_mvs(self.Working, G.confidenceLevel)[0][1][0])
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.Working, G.confidenceLevel)[0][0])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.Working, G.confidenceLevel)[0][1][1])
else:
G.outputSheet.write(G.outputIndex,1,self.Working[0])
G.outputSheet.write(G.outputIndex,2,self.Working[0])
G.outputSheet.write(G.outputIndex,3,self.Working[0])
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Working of "+ self.objName+" is:")
working_ci = self.getConfidenceIntervals(self.Working)
G.outputSheet.write(G.outputIndex, 1, working_ci['min'])
G.outputSheet.write(G.outputIndex, 2, working_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, working_ci['max'])
G.outputIndex+=1 G.outputIndex+=1
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Blockage of "+ self.objName+" is:")
if self.checkIfArrayHasDifValues(self.Blockage):
G.outputSheet.write(G.outputIndex,1,stat.bayes_mvs(self.Blockage, G.confidenceLevel)[0][1][0])
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.Blockage, G.confidenceLevel)[0][0])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.Blockage, G.confidenceLevel)[0][1][1])
else:
G.outputSheet.write(G.outputIndex,1,self.Blockage[0])
G.outputSheet.write(G.outputIndex,2,self.Blockage[0])
G.outputSheet.write(G.outputIndex,3,self.Blockage[0])
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Blockage of "+ self.objName+" is:")
blockage_ci = self.getConfidenceIntervals(self.Blockage)
G.outputSheet.write(G.outputIndex, 1, blockage_ci['min'])
G.outputSheet.write(G.outputIndex, 2, blockage_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, blockage_ci['max'])
G.outputIndex+=1 G.outputIndex+=1
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Waiting of "+ self.objName+" is:") G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Waiting of "+ self.objName+" is:")
if self.checkIfArrayHasDifValues(self.Waiting): waiting_ci = self.getConfidenceIntervals(self.Waiting)
G.outputSheet.write(G.outputIndex,1,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][1][0]) G.outputSheet.write(G.outputIndex, 1, waiting_ci['min'])
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][0]) G.outputSheet.write(G.outputIndex, 2, waiting_ci['avg'])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][1][1]) G.outputSheet.write(G.outputIndex, 3, waiting_ci['max'])
else:
G.outputSheet.write(G.outputIndex,1,self.Waiting[0])
G.outputSheet.write(G.outputIndex,2,self.Waiting[0])
G.outputSheet.write(G.outputIndex,3,self.Waiting[0])
G.outputIndex+=1 G.outputIndex+=1
G.outputIndex+=1 G.outputIndex+=1
...@@ -929,11 +914,11 @@ class Machine(CoreObject): ...@@ -929,11 +914,11 @@ class Machine(CoreObject):
# ======================================================================= # =======================================================================
def outputResultsJSON(self): def outputResultsJSON(self):
from Globals import G from Globals import G
if(G.numberOfReplications==1): #if we had just one replication output the results to excel json = {'_class': self.class_name,
json={} 'id': self.id,
json['_class'] = 'Dream.Machine'; 'results': {}}
json['id'] = str(self.id) if (G.numberOfReplications == 1):
json['results'] = {} # if we had just one replication output the results as numbers
json['results']['failure_ratio']=100*self.totalFailureTime/G.maxSimTime json['results']['failure_ratio']=100*self.totalFailureTime/G.maxSimTime
json['results']['working_ratio']=100*self.totalWorkingTime/G.maxSimTime json['results']['working_ratio']=100*self.totalWorkingTime/G.maxSimTime
json['results']['blockage_ratio']=100*self.totalBlockageTime/G.maxSimTime json['results']['blockage_ratio']=100*self.totalBlockageTime/G.maxSimTime
...@@ -945,35 +930,14 @@ class Machine(CoreObject): ...@@ -945,35 +930,14 @@ class Machine(CoreObject):
json['results']['setup_ratio']=100*self.totalSetupTime/G.maxSimTime json['results']['setup_ratio']=100*self.totalSetupTime/G.maxSimTime
if any(type=='Load' for type in self.multOperationTypeList): if any(type=='Load' for type in self.multOperationTypeList):
json['results']['load_ratio']=100*self.totalLoadTime/G.maxSimTime json['results']['load_ratio']=100*self.totalLoadTime/G.maxSimTime
else: #if we had multiple replications we output confidence intervals to excel
#for some outputs the results may be the same for each run (eg model is stochastic but failures fixed
#so failurePortion will be exactly the same in each run). That will give 0 variability and errors.
#so for each output value we check if there was difference in the runs' results
#if yes we output the Confidence Intervals. if not we output just the fix value
# TODO: update the following with the setup- and load- times
json={}
json['_class'] = 'Dream.Machine';
json['id'] = str(self.id)
json['results'] = {}
for ratio, measureList in (
('failure_ratio', self.Failure),
('working_ratio', self.Working),
('blockage_ratio', self.Blockage),
('waiting_ratio', self.Waiting),
('off_shift_ratio', self.OffShift), ):
json['results'][ratio] = {}
if self.checkIfArrayHasDifValues(measureList):
json['results'][ratio]['min'] = stat.bayes_mvs(
measureList, G.confidenceLevel)[0][1][0]
json['results'][ratio]['avg'] = stat.bayes_mvs(
measureList, G.confidenceLevel)[0][0]
json['results'][ratio]['max'] = stat.bayes_mvs(
measureList, G.confidenceLevel)[0][1][1]
else: else:
json['results'][ratio]['min'] = \ json['results']['failure_ratio'] = self.getConfidenceIntervals(self.Failure)
json['results'][ratio]['avg'] = \ json['results']['working_ratio'] = self.getConfidenceIntervals(self.Working)
json['results'][ratio]['max'] = measureList[0] json['results']['blockage_ratio'] = self.getConfidenceIntervals(self.Blockage)
json['results']['waiting_ratio'] = self.getConfidenceIntervals(self.Waiting)
json['results']['off_shift_ratio'] = self.getConfidenceIntervals(self.OffShift)
json['results']['setup_ratio'] = self.getConfidenceIntervals(self.SettingUp)
json['results']['loading_ratio'] = self.getConfidenceIntervals(self.Loading)
G.outputJSON['elementList'].append(json) G.outputJSON['elementList'].append(json)
...@@ -72,18 +72,6 @@ class ObjectResource(object): ...@@ -72,18 +72,6 @@ class ObjectResource(object):
def outputResultsJSON(self): def outputResultsJSON(self):
pass 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
# ======================================================================= # =======================================================================
# returns the resource # returns the resource
# ======================================================================= # =======================================================================
......
...@@ -33,6 +33,7 @@ from Repairman import Repairman ...@@ -33,6 +33,7 @@ from Repairman import Repairman
# the resource that operates the machines # the resource that operates the machines
# =========================================================================== # ===========================================================================
class Operator(Repairman): # XXX isn't it the other way around ? class Operator(Repairman): # XXX isn't it the other way around ?
class_name = 'Dream.Operator'
def __init__(self, id, name, capacity=1, schedulingRule="FIFO"): def __init__(self, id, name, capacity=1, schedulingRule="FIFO"):
Repairman.__init__(self, id=id, name=name, capacity=capacity) Repairman.__init__(self, id=id, name=name, capacity=capacity)
......
...@@ -35,7 +35,7 @@ from ObjectResource import ObjectResource ...@@ -35,7 +35,7 @@ from ObjectResource import ObjectResource
# the resource that repairs the machines # the resource that repairs the machines
# =========================================================================== # ===========================================================================
class Repairman(ObjectResource): class Repairman(ObjectResource):
class_name = 'Dream.Repairman'
def __init__(self, id, name, capacity=1): def __init__(self, id, name, capacity=1):
ObjectResource.__init__(self) ObjectResource.__init__(self)
self.id=id self.id=id
...@@ -90,25 +90,18 @@ class Repairman(ObjectResource): ...@@ -90,25 +90,18 @@ class Repairman(ObjectResource):
# so for each output value we check if there was difference in the runs' results # so for each output value we check if there was difference in the runs' results
# if yes we output the Confidence Intervals. if not we output just the fix value # if yes we output the Confidence Intervals. if not we output just the fix value
else: else:
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Working of "+self.objName +" is:") G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Working of "+ self.objName+" is:")
if self.checkIfArrayHasDifValues(self.Working): working_ci = self.getConfidenceIntervals(self.Working)
G.outputSheet.write(G.outputIndex,1,stat.bayes_mvs(self.Working, G.confidenceLevel)[0][1][0]) G.outputSheet.write(G.outputIndex, 1, working_ci['min'])
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.Working, G.confidenceLevel)[0][0]) G.outputSheet.write(G.outputIndex, 2, working_ci['avg'])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.Working, G.confidenceLevel)[0][1][1]) G.outputSheet.write(G.outputIndex, 3, working_ci['max'])
else:
G.outputSheet.write(G.outputIndex,1,self.Working[0])
G.outputSheet.write(G.outputIndex,2,self.Working[0])
G.outputSheet.write(G.outputIndex,3,self.Working[0])
G.outputIndex+=1 G.outputIndex+=1
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Waiting of "+self.objName +" is:")
if self.checkIfArrayHasDifValues(self.Waiting): G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Waiting of "+ self.objName+" is:")
G.outputSheet.write(G.outputIndex,1,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][1][0]) waiting_ci = self.getConfidenceIntervals(self.Waiting)
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][0]) G.outputSheet.write(G.outputIndex, 1, waiting_ci['min'])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][1][1]) G.outputSheet.write(G.outputIndex, 2, waiting_ci['avg'])
else: G.outputSheet.write(G.outputIndex, 3, waiting_ci['max'])
G.outputSheet.write(G.outputIndex,1,self.Waiting[0])
G.outputSheet.write(G.outputIndex,2,self.Waiting[0])
G.outputSheet.write(G.outputIndex,3,self.Waiting[0])
G.outputIndex+=1 G.outputIndex+=1
G.outputIndex+=1 G.outputIndex+=1
...@@ -117,42 +110,13 @@ class Repairman(ObjectResource): ...@@ -117,42 +110,13 @@ class Repairman(ObjectResource):
# ======================================================================= # =======================================================================
def outputResultsJSON(self): def outputResultsJSON(self):
from Globals import G from Globals import G
# if we had just one replication output the results to JSON json = {'_class': self.class_name,
'id': self.id,
'results': {}}
if(G.numberOfReplications==1): if(G.numberOfReplications==1):
json={}
json['_class'] = 'Dream.'+self.type;
json['id'] = str(self.id)
json['results'] = {}
json['results']['working_ratio']=100*self.totalWorkingTime/G.maxSimTime json['results']['working_ratio']=100*self.totalWorkingTime/G.maxSimTime
json['results']['waiting_ratio']=100*self.totalWaitingTime/G.maxSimTime json['results']['waiting_ratio']=100*self.totalWaitingTime/G.maxSimTime
#if we had multiple replications we output confidence intervals to excel
# for some outputs the results may be the same for each run (eg model is stochastic but failures fixed
# so failurePortion will be exactly the same in each run). That will give 0 variability and errors.
# so for each output value we check if there was difference in the runs' results
# if yes we output the Confidence Intervals. if not we output just the fix value
else:
json={}
json['_class'] = 'Dream.Repairman';
json['id'] = str(self.id)
json['results'] = {}
json['results']['working_ratio']={}
if self.checkIfArrayHasDifValues(self.Working):
json['results']['working_ratio']['min']=stat.bayes_mvs(self.Working, G.confidenceLevel)[0][1][0]
json['results']['working_ratio']['avg']=stat.bayes_mvs(self.Working, G.confidenceLevel)[0][0]
json['results']['working_ratio']['max']=stat.bayes_mvs(self.Working, G.confidenceLevel)[0][1][1]
else: else:
json['results']['working_ratio']['min']=self.Working[0] json['results']['working_ratio'] = self.getConfidenceIntervals(self.Working)
json['results']['working_ratio']['avg']=self.Working[0] json['results']['waiting_ratio'] = self.getConfidenceIntervals(self.Waiting)
json['results']['working_ratio']['max']=self.Working[0]
json['results']['waiting_ratio']={}
if self.checkIfArrayHasDifValues(self.Waiting):
json['results']['waiting_ratio']['min']=stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][1][0]
json['results']['waiting_ratio']['avg']=stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][0]
json['results']['waiting_ratio']['max']=stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][1][1]
else:
json['results']['waiting_ratio']['min']=self.Waiting[0]
json['results']['waiting_ratio']['avg']=self.Waiting[0]
json['results']['waiting_ratio']['max']=self.Waiting[0]
G.outputJSON['elementList'].append(json) G.outputJSON['elementList'].append(json)
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