Commit 5c41eee8 authored by Georgios Dagkakis's avatar Georgios Dagkakis

main script updated to read new JSON notation (elementList and definition of...

main script updated to read new JSON notation (elementList and definition of successorList in Repairman). Only tested in Topology01 for now
parent c2b64c63
......@@ -341,7 +341,7 @@ class Assembly(Process):
json['results']['waiting_ratio']['avg']=self.Waiting[0]
json['results']['waiting_ratio']['max']=self.Waiting[0]
G.outputJSON['coreObject'].append(json)
G.outputJSON['elementList'].append(json)
......
......@@ -382,7 +382,7 @@ class Conveyer(Process):
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['coreObject'].append(json)
G.outputJSON['elementList'].append(json)
#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!
......
......@@ -339,7 +339,7 @@ class Dismantle(Process):
json['results']['waiting_ratio']['avg']=self.Waiting[0]
json['results']['waiting_ratio']['max']=self.Waiting[0]
G.outputJSON['coreObject'].append(json)
G.outputJSON['elementList'].append(json)
#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!
......
......@@ -249,7 +249,7 @@ class Exit(Process):
json['results']['taktTime']['min']=self.TaktTime[0]
json['results']['taktTime']['avg']=self.TaktTime[0]
json['results']['taktTime']['max']=self.TaktTime[0]
G.outputJSON['coreObject'].append(json)
G.outputJSON['elementList'].append(json)
#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!
......
......@@ -6,14 +6,13 @@
"trace": "No",
"confidenceLevel": "0.95"
},
"modelResource": [
"elementList": [
{"_class": "Dream.Repairman",
"id": "W1",
"name": "W1",
"capacity": "1"
}
],
"coreObject": [
"capacity": "1",
"successorList": ["M1", "M2"]
},
{"_class": "Dream.Source",
"id": "S1",
"name": "Raw Material",
......@@ -35,8 +34,7 @@
"failures":{
"failureDistribution": "Fixed",
"MTTF": "60",
"MTTR": "5",
"repairman": "W1"
"MTTR": "5"
},
"successorList": ["Q1"]
},
......@@ -50,8 +48,7 @@
"failures":{
"failureDistribution": "Fixed",
"MTTF": "40",
"MTTR": "10",
"repairman": "W1"
"MTTR": "10"
},
"successorList": ["E1"]
},
......
......@@ -58,8 +58,8 @@ def readGeneralInput():
#creates the simulation objects
def createObjects():
#Read the json data
coreObjectList = G.JSONData['coreObject']
modelResourceList = G.JSONData['modelResource']
elementList = G.JSONData['elementList']
#modelResourceList = G.JSONData['modelResource']
#define the lists
G.SourceList=[]
......@@ -71,92 +71,94 @@ def createObjects():
G.DismantleList=[]
G.ConveyerList=[]
#loop through all the model resources
#search for repairmen in order to create them
#read the data and create them
for model_resource in modelResourceList:
resourceClass = model_resource.get('_class', 'not found')
for element in elementList:
resourceClass = element.get('_class', 'not found')
if resourceClass=='Dream.Repairman':
id = model_resource.get('id', 'not found')
name = model_resource.get('name', 'not found')
capacity = int(model_resource.get('capacity', '1'))
id = element.get('id', 'not found')
name = element.get('name', 'not found')
capacity = int(element.get('capacity', '1'))
successorList=element.get('successorList', 'not found')
R = Repairman(id, name, capacity)
R.coreObjectIds=successorList
G.RepairmanList.append(R)
#loop through all the core objects
#loop through all the elements
#read the data and create them
for core_object in coreObjectList:
objClass=core_object.get('_class', 'not found')
for element in elementList:
objClass=element.get('_class', 'not found')
if objClass=='Dream.Source':
id=core_object.get('id', 'not found')
name=core_object.get('name', 'not found')
interarrivalTime=core_object.get('interarrivalTime', 'not found')
id=element.get('id', 'not found')
name=element.get('name', 'not found')
interarrivalTime=element.get('interarrivalTime', 'not found')
distributionType=interarrivalTime.get('distributionType', 'not found')
mean=float(interarrivalTime.get('mean', '0'))
entity=str_to_class(core_object.get('entity', 'not found'))
successorList=core_object.get('successorList', 'not found')
entity=str_to_class(element.get('entity', 'not found'))
successorList=element.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=core_object.get('id', 'not found')
name=core_object.get('name', 'not found')
processingTime=core_object.get('processingTime', 'not found')
id=element.get('id', 'not found')
name=element.get('name', 'not found')
processingTime=element.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('max', '0'))
failures=core_object.get('failures', 'not found')
failures=element.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]
successorList=core_object.get('successorList', 'not found')
r='None'
for repairman in G.RepairmanList:
if(id in repairman.coreObjectIds):
r=repairman
successorList=element.get('successorList', 'not found')
M=Machine(id, name, 1, distributionType, [mean,stdev,min,max], failureDistribution,
MTTF, MTTR, availability, repairman)
MTTF, MTTR, availability, r)
M.nextIds=successorList
G.MachineList.append(M)
G.ObjList.append(M)
elif objClass=='Dream.Exit':
id=core_object.get('id', 'not found')
name=core_object.get('name', 'not found')
id=element.get('id', 'not found')
name=element.get('name', 'not found')
E=Exit(id, name)
G.ExitList.append(E)
G.ObjList.append(E)
elif objClass=='Dream.Queue':
id=core_object.get('id', 'not found')
name=core_object.get('name', 'not found')
successorList=core_object.get('successorList', 'not found')
capacity=int(core_object.get('capacity', '1'))
isDummy=bool(int(core_object.get('isDummy', '0')))
id=element.get('id', 'not found')
name=element.get('name', 'not found')
successorList=element.get('successorList', 'not found')
capacity=int(element.get('capacity', '1'))
isDummy=bool(int(element.get('isDummy', '0')))
Q=Queue(id, name, capacity, isDummy)
Q.nextIds=successorList
G.QueueList.append(Q)
G.ObjList.append(Q)
elif objClass=='Dream.Assembly':
id=core_object.get('id', 'not found')
name=core_object.get('name', 'not found')
processingTime=core_object.get('processingTime', 'not found')
id=element.get('id', 'not found')
name=element.get('name', 'not found')
processingTime=element.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('max', '0'))
#predecessorPartList=core_object.get('predecessorPartList', 'not found')
#predecessorFrameList=core_object.get('predecessorFrameList', 'not found')
successorList=core_object.get('successorList', 'not found')
#predecessorPartList=element.get('predecessorPartList', 'not found')
#predecessorFrameList=element.get('predecessorFrameList', 'not found')
successorList=element.get('successorList', 'not found')
A=Assembly(id, name, distributionType, [mean,stdev,min,max])
#A.previousPartIds=predecessorPartList
#A.previousFrameIds=predecessorFrameList
......@@ -165,17 +167,17 @@ def createObjects():
G.ObjList.append(A)
elif objClass=='Dream.Dismantle':
id=core_object.get('id', 'not found')
name=core_object.get('name', 'not found')
processingTime=core_object.get('processingTime', 'not found')
id=element.get('id', 'not found')
name=element.get('name', 'not found')
processingTime=element.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('max', '0'))
successorList=core_object.get('successorList', 'not found')
successorPartList=core_object.get('successorPartList', 'not found')
successorFrameList=core_object.get('successorFrameList', 'not found')
successorList=element.get('successorList', 'not found')
successorPartList=element.get('successorPartList', 'not found')
successorFrameList=element.get('successorFrameList', 'not found')
D=Dismantle(id, name, distributionType, [mean,stdev,min,max])
D.nextPartIds=successorPartList
D.nextFrameIds=successorFrameList
......@@ -184,11 +186,11 @@ def createObjects():
G.ObjList.append(D)
elif objClass=='Dream.Conveyer':
id=core_object.get('id', 'not found')
name=core_object.get('name', 'not found')
length=float(core_object.get('length', '10'))
speed=float(core_object.get('speed', '1'))
successorList=core_object.get('successorList', 'not found')
id=element.get('id', 'not found')
name=element.get('name', 'not found')
length=float(element.get('length', '10'))
speed=float(element.get('speed', '1'))
successorList=element.get('successorList', 'not found')
C=Conveyer(id, name, length, speed)
C.nextIds=successorList
G.ObjList.append(C)
......@@ -196,51 +198,51 @@ def createObjects():
#loop through all the core objects
#to read predecessors
for core_object in G.ObjList:
for element in G.ObjList:
#loop through all the nextIds of the object
for nextId in core_object.nextIds:
for nextId in element.nextIds:
#loop through all the core objects to find the on that has the id that was read in the successorList
for possible_successor in G.ObjList:
if possible_successor.id==nextId:
possible_successor.previousIds.append(core_object.id)
possible_successor.previousIds.append(element.id)
#defines the topology (predecessors and successors for all the objects)
def setTopology():
#loop through all the objects
for core_object in G.ObjList:
for element in G.ObjList:
next=[]
previous=[]
for j in range(len(core_object.previousIds)):
for j in range(len(element.previousIds)):
for q in range(len(G.ObjList)):
if G.ObjList[q].id==core_object.previousIds[j]:
if G.ObjList[q].id==element.previousIds[j]:
previous.append(G.ObjList[q])
for j in range(len(core_object.nextIds)):
for j in range(len(element.nextIds)):
for q in range(len(G.ObjList)):
if G.ObjList[q].id==core_object.nextIds[j]:
if G.ObjList[q].id==element.nextIds[j]:
next.append(G.ObjList[q])
if core_object.type=="Source":
core_object.defineRouting(next)
elif core_object.type=="Exit":
core_object.defineRouting(previous)
if element.type=="Source":
element.defineRouting(next)
elif element.type=="Exit":
element.defineRouting(previous)
#Dismantle should be changed to identify what the the successor is.
#nextPart and nextFrame will become problematic
elif core_object.type=="Dismantle":
elif element.type=="Dismantle":
nextPart=[]
nextFrame=[]
for j in range(len(core_object.nextPartIds)):
for j in range(len(element.nextPartIds)):
for q in range(len(G.ObjList)):
if G.ObjList[q].id==core_object.nextPartIds[j]:
if G.ObjList[q].id==element.nextPartIds[j]:
nextPart.append(G.ObjList[q])
for j in range(len(core_object.nextFrameIds)):
for j in range(len(element.nextFrameIds)):
for q in range(len(G.ObjList)):
if G.ObjList[q].id==core_object.nextFrameIds[j]:
if G.ObjList[q].id==element.nextFrameIds[j]:
nextFrame.append(G.ObjList[q])
core_object.defineRouting(previous, nextPart, nextFrame)
element.defineRouting(previous, nextPart, nextFrame)
else:
core_object.defineRouting(previous, next)
element.defineRouting(previous, next)
#used to convert a string read from the input to object type
def str_to_class(str):
......@@ -248,16 +250,16 @@ def str_to_class(str):
#initializes all the objects that are in the topology
def initializeObjects():
for core_object in G.ObjList:
core_object.initialize()
for element in G.ObjList:
element.initialize()
for repairman in G.RepairmanList:
repairman.initialize()
#activates all the objects
def activateObjects():
for core_object in G.ObjList:
for element in G.ObjList:
try:
activate(core_object, core_object.run())
activate(element, element.run())
except AttributeError:
pass
......@@ -302,8 +304,8 @@ def main(argv=[], input_data=None):
simulate(until=G.maxSimTime) #start the simulation
#carry on the post processing operations for every object in the topology
for core_object in G.ObjList:
core_object.postProcessing(G.maxSimTime)
for element in G.ObjList:
element.postProcessing(G.maxSimTime)
#carry on the post processing operations for every model resource in the topology
for model_resource in G.RepairmanList:
......@@ -314,13 +316,12 @@ def main(argv=[], input_data=None):
G.outputJSON['general'] ={};
G.outputJSON['general']['_class'] = 'Dream.Configuration';
G.outputJSON['general']['totalExecutionTime'] = (time.time()-start);
G.outputJSON['modelResource'] =[];
G.outputJSON['coreObject'] =[];
G.outputJSON['elementList'] =[];
#output data to JSON for every object in the topology
for core_object in G.ObjList:
for element in G.ObjList:
try:
core_object.outputResultsJSON()
element.outputResultsJSON()
except AttributeError:
pass
......
......@@ -496,7 +496,7 @@ class Machine(Process):
json['results']['waiting_ratio']['avg']=self.Waiting[0]
json['results']['waiting_ratio']['max']=self.Waiting[0]
G.outputJSON['coreObject'].append(json)
G.outputJSON['elementList'].append(json)
#takes the array and checks if all its values are identical (returns false) or not (returns true)
......
......@@ -43,6 +43,8 @@ class Repairman(object):
self.Waiting=[]
self.Working=[]
self.coreObjectIds=[] #list with the coreObjects that the repairman repairs
def initialize(self):
self.totalWorkingTime=0 #holds the total working time
self.totalWaitingTime=0 #holds the total waiting time
......@@ -140,7 +142,7 @@ class Repairman(object):
json['results']['waiting_ratio']['avg']=self.Waiting[0]
json['results']['waiting_ratio']['max']=self.Waiting[0]
G.outputJSON['coreObject'].append(json)
G.outputJSON['elementList'].append(json)
#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!
......
{"elementList": [{"_class": "Dream.Machine", "id": "M1", "results": {"working_ratio": 12.760416666666666, "blockage_ratio": 78.17708333333333, "failure_ratio": 9.027777777777779, "waiting_ratio": 0.034722222222222224}}, {"_class": "Dream.Machine", "id": "M2", "results": {"working_ratio": 76.31944444444444, "blockage_ratio": 0.0, "failure_ratio": 19.791666666666668, "waiting_ratio": 3.888888888888889}}, {"_class": "Dream.Exit", "id": "E1", "results": {"throughput": 732, "takt_time": 1.965846994535519, "lifespan": 7.646516393442623}}, {"_class": "Dream.Repairman", "id": "W1", "results": {"working_ratio": 26.73611111111111, "waiting_ratio": 73.26388888888889}}], "_class": "Dream.Simulation", "general": {"totalExecutionTime": 0.2929999828338623, "_class": "Dream.Configuration"}}
\ 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