Commit c983514e authored by Georgios Dagkakis's avatar Georgios Dagkakis

if we evaluate all the ants of the generation stochastically no deterministic run is needed

parent 8b73acdf
...@@ -166,6 +166,25 @@ class BatchesStochasticACO(BatchesACO): ...@@ -166,6 +166,25 @@ class BatchesStochasticACO(BatchesACO):
ant['input'] = ant_data ant['input'] = ant_data
scenario_list.append(ant) scenario_list.append(ant)
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 # run the deterministic ants
for ant in scenario_list: for ant in scenario_list:
self.outputSheet.write(self.rowIndex,1,'running deterministic') self.outputSheet.write(self.rowIndex,1,'running deterministic')
...@@ -178,9 +197,6 @@ class BatchesStochasticACO(BatchesACO): ...@@ -178,9 +197,6 @@ class BatchesStochasticACO(BatchesACO):
self.outputSheet.write(self.rowIndex,3,-ant['score']) self.outputSheet.write(self.rowIndex,3,-ant['score'])
self.rowIndex+=1 self.rowIndex+=1
ants.extend(scenario_list)
antsInCurrentGeneration.extend(scenario_list)
# in this generation remove ants that outputs the same schedules # in this generation 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
# XXX in the stochastic case maybe there is not benefit to remove ants. # XXX in the stochastic case maybe there is not benefit to remove ants.
...@@ -197,6 +213,7 @@ class BatchesStochasticACO(BatchesACO): ...@@ -197,6 +213,7 @@ class BatchesStochasticACO(BatchesACO):
antsForStochasticEvaluationInGeneration = sorted(uniqueAntsInThisGeneration.values(), antsForStochasticEvaluationInGeneration = sorted(uniqueAntsInThisGeneration.values(),
key=operator.itemgetter('score'))[:numberOfAntsForStochasticEvaluationInGeneration] key=operator.itemgetter('score'))[:numberOfAntsForStochasticEvaluationInGeneration]
for ant in antsForStochasticEvaluationInGeneration: for ant in antsForStochasticEvaluationInGeneration:
ant['input']=self.createStochasticData(ant['input']) ant['input']=self.createStochasticData(ant['input'])
ant['input']['general']['numberOfReplications']=numberOfReplicationsInGeneration ant['input']['general']['numberOfReplications']=numberOfReplicationsInGeneration
......
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