Commit 668a51d7 authored by Ioannis Papagiannopoulos's avatar Ioannis Papagiannopoulos Committed by Sebastien Robin

Test vs Topology22 added

parent db943eaa
...@@ -26,6 +26,9 @@ Created on 7 May 2013 ...@@ -26,6 +26,9 @@ Created on 7 May 2013
main script. Reads data from JSON, generates and runs the simulation and prints the results to excel main script. Reads data from JSON, generates and runs the simulation and prints the results to excel
''' '''
# ===========================================================================
# IMPORTS
# ===========================================================================
from warnings import warn from warnings import warn
import logging import logging
logger = logging.getLogger("dream.platform") logger = logging.getLogger("dream.platform")
...@@ -81,15 +84,19 @@ from random import Random ...@@ -81,15 +84,19 @@ from random import Random
import sys import sys
import os.path import os.path
#reads general simulation inputs # ===========================================================================
# reads general simulation inputs
# ===========================================================================
def readGeneralInput(): def readGeneralInput():
general=G.JSONData['general'] general=G.JSONData['general'] # read the dict with key 'general'
G.numberOfReplications=int(general.get('numberOfReplications', '1')) G.numberOfReplications=int(general.get('numberOfReplications', '1')) # read the number of replications
G.maxSimTime=float(general.get('maxSimTime', '100')) G.maxSimTime=float(general.get('maxSimTime', '100')) # get the maxSimTime
G.trace=general.get('trace', 'No') G.trace=general.get('trace', 'No')
G.confidenceLevel=float(general.get('confidenceLevel', '0.95')) G.confidenceLevel=float(general.get('confidenceLevel', '0.95'))
#creates the simulation objects # ===========================================================================
# creates the simulation objects
# ===========================================================================
def createObjects(): def createObjects():
json_data = G.JSONData json_data = G.JSONData
...@@ -463,19 +470,19 @@ def main(argv=[], input_data=None): ...@@ -463,19 +470,19 @@ def main(argv=[], input_data=None):
if input_data is None: if input_data is None:
# user passes the topology filename as first argument to the program # user passes the topology filename as first argument to the program
filename = argv[0] filename = argv[0]
try: try: # try to open the file with the inputs
G.JSONFile=open(filename, "r") G.JSONFile=open(filename, "r") # global variable holding the file to be opened
except IOError: except IOError:
print "%s could not be open" % filename print "%s could not be open" % filename
return "ERROR" return "ERROR"
G.InputData=G.JSONFile.read() G.InputData=G.JSONFile.read() # pass the contents of the input file to the global var InputData
else: else:
G.InputData = input_data G.InputData = input_data
start=time.time() #start counting execution time start=time.time() # start counting execution time
#read the input from the JSON file and create the line #read the input from the JSON file and create the line
G.JSONData=json.loads(G.InputData) G.JSONData=json.loads(G.InputData) # create the dictionary JSONData
readGeneralInput() readGeneralInput()
createObjects() createObjects()
setTopology() setTopology()
...@@ -492,10 +499,12 @@ def main(argv=[], input_data=None): ...@@ -492,10 +499,12 @@ def main(argv=[], input_data=None):
setWIP() setWIP()
activateObjects() activateObjects()
#if the simulation is ran until no more events are scheduled, then we have to find the end time as the time the last entity ended. # if the simulation is ran until no more events are scheduled,
# then we have to find the end time as the time the last entity ended.
if G.maxSimTime==-1: if G.maxSimTime==-1:
simulate(until=infinity) #simulate until there are no more events. If someone does it for a model that has always events, then it will run forever! simulate(until=infinity) # simulate until there are no more events.
#identify from the exits what is the time that the last entity has ended. # If someone does it for a model that has always events, then it will run forever!
# identify from the exits what is the time that the last entity has ended.
endList=[] endList=[]
for exit in G.ExitList: for exit in G.ExitList:
endList.append(exit.timeLastEntityLeft) endList.append(exit.timeLastEntityLeft)
......
{
"elementList": [
{
"_class": "Dream.Exit",
"id": "E1",
"results": {
"throughput": 359,
"takt_time": 4.006963788300836,
"lifespan": 454.0
}
},
{
"_class": "Dream.Machine",
"id": "M1",
"results": {
"working_ratio": 50.06944444444444,
"blockage_ratio": 49.826388888888886,
"failure_ratio": 0.0,
"waiting_ratio": 0.10416666666666667
}
},
{
"_class": "Dream.Machine",
"id": "M2",
"results": {
"working_ratio": 99.89583333333333,
"blockage_ratio": 0.0,
"failure_ratio": 0.0,
"waiting_ratio": 0.10416666666666667
}
},
{
"_class": "Dream.Machine",
"id": "M3",
"results": {
"working_ratio": 24.930555555555557,
"blockage_ratio": 0.0,
"failure_ratio": 0.0,
"waiting_ratio": 75.06944444444444
}
}
],
"_class": "Dream.Simulation",
"general": {
"_class": "Dream.Configuration"
}
}
\ No newline at end of file
...@@ -66,7 +66,7 @@ class SimulationTopology(TestCase): ...@@ -66,7 +66,7 @@ class SimulationTopology(TestCase):
self.assertEquals(stable_result, dump_result, "outputs are different") self.assertEquals(stable_result, dump_result, "outputs are different")
# Automatically create a test method for every topology # Automatically create a test method for every topology
for x in range(1, 22): for x in range(1, 23):
def getTestTopology(): def getTestTopology():
filename = "Topology%02i" % x filename = "Topology%02i" % x
def test_topology(self): def test_topology(self):
......
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