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
833e4c02
Commit
833e4c02
authored
Aug 22, 2014
by
Georgios Dagkakis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
EventGenerator to be defined in new way
parent
1d7a4aeb
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
52 additions
and
41 deletions
+52
-41
dream/simulation/EventGenerator.py
dream/simulation/EventGenerator.py
+12
-7
dream/simulation/Globals.py
dream/simulation/Globals.py
+22
-1
dream/simulation/JSONInputs/Topology27.json
dream/simulation/JSONInputs/Topology27.json
+1
-1
dream/simulation/JSONInputs/Topology48.json
dream/simulation/JSONInputs/Topology48.json
+1
-1
dream/simulation/JSONInputs/Topology78.json
dream/simulation/JSONInputs/Topology78.json
+1
-1
dream/simulation/LineGenerationJSON.py
dream/simulation/LineGenerationJSON.py
+13
-30
dream/simulation/ObjectInterruption.py
dream/simulation/ObjectInterruption.py
+2
-0
No files found.
dream/simulation/EventGenerator.py
View file @
833e4c02
...
...
@@ -31,17 +31,22 @@ import simpy
from
ObjectInterruption
import
ObjectInterruption
class
EventGenerator
(
ObjectInterruption
):
def
__init__
(
self
,
id
=
id
,
name
=
None
,
start
=
None
,
stop
=
None
,
interval
=
None
,
duration
=
None
,
method
=
None
,
argumentDict
=
None
):
def
__init__
(
self
,
id
=
id
,
name
=
None
,
start
=
0
,
stop
=
float
(
'inf'
),
interval
=
1
,
duration
=
0
,
method
=
None
,
argumentDict
=
None
):
ObjectInterruption
.
__init__
(
self
)
self
.
id
=
id
self
.
name
=
name
self
.
start
=
start
#the time that the generator will be activated for the first time
self
.
stop
=
stop
#the time that the generator will stop to trigger events
self
.
interval
=
interval
#the interval that the generator sleeps
self
.
duration
=
duration
#the duration that the generation is awake (this is not active for now)
self
.
start
=
float
(
start
)
#the time that the generator will be activated for the first time
self
.
stop
=
float
(
stop
)
#the time that the generator will stop to trigger events
self
.
interval
=
float
(
interval
)
#the interval that the generator sleeps
self
.
duration
=
float
(
duration
)
#the duration that the generation is awake (this is not active for now)
self
.
method
=
method
#the method to be invoked
self
.
argumentDict
=
argumentDict
#the arguments of the method given in a dict
from
Globals
import
G
G
.
EventGeneratorList
.
append
(
self
)
if
method
:
import
Globals
self
.
method
=
Globals
.
getMethodFromName
(
method
)
def
run
(
self
):
yield
self
.
env
.
timeout
(
self
.
start
)
#wait until the start time
...
...
dream/simulation/Globals.py
View file @
833e4c02
...
...
@@ -165,6 +165,27 @@ def getClassFromName(dotted_name):
_class
=
__import__
(
class_name
)
return
getattr
(
_class
,
class_name
)
# =======================================================================
# returns a method by its name. name should be given as Dream.ClassName.MethodName
# =======================================================================
def
getMethodFromName
(
dotted_name
):
name
=
dotted_name
.
split
(
'.'
)
methodName
=
name
[
-
1
]
# if the method is in this script
if
'Globals'
in
name
:
methodName
=
name
[
name
.
index
(
'Globals'
)
+
1
]
possibles
=
globals
().
copy
()
possibles
.
update
(
locals
())
method
=
possibles
.
get
(
methodName
)
# if the method is in a class
else
:
clsName
=
name
[
0
]
+
'.'
+
name
[
1
]
cls
=
getClassFromName
(
clsName
)
method
=
getattr
(
cls
,
methodName
)
if
not
method
:
raise
Exception
(
"Method %s not implemented"
%
method_name
)
return
method
# =======================================================================
# method finding objects by ID
# =======================================================================
...
...
dream/simulation/JSONInputs/Topology27.json
View file @
833e4c02
...
...
@@ -45,7 +45,7 @@
"to"
:
"E1"
},
"interval"
:
"60"
,
"method"
:
"Globals.moveExcess"
,
"method"
:
"
Dream.
Globals.moveExcess"
,
"name"
:
"ExcessEntitiesMover"
,
"start"
:
"60"
},
...
...
dream/simulation/JSONInputs/Topology48.json
View file @
833e4c02
...
...
@@ -82,7 +82,7 @@
"_class"
:
"Dream.EventGenerator"
,
"argumentDict"
:
{},
"interval"
:
"480"
,
"method"
:
"Globals.countIntervalThroughput"
,
"method"
:
"
Dream.
Globals.countIntervalThroughput"
,
"name"
:
"calculateDailyAttainment"
,
"start"
:
"480"
},
...
...
dream/simulation/JSONInputs/Topology78.json
View file @
833e4c02
...
...
@@ -424,7 +424,7 @@
"name"
:
"attainment"
,
"start"
:
"1440"
,
"interval"
:
"1440"
,
"method"
:
"Globals.countIntervalThroughput"
,
"method"
:
"
Dream.
Globals.countIntervalThroughput"
,
"argumentDict"
:
{
}
}
...
...
dream/simulation/LineGenerationJSON.py
View file @
833e4c02
...
...
@@ -697,29 +697,20 @@ def createObjectInterruptions():
# 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'
)
or
0
)
stop
=
float
(
element
.
get
(
'stop'
)
or
-
1
)
# infinity (had to be done to make it as float)
if
stop
<
0
:
stop
=
float
(
'inf'
)
interval
=
float
(
element
.
get
(
'interval'
)
or
1
)
duration
=
float
(
element
.
get
(
'duration'
)
or
0
)
method
=
(
element
.
get
(
'method'
,
None
))
# get the method to be run / default None
method
=
method
.
split
(
'.'
)
#the method is given as 'Path.MethodName'
method
=
getattr
(
str_to_class
(
method
[
0
]),
method
[
1
])
#and then parsed with getattr
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
objClass
=
element
.
get
(
'_class'
,
'not found'
)
# get the class type of the element
import
Globals
objClass
=
element
.
pop
(
'_class'
)
objectType
=
Globals
.
getClassFromName
(
objClass
)
# from CoreObject import CoreObject
# if issubclass(objectType, CoreObject):
G
.
EventGeneratorList
.
append
(
EV
)
G
.
ObjectInterruptionList
.
append
(
EV
)
if
objClass
==
'Dream.EventGenerator'
:
# check the object type
inputDict
=
dict
(
element
)
# create the CoreObject
objectInterruption
=
objectType
(
**
inputDict
)
G
.
ObjectInterruptionList
.
append
(
objectInterruption
)
elif
element
Class
==
'Dream.CapacityStationController'
:
# check the object type
elif
obj
Class
==
'Dream.CapacityStationController'
:
# 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'
)
or
0
)
...
...
@@ -792,14 +783,6 @@ def createObjectInterruptions():
G
.
ObjectInterruptionList
.
append
(
SS
)
G
.
ShiftSchedulerList
.
append
(
SS
)
# ===========================================================================
# used to convert a string read from the input to object type
# ===========================================================================
def
str_to_class
(
str
):
str
=
str
.
replace
(
"Dream."
,
""
)
# XXX temporary.
# actuall this method can be dropped in favor of getClassFromName
return
getattr
(
sys
.
modules
[
__name__
],
str
)
# ===========================================================================
# the main script that is ran
# ===========================================================================
...
...
dream/simulation/ObjectInterruption.py
View file @
833e4c02
...
...
@@ -38,6 +38,8 @@ class ObjectInterruption(object):
self
.
victim
=
victim
# variable used to hand in control to the objectInterruption
self
.
call
=
False
from
Globals
import
G
# G.ObjectInterruptionList.append(self)
def
initialize
(
self
):
from
Globals
import
G
...
...
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