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
6c5577e4
Commit
6c5577e4
authored
Nov 03, 2015
by
Georgios Dagkakis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
first version working with both layers of stochastic evaluation. Debugging needed
parent
91540be5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
21 deletions
+71
-21
dream/plugins/Batches/BatchesStochasticACO.py
dream/plugins/Batches/BatchesStochasticACO.py
+71
-21
No files found.
dream/plugins/Batches/BatchesStochasticACO.py
View file @
6c5577e4
...
@@ -42,7 +42,6 @@ class BatchesStochasticACO(BatchesACO):
...
@@ -42,7 +42,6 @@ class BatchesStochasticACO(BatchesACO):
if
distribution
:
if
distribution
:
mean
=
distribution
[
'mean'
]
mean
=
distribution
[
'mean'
]
if
mean
:
if
mean
:
print
node
[
'id'
]
processingTime
.
pop
(
'Fixed'
,
None
)
processingTime
.
pop
(
'Fixed'
,
None
)
processingTime
[
'Triangular'
]
=
{
processingTime
[
'Triangular'
]
=
{
"mean"
:
mean
,
"mean"
:
mean
,
...
@@ -51,10 +50,25 @@ class BatchesStochasticACO(BatchesACO):
...
@@ -51,10 +50,25 @@ class BatchesStochasticACO(BatchesACO):
}
}
return
data
return
data
def
calculateStochasticAntScore
(
self
,
ant
):
"""Calculate the score of this ant.
"""
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 Exit get the unitsThroughput
if
element_family
==
'Exit'
:
unitsThroughput
=
element
[
'results'
].
get
(
'unitsThroughput'
,
None
)
averageUnitsThroughput
=
sum
(
unitsThroughput
)
/
float
(
len
(
unitsThroughput
))
# return the negative value since they are ranked this way. XXX discuss this
return
-
averageUnitsThroughput
def
run
(
self
,
data
):
def
run
(
self
,
data
):
"""Preprocess the data.
"""Preprocess the data.
"""
"""
print
'I am IN'
print
'I am IN'
distributor_url
=
data
[
'general'
].
get
(
'distributorURL'
)
distributor_url
=
data
[
'general'
].
get
(
'distributorURL'
)
distributor
=
None
distributor
=
None
if
distributor_url
:
if
distributor_url
:
...
@@ -77,8 +91,12 @@ class BatchesStochasticACO(BatchesACO):
...
@@ -77,8 +91,12 @@ class BatchesStochasticACO(BatchesACO):
numberOfAntsForNextGeneration
=
int
(
data
[
'general'
].
get
(
'numberOfAntsForNextGeneration'
,
1
))
numberOfAntsForNextGeneration
=
int
(
data
[
'general'
].
get
(
'numberOfAntsForNextGeneration'
,
1
))
# this is for how many ants should be evaluated stochastically in every generation
# this is for how many ants should be evaluated stochastically in every generation
numberOfAntsForStochasticEvaluationInGeneration
=
int
(
data
[
'general'
].
get
(
'numberOfAntsForStochasticEvaluationInGeneration'
,
2
))
numberOfAntsForStochasticEvaluationInGeneration
=
int
(
data
[
'general'
].
get
(
'numberOfAntsForStochasticEvaluationInGeneration'
,
2
))
# number of replications for stochastic ants inside the generation
numberOfReplicationsInGeneration
=
data
[
'general'
].
get
(
'numberOfReplicationsInGeneration'
,
3
)
# this is for how many ants should be evaluated stochastically in the end
# this is for how many ants should be evaluated stochastically in the end
numberOfAntsForStochasticEvaluationInTheEnd
=
int
(
data
[
'general'
].
get
(
'numberOfAntsForStochasticEvaluationInTheEnd'
,
2
))
numberOfAntsForStochasticEvaluationInTheEnd
=
int
(
data
[
'general'
].
get
(
'numberOfAntsForStochasticEvaluationInTheEnd'
,
2
))
# number of replications for stochastic ants in the end
numberOfReplicationsInTheEnd
=
data
[
'general'
].
get
(
'numberOfReplicationsInTheEnd'
,
6
)
assert
max_results
>=
1
assert
max_results
>=
1
...
@@ -91,6 +109,7 @@ class BatchesStochasticACO(BatchesACO):
...
@@ -91,6 +109,7 @@ class BatchesStochasticACO(BatchesACO):
# generation can have more than 1 ant)
# generation can have more than 1 ant)
seedPlus
=
0
seedPlus
=
0
for
i
in
range
(
int
(
data
[
"general"
][
"numberOfGenerations"
])):
for
i
in
range
(
int
(
data
[
"general"
][
"numberOfGenerations"
])):
print
'Generation'
,
i
+
1
antsInCurrentGeneration
=
[]
antsInCurrentGeneration
=
[]
scenario_list
=
[]
# for the distributor
scenario_list
=
[]
# for the distributor
# number of ants created per generation
# number of ants created per generation
...
@@ -109,15 +128,19 @@ class BatchesStochasticACO(BatchesACO):
...
@@ -109,15 +128,19 @@ class BatchesStochasticACO(BatchesACO):
# TODO: function to calculate ant id. Store ant id in ant dict
# TODO: function to calculate ant id. Store ant id in ant dict
ant_key
=
repr
(
ant
)
ant_key
=
repr
(
ant
)
# if the ant was not already tested, only then test it
# if the ant was not already tested, only then test it
print
'ants created'
if
ant_key
not
in
tested_ants
:
if
ant_key
not
in
tested_ants
:
tested_ants
.
add
(
ant_key
)
tested_ants
.
add
(
ant_key
)
ant_data
=
deepcopy
(
self
.
createAntData
(
data
,
ant
))
ant_data
=
deepcopy
(
self
.
createAntData
(
data
,
ant
))
ant
[
'key'
]
=
ant_key
ant
[
'key'
]
=
ant_key
ant
[
'input'
]
=
ant_data
ant
[
'input'
]
=
ant_data
scenario_list
.
append
(
ant
)
scenario_list
.
append
(
ant
)
print
ant
[
'key'
]
# run the deterministic ants
# run the deterministic ants
for
ant
in
scenario_list
:
for
ant
in
scenario_list
:
print
'running deterministic'
print
ant
[
'key'
]
ant
[
'result'
]
=
self
.
runOneScenario
(
ant
[
'input'
])[
'result'
]
ant
[
'result'
]
=
self
.
runOneScenario
(
ant
[
'input'
])[
'result'
]
...
@@ -134,32 +157,46 @@ class BatchesStochasticACO(BatchesACO):
...
@@ -134,32 +157,46 @@ class BatchesStochasticACO(BatchesACO):
uniqueAntsInThisGeneration
=
dict
()
uniqueAntsInThisGeneration
=
dict
()
for
ant
in
antsInCurrentGeneration
:
for
ant
in
antsInCurrentGeneration
:
ant_result
,
=
copy
(
ant
[
'result'
][
'result_list'
])
ant_result
,
=
copy
(
ant
[
'result'
][
'result_list'
])
# ant_result['general'].pop('totalExecutionTime', None)
ant_result
=
json
.
dumps
(
ant_result
,
sort_keys
=
True
)
ant_result
=
json
.
dumps
(
ant_result
,
sort_keys
=
True
)
uniqueAntsInThisGeneration
[
ant_result
]
=
ant
uniqueAntsInThisGeneration
[
ant_result
]
=
ant
print
ant_result
# The ants in this generation are ranked based on their scores and the
# The ants in this generation are ranked based on their scores and the
# best (numberOfAntsForStochasticEvaluationInGeneration) are selected to
# best (numberOfAntsForStochasticEvaluationInGeneration) are selected to
# be evaluated stochastically
# be evaluated stochastically
antsForStochasticEvaluationInGeneration
=
sorted
(
uniqueAntsInThisGeneration
.
values
(),
antsForStochasticEvaluationInGeneration
=
sorted
(
uniqueAntsInThisGeneration
.
values
(),
key
=
operator
.
itemgetter
(
'score'
))[:
numberOfAntsForStochasticEvaluationInGeneration
]
key
=
operator
.
itemgetter
(
'score'
))[:
numberOfAntsForStochasticEvaluationInGeneration
]
# # The ants in this generation are ranked based on their scores and the
for
ant
in
antsForStochasticEvaluationInGeneration
:
# # best (numberOfAntsForNextGeneration) are selected to carry their pheromones to next generation
ant
[
'input'
]
=
self
.
createStochasticData
(
ant
[
'input'
])
# antsForNextGeneration = sorted(uniqueAntsInThisGeneration.values(),
ant
[
'input'
][
'general'
][
'numberOfReplications'
]
=
numberOfReplicationsInGeneration
# key=operator.itemgetter('score'))[:numberOfAntsForNextGeneration]
print
'running stochastic for'
,
numberOfReplicationsInGeneration
,
'replications'
#
print
ant
[
'key'
]
# for l in antsForNextGeneration:
ant
[
'result'
]
=
self
.
runOneScenario
(
ant
[
'input'
])[
'result'
]
# # update the options list to ensure that good performing queue-rule
ant
[
'score'
]
=
self
.
calculateStochasticAntScore
(
ant
)
# # combinations have increased representation and good chance of
# # being selected in the next generation
# if we had stochastic evaluation keep only those ants in sorting
# for m in collated.keys():
if
numberOfAntsForStochasticEvaluationInGeneration
:
# # e.g. if using EDD gave good performance for Q1, then another
uniqueAntsInThisGeneration
=
dict
()
# # 'EDD' is added to Q1 so there is a higher chance that it is
for
ant
in
antsForStochasticEvaluationInGeneration
:
# # selected by the next ants.
ant_result
,
=
copy
(
ant
[
'result'
][
'result_list'
])
# collated[m].append(l[m])
ant_result
=
json
.
dumps
(
ant_result
,
sort_keys
=
True
)
uniqueAntsInThisGeneration
[
ant_result
]
=
ant
antsForNextGeneration
=
sorted
(
uniqueAntsInThisGeneration
.
values
(),
key
=
operator
.
itemgetter
(
'score'
))[:
numberOfAntsForNextGeneration
]
for
l
in
antsForNextGeneration
:
print
l
[
'key'
],
'will carry pheromone next generation'
# update the options list to ensure that good performing queue-rule
# combinations have increased representation and good chance of
# being selected in the next generation
for
m
in
collated
.
keys
():
# e.g. if using EDD gave good performance for Q1, then another
# 'EDD' is added to Q1 so there is a higher chance that it is
# selected by the next ants.
collated
[
m
].
append
(
l
[
m
])
print
'ACO Ended, post processing to follow for '
,
numberOfAntsForStochasticEvaluationInTheEnd
,
'Ants'
# from all the ants in the experiment remove ants that outputs the same schedules
# from all the ants in the experiment remove ants that outputs the same schedules
# XXX we in fact remove ants that produce the same output json
# XXX we in fact remove ants that produce the same output json
uniqueAnts
=
dict
()
uniqueAnts
=
dict
()
...
@@ -168,9 +205,22 @@ class BatchesStochasticACO(BatchesACO):
...
@@ -168,9 +205,22 @@ class BatchesStochasticACO(BatchesACO):
ant_result
[
'general'
].
pop
(
'totalExecutionTime'
,
None
)
ant_result
[
'general'
].
pop
(
'totalExecutionTime'
,
None
)
ant_result
=
json
.
dumps
(
ant_result
,
sort_keys
=
True
)
ant_result
=
json
.
dumps
(
ant_result
,
sort_keys
=
True
)
uniqueAnts
[
ant_result
]
=
ant
uniqueAnts
[
ant_result
]
=
ant
# The ants are ranked based on their scores and the
# best (max_results) are selected to be returned
if
numberOfAntsForStochasticEvaluationInTheEnd
>
0
:
ants
=
sorted
(
uniqueAnts
.
values
(),
key
=
operator
.
itemgetter
(
'score'
))[:
numberOfAntsForStochasticEvaluationInTheEnd
]
for
ant
in
ants
:
ant
[
'input'
]
=
self
.
createStochasticData
(
ant
[
'input'
])
ant
[
'input'
][
'general'
][
'numberOfReplications'
]
=
numberOfReplicationsInTheEnd
print
'running stochastic for'
,
numberOfReplicationsInTheEnd
,
'replications'
print
ant
[
'key'
]
ant
[
'result'
]
=
self
.
runOneScenario
(
ant
[
'input'
])[
'result'
]
ant
[
'score'
]
=
self
.
calculateStochasticAntScore
(
ant
)
# The ants
in this generation
are ranked based on their scores and the
# The ants are ranked based on their scores and the
# best (max_results) are selected
# best (max_results) are selected
to be returned
ants
=
sorted
(
uniqueAnts
.
values
(),
ants
=
sorted
(
uniqueAnts
.
values
(),
key
=
operator
.
itemgetter
(
'score'
))[:
max_results
]
key
=
operator
.
itemgetter
(
'score'
))[:
max_results
]
...
...
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