Commit 3cc9ee98 authored by Georgios Dagkakis's avatar Georgios Dagkakis

cleanup

parent 3bad49dd
......@@ -121,9 +121,10 @@ def readGeneralInput():
# generic for the model
# ===========================================================================
# creates the simulation objects
# creates first the object interruptions
# and then the core objects
# ===========================================================================
def createObjects():
def createObjectResourcesAndCoreObjects():
json_data = G.JSONData
#Read the json data
......@@ -289,61 +290,100 @@ def createObjects():
possible_successor.previousIds.append(element.id)
# ===========================================================================
# defines the topology (predecessors and successors for all the objects)
# ===========================================================================
def setTopology():
#loop through all the objects
for element in G.ObjList:
next=[]
previous=[]
for j in range(len(element.previousIds)):
for q in range(len(G.ObjList)):
if G.ObjList[q].id==element.previousIds[j]:
previous.append(G.ObjList[q])
for j in range(len(element.nextIds)):
for q in range(len(G.ObjList)):
if G.ObjList[q].id==element.nextIds[j]:
next.append(G.ObjList[q])
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 element.type=="Dismantle":
nextPart=[]
nextFrame=[]
for j in range(len(element.nextPartIds)):
for q in range(len(G.ObjList)):
if G.ObjList[q].id==element.nextPartIds[j]:
nextPart.append(G.ObjList[q])
for j in range(len(element.nextFrameIds)):
for q in range(len(G.ObjList)):
if G.ObjList[q].id==element.nextFrameIds[j]:
nextFrame.append(G.ObjList[q])
element.defineRouting(previous, next)
element.definePartFrameRouting(nextPart, nextFrame)
else:
element.defineRouting(previous, next)
# ===========================================================================
# initializes all the objects that are in the topology
# ===========================================================================
def initializeObjects():
for element in G.ObjList + G.ObjectResourceList + G.EntityList + G.ObjectInterruptionList:
element.initialize()
# creates the object interruptions
# ===========================================================================
# activates all the objects
# ===========================================================================
def activateObjects():
for element in G.ObjList + G.ObjectInterruptionList:
G.env.process(element.run())
def createObjectInterruptions():
G.ObjectInterruptionList=[]
G.ScheduledMaintenanceList=[]
G.FailureList=[]
G.ShiftSchedulerList=[]
G.EventGeneratorList=[]
G.CapacityStationControllerList=[]
json_data = G.JSONData
#Read the json data
nodes = json_data['nodes'] # read from the dictionary the dicts with key 'nodes'
# -----------------------------------------------------------------------
# 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
objClass = element.get('_class', 'not found') # get the class type of the element
from ObjectInterruption import ObjectInterruption
import Globals
objClass = element.pop('_class')
objectType=Globals.getClassFromName(objClass)
# from CoreObject import CoreObject
# if issubclass(objectType, CoreObject):
if issubclass(objectType,ObjectInterruption): # check the object type
inputDict=dict(element)
# create the ObjectInterruption
objectInterruption=objectType(**inputDict)
G.ObjectInterruptionList.append(objectInterruption)
# search inside the nodes for encapsulated ObjectInterruptions (failures etc)
# ToDo this will be cleaned a lot if we update the JSON notation:
# define ObjectInterruption echelon inside node
# define interruptions' distribution better
for (element_id, element) in nodes.iteritems():
element['id'] = element_id
scheduledMaintenance=element.get('scheduledMaintenance', {})
# if there is a scheduled maintenance initiate it and append it
# to the interruptions- and scheduled maintenances- list
if len(scheduledMaintenance):
start=float(scheduledMaintenance.get('start', 0))
duration=float(scheduledMaintenance.get('duration', 1))
victim=Globals.findObjectById(element['id'])
SM=ScheduledMaintenance(victim=victim, start=start, duration=duration)
victim.objectInterruptions.append(SM)
G.ObjectInterruptionList.append(SM)
G.ScheduledMaintenanceList.append(SM)
failure=element.get('failures', None)
# if there are failures assigned
# initiate them
if failure:
distributionType=failure.get('distributionType', 'No')
if distributionType=='No':
pass
else:
victim=Globals.findObjectById(element['id'])
deteriorationType=failure.get('deteriorationType', 'constant')
F=Failure(victim, distribution=failure, repairman=victim.repairman, deteriorationType=deteriorationType)
victim.objectInterruptions.append(F)
G.ObjectInterruptionList.append(F)
G.FailureList.append(F)
# if there is a shift pattern defined
# initiate them
shift=element.get('shift', {})
if len(shift):
victim=Globals.findObjectById(element['id'])
shiftPattern=list(shift.get('shiftPattern', []))
# patch to correct if input has end of shift at the same time of start of next shift
# TODO check if the backend should be able to handle this
for index, element in enumerate(shiftPattern):
if element is shiftPattern[-1]:
break
next = shiftPattern[index + 1]
if element[1]==next[0]:
element[1]=next[1]
shiftPattern.remove(next)
endUnfinished=bool(int(shift.get('endUnfinished', 0)))
receiveBeforeEndThreshold=float(shift.get('receiveBeforeEndThreshold', 0))
SS=ShiftScheduler(victim, shiftPattern=shiftPattern, endUnfinished=endUnfinished,
receiveBeforeEndThreshold=receiveBeforeEndThreshold)
victim.objectInterruptions.append(SS)
G.ObjectInterruptionList.append(SS)
G.ShiftSchedulerList.append(SS)
# ===========================================================================
# reads the WIP of the stations
# creates the entities that are wip
# ===========================================================================
def createWIP():
G.JobList=[]
......@@ -373,14 +413,14 @@ def createWIP():
entityType=Globals.getClassFromName(entityClass)
inputDict=dict(entity)
inputDict.pop('_class')
if entityClass in ['Dream.CapacityEntity', 'Dream.CapacityProject', 'Dream.Part',
'Dream.Batch', 'Dream.SubBatch', 'Dream.Job', 'Dream.Mould', 'Dream.OrderComponent']:
from Entity import Entity
if issubclass(entityType, Entity) and (not entityClass=='Dream.Order'):
entity=entityType(**inputDict)
G.EntityList.append(entity)
object=Globals.findObjectById(element['id'])
entity.currentStation=object
# ToDo order is to defined in a new way
if entityClass=='Dream.Order':
id=entity.get('id', 'not found')
name=entity.get('name', 'not found')
......@@ -449,99 +489,60 @@ def createWIP():
G.WipList.append(OD)
G.EntityList.append(OD)
G.JobList.append(OD)
# ===========================================================================
# reads the interruptions of the stations
# defines the topology (predecessors and successors for all the objects)
# ===========================================================================
def createObjectInterruptions():
G.ObjectInterruptionList=[]
G.ScheduledMaintenanceList=[]
G.FailureList=[]
G.ShiftSchedulerList=[]
G.EventGeneratorList=[]
G.CapacityStationControllerList=[]
json_data = G.JSONData
#Read the json data
nodes = json_data['nodes'] # read from the dictionary the dicts with key 'nodes'
# -----------------------------------------------------------------------
# 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
objClass = element.get('_class', 'not found') # get the class type of the element
from ObjectInterruption import ObjectInterruption
import Globals
objClass = element.pop('_class')
objectType=Globals.getClassFromName(objClass)
# from CoreObject import CoreObject
# if issubclass(objectType, CoreObject):
if issubclass(objectType,ObjectInterruption): # check the object type
inputDict=dict(element)
# create the ObjectInterruption
objectInterruption=objectType(**inputDict)
G.ObjectInterruptionList.append(objectInterruption)
# search inside the nodes for encapsulated ObjectInterruptions (failures etc)
# ToDo this will be cleaned a lot if we update the JSON notation:
# define ObjectInterruption echelon inside node
# define interruptions' distribution better
for (element_id, element) in nodes.iteritems():
element['id'] = element_id
scheduledMaintenance=element.get('scheduledMaintenance', {})
# if there is a scheduled maintenance initiate it and append it
# to the interruptions- and scheduled maintenances- list
if len(scheduledMaintenance):
start=float(scheduledMaintenance.get('start', 0))
duration=float(scheduledMaintenance.get('duration', 1))
victim=Globals.findObjectById(element['id'])
SM=ScheduledMaintenance(victim=victim, start=start, duration=duration)
victim.objectInterruptions.append(SM)
G.ObjectInterruptionList.append(SM)
G.ScheduledMaintenanceList.append(SM)
failure=element.get('failures', None)
# if there are failures assigned
# initiate them
if failure:
distributionType=failure.get('distributionType', 'No')
if distributionType=='No':
pass
else:
victim=Globals.findObjectById(element['id'])
deteriorationType=failure.get('deteriorationType', 'constant')
F=Failure(victim, distribution=failure, repairman=victim.repairman, deteriorationType=deteriorationType)
victim.objectInterruptions.append(F)
G.ObjectInterruptionList.append(F)
G.FailureList.append(F)
# if there is a shift pattern defined
# initiate them
shift=element.get('shift', {})
if len(shift):
victim=Globals.findObjectById(element['id'])
shiftPattern=list(shift.get('shiftPattern', []))
# patch to correct if input has end of shift at the same time of start of next shift
# TODO check if the backend should be able to handle this
for index, element in enumerate(shiftPattern):
if element is shiftPattern[-1]:
break
next = shiftPattern[index + 1]
if element[1]==next[0]:
element[1]=next[1]
shiftPattern.remove(next)
endUnfinished=bool(int(shift.get('endUnfinished', 0)))
receiveBeforeEndThreshold=float(shift.get('receiveBeforeEndThreshold', 0))
SS=ShiftScheduler(victim, shiftPattern=shiftPattern, endUnfinished=endUnfinished,
receiveBeforeEndThreshold=receiveBeforeEndThreshold)
victim.objectInterruptions.append(SS)
G.ObjectInterruptionList.append(SS)
G.ShiftSchedulerList.append(SS)
def setTopology():
#loop through all the objects
for element in G.ObjList:
next=[]
previous=[]
for j in range(len(element.previousIds)):
for q in range(len(G.ObjList)):
if G.ObjList[q].id==element.previousIds[j]:
previous.append(G.ObjList[q])
for j in range(len(element.nextIds)):
for q in range(len(G.ObjList)):
if G.ObjList[q].id==element.nextIds[j]:
next.append(G.ObjList[q])
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 element.type=="Dismantle":
nextPart=[]
nextFrame=[]
for j in range(len(element.nextPartIds)):
for q in range(len(G.ObjList)):
if G.ObjList[q].id==element.nextPartIds[j]:
nextPart.append(G.ObjList[q])
for j in range(len(element.nextFrameIds)):
for q in range(len(G.ObjList)):
if G.ObjList[q].id==element.nextFrameIds[j]:
nextFrame.append(G.ObjList[q])
element.defineRouting(previous, next)
element.definePartFrameRouting(nextPart, nextFrame)
else:
element.defineRouting(previous, next)
# ===========================================================================
# initializes all the objects that are in the topology
# ===========================================================================
def initializeObjects():
for element in G.ObjList + G.ObjectResourceList + G.EntityList + G.ObjectInterruptionList:
element.initialize()
# ===========================================================================
# activates all the objects
# ===========================================================================
def activateObjects():
for element in G.ObjList + G.ObjectInterruptionList:
G.env.process(element.run())
# ===========================================================================
# the main script that is ran
......@@ -568,7 +569,7 @@ def main(argv=[], input_data=None):
#read the input from the JSON file and create the line
G.JSONData=json.loads(G.InputData) # create the dictionary JSONData
readGeneralInput()
createObjects()
createObjectResourcesAndCoreObjects()
createObjectInterruptions()
setTopology()
......
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