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

main JSON script updated to read the event generator. Topology27 added for test

parent 7eafac20
...@@ -30,8 +30,10 @@ from SimPy.Simulation import now, hold, Process ...@@ -30,8 +30,10 @@ from SimPy.Simulation import now, hold, Process
from ObjectInterruption import ObjectInterruption from ObjectInterruption import ObjectInterruption
class EventGenerator(ObjectInterruption): class EventGenerator(ObjectInterruption):
def __init__(self, start=None, stop=None, interval=None, duration=None, method=None, argumentDict=None): def __init__(self, id=id, name=None, start=None, stop=None, interval=None, duration=None, method=None, argumentDict=None):
ObjectInterruption.__init__(self) ObjectInterruption.__init__(self)
self.id=id
self.name=name
self.start=start self.start=start
self.stop=stop self.stop=stop
self.interval=interval self.interval=interval
......
...@@ -71,6 +71,22 @@ class G: ...@@ -71,6 +71,22 @@ class G:
numberOfEntities = 0 numberOfEntities = 0
def moveExcess(argumentDict={}):
giver=findObjectById(argumentDict.get('from', None))
receiver=findObjectById(argumentDict.get('to', None))
safetyStock=int(argumentDict.get('safetyStock', 10))
consumption=int(argumentDict.get('consumption', 1))
if giver and receiver:
if len(giver.getActiveObjectQueue())>safetyStock:
giver.next=[receiver]
receiver.previous=[giver]
for i in range(consumption):
receiver.getEntity()
giver.next=[]
receiver.previous=[]
else:
print "Giver and/or Receiver not defined"
def findObjectById(id): def findObjectById(id):
for obj in G.ObjList: for obj in G.ObjList:
if obj.id==id: if obj.id==id:
...@@ -88,18 +104,4 @@ def setWIP(entityList): ...@@ -88,18 +104,4 @@ def setWIP(entityList):
entity.schedule.append([object,now()]) #append the time to schedule so that it can be read in the result entity.schedule.append([object,now()]) #append the time to schedule so that it can be read in the result
entity.currentStation=object # update the current station of the entity entity.currentStation=object # update the current station of the entity
def moveExcess(argumentDict={}):
giver=argumentDict.get('from', None)
receiver=argumentDict.get('to', None)
safetyStock=int(argumentDict.get('safetyStock', 10))
consumption=int(argumentDict.get('consumption', 1))
if giver and receiver:
if len(giver.getActiveObjectQueue())>safetyStock:
giver.next=[receiver]
receiver.previous=[giver]
for i in range(consumption):
receiver.getEntity()
giver.next=[]
receiver.previous=[]
else:
print "Giver and/or Receiver not defined"
{
"_class": "Dream.Simulation",
"edges": {
"0": [
"S1",
"M1",
{}
],
"1": [
"M1",
"Q1",
{}
],
"2": [
"Q1",
"M2",
{}
],
"3": [
"M2",
"Q2",
{}
]
},
"general": {
"_class": "Dream.Configuration",
"confidenceLevel": "0.95",
"maxSimTime": "400",
"numberOfReplications": "1",
"trace": "No"
},
"nodes": {
"E1": {
"_class": "Dream.Exit",
"left": 0.2978723404255319,
"name": "Stock",
"top": 0.045454545454545414
},
"M1": {
"_class": "Dream.Machine",
"failures": {},
"left": 0.4414893617021277,
"name": "Machine1",
"processingTime": {
"distributionType": "Fixed",
"mean": "0.75"
},
"top": 0.5909090909090908
},
"M2": {
"_class": "Dream.Machine",
"failures": {},
"left": 0.2978723404255319,
"name": "Machine2",
"processingTime": {
"distributionType": "Fixed",
"mean": "0.75"
},
"top": 0.2272727272727273
},
"Q1": {
"_class": "Dream.Queue",
"capacity": "-1",
"isDummy": "0",
"left": 0.4414893617021277,
"name": "Queue2",
"top": 0.40909090909090906
},
"Q2": {
"_class": "Dream.Queue",
"capacity": "-1",
"isDummy": "0",
"left": 0.4414893617021277,
"name": "Queue1",
"top": 0.40909090909090906
},
"S1": {
"_class": "Dream.Source",
"entity": "Part",
"interarrivalTime": {
"distributionType": "Fixed",
"mean": "1"
},
"left": 0.6968085106382979,
"name": "Raw Material",
"top": 0.9545454545454546
},
"EV": {
"_class": "Dream.EventGenerator",
"name": "ExcessEntitiesMover",
"start": "60",
"interval": "60",
"method": "Globals.moveExcess",
"argumentDict": {
"from": "Q2",
"to": "E1",
"safetyStock": 70,
"consumption": 20
}
}
}
}
\ No newline at end of file
...@@ -77,6 +77,7 @@ from BatchDecomposition import BatchDecomposition ...@@ -77,6 +77,7 @@ from BatchDecomposition import BatchDecomposition
from BatchReassembly import BatchReassembly from BatchReassembly import BatchReassembly
from BatchScrapMachine import BatchScrapMachine from BatchScrapMachine import BatchScrapMachine
from LineClearance import LineClearance from LineClearance import LineClearance
from EventGenerator import EventGenerator
import ExcelHandler import ExcelHandler
import time import time
...@@ -85,6 +86,8 @@ from random import Random ...@@ -85,6 +86,8 @@ from random import Random
import sys import sys
import os.path import os.path
import Globals import Globals
import ast
# =========================================================================== # ===========================================================================
# reads general simulation inputs # reads general simulation inputs
...@@ -141,6 +144,7 @@ def createObjects(): ...@@ -141,6 +144,7 @@ def createObjects():
G.BatchReassemblyList=[] G.BatchReassemblyList=[]
G.LineClearanceList=[] G.LineClearanceList=[]
G.BatchScrapMachine=[] G.BatchScrapMachine=[]
G.EventGeneratorList=[]
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
# loop through all the model resources # loop through all the model resources
...@@ -415,7 +419,40 @@ def createObjects(): ...@@ -415,7 +419,40 @@ def createObjects():
LC.nextIds=getSuccessorList(id) LC.nextIds=getSuccessorList(id)
G.LineClearanceList.append(LC) G.LineClearanceList.append(LC)
G.ObjList.append(LC) G.ObjList.append(LC)
# -----------------------------------------------------------------------
# loop through all the nodes to
# search for Event Generator and create them
# this is put last, since the EventGenerator
# may take other objects as argument
# -----------------------------------------------------------------------
for (element_id, element) in nodes.iteritems(): # use an iterator to go through all the nodes
# the key is the element_id and the second is the
# element itself
element['id'] = element_id # create a new entry for the element (dictionary)
# with key 'id' and value the the element_id
elementClass = element.get('_class', 'not found') # get the class type of the element
if elementClass=='Dream.EventGenerator': # check the object type
id = element.get('id', 'not found') # get the id of the element / default 'not_found'
name = element.get('name', 'not found') # get the name of the element / default 'not_found'
start = float(element.get('start', '0')) # get the start of the generator / default 0
stop = float(element.get('stop', -1)) # get the stop of the generator / default -1 that leads yo
# infinity (had to be done to make it as float)
if stop<0:
stop=infinity
interval = float(element.get('start', '1')) # get the interval of the generator / default 1
duration = float(element.get('duration', 0)) # get the duration of the generator / default 0
method = (element.get('method', None)) # get the method to be run / default None
method = method.split('.')
method=getattr(str_to_class(method[0]),method[1])
#argumentDict=ast.literal_eval(element.get('argumentDict', {}))
argumentDict=(element.get('argumentDict', {})) # get the arguments of the method as a dict / default {}
EV = EventGenerator(id, name, start=start, stop=stop, interval=interval,
duration=duration, method=method, argumentDict=argumentDict) # create the EventGenerator object
# calling the getSuccessorList() method on the repairman
G.EventGeneratorList.append(EV) # add the Event Generator to the RepairmanList
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
# loop through all the core objects # loop through all the core objects
# to read predecessors # to read predecessors
...@@ -469,12 +506,6 @@ def setTopology(): ...@@ -469,12 +506,6 @@ def setTopology():
else: else:
element.defineRouting(previous, next) element.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 # initializes all the objects that are in the topology
# =========================================================================== # ===========================================================================
...@@ -485,6 +516,8 @@ def initializeObjects(): ...@@ -485,6 +516,8 @@ def initializeObjects():
repairman.initialize() repairman.initialize()
for entity in G.EntityList: for entity in G.EntityList:
entity.initialize() entity.initialize()
for ev in G.EventGeneratorList:
ev.initialize()
# =========================================================================== # ===========================================================================
# activates all the objects # activates all the objects
...@@ -495,6 +528,11 @@ def activateObjects(): ...@@ -495,6 +528,11 @@ def activateObjects():
activate(element, element.run()) activate(element, element.run())
except AttributeError: except AttributeError:
pass pass
for ev in G.EventGeneratorList:
try:
activate(ev, ev.run())
except AttributeError:
pass
# =========================================================================== # ===========================================================================
# reads the WIP of the stations # reads the WIP of the stations
...@@ -568,7 +606,13 @@ def createWIP(): ...@@ -568,7 +606,13 @@ def createWIP():
G.WipList.append(J) G.WipList.append(J)
G.EntityList.append(J) G.EntityList.append(J)
# ===========================================================================
# used to convert a string read from the input to object type
# ===========================================================================
def str_to_class(str):
return getattr(sys.modules[__name__], str)
# =========================================================================== # ===========================================================================
# the main script that is ran # the main script that is ran
# =========================================================================== # ===========================================================================
......
...@@ -53,8 +53,8 @@ Q1.defineRouting([M1],[M2]) ...@@ -53,8 +53,8 @@ Q1.defineRouting([M1],[M2])
M2.defineRouting([Q1],[Q2]) M2.defineRouting([Q1],[Q2])
Q2.defineRouting([M2]) Q2.defineRouting([M2])
argumentDict={'from':Q2,'to':E, 'safetyStock':70, 'consumption':20} argumentDict={'from':'Q2','to':'E1','safetyStock':70,'consumption':20}
EG=EventGenerator(start=60, interval=60, method=Globals.moveExcess, argumentDict=argumentDict) EG=EventGenerator(id="EV", name="ExcessEntitiesMover" ,start=60, interval=60, method=Globals.moveExcess, argumentDict=argumentDict)
G.ObjList=[S,M1,M2,E,Q1,Q2,EG] G.ObjList=[S,M1,M2,E,Q1,Q2,EG]
initialize() #initialize the simulation (SimPy method) initialize() #initialize the simulation (SimPy method)
......
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