def __init__(self, config): self.identifier = config.identifier self.num_sweeps = int(config.static_parameters['num_sweeps']) self.model_config = Config() model_config_file_name = config.get_static_parameters()['model_config_file_name'] self.model_config.read_xml_config_file(model_config_file_name) self.results = [] self.output_file_name = config.static_parameters['output_file_name']
class Runner(BaseRunner): identifier = "" num_sweeps = 0 def get_identifier(self): return self.identifier def set_identifier(self, _value): super(Runner, self).set_identifier(_value) def get_num_sweeps(self): return self.num_sweeps def set_num_sweeps(self, _value): super(Runner, self).set_num_sweeps(_value) def __init__(self, config): self.identifier = config.identifier self.num_sweeps = int(config.static_parameters['num_sweeps']) self.model_config = Config() model_config_file_name = config.get_static_parameters()['model_config_file_name'] self.model_config.read_xml_config_file(model_config_file_name) self.results = [] self.output_file_name = config.static_parameters['output_file_name'] def write_results(self, model): out_text = "" # loop over all results for result in self.results: # each result is a list (of lists) itself for entry in result: out_text += str(entry) + ";" out_text += "\n" out_file_name = self.output_file_name out_file = open(out_file_name, 'w') out_file.write(out_text) out_file.close() def do_run(self): measurement = Measurement(self.model_config, self) # And open the output file measurement.open_file() for i in range(0, self.num_sweeps): model = Model(self.model_config) model.initialize_agents() result = model.do_update() self.results = result # self.write_results(model) measurement.write_to_file() measurement.close_file()
# -*- coding: utf-8 -*- """ Sample implementation of the abm_template The description of the model implemented is presented in the README.md file This script needs to be ran with the runner config file as parameter. Author: Pawel Fiedor ([email protected]) Co-Pierre Georg ([email protected]) Date of last update: 20-11-2015 (Cape Town) """ if __name__ == '__main__': import sys from samples.sample_config import Config from samples.sample_runner import Runner args = sys.argv if len(args) != 2: print "Usage: ./sample runner_config_file_path.xml" sys.exit() config = Config() config.read_xml_config_file(str(args[1])) runner = Runner(config) runner.do_run()