def test_simulation_add_save_opt_valid_config_no_args(self): try: dataset = Dataset('name', 30, 5, 5, 5, []) simulation = Simulation(dataset=dataset, n_fes=30, np=5, save_to_dir='/notNeeded') simulation.add_save_option( OutputOptionConfig(class_name='ConsoleOutputOption', included_kwargs=[])) except InvalidSaveOptionName: self.fail('Valid save option kwargs was not accepted.')
def test_simulation_add_save_opt_none_name_string(self): try: dataset = Dataset('name', 30, 5, 5, 5, []) simulation = Simulation(dataset=dataset, n_fes=30, np=5, save_to_dir='/notNeeded') simulation.add_save_option( OutputOptionConfig(class_name=None, included_kwargs=['dir_path', 'dataset'])) self.fail('None value save option should raise error') except InvalidSaveOptionName: pass
def test_simulation_add_save_opt_invalid_kwargs(self): try: dataset = Dataset('name', 30, 5, 5, 5, []) simulation = Simulation(dataset=dataset, n_fes=30, np=5, save_to_dir='/notNeeded') simulation.add_save_option( OutputOptionConfig(class_name='GraphOutputOption', included_kwargs=[])) self.fail('Invalid save option kwargs should raise error') except InvalidSaveOptionName: pass
def test_simulation_should_not_start_with_no_algorithms(self): try: dataset = Dataset('name', 30, 5, 5, 5, []) simulation = Simulation(dataset=dataset, n_fes=30, np=5, save_to_dir='../results') simulation.add_save_option( OutputOptionConfig(class_name='ConsoleOutputOption', included_kwargs=[])) simulation.run(sort_by_best=SortAttribute.fitness) self.fail("Simulation started with no algorithms") except InvalidSimulationInitialState: pass
def test_simulation_should_not_start_with_invalid_dataset_invalid_package_count( self): try: dataset = Dataset( 'name', 30, 5, 5, 5, [Package(id_num=1, station_in=1, station_out=3, weight=30)]) simulation = Simulation(dataset=dataset, n_fes=30, np=5, save_to_dir='../results') simulation.add_algorithm('GreyWolfOptimizer') simulation.add_save_option( OutputOptionConfig(class_name='ConsoleOutputOption', included_kwargs=[])) simulation.run(sort_by_best=SortAttribute.fitness) self.fail("Simulation started with no algorithms") except InvalidSimulationInitialState: pass
config_data = json.load(open(configFile, 'r')) dataset = CSVDatasetReader().read(config_data['dataset']) result_dir_path = os.path.join( config_data['saveToDir'], datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')) os.mkdir(path=result_dir_path) simulation = Simulation(dataset=dataset, n_fes=config_data['n_fes'], np=config_data['np'], save_to_dir=result_dir_path) for algorithm in config_data['algorithms']: simulation.add_algorithm(algorithm) save_opt_configs = [ OutputOptionConfig(class_name=config['class'], included_kwargs=config['included_kwargs']) for config in config_data['outputOptions'] ] for output_option in save_opt_configs: simulation.add_save_option(output_option) simulation.run( sort_by_best=SortAttribute[config_data['sortByBest'].lower()]) except Exception as e: print('Execution stopped with error: {0}'.format(str(e)))