Commit b6b837a3 authored by Georgios Dagkakis's avatar Georgios Dagkakis Committed by Sebastien Robin

full JSON version with JSON files and Plant Topologies to compare

parent 510e9892
{"_class": "Dream.Simulation",
"general": {
"_class": "Dream.Configuration",
"numberOfReplications": "1",
"maxSimTime": "1440",
"trace": "Yes",
"confidenceLevel": "0.95"
},
"modelResource": [
{"_class": "Dream.Repairman",
"id": "W1",
"name": "W1",
"capacity": "1"
}
],
"coreObject": [
{"_class": "Dream.Source",
"id": "S1",
"name": "Raw Material",
"interarrivalTime":
{
"distributionType": "Fixed",
"mean": "0.5"
},
"entity": "Part",
"successorList": ["DummyQ"]
},
{"_class": "Dream.Machine",
"id": "M1",
"name": "Machine1",
"processingTime": {
"distributionType": "Fixed",
"mean": "0.25"
},
"failures":{
"failureDistribution": "Fixed",
"MTTF": "60",
"MTTR": "5",
"repairman": "W1"
},
"predecessorList": ["DummyQ"],
"successorList": ["Q1"]
},
{"_class": "Dream.Machine",
"id": "M2",
"name": "Machine2",
"processingTime": {
"distributionType": "Fixed",
"mean": "1.5"
},
"failures":{
"failureDistribution": "Fixed",
"MTTF": "40",
"MTTR": "10",
"repairman": "W1"
},
"predecessorList": ["Q1"],
"successorList": ["E1"]
},
{"_class": "Dream.Queue",
"id": "DummyQ",
"name": "DummyQ",
"isDummy": "True",
"capacity": "1",
"predecessorList": ["S1"],
"successorList": ["M1"]
},
{"_class": "Dream.Queue",
"id": "Q1",
"name": "Q1",
"isDummy": "False",
"capacity": "1",
"predecessorList": ["M1"],
"successorList": ["M2"]
},
{"_class": "Dream.Exit",
"id": "E1",
"name": "Stock",
"predecessorList": ["M2"]
}
]
}
{"_class": "Dream.Simulation",
"general": {
"_class": "Dream.Configuration",
"numberOfReplications": "1",
"maxSimTime": "1440",
"trace": "Yes",
"confidenceLevel": "0.95"
},
"modelResource": [
],
"coreObject": [
{"_class": "Dream.Source",
"id": "S1",
"name": "Parts",
"interarrivalTime":
{
"distributionType": "Fixed",
"mean": "0.5"
},
"entity": "Part",
"successorList": ["Α1"]
},
{"_class": "Dream.Source",
"id": "S2",
"name": "Frames",
"interarrivalTime":
{
"distributionType": "Fixed",
"mean": "2"
},
"entity": "Frame",
"successorList": ["Α1"]
},
{"_class": "Dream.Assembly",
"id": "A1",
"name": "Assembly",
"processingTime": {
"distributionType": "Fixed",
"mean": "2"
},
"entity": "Frame",
"predecessorPartList": ["S1"],
"predecessorFrameList": ["S2"],
"successorList": ["M1"]
},
{"_class": "Dream.Machine",
"id": "M1",
"name": "Moulding",
"processingTime": {
"distributionType": "Fixed",
"mean": "0.25"
},
"failures":{
"failureDistribution": "Fixed",
"MTTF": "60",
"MTTR": "5",
"repairman": "None"
},
"predecessorList": ["A1"],
"successorList": ["E1"]
},
{"_class": "Dream.Exit",
"id": "E1",
"name": "Stock",
"predecessorList": ["M1"]
}
]
}
{"_class": "Dream.Simulation",
"general": {
"_class": "Dream.Configuration",
"numberOfReplications": "1",
"maxSimTime": "1440",
"trace": "Yes",
"confidenceLevel": "0.95"
},
"modelResource": [
{"_class": "Dream.Repairman",
"id": "W1",
"name": "W1",
"capacity": "1"
}
],
"coreObject": [
{"_class": "Dream.Source",
"id": "S1",
"name": "Raw Material",
"interarrivalTime":
{
"distributionType": "Fixed",
"mean": "0.5"
},
"entity": "Part",
"successorList": ["DummyQ"]
},
{"_class": "Dream.Machine",
"id": "M1",
"name": "Machine1",
"processingTime": {
"distributionType": "Fixed",
"mean": "0.25"
},
"failures":{
"failureDistribution": "Fixed",
"MTTF": "60",
"MTTR": "5",
"repairman": "W1"
},
"predecessorList": ["DummyQ"],
"successorList": ["M2"]
},
{"_class": "Dream.Machine",
"id": "M2",
"name": "Machine2",
"processingTime": {
"distributionType": "Fixed",
"mean": "1.5"
},
"failures":{
"failureDistribution": "Fixed",
"MTTF": "40",
"MTTR": "10",
"repairman": "W1"
},
"predecessorList": ["M1"],
"successorList": ["E1"]
},
{"_class": "Dream.Queue",
"id": "DummyQ",
"name": "DummyQ",
"isDummy": "True",
"capacity": "1",
"predecessorList": ["S1"],
"successorList": ["M1"]
},
{"_class": "Dream.Exit",
"id": "E1",
"name": "Stock",
"predecessorList": ["M2"]
}
]
}
{"_class": "Dream.Simulation",
"general": {
"_class": "Dream.Configuration",
"numberOfReplications": "1",
"maxSimTime": "1440",
"trace": "Yes",
"confidenceLevel": "0.95"
},
"modelResource": [
{"_class": "Dream.Repairman",
"id": "W1",
"name": "W1",
"capacity": "1"
}
],
"coreObject": [
{"_class": "Dream.Source",
"id": "S1",
"name": "Raw Material",
"interarrivalTime":
{
"distributionType": "Fixed",
"mean": "0.5"
},
"entity": "Part",
"successorList": ["DummyQ"]
},
{"_class": "Dream.Machine",
"id": "M1",
"name": "Machine1",
"processingTime": {
"distributionType": "Fixed",
"mean": "0.25"
},
"failures":{
"failureDistribution": "Fixed",
"MTTF": "60",
"MTTR": "5",
"repairman": "W1"
},
"predecessorList": ["Q1"],
"successorList": ["E1"]
},
{"_class": "Dream.Machine",
"id": "M2",
"name": "Machine2",
"processingTime": {
"distributionType": "Fixed",
"mean": "1.5"
},
"failures":{
"failureDistribution": "Fixed",
"MTTF": "40",
"MTTR": "10",
"repairman": "W1"
},
"predecessorList": ["DummyQ"],
"successorList": ["Q1"]
},
{"_class": "Dream.Queue",
"id": "DummyQ",
"name": "DummyQ",
"isDummy": "True",
"capacity": "1",
"predecessorList": ["S1"],
"successorList": ["M2"]
},
{"_class": "Dream.Queue",
"id": "Q1",
"name": "Q1",
"isDummy": "False",
"capacity": "1",
"predecessorList": ["M2"],
"successorList": ["M1"]
},
{"_class": "Dream.Exit",
"id": "E1",
"name": "Stock",
"predecessorList": ["M1"]
}
]
}
{"_class": "Dream.Simulation",
"general": {
"_class": "Dream.Configuration",
"numberOfReplications": "1",
"maxSimTime": "1440",
"trace": "Yes",
"confidenceLevel": "0.95"
},
"modelResource": [
],
"coreObject": [
{"_class": "Dream.Source",
"id": "S1",
"name": "Parts",
"interarrivalTime":
{
"distributionType": "Fixed",
"mean": "0.5"
},
"entity": "Part",
"successorList": ["Α1"]
},
{"_class": "Dream.Source",
"id": "S2",
"name": "Frames",
"interarrivalTime":
{
"distributionType": "Fixed",
"mean": "2"
},
"entity": "Frame",
"successorList": ["Α1"]
},
{"_class": "Dream.Assembly",
"id": "A1",
"name": "Assembly",
"processingTime": {
"distributionType": "Fixed",
"mean": "2"
},
"entity": "Frame",
"predecessorPartList": ["S1"],
"predecessorFrameList": ["S2"],
"successorList": ["M1"]
},
{"_class": "Dream.Machine",
"id": "M1",
"name": "Moulding",
"processingTime": {
"distributionType": "Fixed",
"mean": "0.25"
},
"failures":{
"failureDistribution": "Fixed",
"MTTF": "60",
"MTTR": "5",
"repairman": "None"
},
"predecessorList": ["A1"],
"successorList": ["Q1"]
},
{"_class": "Dream.Machine",
"id": "M2",
"name": "Machine2",
"processingTime": {
"distributionType": "Fixed",
"mean": "1.5"
},
"failures":{
"failureDistribution": "Fixed",
"MTTF": "40",
"MTTR": "10",
"repairman": "None"
},
"predecessorList": ["Q1"],
"successorList": ["E1"]
},
{"_class": "Dream.Queue",
"id": "Q1",
"name": "Q1",
"isDummy": "False",
"capacity": "1",
"predecessorList": ["M1"],
"successorList": ["M2"]
},
{"_class": "Dream.Exit",
"id": "E1",
"name": "Stock",
"predecessorList": ["M2"]
}
]
}
{"_class": "Dream.Simulation",
"general": {
"_class": "Dream.Configuration",
"numberOfReplications": "1",
"maxSimTime": "1440",
"trace": "Yes",
"confidenceLevel": "0.95"
},
"modelResource": [
{"_class": "Dream.Repairman",
"id": "W1",
"name": "W1",
"capacity": "1"
}
],
"coreObject": [
{"_class": "Dream.Source",
"id": "S1",
"name": "Raw Material",
"interarrivalTime":
{
"distributionType": "Fixed",
"mean": "0.5"
},
"entity": "Part",
"successorList": ["DummyQ"]
},
{"_class": "Dream.Machine",
"id": "M1",
"name": "Machine1",
"processingTime": {
"distributionType": "Fixed",
"mean": "0.25"
},
"failures":{
"failureDistribution": "Fixed",
"MTTF": "60",
"MTTR": "5",
"repairman": "W1"
},
"predecessorList": ["DummyQ"],
"successorList": ["Q1"]
},
{"_class": "Dream.Machine",
"id": "M2",
"name": "Machine2",
"processingTime": {
"distributionType": "Fixed",
"mean": "1.5"
},
"failures":{
"failureDistribution": "Fixed",
"MTTF": "40",
"MTTR": "10",
"repairman": "W1"
},
"predecessorList": ["Q1"],
"successorList": ["M3"]
},
{"_class": "Dream.Machine",
"id": "M3",
"name": "Machine3",
"processingTime": {
"distributionType": "Fixed",
"mean": "3"
},
"failures":{
"failureDistribution": "No"
},
"predecessorList": ["M2"],
"successorList": ["E1"]
},
{"_class": "Dream.Queue",
"id": "DummyQ",
"name": "DummyQ",
"isDummy": "True",
"capacity": "1",
"predecessorList": ["S1"],
"successorList": ["M1"]
},
{"_class": "Dream.Queue",
"id": "Q1",
"name": "Q1",
"isDummy": "False",
"capacity": "1",
"predecessorList": ["M1"],
"successorList": ["M2"]
},
{"_class": "Dream.Exit",
"id": "E1",
"name": "Stock",
"predecessorList": ["M3"]
}
]
}
{"_class": "Dream.Simulation",
"general": {
"_class": "Dream.Configuration",
"numberOfReplications": "1",
"maxSimTime": "1440",
"trace": "Yes",
"confidenceLevel": "0.95"
},
"modelResource": [
],
"coreObject": [
{"_class": "Dream.Source",
"id": "S1",
"name": "Raw Material 1",
"interarrivalTime":
{
"distributionType": "Fixed",
"mean": "0.5"
},
"entity": "Part",
"successorList": ["M1"]
},
{"_class": "Dream.Source",
"id": "S2",
"name": "Raw Material 2",
"interarrivalTime":
{
"distributionType": "Fixed",
"mean": "1"
},
"entity": "Part",
"successorList": ["M2"]
},
{"_class": "Dream.Machine",
"id": "M1",
"name": "Machine1",
"processingTime": {
"distributionType": "Fixed",
"mean": "0.25"
},
"failures":{
"failureDistribution": "Fixed",
"MTTF": "60",
"MTTR": "5",
"repairman": "None"
},
"predecessorList": ["S1"],
"successorList": ["Q1"]
},
{"_class": "Dream.Machine",
"id": "M2",
"name": "Machine2",
"processingTime": {
"distributionType": "Fixed",
"mean": "1.5"
},
"failures":{
"failureDistribution": "Fixed",
"MTTF": "40",
"MTTR": "10",
"repairman": "None"
},
"predecessorList": ["S2"],
"successorList": ["Q1"]
},
{"_class": "Dream.Machine",
"id": "M3",
"name": "Machine3",
"processingTime": {
"distributionType": "Fixed",
"mean": "1"
},
"failures":{
"failureDistribution": "No"
},
"predecessorList": ["Q1"],
"successorList": ["E1"]
},
{"_class": "Dream.Queue",
"id": "Q1",
"name": "Q1",
"isDummy": "False",
"capacity": "1",
"predecessorList": ["M1", "M2"],
"successorList": ["M3"]
},
{"_class": "Dream.Exit",
"id": "E1",
"name": "Stock",
"predecessorList": ["M3"]
}
]
}
{"_class": "Dream.Simulation",
"general": {
"_class": "Dream.Configuration",
"numberOfReplications": "1",
"maxSimTime": "1440",
"trace": "Yes",
"confidenceLevel": "0.95"
},
"modelResource": [
],
"coreObject": [
{"_class": "Dream.Source",
"id": "S1",
"name": "Raw Material 1",
"interarrivalTime":
{
"distributionType": "Fixed",
"mean": "0.5"
},
"entity": "Part",
"successorList": ["M1"]
},
{"_class": "Dream.Source",
"id": "S2",
"name": "Raw Material 2",
"interarrivalTime":
{
"distributionType": "Fixed",
"mean": "1"
},
"entity": "Part",
"successorList": ["M2"]
},
{"_class": "Dream.Source",
"id": "S3",
"name": "Raw Material 3",
"interarrivalTime":
{
"distributionType": "Fixed",
"mean": "2"
},
"entity": "Part",
"successorList": ["M3"]
},
{"_class": "Dream.Machine",
"id": "M1",
"name": "Machine1",
"processingTime": {
"distributionType": "Fixed",
"mean": "0.25"
},
"failures":{
"failureDistribution": "No"
},
"predecessorList": ["S1"],
"successorList": ["Q1"]
},
{"_class": "Dream.Machine",
"id": "M2",
"name": "Machine2",
"processingTime": {
"distributionType": "Fixed",
"mean": "1.5"
},
"failures":{
"failureDistribution": "No"
},
"predecessorList": ["S2"],
"successorList": ["Q1"]
},
{"_class": "Dream.Machine",
"id": "M3",
"name": "Machine3",
"processingTime": {
"distributionType": "Fixed",
"mean": "1"
},
"failures":{
"failureDistribution": "No"
},
"predecessorList": ["S3"],
"successorList": ["Q1"]
},
{"_class": "Dream.Machine",
"id": "M4",
"name": "Machine4",
"processingTime": {
"distributionType": "Fixed",
"mean": "1.25"
},
"failures":{
"failureDistribution": "No"
},
"predecessorList": ["Q1"],
"successorList": ["E1"]
},
{"_class": "Dream.Queue",
"id": "Q1",
"name": "Q1",
"isDummy": "False",
"capacity": "1",
"predecessorList": ["M1", "M2","M3"],
"successorList": ["M4"]
},
{"_class": "Dream.Exit",
"id": "E1",
"name": "Stock",
"predecessorList": ["M4"]
}
]
}
{"_class": "Dream.Simulation",
"general": {
"_class": "Dream.Configuration",
"numberOfReplications": "1",
"maxSimTime": "1440",
"trace": "Yes",
"confidenceLevel": "0.95"
},
"modelResource": [
],
"coreObject": [
{"_class": "Dream.Source",
"id": "S1",
"name": "Raw Material",
"interarrivalTime":
{
"distributionType": "Fixed",
"mean": "0.5"
},
"entity": "Part",
"successorList": ["M1"]
},
{"_class": "Dream.Machine",
"id": "M1",
"name": "Moulding",
"processingTime": {
"distributionType": "Fixed",
"mean": "0.25"
},
"failures":{
"failureDistribution": "No"
},
"predecessorList": ["S1"],
"successorList": ["E1"]
},
{"_class": "Dream.Exit",
"id": "E1",
"name": "Stock",
"predecessorList": ["M1"]
}
]
}
{"_class": "Dream.Simulation",
"general": {
"_class": "Dream.Configuration",
"numberOfReplications": "1",
"maxSimTime": "1440",
"trace": "Yes",
"confidenceLevel": "0.95"
},
"modelResource": [
],
"coreObject": [
{"_class": "Dream.Source",
"id": "S1",
"name": "Raw Material 1",
"interarrivalTime":
{
"distributionType": "Fixed",
"mean": "0.5"
},
"entity": "Part",
"successorList": ["M1"]
},
{"_class": "Dream.Source",
"id": "S2",
"name": "Raw Material 2",
"interarrivalTime":
{
"distributionType": "Fixed",
"mean": "1"
},
"entity": "Part",
"successorList": ["M2"]
},
{"_class": "Dream.Machine",
"id": "M1",
"name": "Machine1",
"processingTime": {
"distributionType": "Fixed",
"mean": "0.25"
},
"failures":{
"failureDistribution": "No"
},
"predecessorList": ["S1"],
"successorList": ["Q1"]
},
{"_class": "Dream.Machine",
"id": "M2",
"name": "Machine2",
"processingTime": {
"distributionType": "Fixed",
"mean": "1.5"
},
"failures":{
"failureDistribution": "No"
},
"predecessorList": ["S2"],
"successorList": ["Q1"]
},
{"_class": "Dream.Machine",
"id": "M3",
"name": "Machine3",
"processingTime": {
"distributionType": "Fixed",
"mean": "1"
},
"failures":{
"failureDistribution": "No"
},
"predecessorList": ["Q1"],
"successorList": ["E1"]
},
{"_class": "Dream.Machine",
"id": "M4",
"name": "Machine4",
"processingTime": {
"distributionType": "Fixed",
"mean": "1.25"
},
"failures":{
"failureDistribution": "No"
},
"predecessorList": ["Q1"],
"successorList": ["E1"]
},
{"_class": "Dream.Queue",
"id": "Q1",
"name": "Q1",
"isDummy": "False",
"capacity": "1",
"predecessorList": ["M1","M2"],
"successorList": ["M3","M4"]
},
{"_class": "Dream.Exit",
"id": "E1",
"name": "Stock",
"predecessorList": ["M3","M4"]
}
]
}
'''
Created on 7 May 2013
@author: George
'''
'''
main script. Reads data from JSON, generates and runs the simulation and prints the results to excel
'''
from SimPy.Simulation import *
from Source import Source
from Globals import G
from Machine import Machine
from Exit import Exit
from Queue import Queue
from QueueLIFO import QueueLIFO
from Repairman import Repairman
from Part import Part
from Frame import Frame
from Assembly import Assembly
import xlwt
import xlrd
import time
import numpy as np
import json
from random import Random
import sys
#read general simulation inputs
def readGeneralInput():
general=G.JSONData['general']
G.numberOfReplications=int(general.get('numberOfReplications', 'not found'))
G.maxSimTime=float(general.get('maxSimTime', 'not found'))
G.trace=general.get('trace', 'not found')
G.confidenceLevel=float(general.get('confidenceLevel', 'not found'))
#create the simulation objects
def createObjects():
#Read the json data
coreObject=G.JSONData['coreObject']
modelResource=G.JSONData['modelResource']
#define the lists
G.SourceList=[]
G.MachineList=[]
G.ExitList=[]
G.QueueList=[]
G.RepairmanList=[]
G.AssemblyList=[]
#loop through all the model resources
#read the data and create them
for i in range(len(modelResource)):
resourceClass=modelResource[i].get('_class', 'not found')
if resourceClass=='Dream.Repairman':
id=modelResource[i].get('id', 'not found')
name=modelResource[i].get('name', 'not found')
capacity=int(modelResource[i].get('capacity', '1'))
R=Repairman(id, name, capacity)
G.RepairmanList.append(R)
#loop through all the core objects
#read the data and create them
for i in range(len(coreObject)):
objClass=coreObject[i].get('_class', 'not found')
if objClass=='Dream.Source':
id=coreObject[i].get('id', 'not found')
name=coreObject[i].get('name', 'not found')
interarrivalTime=coreObject[i].get('interarrivalTime', 'not found')
distributionType=interarrivalTime.get('distributionType', 'not found')
mean=float(interarrivalTime.get('mean', '0'))
entity=str_to_class(coreObject[i].get('entity', 'not found'))
successorList=coreObject[i].get('successorList', 'not found')
S=Source(id, name, distributionType, mean, entity)
S.nextIds=successorList
G.SourceList.append(S)
G.ObjList.append(S)
elif objClass=='Dream.Machine':
id=coreObject[i].get('id', 'not found')
name=coreObject[i].get('name', 'not found')
processingTime=coreObject[i].get('processingTime', 'not found')
distributionType=processingTime.get('distributionType', 'not found')
mean=float(processingTime.get('mean', '0'))
stdev=float(processingTime.get('stdev', '0'))
min=float(processingTime.get('min', '0'))
max=float(processingTime.get('stdev', '0'))
failures=coreObject[i].get('failures', 'not found')
failureDistribution=failures.get('failureDistribution', 'not found')
MTTF=float(failures.get('MTTF', '0'))
MTTR=float(failures.get('MTTR', '0'))
availability=float(failures.get('availability', '0'))
needRepairman=failures.get('repairman', 'None')
if(needRepairman=='None'):
repairman=needRepairman
else:
for j in range(len(G.RepairmanList)):
if(G.RepairmanList[j].id==needRepairman):
repairman=G.RepairmanList[j]
predecessorList=coreObject[i].get('predecessorList', 'not found')
successorList=coreObject[i].get('successorList', 'not found')
M=Machine(id, name, 1, distributionType, [mean,stdev,min,max], failureDistribution,
MTTF, MTTR, availability, repairman)
M.previousIds=predecessorList
M.nextIds=successorList
G.MachineList.append(M)
G.ObjList.append(M)
elif objClass=='Dream.Exit':
id=coreObject[i].get('id', 'not found')
name=coreObject[i].get('name', 'not found')
predecessorList=coreObject[i].get('predecessorList', 'not found')
E=Exit(id, name)
E.previousIds=predecessorList
G.ExitList.append(E)
G.ObjList.append(E)
elif objClass=='Dream.Queue':
id=coreObject[i].get('id', 'not found')
name=coreObject[i].get('name', 'not found')
successorList=coreObject[i].get('successorList', 'not found')
predecessorList=coreObject[i].get('predecessorList', 'not found')
capacity=int(coreObject[i].get('capacity', '1'))
isDummy=bool(coreObject[i].get('isDummy', 'False'))
Q=Queue(id, name, capacity, isDummy)
Q.previousIds=predecessorList
Q.nextIds=successorList
G.QueueList.append(Q)
G.ObjList.append(Q)
elif objClass=='Dream.Assembly':
id=coreObject[i].get('id', 'not found')
name=coreObject[i].get('name', 'not found')
processingTime=coreObject[i].get('processingTime', 'not found')
distributionType=processingTime.get('distributionType', 'not found')
mean=float(processingTime.get('mean', '0'))
stdev=float(processingTime.get('stdev', '0'))
min=float(processingTime.get('min', '0'))
max=float(processingTime.get('stdev', '0'))
predecessorPartList=coreObject[i].get('predecessorPartList', 'not found')
predecessorFrameList=coreObject[i].get('predecessorFrameList', 'not found')
successorList=coreObject[i].get('successorList', 'not found')
A=Assembly(id, name, distributionType, [mean,stdev,min,max])
A.previousPartIds=predecessorPartList
A.previousFrameIds=predecessorFrameList
A.nextIds=successorList
G.AssemblyList.append(A)
G.ObjList.append(A)
#reads the topology and defines it for the objects
def setTopology():
#loop through all the objects
for i in range(len(G.ObjList)):
next=[]
previous=[]
for j in range(len(G.ObjList[i].previousIds)):
for q in range(len(G.ObjList)):
if G.ObjList[q].id==G.ObjList[i].previousIds[j]:
previous.append(G.ObjList[q])
for j in range(len(G.ObjList[i].nextIds)):
for q in range(len(G.ObjList)):
if G.ObjList[q].id==G.ObjList[i].nextIds[j]:
next.append(G.ObjList[q])
if G.ObjList[i].type=="Source":
G.ObjList[i].defineRouting(next)
elif G.ObjList[i].type=="Exit":
G.ObjList[i].defineRouting(previous)
elif G.ObjList[i].type=="Assembly":
previousPart=[]
previousFrame=[]
for j in range(len(G.ObjList[i].previousPartIds)):
for q in range(len(G.ObjList)):
if G.ObjList[q].id==G.ObjList[i].previousPartIds[j]:
previousPart.append(G.ObjList[q])
for j in range(len(G.ObjList[i].previousFrameIds)):
for q in range(len(G.ObjList)):
if G.ObjList[q].id==G.ObjList[i].previousFrameIds[j]:
previousFrame.append(G.ObjList[q])
G.ObjList[i].defineRouting(previousPart, previousFrame, next)
else:
G.ObjList[i].defineRouting(previous, next)
#used to convert a string read from the input to object type
def str_to_class(str):
return getattr(sys.modules[__name__], str)
#initializes all the objects that are in the topology
def initializeObjects():
for j in range(len(G.ObjList)):
G.ObjList[j].initialize()
for j in range(len(G.RepairmanList)):
G.RepairmanList[j].initialize()
#activates all the objects
def activateObjects():
for j in range(len(G.ObjList)):
try:
activate(G.ObjList[j],G.ObjList[j].Run())
except AttributeError:
pass
#the main script that is ran
def main():
#topologyId=raw_input("give the topology id\n")
G.ObjList=[]
topologyId=raw_input("give the topology id\n")
try:
G.JSONFile=open('JSONInputs/Topology'+str(topologyId)+'.JSON', "r")
except IOError:
print "no such topology file. The programm is terminated"
sys.exit()
start=time.time() #start counting execution time
G.InputData=G.JSONFile.read()
G.JSONData=json.loads(G.InputData)
#print G.JSONData
readGeneralInput()
createObjects()
setTopology()
for i in range(G.numberOfReplications):
print "start run number "+str(i+1)
G.seed+=1
G.Rnd=Random(G.seed)
initialize() #initialize the simulation
initializeObjects()
activateObjects()
simulate(until=G.maxSimTime) #start the simulation
#carry on the post processing operations for every object in the topology
for j in range(len(G.ObjList)):
G.ObjList[j].postProcessing(G.maxSimTime)
#output trace to excel
if(G.trace=="Yes"):
G.traceFile.save('trace'+str(i+1)+'.xls')
G.traceIndex=0 #index that shows in what row we are
G.sheetIndex=1 #index that shows in what sheet we are
G.traceFile = xlwt.Workbook() #create excel file
G.traceSheet = G.traceFile.add_sheet('sheet '+str(G.sheetIndex), cell_overwrite_ok=True) #create excel sheet
G.outputSheet.write(G.outputIndex,0, "Execution Time")
G.outputSheet.write(G.outputIndex,1, str(time.time()-start)+" seconds")
G.outputIndex+=2
#output data to excel for every object in the topology
for j in range(len(G.ObjList)):
G.ObjList[j].outputResultsXL(G.maxSimTime)
G.outputFile.save("output.xls")
print "execution time="+str(time.time()-start)
if __name__ == '__main__': main()
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment