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
#the Assembly object
class Assembly(CoreObject):
class_name = 'Dream.Assembly'
#initialize the object
def __init__(self, id, name, processingTime=None):
if not processingTime:
......@@ -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,1,100*self.totalWaitingTime/MaxSimtime)
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:
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])
else:
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.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.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,1,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][1][0])
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][0])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][1][1])
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.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Waiting of "+ self.objName+" is:")
waiting_ci = self.getConfidenceIntervals(self.Waiting)
G.outputSheet.write(G.outputIndex, 1, waiting_ci['min'])
G.outputSheet.write(G.outputIndex, 2, waiting_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, waiting_ci['max'])
G.outputIndex+=1
G.outputIndex+=1
#outputs results to JSON File
def outputResultsJSON(self):
from Globals import G
if(G.numberOfReplications==1): #if we had just one replication output the results to excel
json={}
json['_class'] = 'Dream.Assembly';
json['id'] = str(self.id)
json['results'] = {}
json = {'_class': self.class_name,
'id': self.id,
'results': {}}
if(G.numberOfReplications==1):
json['results']['working_ratio']=100*self.totalWorkingTime/G.maxSimTime
json['results']['blockage_ratio']=100*self.totalBlockageTime/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:
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]
else:
json['results']['working_ratio'] = self.getConfidenceIntervals(self.Working)
json['results']['blockage_ratio'] = self.getConfidenceIntervals(self.Blockage)
json['results']['waiting_ratio'] = self.getConfidenceIntervals(self.Waiting)
G.outputJSON['elementList'].append(json)
......@@ -34,7 +34,7 @@ from CoreObject import CoreObject
#The conveyer object
class Conveyer(CoreObject):
class_name = 'Dream.Conveyer'
def __init__(self, id, name, length, speed):
CoreObject.__init__(self, id, name)
self.type="Conveyer"
......@@ -314,73 +314,46 @@ class Conveyer(CoreObject):
#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:
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])
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.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.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,1,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][1][0])
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][0])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][1][1])
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.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Waiting of "+ self.objName+" is:")
waiting_ci = self.getConfidenceIntervals(self.Waiting)
G.outputSheet.write(G.outputIndex, 1, waiting_ci['min'])
G.outputSheet.write(G.outputIndex, 2, waiting_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, waiting_ci['max'])
G.outputIndex+=1
G.outputIndex+=1
G.outputIndex+=1
#outputs results to JSON File
def outputResultsJSON(self):
from Globals import G
json={}
json['_class'] = 'Dream.Conveyer';
json['id'] = str(self.id)
json['results'] = {}
if(G.numberOfReplications==1): #if we had just one replication output the results to excel
json = {'_class': self.class_name,
'id': self.id,
'results': {}}
if (G.numberOfReplications == 1):
# if we had just one replication output the results as numbers
json['results']['working_ratio']=100*self.totalWorkingTime/G.maxSimTime
json['results']['blockage_ratio']=100*self.totalBlockageTime/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:
json['results'][ratio]['min'] = \
json['results'][ratio]['avg'] = \
json['results'][ratio]['max'] = measureList[0]
else:
json['results']['working_ratio'] = self.getConfidenceIntervals(self.Working)
json['results']['blockage_ratio'] = self.getConfidenceIntervals(self.Blockage)
json['results']['waiting_ratio'] = self.getConfidenceIntervals(self.Waiting)
G.outputJSON['elementList'].append(json)
#Process that handles the moves of the conveyer
class ConveyerMover(Process):
def __init__(self, conveyer):
......
......@@ -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
import scipy.stats as stat
# ===========================================================================
# the core object
......@@ -308,18 +309,21 @@ class CoreObject(Process):
# =======================================================================
def sortEntities(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
# Helper method to calculate the min, max and average values of a serie
# =======================================================================
def getConfidenceIntervals(self, value_list):
from Globals import G
if len(set(value_list)) == 1:
# All values are same, no need to perform statistical analysis
return { 'min': value_list[0],
'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
......
......@@ -38,6 +38,7 @@ from CoreObject import CoreObject
# the Dismantle object
# ===========================================================================
class Dismantle(CoreObject):
class_name = 'Dream.Dismantle'
# =======================================================================
# initialize the object
# =======================================================================
......@@ -292,93 +293,43 @@ class Dismantle(CoreObject):
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.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:
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])
else:
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.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.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,1,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][1][0])
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][0])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][1][1])
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.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Waiting of "+ self.objName+" is:")
waiting_ci = self.getConfidenceIntervals(self.Waiting)
G.outputSheet.write(G.outputIndex, 1, waiting_ci['min'])
G.outputSheet.write(G.outputIndex, 2, waiting_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, waiting_ci['max'])
G.outputIndex+=1
G.outputIndex+=1
G.outputIndex+=1
# =======================================================================
# outputs results to JSON File
# =======================================================================
def outputResultsJSON(self):
from Globals import G
if(G.numberOfReplications==1): #if we had just one replication output the results to excel
json={}
json['_class'] = 'Dream.Dismantle';
json['id'] = str(self.id)
json['results'] = {}
json = {'_class': self.class_name,
'id': self.id,
'results': {}}
if(G.numberOfReplications==1):
json['results']['working_ratio']=100*self.totalWorkingTime/G.maxSimTime
json['results']['blockage_ratio']=100*self.totalBlockageTime/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:
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:
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]
else:
json['results']['working_ratio'] = self.getConfidenceIntervals(self.Working)
json['results']['blockage_ratio'] = self.getConfidenceIntervals(self.Blockage)
json['results']['waiting_ratio'] = self.getConfidenceIntervals(self.Waiting)
G.outputJSON['elementList'].append(json)
......@@ -32,8 +32,8 @@ from CoreObject import CoreObject
# ===========================================================================
# The exit object
# ===========================================================================
class Exit(CoreObject):
class Exit(CoreObject):
class_name = 'Dream.Exit'
def __init__(self, id, name=None):
if not name:
name = id
......@@ -172,35 +172,24 @@ class Exit(CoreObject):
#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 Throughput in " +self.objName + " is:")
if self.checkIfArrayHasDifValues(self.Exits):
G.outputSheet.write(G.outputIndex,1,stat.bayes_mvs(self.Exits, G.confidenceLevel)[0][1][0])
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.Exits, G.confidenceLevel)[0][0])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.Exits, G.confidenceLevel)[0][1][1])
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])
throughput_ci = self.getConfidenceIntervals(self.Exits)
G.outputSheet.write(G.outputIndex, 1, throughput_ci['min'])
G.outputSheet.write(G.outputIndex, 2, throughput_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, throughput_ci['max'])
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:")
if self.checkIfArrayHasDifValues(self.Lifespan):
G.outputSheet.write(G.outputIndex,1,stat.bayes_mvs(self.Lifespan, G.confidenceLevel)[0][1][0])
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.Lifespan, G.confidenceLevel)[0][0])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.Lifespan, G.confidenceLevel)[0][1][1])
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.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean Lifespan of an entity that exited from "+ self.objName + " is:")
lifespan_ci = self.getConfidenceIntervals(self.Lifespan)
G.outputSheet.write(G.outputIndex, 1, lifespan_ci['min'])
G.outputSheet.write(G.outputIndex, 2, lifespan_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, lifespan_ci['max'])
G.outputIndex+=1
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):
G.outputSheet.write(G.outputIndex,1,stat.bayes_mvs(self.TaktTime, G.confidenceLevel)[0][1][0])
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.TaktTime, G.confidenceLevel)[0][0])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.TaktTime, G.confidenceLevel)[0][1][1])
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.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the avg takt time in "+ self.objName + " is:")
takt_time_ci = self.getConfidenceIntervals(self.TaktTime)
G.outputSheet.write(G.outputIndex, 1, takt_time_ci['min'])
G.outputSheet.write(G.outputIndex, 2, takt_time_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, takt_time_ci['max'])
G.outputIndex+=1
G.outputIndex+=1
# =======================================================================
......@@ -208,11 +197,10 @@ class Exit(CoreObject):
# =======================================================================
def outputResultsJSON(self):
from Globals import G
if(G.numberOfReplications==1): #if we had just one replication output the results to excel
json={}
json['_class'] = 'Dream.Exit';
json['id'] = str(self.id)
json['results'] = {}
json = { '_class': self.class_name,
'id': self.id,
'results': {} }
if(G.numberOfReplications==1):
json['results']['throughput']=self.numOfExits
if self.totalNumberOfUnitsExited!=self.numOfExits: #output this only if there was variability in units
json['results']['unitsThroughput']=self.totalNumberOfUnitsExited
......@@ -220,52 +208,12 @@ class Exit(CoreObject):
#TODO - check how to output in stochastic cases
json['results']['intervalThroughputList']=self.intervalThroughPutList
json['results']['lifespan']=self.Lifespan[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:
json['results']['throughput']['min']=self.Exits[0]
json['results']['throughput']['avg']=self.Exits[0]
json['results']['throughput']['max']=self.Exits[0]
json['results']['takt_time']=self.TaktTime[0]
else:
json['results']['throughput'] = self.getConfidenceIntervals(self.Exits)
json['results']['lifespan'] = self.getConfidenceIntervals(self.Lifespan)
json['results']['takt_time'] = self.getConfidenceIntervals(self.TaktTime)
if self.Exits!=self.UnitExits: #output this only if there was variability in units
json['results']['unitsThroughput']={}
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]
json['results']['unitsThroughput'] = self.getConfidenceIntervals(self.UnitExits)
G.outputJSON['elementList'].append(json)
......@@ -43,6 +43,7 @@ import scipy.stats as stat
# the Machine object
# ===========================================================================
class Machine(CoreObject):
class_name = 'Dream.Machine'
# =======================================================================
# initialise the id the capacity, of the resource and the distribution
# =======================================================================
......@@ -880,60 +881,44 @@ class Machine(CoreObject):
#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:")
if self.checkIfArrayHasDifValues(self.Failure):
G.outputSheet.write(G.outputIndex,1,stat.bayes_mvs(self.Failure, G.confidenceLevel)[0][1][0])
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.Failure, G.confidenceLevel)[0][0])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.Failure, G.confidenceLevel)[0][1][1])
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
failure_ci = self.getConfidenceIntervals(self.Failure)
G.outputSheet.write(G.outputIndex, 1, failure_ci['min'])
G.outputSheet.write(G.outputIndex, 2, failure_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, failure_ci['max'])
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.outputIndex+=1
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.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.outputIndex+=1
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.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,1,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][1][0])
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][0])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][1][1])
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
waiting_ci = self.getConfidenceIntervals(self.Waiting)
G.outputSheet.write(G.outputIndex, 1, waiting_ci['min'])
G.outputSheet.write(G.outputIndex, 2, waiting_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, waiting_ci['max'])
G.outputIndex+=1
G.outputIndex+=1
# =======================================================================
# outputs results to JSON File
# =======================================================================
def outputResultsJSON(self):
from Globals import G
if(G.numberOfReplications==1): #if we had just one replication output the results to excel
json={}
json['_class'] = 'Dream.Machine';
json['id'] = str(self.id)
json['results'] = {}
json = {'_class': self.class_name,
'id': self.id,
'results': {}}
if (G.numberOfReplications == 1):
# if we had just one replication output the results as numbers
json['results']['failure_ratio']=100*self.totalFailureTime/G.maxSimTime
json['results']['working_ratio']=100*self.totalWorkingTime/G.maxSimTime
json['results']['blockage_ratio']=100*self.totalBlockageTime/G.maxSimTime
......@@ -945,35 +930,14 @@ class Machine(CoreObject):
json['results']['setup_ratio']=100*self.totalSetupTime/G.maxSimTime
if any(type=='Load' for type in self.multOperationTypeList):
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:
json['results'][ratio]['min'] = \
json['results'][ratio]['avg'] = \
json['results'][ratio]['max'] = measureList[0]
else:
json['results']['failure_ratio'] = self.getConfidenceIntervals(self.Failure)
json['results']['working_ratio'] = self.getConfidenceIntervals(self.Working)
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)
......@@ -72,18 +72,6 @@ class ObjectResource(object):
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
# =======================================================================
# returns the resource
# =======================================================================
......
......@@ -33,6 +33,7 @@ from Repairman import Repairman
# the resource that operates the machines
# ===========================================================================
class Operator(Repairman): # XXX isn't it the other way around ?
class_name = 'Dream.Operator'
def __init__(self, id, name, capacity=1, schedulingRule="FIFO"):
Repairman.__init__(self, id=id, name=name, capacity=capacity)
......
......@@ -35,7 +35,7 @@ from ObjectResource import ObjectResource
# the resource that repairs the machines
# ===========================================================================
class Repairman(ObjectResource):
class_name = 'Dream.Repairman'
def __init__(self, id, name, capacity=1):
ObjectResource.__init__(self)
self.id=id
......@@ -90,25 +90,18 @@ class Repairman(ObjectResource):
# 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:
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.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,1,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][1][0])
G.outputSheet.write(G.outputIndex,2,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][0])
G.outputSheet.write(G.outputIndex,3,stat.bayes_mvs(self.Waiting, G.confidenceLevel)[0][1][1])
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.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Waiting of "+ self.objName+" is:")
waiting_ci = self.getConfidenceIntervals(self.Waiting)
G.outputSheet.write(G.outputIndex, 1, waiting_ci['min'])
G.outputSheet.write(G.outputIndex, 2, waiting_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, waiting_ci['max'])
G.outputIndex+=1
G.outputIndex+=1
......@@ -117,42 +110,13 @@ class Repairman(ObjectResource):
# =======================================================================
def outputResultsJSON(self):
from Globals import G
# if we had just one replication output the results to JSON
if(G.numberOfReplications==1):
json={}
json['_class'] = 'Dream.'+self.type;
json['id'] = str(self.id)
json['results'] = {}
json = {'_class': self.class_name,
'id': self.id,
'results': {}}
if(G.numberOfReplications==1):
json['results']['working_ratio']=100*self.totalWorkingTime/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:
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']['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]
else:
json['results']['working_ratio'] = self.getConfidenceIntervals(self.Working)
json['results']['waiting_ratio'] = self.getConfidenceIntervals(self.Waiting)
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