Commit 5a491d02 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki Committed by Jérome Perrin

return top 4 results.

parent db0a53dc
...@@ -30,6 +30,8 @@ def calculateAntScore(ant): ...@@ -30,6 +30,8 @@ def calculateAntScore(ant):
class Simulation(DefaultSimulation): class Simulation(DefaultSimulation):
max_results = 4
def _setWIP(self, in_data): def _setWIP(self, in_data):
""" Set the WIP in queue from spreadsheet data. """ Set the WIP in queue from spreadsheet data.
""" """
...@@ -112,13 +114,14 @@ class Simulation(DefaultSimulation): ...@@ -112,13 +114,14 @@ class Simulation(DefaultSimulation):
# property to change (instead of hardcoding schedulingRule) # property to change (instead of hardcoding schedulingRule)
ant_data["nodes"][k]['schedulingRule'] = v ant_data["nodes"][k]['schedulingRule'] = v
ant['key'] = ant_key
# TODO: those two steps have to be parallelized # TODO: those two steps have to be parallelized
ant['result'] = DefaultSimulation.run(self, ant_data) ant['result'] = DefaultSimulation.run(self, ant_data)
ant['score'] = calculateAntScore(ant) ant['score'] = calculateAntScore(ant)
# 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 4 are selected # best (max_results) are selected
ants = sorted(ants, key=operator.itemgetter('score'))[:4] ants = sorted(ants, key=operator.itemgetter('score'))[:self.max_results]
for l in ants: for l in ants:
# update the options list to ensure that good performing queue-rule # update the options list to ensure that good performing queue-rule
...@@ -130,20 +133,12 @@ class Simulation(DefaultSimulation): ...@@ -130,20 +133,12 @@ class Simulation(DefaultSimulation):
# selected by the next ants. # selected by the next ants.
collated[m].append(l[m]) collated[m].append(l[m])
result_count = min(4, len(ants)) # print repr(ants)
print repr(ants) print '%s best results :' % len(ants)
print '%s best results :' % result_count for ant in ants:
for i in range(result_count):
ant = ants[i]
displayed_ant = copy(ant)
displayed_ant.pop('result')
print '=================' print '================='
print displayed_ant print repr({'key':ant['key'], 'score':ant['score']})
print "execution time=", str(time.time()-start) print "execution time=", str(time.time()-start)
# TODO: return multiple results in the GUI return ants
# { ant_key: {'score': 108, 'resultJSON': ..},
# ant2_key: {'score': 108, 'resultJSON': ..},
# }
return DefaultSimulation.run(self, data)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment