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
4f9afb83
Commit
4f9afb83
authored
Jun 08, 2015
by
Ioannis Papagiannopoulos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
JobShopACO to inherit from ACO abstract class
parent
b83a5de8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
28 deletions
+55
-28
dream/plugins/ACO.py
dream/plugins/ACO.py
+11
-28
dream/plugins/JobShop/JobShopACO.py
dream/plugins/JobShop/JobShopACO.py
+44
-0
No files found.
dream/plugins/ACO.py
View file @
4f9afb83
...
...
@@ -20,39 +20,22 @@ def runAntInSubProcess(ant):
class
ACO
(
plugin
.
ExecutionPlugin
):
def
_calculateAntScore
(
self
,
ant
):
"""Calculate the score of this ant.
"""Calculate the score of this ant.
Implemented in the Subclass, raises NotImplementedError
"""
totalDelay
=
0
#set the total delay to 0
result
,
=
ant
[
'result'
][
'result_list'
]
#read the result as JSON
#loop through the elements
for
element
in
result
[
'elementList'
]:
element_family
=
element
.
get
(
'family'
,
None
)
#id the class is Job
if
element_family
==
'Job'
:
results
=
element
[
'results'
]
delay
=
float
(
results
.
get
(
'delay'
,
"0"
))
# A negative delay would mean we are ahead of schedule. This
# should not be considered better than being on time.
totalDelay
+=
max
(
delay
,
0
)
return
totalDelay
# creates the collated scenarios, i.e. the list
# of options collated into a dictionary for ease of referencing in ManPy
raise
NotImplementedError
(
"ACO subclass must define '_calculateAntScore' method"
)
def
createCollatedScenarios
(
self
,
data
):
collated
=
dict
()
for
node_id
,
node
in
data
[
'graph'
][
'node'
].
items
():
node_class
=
getClassFromName
(
node
[
'_class'
])
if
issubclass
(
node_class
,
Queue
)
or
issubclass
(
node_class
,
Operator
):
collated
[
node_id
]
=
list
(
node_class
.
getSupportedSchedulingRules
())
return
collated
"""creates the collated scenarios, i.e. the list of options collated into a dictionary for ease of referencing in ManPy
to be implemented in the subclass
"""
raise
NotImplementedError
(
"ACO subclass must define 'createCollatedScenarios' method"
)
# creates the ant scenario based on what ACO randomly selected
def
createAntData
(
self
,
data
,
ant
):
# set scheduling rule on queues based on ant data
ant_data
=
copy
(
data
)
for
k
,
v
in
ant
.
items
():
ant_data
[
"graph"
][
"node"
][
k
][
'schedulingRule'
]
=
v
return
ant_data
"""creates the ant scenario based on what ACO randomly selected.
raises NotImplementedError
"""
raise
NotImplementedError
(
"ACO subclass must define 'createAntData' method"
)
def
run
(
self
,
data
):
...
...
dream/plugins/JobShop/JobShopACO.py
0 → 100644
View file @
4f9afb83
from
pprint
import
pformat
from
copy
import
copy
,
deepcopy
import
time
from
dream.simulation.Queue
import
Queue
from
dream.simulation.Operator
import
Operator
from
dream.simulation.Globals
import
getClassFromName
from
dream.plugins.ACO
import
ACO
class
JobShopACO
(
ACO
):
def
_calculateAntScore
(
self
,
ant
):
"""Calculate the score of this ant.
"""
totalDelay
=
0
#set the total delay to 0
result
,
=
ant
[
'result'
][
'result_list'
]
#read the result as JSON
#loop through the elements
for
element
in
result
[
'elementList'
]:
element_family
=
element
.
get
(
'family'
,
None
)
#id the class is Job
if
element_family
==
'Job'
:
results
=
element
[
'results'
]
delay
=
float
(
results
.
get
(
'delay'
,
"0"
))
# A negative delay would mean we are ahead of schedule. This
# should not be considered better than being on time.
totalDelay
+=
max
(
delay
,
0
)
return
totalDelay
# creates the collated scenarios, i.e. the list
# of options collated into a dictionary for ease of referencing in ManPy
def
createCollatedScenarios
(
self
,
data
):
collated
=
dict
()
for
node_id
,
node
in
data
[
'graph'
][
'node'
].
items
():
node_class
=
getClassFromName
(
node
[
'_class'
])
if
issubclass
(
node_class
,
Queue
)
or
issubclass
(
node_class
,
Operator
):
collated
[
node_id
]
=
list
(
node_class
.
getSupportedSchedulingRules
())
return
collated
# creates the ant scenario based on what ACO randomly selected
def
createAntData
(
self
,
data
,
ant
):
# set scheduling rule on queues based on ant data
ant_data
=
copy
(
data
)
for
k
,
v
in
ant
.
items
():
ant_data
[
"graph"
][
"node"
][
k
][
'schedulingRule'
]
=
v
return
ant_data
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