Commit 7c6b1efb authored by panos's avatar panos

Rename the folder with the Simul8 examples

parent 8692a4fe
'''
Created on 3 Dec 2014
@author: Panos
'''
# ===========================================================================
# Copyright 2013 University of Limerick
#
# This file is part of DREAM.
#
# DREAM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DREAM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DREAM. If not, see <http://www.gnu.org/licenses/>.
# ===========================================================================
from Transformations import BasicTransformations
from DistributionFitting import Distributions
import ImportDatabase
from xml.etree import ElementTree as et
from Simul8XML import Simul8Output
#================================= Extract data from the database ==========================================#
#The Import Database object is used to import the data, the user has to specify the path to the file containing the connection data
cnxn=ImportDatabase.ConnectionData(seekName='ServerData', implicitExt='txt', number_of_cursors=3)
cursors=cnxn.getCursors()
#Database queries used to extract the required data, in this example the processing times are given subtracting the TIME IN data point from the TIME OUT data point
a = cursors[0].execute("""
select prod_code, stat_code,emp_no, TIMEIN, TIMEOUT
from production_status
""")
MILL1=[] #Initialization of MILL1 list
MILL2=[] #Initialization of MILL2 list
for j in range(a.rowcount):
#get the next line
ind1=a.fetchone()
if ind1.stat_code == 'MILL1':
procTime=[]
procTime.insert(0,ind1.TIMEIN)
procTime.insert(1,ind1.TIMEOUT)
MILL1.append(procTime)
elif ind1.stat_code == 'MILL2':
procTime=[]
procTime.insert(0,ind1.TIMEIN)
procTime.insert(1,ind1.TIMEOUT)
MILL2.append(procTime)
else:
continue
#The BasicTransformations object is called to conduct some data transformations
transform = BasicTransformations()
procTime_MILL1=[]
for elem in MILL1:
t1=[]
t2=[]
t1.append(((elem[0].hour)*60)*60 + (elem[0].minute)*60 + elem[0].second)
t2.append(((elem[1].hour)*60)*60 + (elem[1].minute)*60 + elem[1].second)
dt=transform.subtraction(t2, t1)
procTime_MILL1.append(dt[0])
procTime_MILL2=[]
for elem in MILL2:
t1=[]
t2=[]
t1.append(((elem[0].hour)*60)*60 + (elem[0].minute)*60 + elem[0].second)
t2.append(((elem[1].hour)*60)*60 + (elem[1].minute)*60 + elem[1].second)
dt=transform.subtraction(t2, t1)
procTime_MILL2.append(dt[0])
#Database queries used again to extract the MTTF and MTTR data points
b = cursors[1].execute("""
select stat_code, MTTF_hour
from failures
""")
c = cursors[2].execute("""
select stat_code, MTTR_hour
from repairs
""")
MTTF_MILL1=[] #Initialization of the list that will contain the MTTF data points for MILL1
MTTF_MILL2=[] #Initialization of the list that will contain the MTTF data points for MILL2
for j in range(b.rowcount):
#get the next line
ind2=b.fetchone()
if ind2.stat_code == 'MILL1':
MTTF_MILL1.append(ind2.MTTF_hour)
elif ind2.stat_code == 'MILL2':
MTTF_MILL2.append(ind2.MTTF_hour)
else:
continue
MTTR_MILL1=[] #Initialization of the list that will contain the MTTR data points for MILL1
MTTR_MILL2=[] #Initialization of the list that will contain the MTTR data points for MILL1
for j in range(c.rowcount):
#get the next line
ind3=c.fetchone()
if ind3.stat_code == 'MILL1':
MTTR_MILL1.append(ind3.MTTR_hour)
elif ind3.stat_code == 'MILL2':
MTTR_MILL2.append(ind3.MTTR_hour)
else:
continue
#======================= Fit data to statistical distributions ================================#
#The Distributions object is called to fit statistical distributions to the in scope data
dist_proctime = Distributions()
distProcTime_MILL1 = dist_proctime.Lognormal_distrfit(procTime_MILL1)
distProcTime_MILL2 = dist_proctime.Weibull_distrfit(procTime_MILL2)
dist_MTTF = Distributions()
dist_MTTR = Distributions()
distMTTF_MILL1 = dist_MTTF.Exponential_distrfit(MTTF_MILL1)
distMTTF_MILL2 = dist_MTTF.Exponential_distrfit(MTTF_MILL2)
distMTTR_MILL1 = dist_MTTR.Normal_distrfit(MTTR_MILL1)
distMTTR_MILL2 = dist_MTTR.Normal_distrfit(MTTR_MILL2)
#======================= Output preparation: output the updated values in the XML file of this example ================================#
datafile = ('ParallelStations.xml') #define the input xml file
tree = et.parse(datafile)
simul8 = Simul8Output() #Call the Simul8Output object
#Assign the statistical distribution found above in the XML file using methods of the Simul8Output object
procTimes1 = simul8.ProcTimes(tree,'MILL1',distProcTime_MILL1)
procTimes2 = simul8.ProcTimes(procTimes1,'MILL2',distProcTime_MILL2)
#Again assign the MTTF and MTTR probability distributions calling the relevant methods from the Simul8Output object
MTTF1 = simul8.MTBF(procTimes2,'MILL1',distMTTF_MILL1)
MTTR1 = simul8.MTTR(MTTF1,'MILL1',distMTTR_MILL1)
MTTF2 = simul8.MTBF(MTTR1,'MILL2',distMTTF_MILL2)
MTTR2 = simul8.MTTR(MTTF2,'MILL2',distMTTR_MILL2)
#Output the XML file with the processed data
output= MTTR2.write('KEtool_ParallelStations.xml')
'''
Created on 3 Dec 2014
@author: Panos
'''
# ===========================================================================
# Copyright 2013 University of Limerick
#
# This file is part of DREAM.
#
# DREAM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DREAM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DREAM. If not, see <http://www.gnu.org/licenses/>.
# ===========================================================================
from ImportExceldata import Import_Excel
from DistributionFitting import DistFittest
from DistributionFitting import Distributions
import xlrd
from xml.etree import ElementTree as et
from Simul8XML import Simul8Output
import os
def main(test=0, ExcelFileName1='InterarrivalsData.xls',
ExcelFileName2='ProcData.xls',
simul8XMLFileName='SingleServer.xml',
workbook1=None, workbook2=None, simul8XMLFile=None):
#Read from the given directory the Excel document with the processing times data
if not workbook2:
workbook2 = xlrd.open_workbook(os.path.join(os.path.dirname(os.path.realpath(__file__)), ExcelFileName2))
worksheets = workbook2.sheet_names()
worksheet_Proc = worksheets[0] #Define the worksheet with the Processing time data
importData = Import_Excel() #Call the Python object Import_Excel
procTimes = importData.Input_data(worksheet_Proc, workbook2) #Create the Processing times dictionary with key the M1 and values the processing time data
#Get from the above dictionaries the M1 key and the Source key and define the following lists with data
M1 = procTimes.get('M1',[])
distFitting = DistFittest() #Call the DistFittest object
M1 = distFitting.ks_test(M1)
#Read from the given directory the Excel document with the inter-arrivals data
if not workbook1:
workbook1 = xlrd.open_workbook(os.path.join(os.path.dirname(os.path.realpath(__file__)), ExcelFileName1))
worksheets = workbook1.sheet_names()
worksheet_Inter = worksheets[0] #Define the worksheet with the Inter-arrivals time data
data = Import_Excel()
interTimes = data.Input_data(worksheet_Inter, workbook1) #Create the Inter-arrival times dictionary with key the Source and values the inter-arrival time data
S1 = interTimes.get('Source',[])
distMLE = Distributions() #Call the Distributions object
S1 = distMLE.Exponential_distrfit(S1)
if not simul8XMLFile:
datafile=(os.path.join(os.path.dirname(os.path.realpath(__file__)), simul8XMLFileName)) #It defines the name or the directory of the XML file that is manually written the CMSD information model
tree = et.parse(datafile)
simul8 = Simul8Output() #Call the Simul8Output object
title = 'KEtool_SingleServer'
interTimes = simul8.InterArrivalTime(tree,'Source', S1)
procTimes = simul8.ProcTimes(interTimes,'Activity 1', M1)
title = simul8.Title(procTimes,title)
#Output the XML file with the processed data
output= procTimes.write('KEtool_SingleServer.xml')
if test:
return output
if __name__ == '__main__':
main()
Activity 2,Activity 3
0.605703539,0.964730988
0.316191544,0.026733702
0.316191544,0.026733702
0.705934251,0.143290362
0.443313263,0.457859747
0.760824832,0.360404368
0.053600175,0.724183619
0.781035648,0.705351425
0.626433697,0.616910323
0.183075027,0.766356281
0.605703539,0.964730988
0.316191544,0.026733702
0.705934251,0.143290362
0.443313263,0.457859747
0.760824832,0.360404368
0.053600175,0.724183619
0.781035648,0.705351425
0.626433697,0.616910323
0.605703539,0.964730988
0.316191544,0.026733702
0.705934251,0.143290362
0.443313263,0.457859747
0.760824832,0.360404368
0.053600175,0.724183619
0.781035648,0.705351425
0.626433697,0.616910323
0.183075027,0.766356281
0.183075027,0.766356281
0.605703539,0.964730988
0.316191544,0.026733702
0.705934251,0.143290362
0.443313263,0.457859747
0.760824832,0.360404368
0.053600175,0.724183619
0.781035648,0.705351425
0.626433697,0.616910323
0.183075027,0.766356281
0.605703539,0.964730988
0.316191544,0.026733702
0.705934251,0.143290362
0.443313263,0.457859747
0.760824832,0.360404368
0.053600175,0.724183619
0.781035648,0.705351425
0.626433697,0.616910323
0.183075027,0.766356281
0.605703539,0.964730988
0.705934251,0.143290362
0.443313263,0.457859747
0.760824832,0.360404368
0.053600175,0.724183619
0.781035648,0.705351425
0.626433697,0.616910323
0.183075027,0.766356281
0.605703539,0.964730988
0.316191544,0.026733702
0.705934251,0.143290362
0.443313263,0.457859747
0.760824832,0.360404368
0.053600175,0.724183619
0.781035648,0.705351425
0.626433697,0.616910323
0.605703539,0.964730988
0.316191544,0.026733702
0.705934251,0.143290362
0.443313263,0.457859747
0.760824832,0.360404368
0.053600175,0.724183619
0.781035648,0.705351425
0.626433697,0.616910323
0.183075027,0.766356281
0.183075027,0.766356281
0.605703539,0.964730988
0.316191544,0.026733702
0.705934251,0.143290362
0.443313263,0.457859747
0.760824832,0.360404368
0.053600175,0.724183619
0.781035648,0.705351425
0.626433697,0.616910323
0.183075027,0.766356281
0.605703539,0.964730988
0.316191544,0.026733702
0.705934251,0.143290362
0.443313263,0.457859747
0.760824832,0.360404368
0.053600175,0.724183619
0.781035648,0.705351425
0.626433697,0.616910323
0.183075027,0.766356281
0.605703539,0.964730988
0.316191544,0.026733702
0.705934251,0.143290362
0.443313263,0.457859747
0.760824832,0.360404368
0.053600175,0.724183619
0.781035648,0.705351425
0.626433697,0.616910323
0.183075027,0.766356281
0.605703539,0.964730988
0.316191544,0.026733702
0.705934251,0.143290362
0.443313263,0.457859747
0.760824832,0.360404368
0.053600175,0.724183619
0.781035648,0.705351425
0.626433697,0.616910323
0.605703539,0.964730988
0.316191544,0.026733702
0.705934251,0.143290362
0.443313263,0.457859747
0.760824832,0.360404368
0.053600175,0.724183619
0.781035648,0.705351425
0.626433697,0.616910323
0.183075027,0.766356281
0.183075027,0.766356281
0.605703539,0.964730988
0.316191544,0.026733702
0.705934251,0.143290362
0.443313263,0.457859747
0.760824832,0.360404368
0.053600175,0.724183619
0.781035648,0.705351425
0.626433697,0.616910323
0.183075027,0.766356281
0.605703539,0.964730988
0.316191544,0.026733702
0.705934251,0.143290362
0.443313263,0.457859747
0.760824832,0.360404368
0.053600175,0.724183619
0.781035648,0.705351425
0.626433697,0.616910323
0.183075027,0.766356281
0.605703539,0.964730988
0.316191544,0.026733702
0.705934251,0.143290362
0.443313263,0.457859747
0.760824832,0.360404368
0.053600175,0.724183619
0.781035648,0.705351425
0.626433697,0.616910323
0.183075027,0.766356281
0.605703539,0.964730988
0.316191544,0.026733702
0.705934251,0.143290362
0.443313263,0.457859747
0.760824832,0.360404368
0.053600175,0.724183619
0.781035648,0.705351425
0.626433697,0.616910323
0.183075027,0.766356281
0.605703539,0.964730988
0.316191544,0.026733702
0.705934251,0.143290362
0.443313263,0.457859747
0.760824832,0.360404368
0.053600175,0.724183619
0.781035648,0.705351425
0.626433697,0.616910323
0.183075027,0.766356281
0.605703539,0.964730988
0.316191544,0.026733702
0.705934251,0.143290362
0.443313263,0.457859747
0.760824832,0.360404368
0.053600175,0.724183619
0.781035648,0.705351425
0.626433697,0.616910323
0.183075027,0.766356281
\ No newline at end of file
'''
Created on 4 Dec 2014
@author: Panos
'''
# ===========================================================================
# Copyright 2013 University of Limerick
#
# This file is part of DREAM.
#
# DREAM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DREAM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DREAM. If not, see <http://www.gnu.org/licenses/>.
# ===========================================================================
from DistributionFitting import Distributions
from DistributionFitting import DistFittest
from xml.etree import ElementTree as et
from Simul8XML import Simul8Output
from ImportCSVdata import Import_CSV
from ImportExceldata import Import_Excel
import xlrd
#================================= Extract the required data from the data files ==========================================#
filename = ("ProcTimesData.csv")
csv = Import_CSV() #call the Import_CSV module and using its method Input_data import the data set from the CSV file to the tool
Data = csv.Input_data(filename)
Activity2_Proc = Data.get('Activity 2',[]) #get from the returned Python dictionary the two data sets
Activity3_Proc = Data.get('Activity 3',[])
#Read from the given directory the Excel document with the data
workbook = xlrd.open_workbook('DataSet.xlsx')
worksheets = workbook.sheet_names()
worksheet_Inter = worksheets[0] #Define the worksheet with the Inter-arrivals time data
data = Import_Excel()
interTimes = data.Input_data(worksheet_Inter, workbook) #Create the Inter-arrival times dictionary with key the Source and values the inter-arrival time data
S1 = interTimes.get('Source',[])
#Read from the given directory the Excel document with the data
workbook = xlrd.open_workbook('DataSet.xlsx')
worksheets = workbook.sheet_names()
worksheet_Fail = worksheets[1] #Define the worksheet with the failures data (MTTF,MTTR)
data = Import_Excel()
failures = data.Input_data(worksheet_Fail, workbook) #Create the failures dictionary with key the MTTF and MTTR data points
MTTF = failures.get('MTTF',[])
MTTR = failures.get('MTTR',[])
#======================= Fit data to probability distributions ================================#
#The Distributions and DistFittest objects are called to fit statistical distributions to the in scope data
dist = Distributions()
act2Proc = dist.Weibull_distrfit(Activity2_Proc)
act3Proc = dist.Weibull_distrfit(Activity3_Proc)
s1Times = dist.Exponential_distrfit(S1)
distFit = DistFittest()
act1MTTF = distFit.ks_test(MTTF)
act1MTTR = distFit.ks_test(MTTR)
#======================= Output preparation: output the updated values in the XML file of this example ================================#
datafile = ('Topology1.xml') #define the input xml file
tree = et.parse(datafile)
simul8 = Simul8Output() #Call the Simul8Output object
#Assign the statistical distribution calculated above in the XML file using methods of the Simul8Output object
interTimes = simul8.InterArrivalTime(tree,'Source', s1Times)
procTimes2 = simul8.ProcTimes(interTimes,'Activity 2', act2Proc)
procTimes3 = simul8.ProcTimes(procTimes2,'Activity 3', act3Proc)
#Again assign the MTTF and MTTR probability distributions calling the relevant methods from the Simul8Output object
MTTF1 = simul8.MTBF(procTimes3,'Activity 1', act1MTTF)
MTTR1 = simul8.MTTR(MTTF1,'Activity 1', act1MTTR )
#Output the XML file with the processed data
output= MTTR1.write('KEtool_Topology1.xml')
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