Commit b4049b58 authored by panos's avatar panos Committed by Georgios Dagkakis

Add the Assembly line example

parent c43bfe1f
'''
Created on 9 Oct 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/>.
# ===========================================================================
import json
#Create a method that receives the three dictionaries from the KE tool main script, updates the JSON schema and returns it to the KE tool main script
def JSON_example(list1,list2,list3):
jsonFile= open('JSON_example.json', 'r') #open the JSON_example.json file
data = json.load(jsonFile)
jsonFile.close()
nodes=data.get('nodes',{})
batchWIP={}
for (element_id,element) in nodes.iteritems():
name=element.get('name')
wip=element.get('wip',[])
for key in list3.keys(): # conduct a loop statement in the keys of the list3, which actually is the WIP dict
batchWIP['_class']='Dream.Batch' # static inputs to batchWIP dict
batchWIP['numberOfUnits']="80"
batchWIP['name']='Batch'
if list3[key][0]== name: # condition that checks if the element in the list3 dict is the same as the name of the element in JSON file
batchWIP['id']=str(key) # input the container id of the WIP batch to the batchWIP dict
try:
if list3[key][2]: # a condition to check if the WIP is in a station and not in a buffer
batchWIP['unitsToProcess']=str(list3[key][2]) # input the unitsToProcess attribute to the batchWIP dict
wip.append(batchWIP) # append in the wip attribute in JSON the batchWIP dict
batchWIP={}
except IndexError:
wip.append(batchWIP) # in case the WIP is not in a station but it's in a buffer; append again the batchWIP dict (without the unitsToProcess this time)
batchWIP={}
else:
continue
if name in list1.keys(): # condition that checks if the element in the list1 is the same as the name of the element in JSON file
element['processingTime']= list1[name] # input the attributes of list1[name] to the JSON's element 'processingTime'
else:
continue
if name in list2.keys(): # condition that checks if the element in the list2 is the same as the name of the element in JSON file
element['scrapQuantity']= list2[name] # input the attributes of list2[name] to the JSON's element 'scrapQuantity'
else:
continue
jsonFile = open('JSON_exampleOutput.json',"w")
jsonFile.write(json.dumps(data, indent=True))
jsonFile.close()
return json.dumps(data, indent=True)
\ No newline at end of file
{
"edges": {
"con_140": [
"S1",
"QStart",
{}
],
"con_145": [
"QStart",
"BDA",
{}
],
"con_150": [
"QStart",
"BDB",
{}
],
"con_155": [
"BDA",
"M1A",
{}
],
"con_160": [
"M1A",
"Q2A",
{}
],
"con_165": [
"Q2A",
"M2A",
{}
],
"con_170": [
"M2A",
"Q3A",
{}
],
"con_175": [
"Q3A",
"M3A",
{}
],
"con_180": [
"M3A",
"BRA",
{}
],
"con_185": [
"BRA",
"QM",
{}
],
"con_190": [
"BDB",
"M1B",
{}
],
"con_195": [
"M1B",
"Q2B",
{}
],
"con_200": [
"Q2B",
"M2B",
{}
],
"con_205": [
"M2B",
"Q3B",
{}
],
"con_210": [
"Q3B",
"M3B",
{}
],
"con_215": [
"M3B",
"BRB",
{}
],
"con_220": [
"BRB",
"QM",
{}
],
"con_225": [
"QM",
"MM",
{}
],
"con_230": [
"MM",
"QPr",
{}
],
"con_235": [
"QPr",
"PrA",
{}
],
"con_240": [
"QPr",
"PrB",
{}
],
"con_245": [
"PrA",
"QPa",
{}
],
"con_250": [
"PrB",
"QPa",
{}
],
"con_255": [
"QPa",
"PaA",
{}
],
"con_260": [
"QPa",
"PaB",
{}
],
"con_265": [
"PaA",
"E1",
{}
],
"con_270": [
"PaB",
"E1",
{}
]
},
"general": {
"confidenceLevel": "0.95",
"maxSimTime": "2880",
"numberOfReplications": "1",
"processTimeout": "0.5",
"trace": "No"
},
"nodes": {
"BDA": {
"_class": "Dream.BatchDecompositionStartTime",
"element_id": "DreamNode_1",
"name": "Deco_A",
"numberOfSubBatches": 4,
"processingTime": {
"distributionType": "Fixed",
"mean": "0"
}
},
"BDB": {
"_class": "Dream.BatchDecompositionStartTime",
"element_id": "DreamNode_2",
"name": "Deco_B",
"numberOfSubBatches": 4,
"processingTime": {
"distributionType": "Fixed",
"mean": "0"
}
},
"BRA": {
"_class": "Dream.BatchReassembly",
"element_id": "DreamNode_3",
"name": "Assembly_A",
"numberOfSubBatches": 4,
"processingTime": {
"distributionType": "Fixed",
"mean": "0"
}
},
"BRB": {
"_class": "Dream.BatchReassembly",
"element_id": "DreamNode_4",
"name": "Assembly_B",
"numberOfSubBatches": 4,
"processingTime": {
"distributionType": "Fixed",
"mean": "0"
}
},
"E1": {
"_class": "Dream.Exit",
"element_id": "DreamNode_5",
"name": "Stock"
},
"M1A": {
"_class": "Dream.BatchScrapMachine",
"element_id": "DreamNode_6",
"failures": {},
"name": "M1A",
"shift": {
"shiftPattern": [[360,780], [1800,2220]],
"endUnfinished": 0
},
"scrapQuantity": {
},
"processingTime": {
},
"wip": [
]
},
"M1B": {
"_class": "Dream.BatchScrapMachine",
"element_id": "DreamNode_7",
"failures": {},
"name": "M1B",
"shift": {
"shiftPattern": [[360,1260], [1800,2700]],
"endUnfinished": 0
},
"scrapQuantity": {
},
"processingTime": {
},
"wip": [
]
},
"M2A": {
"_class": "Dream.BatchScrapMachine",
"element_id": "DreamNode_8",
"failures": {},
"name": "M2A",
"shift": {
"shiftPattern": [[360,780], [1800,2220]],
"endUnfinished": 0
},
"scrapQuantity": {
},
"processingTime": {
},
"wip": [
]
},
"M2B": {
"_class": "Dream.BatchScrapMachine",
"element_id": "DreamNode_9",
"failures": {},
"name": "M2B",
"shift": {
"shiftPattern": [[360,1260], [1800,2700]],
"endUnfinished": 0
},
"scrapQuantity": {
},
"processingTime": {
},
"wip": [
]
},
"M3A": {
"_class": "Dream.BatchScrapMachine",
"element_id": "DreamNode_10",
"failures": {},
"name": "M3A",
"shift": {
"shiftPattern": [[360,780], [1800,2220]],
"endUnfinished": 0
},
"scrapQuantity": {
},
"processingTime": {
},
"wip": [
]
},
"M3B": {
"_class": "Dream.BatchScrapMachine",
"element_id": "DreamNode_11",
"failures": {},
"name": "M3B",
"shift": {
"shiftPattern": [[360,1260], [1800,2700]],
"endUnfinished": 0
},
"scrapQuantity": {
},
"processingTime": {
},
"wip": [
]
},
"MM": {
"_class": "Dream.BatchScrapMachine",
"element_id": "DreamNode_12",
"failures": {},
"name": "MM",
"shift": {
"shiftPattern": [[360,1260], [1800,2700]],
"endUnfinished": 0
},
"scrapQuantity": {
},
"processingTime": {
},
"wip": [
]
},
"PaA": {
"_class": "Dream.BatchScrapMachine",
"element_id": "DreamNode_13",
"failures": {},
"name": "PaA",
"shift": {
"shiftPattern": [[360,780], [1800,2220]],
"endUnfinished": 0
},
"scrapQuantity": {
},
"processingTime": {
},
"wip": [
]
},
"PaB": {
"_class": "Dream.BatchScrapMachine",
"element_id": "DreamNode_14",
"failures": {},
"name": "PaB",
"shift": {
"shiftPattern": [[360,1260], [1800,2700]],
"endUnfinished": 0
},
"scrapQuantity": {
},
"processingTime": {
},
"wip": [
]
},
"PrA": {
"_class": "Dream.BatchScrapMachine",
"element_id": "DreamNode_15",
"failures": {},
"name": "PrA",
"shift": {
"shiftPattern": [[360,780], [1800,2220]],
"endUnfinished": 0
},
"scrapQuantity": {
},
"processingTime": {
},
"wip": [
]
},
"PrB": {
"_class": "Dream.BatchScrapMachine",
"element_id": "DreamNode_16",
"failures": {},
"name": "PrB",
"shift": {
"shiftPattern": [[360,1260], [1800,2700]],
"endUnfinished": 0
},
"scrapQuantity": {
},
"processingTime": {
},
"wip": [
]
},
"Q2A": {
"_class": "Dream.LineClearance",
"capacity": "2",
"element_id": "DreamNode_17",
"isDummy": "0",
"name": "Q2A",
"schedulingRule": "FIFO",
"wip": [
]
},
"Q2B": {
"_class": "Dream.LineClearance",
"capacity": "2",
"element_id": "DreamNode_18",
"isDummy": "0",
"name": "Q2B",
"schedulingRule": "FIFO",
"wip": [
]
},
"Q3A": {
"_class": "Dream.LineClearance",
"capacity": "2",
"element_id": "DreamNode_19",
"isDummy": "0",
"name": "Q3A",
"schedulingRule": "FIFO",
"wip": [
]
},
"Q3B": {
"_class": "Dream.LineClearance",
"capacity": "2",
"element_id": "DreamNode_20",
"isDummy": "0",
"name": "Q3B",
"schedulingRule": "FIFO",
"wip": [
]
},
"QM": {
"_class": "Dream.Queue",
"capacity": "3",
"element_id": "DreamNode_21",
"isDummy": "0",
"name": "QM",
"schedulingRule": "FIFO",
"wip": [
]
},
"QPa": {
"_class": "Dream.Queue",
"capacity": "3",
"element_id": "DreamNode_22",
"isDummy": "0",
"name": "QPa",
"schedulingRule": "FIFO",
"wip": [
]
},
"QPr": {
"_class": "Dream.Queue",
"capacity": "3",
"element_id": "DreamNode_23",
"isDummy": "0",
"name": "QPr",
"schedulingRule": "FIFO",
"wip": [
]
},
"QStart": {
"_class": "Dream.Queue",
"capacity": "1",
"element_id": "DreamNode_24",
"isDummy": "0",
"name": "StartQueue",
"schedulingRule": "FIFO",
"wip": [
]
},
"S1": {
"_class": "Dream.BatchSource",
"batchNumberOfUnits": 100,
"element_id": "DreamNode_25",
"entity": "Dream.Batch",
"interarrivalTime": {
"distributionType": "Fixed",
"mean": "0.5"
},
"name": "Source"
},
"EV": {
"_class": "Dream.EventGenerator",
"name": "attainment",
"start": "1440",
"interval": "1440",
"method": "Dream.Globals.countIntervalThroughput",
"argumentDict": {
}
}
},
"spreadsheet": [
[
"Jobs",
"ID",
"Order Date",
"Due Date",
"Priority",
"Material",
"Sequence",
"Processing Times"
],
[
null,
null,
null,
null,
null,
null,
null,
null
]
]
}
\ No newline at end of file
'''
Created on 9 Oct 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/>.
# ===========================================================================
import datetime
import operator
# This method that returns the actual WIP (Work-In-Process containers ids) either in stations or buffers of the production line
def currentWIP(processStory, stopTime):
Stations={}
LastStation={}
for key in processStory.keys():
Stations[key]=[]
LastStation[key]=[]
sorted_proc=sorted(processStory[key].iteritems(), key=operator.itemgetter(1))
for i in range(len(sorted_proc)):
Stations[key].append(sorted_proc[i])
for key in Stations.keys():
for elem in range(len(Stations[key])):
try:
if Stations[key][elem][1][0][0] > stopTime and Stations[key][elem][1][1][0] > stopTime:
del Stations[key][elem]
elif Stations[key][elem][1][1][0] > stopTime:
del Stations[key][elem][1][1]
elif Stations[key][elem][1][0][0] > stopTime:
del Stations[key][elem][1][0]
except IndexError:
continue
try:
LastStation[key]=Stations[key][-1]
except KeyError:
continue
for key in LastStation.keys():
try:
if (LastStation[key][0]=='PaA' or LastStation[key][0]=='PaB') and (stopTime - LastStation[key][1][0][0] > datetime.timedelta(0,500)):
del LastStation[key]
except IndexError:
continue
WIP={}
for key in LastStation.keys():
WIP[key]=[]
try:
if not LastStation[key][1][1]:
continue
except IndexError:
WIP[key].append(LastStation[key][0])
try:
dif= stopTime - LastStation[key][1][0][0]
WIP[key].append(dif)
except IndexError:
continue
for key in LastStation.keys():
try:
if LastStation[key][0]=='MA' and LastStation[key][1][1]:
WIP[key].append('QStart')
elif LastStation[key][0]=='M1A' and LastStation[key][1][1]:
WIP[key].append('Q2A')
elif LastStation[key][0]=='M1B' and LastStation[key][1][1]:
WIP[key].append('Q2B')
elif LastStation[key][0]=='M2A' and LastStation[key][1][1]:
WIP[key].append('Q3A')
elif LastStation[key][0]=='M2B' and LastStation[key][1][1]:
WIP[key].append('Q3B')
elif (LastStation[key][0]=='M3A' or LastStation[key][0]=='M3B') and LastStation[key][1][1]:
WIP[key].append('QM')
elif LastStation[key][0]=='MM' and LastStation[key][1][1]:
WIP[key].append('QPr')
elif (LastStation[key][0]=='PrA' and LastStation[key][1][1]) or (LastStation[key][0]=='PrB' and LastStation[key][1][1]):
WIP[key].append('QPa')
except IndexError:
continue
return WIP
\ 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