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
c983514e
Commit
c983514e
authored
Nov 19, 2015
by
Georgios Dagkakis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
if we evaluate all the ants of the generation stochastically no deterministic run is needed
parent
8b73acdf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
26 deletions
+43
-26
dream/plugins/Batches/BatchesStochasticACO.py
dream/plugins/Batches/BatchesStochasticACO.py
+43
-26
No files found.
dream/plugins/Batches/BatchesStochasticACO.py
View file @
c983514e
...
...
@@ -166,36 +166,53 @@ class BatchesStochasticACO(BatchesACO):
ant
[
'input'
]
=
ant_data
scenario_list
.
append
(
ant
)
# run the deterministic ants
for
ant
in
scenario_list
:
self
.
outputSheet
.
write
(
self
.
rowIndex
,
1
,
'running deterministic'
)
self
.
outputSheet
.
write
(
self
.
rowIndex
,
2
,
ant
[
'key'
])
self
.
rowIndex
+=
1
ant
[
'result'
]
=
self
.
runOneScenario
(
ant
[
'input'
])[
'result'
]
ant
[
'score'
]
=
self
.
_calculateAntScore
(
ant
)
ant
[
'evaluationType'
]
=
'deterministic'
self
.
outputSheet
.
write
(
self
.
rowIndex
,
2
,
'Units Throughput'
)
self
.
outputSheet
.
write
(
self
.
rowIndex
,
3
,
-
ant
[
'score'
])
self
.
rowIndex
+=
1
ants
.
extend
(
scenario_list
)
antsInCurrentGeneration
.
extend
(
scenario_list
)
# if all the ants of the generation will be evaluated stochastically
# do not do deterministic runs
if
numberOfAntsForStochasticEvaluationInGeneration
==
int
(
data
[
"general"
][
"numberOfAntsPerGenerations"
]):
uniqueAntsInThisGeneration
=
dict
()
for
ant
in
antsInCurrentGeneration
:
ant
[
'result'
]
=
dict
()
ant
[
'result'
][
'result_list'
]
=
[
ant
[
'key'
]]
ant
[
'score'
]
=
0
ant_result
,
=
copy
(
ant
[
'result'
][
'result_list'
])
ant_result
=
json
.
dumps
(
ant_result
,
sort_keys
=
True
)
uniqueAntsInThisGeneration
[
ant_result
]
=
ant
antsForStochasticEvaluationInGeneration
=
sorted
(
uniqueAntsInThisGeneration
.
values
(),
key
=
operator
.
itemgetter
(
'score'
))[:
numberOfAntsForStochasticEvaluationInGeneration
]
else
:
# run the deterministic ants
for
ant
in
scenario_list
:
self
.
outputSheet
.
write
(
self
.
rowIndex
,
1
,
'running deterministic'
)
self
.
outputSheet
.
write
(
self
.
rowIndex
,
2
,
ant
[
'key'
])
self
.
rowIndex
+=
1
ant
[
'result'
]
=
self
.
runOneScenario
(
ant
[
'input'
])[
'result'
]
ant
[
'score'
]
=
self
.
_calculateAntScore
(
ant
)
ant
[
'evaluationType'
]
=
'deterministic'
self
.
outputSheet
.
write
(
self
.
rowIndex
,
2
,
'Units Throughput'
)
self
.
outputSheet
.
write
(
self
.
rowIndex
,
3
,
-
ant
[
'score'
])
self
.
rowIndex
+=
1
# in this generation remove ants that outputs the same schedules
# XXX we in fact remove ants that produce the same output json
# XXX in the stochastic case maybe there is not benefit to remove ants.
# XXX so I kept totalExecutionTime to have them all
uniqueAntsInThisGeneration
=
dict
()
for
ant
in
antsInCurrentGeneration
:
ant_result
,
=
copy
(
ant
[
'result'
][
'result_list'
])
ant_result
=
json
.
dumps
(
ant_result
,
sort_keys
=
True
)
uniqueAntsInThisGeneration
[
ant_result
]
=
ant
# The ants in this generation are ranked based on their scores and the
# best (numberOfAntsForStochasticEvaluationInGeneration) are selected to
# be evaluated stochastically
antsForStochasticEvaluationInGeneration
=
sorted
(
uniqueAntsInThisGeneration
.
values
(),
key
=
operator
.
itemgetter
(
'score'
))[:
numberOfAntsForStochasticEvaluationInGeneration
]
# in this generation remove ants that outputs the same schedules
# XXX we in fact remove ants that produce the same output json
# XXX in the stochastic case maybe there is not benefit to remove ants.
# XXX so I kept totalExecutionTime to have them all
uniqueAntsInThisGeneration
=
dict
()
for
ant
in
antsInCurrentGeneration
:
ant_result
,
=
copy
(
ant
[
'result'
][
'result_list'
])
ant_result
=
json
.
dumps
(
ant_result
,
sort_keys
=
True
)
uniqueAntsInThisGeneration
[
ant_result
]
=
ant
# The ants in this generation are ranked based on their scores and the
# best (numberOfAntsForStochasticEvaluationInGeneration) are selected to
# be evaluated stochastically
antsForStochasticEvaluationInGeneration
=
sorted
(
uniqueAntsInThisGeneration
.
values
(),
key
=
operator
.
itemgetter
(
'score'
))[:
numberOfAntsForStochasticEvaluationInGeneration
]
for
ant
in
antsForStochasticEvaluationInGeneration
:
ant
[
'input'
]
=
self
.
createStochasticData
(
ant
[
'input'
])
...
...
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