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

make run() return dict and _runSimulation() convert it to JSON.

parent b200f808
......@@ -114,7 +114,7 @@ def _runSimulation(parameter_dict, queue):
parameter_dict['general']['simulationClass']
klass = __import__(klass_name, globals(), {}, klass_name)
result = klass.Simulation(logger=app.logger).run(parameter_dict)
queue.put(dict(success=json.loads(result)))
queue.put(dict(success=result))
except Exception, e:
tb = traceback.format_exc()
app.logger.error(tb)
......
......@@ -6,4 +6,4 @@ class Simulation:
self.logger = logger
def run(self, data):
return simulate_line_json(input_data=json.dumps(data))
return json.loads(simulate_line_json(input_data=json.dumps(data)))
......@@ -15,7 +15,7 @@ def calculateAntScore(ant):
XXX Maybe this can be based on other criterions, such as completion time ?
"""
totalDelay=0 #set the total delay to 0
jsonData=json.loads(ant['resultJSON']) #read the result as JSON
jsonData=ant['result'] #read the result as JSON
elementList = jsonData['elementList'] #find the route of JSON
#loop through the elements
for element in elementList:
......@@ -113,7 +113,7 @@ class Simulation(DefaultSimulation):
ant_data["nodes"][k]['schedulingRule'] = v
# TODO: those two steps have to be parallelized
ant['resultJSON'] = DefaultSimulation.run(self, ant_data)
ant['result'] = DefaultSimulation.run(self, ant_data)
ant['score'] = calculateAntScore(ant)
# The ants in this generation are ranked based on their scores and the
......@@ -131,11 +131,12 @@ class Simulation(DefaultSimulation):
collated[m].append(l[m])
result_count = min(4, len(ants))
print repr(ants)
print '%s best results :' % result_count
for i in range(result_count):
ant = ants[i]
displayed_ant = copy(ant)
displayed_ant.pop('resultJSON')
displayed_ant.pop('result')
print '================='
print displayed_ant
......
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