Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
dream
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
dream
Commits
3cc9ee98
Commit
3cc9ee98
authored
Aug 22, 2014
by
Georgios Dagkakis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup
parent
3bad49dd
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
150 additions
and
149 deletions
+150
-149
dream/simulation/LineGenerationJSON.py
dream/simulation/LineGenerationJSON.py
+150
-149
No files found.
dream/simulation/LineGenerationJSON.py
View file @
3cc9ee98
...
@@ -121,9 +121,10 @@ def readGeneralInput():
...
@@ -121,9 +121,10 @@ def readGeneralInput():
# generic for the model
# generic for the model
# ===========================================================================
# ===========================================================================
# creates the simulation objects
# creates first the object interruptions
# and then the core objects
# ===========================================================================
# ===========================================================================
def
createObjects
():
def
createObject
ResourcesAndCoreObject
s
():
json_data
=
G
.
JSONData
json_data
=
G
.
JSONData
#Read the json data
#Read the json data
...
@@ -289,61 +290,100 @@ def createObjects():
...
@@ -289,61 +290,100 @@ def createObjects():
possible_successor
.
previousIds
.
append
(
element
.
id
)
possible_successor
.
previousIds
.
append
(
element
.
id
)
# ===========================================================================
# ===========================================================================
#
defines the topology (predecessors and successors for all the objects)
#
creates the object interruptions
# ===========================================================================
# ===========================================================================
def
setTopology
():
def
createObjectInterruptions
():
#loop through all the objects
G
.
ObjectInterruptionList
=
[]
for
element
in
G
.
ObjList
:
G
.
ScheduledMaintenanceList
=
[]
next
=
[]
G
.
FailureList
=
[]
previous
=
[]
G
.
ShiftSchedulerList
=
[]
for
j
in
range
(
len
(
element
.
previousIds
)):
G
.
EventGeneratorList
=
[]
for
q
in
range
(
len
(
G
.
ObjList
)):
G
.
CapacityStationControllerList
=
[]
if
G
.
ObjList
[
q
].
id
==
element
.
previousIds
[
j
]:
json_data
=
G
.
JSONData
previous
.
append
(
G
.
ObjList
[
q
])
#Read the json data
nodes
=
json_data
[
'nodes'
]
# read from the dictionary the dicts with key 'nodes'
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
)
# loop through all the nodes to
elif
element
.
type
==
"Exit"
:
# search for Event Generator and create them
element
.
defineRouting
(
previous
)
# this is put last, since the EventGenerator
#Dismantle should be changed to identify what the the successor is.
# may take other objects as argument
#nextPart and nextFrame will become problematic
# -----------------------------------------------------------------------
elif
element
.
type
==
"Dismantle"
:
for
(
element_id
,
element
)
in
nodes
.
iteritems
():
# use an iterator to go through all the nodes
nextPart
=
[]
# the key is the element_id and the second is the
nextFrame
=
[]
# element itself
for
j
in
range
(
len
(
element
.
nextPartIds
)):
element
[
'id'
]
=
element_id
# create a new entry for the element (dictionary)
for
q
in
range
(
len
(
G
.
ObjList
)):
# with key 'id' and value the the element_id
if
G
.
ObjList
[
q
].
id
==
element
.
nextPartIds
[
j
]:
objClass
=
element
.
get
(
'_class'
,
'not found'
)
# get the class type of the element
nextPart
.
append
(
G
.
ObjList
[
q
])
from
ObjectInterruption
import
ObjectInterruption
for
j
in
range
(
len
(
element
.
nextFrameIds
)):
import
Globals
for
q
in
range
(
len
(
G
.
ObjList
)):
objClass
=
element
.
pop
(
'_class'
)
if
G
.
ObjList
[
q
].
id
==
element
.
nextFrameIds
[
j
]:
objectType
=
Globals
.
getClassFromName
(
objClass
)
nextFrame
.
append
(
G
.
ObjList
[
q
])
# from CoreObject import CoreObject
element
.
defineRouting
(
previous
,
next
)
# if issubclass(objectType, CoreObject):
element
.
definePartFrameRouting
(
nextPart
,
nextFrame
)
else
:
element
.
defineRouting
(
previous
,
next
)
# ===========================================================================
if
issubclass
(
objectType
,
ObjectInterruption
):
# check the object type
# initializes all the objects that are in the topology
inputDict
=
dict
(
element
)
# ===========================================================================
# create the ObjectInterruption
def
initializeObjects
():
objectInterruption
=
objectType
(
**
inputDict
)
for
element
in
G
.
ObjList
+
G
.
ObjectResourceList
+
G
.
EntityList
+
G
.
ObjectInterruptionList
:
G
.
ObjectInterruptionList
.
append
(
objectInterruption
)
element
.
initialize
()
# ===========================================================================
# search inside the nodes for encapsulated ObjectInterruptions (failures etc)
# activates all the objects
# ToDo this will be cleaned a lot if we update the JSON notation:
# ===========================================================================
# define ObjectInterruption echelon inside node
def
activateObjects
():
# define interruptions' distribution better
for
element
in
G
.
ObjList
+
G
.
ObjectInterruptionList
:
for
(
element_id
,
element
)
in
nodes
.
iteritems
():
G
.
env
.
process
(
element
.
run
())
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
():
def
createWIP
():
G
.
JobList
=
[]
G
.
JobList
=
[]
...
@@ -373,14 +413,14 @@ def createWIP():
...
@@ -373,14 +413,14 @@ def createWIP():
entityType
=
Globals
.
getClassFromName
(
entityClass
)
entityType
=
Globals
.
getClassFromName
(
entityClass
)
inputDict
=
dict
(
entity
)
inputDict
=
dict
(
entity
)
inputDict
.
pop
(
'_class'
)
inputDict
.
pop
(
'_class'
)
if
entityClass
in
[
'Dream.CapacityEntity'
,
'Dream.CapacityProject'
,
'Dream.Part'
,
from
Entity
import
Entity
'Dream.Batch'
,
'Dream.SubBatch'
,
'Dream.Job'
,
'Dream.Mould'
,
'Dream.OrderComponent'
]
:
if
issubclass
(
entityType
,
Entity
)
and
(
not
entityClass
==
'Dream.Order'
)
:
entity
=
entityType
(
**
inputDict
)
entity
=
entityType
(
**
inputDict
)
G
.
EntityList
.
append
(
entity
)
G
.
EntityList
.
append
(
entity
)
object
=
Globals
.
findObjectById
(
element
[
'id'
])
object
=
Globals
.
findObjectById
(
element
[
'id'
])
entity
.
currentStation
=
object
entity
.
currentStation
=
object
# ToDo order is to defined in a new way
if
entityClass
==
'Dream.Order'
:
if
entityClass
==
'Dream.Order'
:
id
=
entity
.
get
(
'id'
,
'not found'
)
id
=
entity
.
get
(
'id'
,
'not found'
)
name
=
entity
.
get
(
'name'
,
'not found'
)
name
=
entity
.
get
(
'name'
,
'not found'
)
...
@@ -451,97 +491,58 @@ def createWIP():
...
@@ -451,97 +491,58 @@ def createWIP():
G
.
JobList
.
append
(
OD
)
G
.
JobList
.
append
(
OD
)
# ===========================================================================
# ===========================================================================
#
reads the interruptions of the stations
#
defines the topology (predecessors and successors for all the objects)
# ===========================================================================
# ===========================================================================
def
createObjectInterruptions
():
def
setTopology
():
G
.
ObjectInterruptionList
=
[]
#loop through all the objects
G
.
ScheduledMaintenanceList
=
[]
for
element
in
G
.
ObjList
:
G
.
FailureList
=
[]
next
=
[]
G
.
ShiftSchedulerList
=
[]
previous
=
[]
G
.
EventGeneratorList
=
[]
for
j
in
range
(
len
(
element
.
previousIds
)):
G
.
CapacityStationControllerList
=
[]
for
q
in
range
(
len
(
G
.
ObjList
)):
json_data
=
G
.
JSONData
if
G
.
ObjList
[
q
].
id
==
element
.
previousIds
[
j
]:
#Read the json data
previous
.
append
(
G
.
ObjList
[
q
])
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
for
j
in
range
(
len
(
element
.
nextIds
)):
inputDict
=
dict
(
element
)
for
q
in
range
(
len
(
G
.
ObjList
)):
# create the ObjectInterruption
if
G
.
ObjList
[
q
].
id
==
element
.
nextIds
[
j
]:
objectInterruption
=
objectType
(
**
inputDict
)
next
.
append
(
G
.
ObjList
[
q
])
G
.
ObjectInterruptionList
.
append
(
objectInterruption
)
# search inside the nodes for encapsulated ObjectInterruptions (failures etc)
if
element
.
type
==
"Source"
:
# ToDo this will be cleaned a lot if we update the JSON notation:
element
.
defineRouting
(
next
)
# define ObjectInterruption echelon inside node
elif
element
.
type
==
"Exit"
:
# define interruptions' distribution better
element
.
defineRouting
(
previous
)
for
(
element_id
,
element
)
in
nodes
.
iteritems
():
#Dismantle should be changed to identify what the the successor is.
element
[
'id'
]
=
element_id
#nextPart and nextFrame will become problematic
scheduledMaintenance
=
element
.
get
(
'scheduledMaintenance'
,
{})
elif
element
.
type
==
"Dismantle"
:
# if there is a scheduled maintenance initiate it and append it
nextPart
=
[]
# to the interruptions- and scheduled maintenances- list
nextFrame
=
[]
if
len
(
scheduledMaintenance
):
for
j
in
range
(
len
(
element
.
nextPartIds
)):
start
=
float
(
scheduledMaintenance
.
get
(
'start'
,
0
))
for
q
in
range
(
len
(
G
.
ObjList
)):
duration
=
float
(
scheduledMaintenance
.
get
(
'duration'
,
1
))
if
G
.
ObjList
[
q
].
id
==
element
.
nextPartIds
[
j
]:
victim
=
Globals
.
findObjectById
(
element
[
'id'
])
nextPart
.
append
(
G
.
ObjList
[
q
])
SM
=
ScheduledMaintenance
(
victim
=
victim
,
start
=
start
,
duration
=
duration
)
for
j
in
range
(
len
(
element
.
nextFrameIds
)):
victim
.
objectInterruptions
.
append
(
SM
)
for
q
in
range
(
len
(
G
.
ObjList
)):
G
.
ObjectInterruptionList
.
append
(
SM
)
if
G
.
ObjList
[
q
].
id
==
element
.
nextFrameIds
[
j
]:
G
.
ScheduledMaintenanceList
.
append
(
SM
)
nextFrame
.
append
(
G
.
ObjList
[
q
])
failure
=
element
.
get
(
'failures'
,
None
)
element
.
defineRouting
(
previous
,
next
)
# if there are failures assigned
element
.
definePartFrameRouting
(
nextPart
,
nextFrame
)
# initiate them
if
failure
:
distributionType
=
failure
.
get
(
'distributionType'
,
'No'
)
if
distributionType
==
'No'
:
pass
else
:
else
:
victim
=
Globals
.
findObjectById
(
element
[
'id'
])
element
.
defineRouting
(
previous
,
next
)
deteriorationType
=
failure
.
get
(
'deteriorationType'
,
'constant'
)
F
=
Failure
(
victim
,
distribution
=
failure
,
repairman
=
victim
.
repairman
,
deteriorationType
=
deteriorationType
)
# ===========================================================================
victim
.
objectInterruptions
.
append
(
F
)
# initializes all the objects that are in the topology
G
.
ObjectInterruptionList
.
append
(
F
)
# ===========================================================================
G
.
FailureList
.
append
(
F
)
def
initializeObjects
():
# if there is a shift pattern defined
for
element
in
G
.
ObjList
+
G
.
ObjectResourceList
+
G
.
EntityList
+
G
.
ObjectInterruptionList
:
# initiate them
element
.
initialize
()
shift
=
element
.
get
(
'shift'
,
{})
if
len
(
shift
):
# ===========================================================================
victim
=
Globals
.
findObjectById
(
element
[
'id'
])
# activates all the objects
shiftPattern
=
list
(
shift
.
get
(
'shiftPattern'
,
[]))
# ===========================================================================
# patch to correct if input has end of shift at the same time of start of next shift
def
activateObjects
():
# TODO check if the backend should be able to handle this
for
element
in
G
.
ObjList
+
G
.
ObjectInterruptionList
:
for
index
,
element
in
enumerate
(
shiftPattern
):
G
.
env
.
process
(
element
.
run
())
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
)
# ===========================================================================
# ===========================================================================
# the main script that is ran
# the main script that is ran
...
@@ -568,7 +569,7 @@ def main(argv=[], input_data=None):
...
@@ -568,7 +569,7 @@ def main(argv=[], input_data=None):
#read the input from the JSON file and create the line
#read the input from the JSON file and create the line
G
.
JSONData
=
json
.
loads
(
G
.
InputData
)
# create the dictionary JSONData
G
.
JSONData
=
json
.
loads
(
G
.
InputData
)
# create the dictionary JSONData
readGeneralInput
()
readGeneralInput
()
createObjects
()
createObject
ResourcesAndCoreObject
s
()
createObjectInterruptions
()
createObjectInterruptions
()
setTopology
()
setTopology
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment