Commit fb47a826 authored by Georgios Dagkakis's avatar Georgios Dagkakis

full JSON version with JSON files and Plant Topologies to compare

parent b30cacb0
[user]
name = george dagkakis
email = gdagkakis@yahoo.com
name = Georgios Dagkakis
email = georgios.dagkakis@ul.ie
[push]
default = simple
{"_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
......@@ -19,5 +19,5 @@
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" ></uses-permission>
</manifest>
\ No newline at end of file
......@@ -19,7 +19,7 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:layout_below="@+id/camera3"
android:src="@drawable/ic_launcher"/>
android:layout_below="@+id/camera3"/>
</RelativeLayout >
\ No newline at end of file
package mobile.event.org;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.http.HttpConnection;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
public class MobileEventGuide extends Activity implements OnClickListener{
/** Called when the activity is first created. */
int CAMERA_PIC_REQUEST=3333;
private int CAMERA_PIC_REQUEST=3333;
private Bitmap pic=null;
@Override
......@@ -27,30 +44,144 @@ public class MobileEventGuide extends Activity implements OnClickListener{
public void Camera(){
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_PIC_REQUEST) //
if (resultCode == Activity.RESULT_OK) {
// Display image received on the view
Bundle b = data.getExtras(); // Kept as a Bundle to check for other things in my actual code
Bitmap pic = (Bitmap) b.get("data");
pic = (Bitmap) b.get("data");
// String Image=data.getData();
if (pic != null) {
//Display your image in an ImageView in your layout (if you want to test it)
ImageView pictureHolder = (ImageView) this.findViewById(R.id.pictureholder);
pictureHolder.setImageBitmap(pic);
//handlePicture(pic, "jpg");
pictureHolder.invalidate();
}
}
else if (resultCode == Activity.RESULT_CANCELED) {}
}
/*public void post(){
String url = "http://???.???.??/CommunicationOfficeService/TempExchangeRatesService.asmx";
HttpURLConnection hc = (HttpURLConnection) Connector.open(url);
//Some web servers requires these properties
hc.setRequestMethod(HttpConnection.POST);
hc.setRequestProperty("SOAPAction", "http://www.???.??/TempExchangeRatesService/GetCurrentExchangeRatesXML");
hc.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Configuration/CLDC-1.0");
hc.setRequestProperty("Content-Type", "text/xml;charset=utf-8");
hc.setRequestProperty("Content-Length", Integer.toString(message.length()));
hc.setRequestProperty("Connection", "close");
OutputStream os = hc.openOutputStream();
os.write(message.getBytes());
os.close();
}*/
private boolean handlePicture(String mimeType) {
HttpURLConnection connection = null;
DataOutputStream outStream = null;
DataInputStream inStream = null;
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
int bytesRead, bytesAvailable, bufferSize;
byte[] buffer;
int maxBufferSize = 1*1024*1024;
String urlString = "http://megimage.heroku.com/upload";
try {
/*FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream(new File(filePath));
} catch(FileNotFoundException e) { }
*/
URL url = new URL(urlString);
connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
outStream = new DataOutputStream(connection.getOutputStream());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
pic.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] byteArray = baos.toByteArray();
//byte[] byteArray = {(byte) 1, (byte) 2};
outStream.write(byteArray);
outStream.flush();
outStream.close();
/*outStream.writeBytes(addParam("someparam", "content of some param", twoHyphens, boundary, lineEnd));
//outStream.writeBytes(twoHyphens + boundary + lineEnd);
outStream.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + filePath +"\"" + lineEnd + "Content-Type: " + mimeType + lineEnd + "Content-Transfer-Encoding: binary" + lineEnd);
outStream.writeBytes(lineEnd);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
buffer = new byte[bufferSize];
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
while (bytesRead > 0) {
outStream.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
}
outStream.writeBytes(lineEnd);
outStream.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
fileInputStream.close();
outStream.flush();
outStream.close(); */
} catch (MalformedURLException e) {
Log.e("DEBUG", "[MalformedURLException while sending a picture]");
} catch (IOException e) {
Log.e("DEBUG", "[IOException while sending a picture]");
}
try {
inStream = new DataInputStream( connection.getInputStream() );
String str;
while (( str = inStream.readLine()) != null) {
if(str=="1") {
return true;
} else {
return false;
}
}
inStream.close();
} catch (IOException e){
Log.e("DEBUG", "[IOException while sending a picture and receiving the response]");
}
return false;
}
private String addParam(String key, String value, String twoHyphens, String boundary, String lineEnd) {
return twoHyphens + boundary + lineEnd + "Content-Disposition: form-data; name=\"" + key + "\"" + lineEnd + lineEnd + value + lineEnd;
}
@Override
public void onClick(View v) {
switch (v.getId()) {
......
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