def test_simulation_should_not_start_with_no_save_options(self):
     try:
         dataset = Dataset('name', 30, 5, 5, 5, [])
         simulation = Simulation(dataset=dataset,
                                 n_fes=30,
                                 np=5,
                                 save_to_dir='../results')
         simulation.add_algorithm('GreyWolfOptimizer')
         simulation.run(sort_by_best=SortAttribute.fitness)
         self.fail("Simulation started with no algorithms")
     except InvalidSimulationInitialState:
         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
예제 #4
0
        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)))