Esempio n. 1
0
 def test_validate_adaptation_type__invalid_value(self, min_limit, max_limit, population_size_boundaries):
     self.mock_adaptation_problem_object.MIN_POPULATION_SIZE = min_limit
     self.mock_adaptation_problem_object.MAX_POPULATION_SIZE = max_limit
     with pytest.raises(ValueError):
         EvolutionaryAlgorithmAdaptationProblem._validate_population_size_boundaries(
             self=self.mock_adaptation_problem_object,
             population_size_boundaries=population_size_boundaries)
Esempio n. 2
0
 def test_validate_mutation_chance_boundaries__invalid_value(self, min_limit, max_limit, mutation_chance_boundaries):
     self.mock_adaptation_problem_object.MIN_MUTATION_CHANCE = min_limit
     self.mock_adaptation_problem_object.MAX_MUTATION_CHANCE = max_limit
     with pytest.raises(ValueError):
         EvolutionaryAlgorithmAdaptationProblem._validate_mutation_chance_boundaries(
             self=self.mock_adaptation_problem_object,
             mutation_chance_boundaries=mutation_chance_boundaries)
Esempio n. 3
0
 def test_validate_mutation_chance_boundaries__valid(self, min_limit, min_mutation_chance, max_mutation_chance,
                                                     max_limit):
     self.mock_adaptation_problem_object.MIN_MUTATION_CHANCE = min_limit
     self.mock_adaptation_problem_object.MAX_MUTATION_CHANCE = max_limit
     EvolutionaryAlgorithmAdaptationProblem._validate_mutation_chance_boundaries(
         self=self.mock_adaptation_problem_object,
         mutation_chance_boundaries=(min_mutation_chance, max_mutation_chance)) is None
Esempio n. 4
0
 def test_get_objective_function__ont_implemented(self, adaptation_type, example_population_size_boundaries):
     with pytest.raises(NotImplementedError):
         EvolutionaryAlgorithmAdaptationProblem._get_objective_function(
             self=self.mock_adaptation_problem_object,
             adaptation_type=adaptation_type,
             solutions_percentile=None,
             solutions_number=None,
             population_size_boundaries=example_population_size_boundaries)
Esempio n. 5
0
 def test_get_objective_function__invalid_value(self, adaptation_type, solutions_percentile, solutions_number,
                                                population_size_boundaries):
     with pytest.raises(ValueError):
         EvolutionaryAlgorithmAdaptationProblem._get_objective_function(
             self=self.mock_adaptation_problem_object,
             adaptation_type=adaptation_type,
             solutions_percentile=solutions_percentile,
             solutions_number=solutions_number,
             population_size_boundaries=population_size_boundaries)
Esempio n. 6
0
 def test_init(self, example_adaptation_type, example_population_size_boundaries, example_selection_types,
               example_crossover_types, example_mutation_types, example_mutation_chance_boundaries,
               example_apply_elitism_options, adaptation_params, additional_decision_variables_params):
     EvolutionaryAlgorithmAdaptationProblem.__init__(
         self=self.mock_adaptation_problem_object,
         adaptation_type=example_adaptation_type,
         population_size_boundaries=example_population_size_boundaries,
         selection_types=example_selection_types,
         crossover_types=example_crossover_types,
         mutation_types=example_mutation_types,
         mutation_chance_boundaries=example_mutation_chance_boundaries,
         apply_elitism_options=example_apply_elitism_options,
         **adaptation_params, **additional_decision_variables_params
     )
     self.mock_validate_mandatory_parameters.assert_called_once_with(
         adaptation_type=example_adaptation_type,
         population_size_boundaries=example_population_size_boundaries,
         selection_types=example_selection_types,
         crossover_types=example_crossover_types,
         mutation_types=example_mutation_types,
         mutation_chance_boundaries=example_mutation_chance_boundaries,
         apply_elitism_options=example_apply_elitism_options
     )
     self.mock_get_main_decision_variables.assert_called_once_with(
         population_size_boundaries=example_population_size_boundaries,
         selection_types=example_selection_types,
         crossover_types=example_crossover_types,
         mutation_types=example_mutation_types,
         mutation_chance_boundaries=example_mutation_chance_boundaries,
         apply_elitism_options=example_apply_elitism_options
     )
     self.mock_get_objective_function.assert_called_once_with(
         adaptation_type=example_adaptation_type,
         solutions_percentile=adaptation_params.get("solutions_percentile", None)
         if example_adaptation_type == AdaptationType.BestSolutionsPercentile else None,
         solutions_number=adaptation_params.get("solutions_number", None)
         if example_adaptation_type == AdaptationType.BestSolutions else None,
         population_size_boundaries=example_population_size_boundaries
     )
     self.mock_optimization_problem_init.assert_called_once_with(
         decision_variables=self.mock_get_main_decision_variables.return_value,
         constraints=self.mock_get_constraints.return_value,
         penalty_function=self.mock_get_penalty_function.return_value,
         objective_function=self.mock_get_objective_function.return_value,
         optimization_type=OptimizationType.Maximize
     )
     self.mock_get_additional_decision_variables.assert_called_once()
     assert self.mock_adaptation_problem_object.additional_decision_variable \
            == self.mock_get_additional_decision_variables.return_value
Esempio n. 7
0
 def test_validate_mandatory_parameters__valid(self, example_adaptation_type, example_population_size_boundaries,
                                               example_selection_types, example_crossover_types,
                                               example_mutation_types, example_mutation_chance_boundaries,
                                               example_apply_elitism_options):
     assert EvolutionaryAlgorithmAdaptationProblem._validate_mandatory_parameters(
         self=self.mock_adaptation_problem_object,
         adaptation_type=example_adaptation_type,
         population_size_boundaries=example_population_size_boundaries,
         selection_types=example_selection_types,
         crossover_types=example_crossover_types,
         mutation_types=example_mutation_types,
         mutation_chance_boundaries=example_mutation_chance_boundaries,
         apply_elitism_options=example_apply_elitism_options) is None
     self.mock_adaptation_problem_object._validate_adaptation_type.assert_called_once_with(
         adaptation_type=example_adaptation_type)
     self.mock_adaptation_problem_object._validate_population_size_boundaries.assert_called_once_with(
         population_size_boundaries=example_population_size_boundaries)
     self.mock_adaptation_problem_object._validate_selection_types.assert_called_once_with(
         selection_types=example_selection_types)
     self.mock_adaptation_problem_object._validate_crossover_types.assert_called_once_with(
         crossover_types=example_crossover_types)
     self.mock_adaptation_problem_object._validate_mutation_types.assert_called_once_with(
         mutation_types=example_mutation_types)
     self.mock_adaptation_problem_object._validate_mutation_chance_boundaries.assert_called_once_with(
         mutation_chance_boundaries=example_mutation_chance_boundaries)
     self.mock_adaptation_problem_object._validate_apply_elitism_options.assert_called_once_with(
         apply_elitism_options=example_apply_elitism_options)
Esempio n. 8
0
 def test_get_main_decision_variables(self, population_size_boundaries, selection_types, crossover_types,
                                      mutation_types, mutation_chance_boundaries, apply_elitism_options):
     return_value = EvolutionaryAlgorithmAdaptationProblem._get_main_decision_variables(
         population_size_boundaries=population_size_boundaries,
         selection_types=selection_types,
         crossover_types=crossover_types,
         mutation_types=mutation_types,
         mutation_chance_boundaries=mutation_chance_boundaries,
         apply_elitism_options=apply_elitism_options
     )
     self.mock_discrete_variable_class.assert_has_calls([call(min_value=population_size_boundaries[0],
                                                              max_value=population_size_boundaries[1], step=2)])
     self.mock_choice_variable_class.assert_has_calls([call(possible_values=selection_types),
                                                       call(possible_values=crossover_types),
                                                       call(possible_values=mutation_types),
                                                       call(possible_values=apply_elitism_options)])
     self.mock_float_variable_class.assert_has_calls([call(min_value=mutation_chance_boundaries[0],
                                                           max_value=mutation_chance_boundaries[1])])
     assert isinstance(return_value, OrderedDict)
     assert return_value["population_size"] == self.mock_discrete_variable_class.return_value
     assert return_value["selection_type"] == self.mock_choice_variable_class.return_value
     assert return_value["crossover_type"] == self.mock_choice_variable_class.return_value
     assert return_value["mutation_type"] == self.mock_choice_variable_class.return_value
     assert return_value["mutation_chance"] == self.mock_float_variable_class.return_value
     assert return_value["apply_elitism"] == self.mock_choice_variable_class.return_value
Esempio n. 9
0
 def test_get_objective_function__valid(self, adaptation_type, solutions_percentile, solutions_number,
                                        population_size_boundaries):
     return_value = EvolutionaryAlgorithmAdaptationProblem._get_objective_function(
         self=self.mock_adaptation_problem_object,
         adaptation_type=adaptation_type,
         solutions_percentile=solutions_percentile,
         solutions_number=solutions_number,
         population_size_boundaries=population_size_boundaries)
     self.mock_adaptation_problem_object._create_objective_function.assert_called_once_with(
         adaptation_type=adaptation_type,
         solutions_percentile=solutions_percentile,
         solutions_number=solutions_number)
     assert return_value == self.mock_adaptation_problem_object._create_objective_function.return_value
Esempio n. 10
0
 def test_get_additional_decision_variables__valid(self, additional_params, default_min_tournament_group_size,
                                                   default_max_tournament_group_size,
                                                   default_min_ranking_bias, default_max_ranking_bias,
                                                   default_min_roulette_bias, default_max_roulette_bias):
     return_value = EvolutionaryAlgorithmAdaptationProblem._get_additional_decision_variables(**additional_params)
     self.mock_integer_variable_class.assert_has_calls([
         call(min_value=additional_params.get("min_tournament_group_size", default_min_tournament_group_size),
              max_value=additional_params.get("max_tournament_group_size", default_max_tournament_group_size))
     ])
     self.mock_float_variable_class.assert_has_calls([
         call(min_value=additional_params.get("min_roulette_bias", default_min_roulette_bias),
              max_value=additional_params.get("max_roulette_bias", default_max_roulette_bias)),
         call(min_value=additional_params.get("min_ranking_bias", default_min_ranking_bias),
              max_value=additional_params.get("max_ranking_bias", default_max_ranking_bias)),
     ])
     assert isinstance(return_value, dict)
     assert return_value["tournament_group_size"] == self.mock_integer_variable_class.return_value
     assert return_value["roulette_bias"] == self.mock_float_variable_class.return_value
     assert return_value["ranking_bias"] == self.mock_float_variable_class.return_value
     assert return_value["crossover_points_number"] == self.mock_integer_variable_class.return_value
     assert return_value["crossover_patter"] == self.mock_integer_variable_class.return_value
     assert return_value["mutation_points_number"] == self.mock_integer_variable_class.return_value
Esempio n. 11
0
 def test_validate_adaptation_type__invalid_type(self, adaptation_type):
     with pytest.raises(TypeError):
         EvolutionaryAlgorithmAdaptationProblem._validate_adaptation_type(adaptation_type=adaptation_type)
Esempio n. 12
0
 def test_validate_adaptation_type__valid(self, min_limit, min_population_size, max_population_size, max_limit):
     self.mock_adaptation_problem_object.MIN_POPULATION_SIZE = min_limit
     self.mock_adaptation_problem_object.MAX_POPULATION_SIZE = max_limit
     assert EvolutionaryAlgorithmAdaptationProblem._validate_population_size_boundaries(
         self=self.mock_adaptation_problem_object,
         population_size_boundaries=(min_population_size, max_population_size)) is None
Esempio n. 13
0
 def test_validate_crossover_types__invalid_value(self, crossover_types):
     with pytest.raises(ValueError):
         EvolutionaryAlgorithmAdaptationProblem._validate_crossover_types(crossover_types=crossover_types)
Esempio n. 14
0
 def test_create_objective_function__invalid_type(self, adaptation_type):
     with pytest.raises(NotImplementedError):
         EvolutionaryAlgorithmAdaptationProblem._create_objective_function(adaptation_type=adaptation_type,
                                                                           solutions_percentile=None,
                                                                           solutions_number=None)
Esempio n. 15
0
 def test_validate_apply_elitism_options__valid(self, apply_elitism_options):
     assert EvolutionaryAlgorithmAdaptationProblem._validate_apply_elitism_options(
         apply_elitism_options=apply_elitism_options) is None
Esempio n. 16
0
 def test_validate_crossover_types__invalid_value(self, apply_elitism_options):
     with pytest.raises(ValueError):
         EvolutionaryAlgorithmAdaptationProblem._validate_apply_elitism_options(
             apply_elitism_options=apply_elitism_options)
Esempio n. 17
0
 def test_validate_adaptation_type__valid(self, example_adaptation_type):
     assert EvolutionaryAlgorithmAdaptationProblem._validate_adaptation_type(
         adaptation_type=example_adaptation_type) is None
Esempio n. 18
0
 def test_validate_adaptation_type__invalid_type(self, population_size_boundaries):
     with pytest.raises(TypeError):
         EvolutionaryAlgorithmAdaptationProblem._validate_population_size_boundaries(
             self=self.mock_adaptation_problem_object,
             population_size_boundaries=population_size_boundaries)
Esempio n. 19
0
 def test_validate_selection_types__invalid_type(self, selection_types):
     with pytest.raises(TypeError):
         EvolutionaryAlgorithmAdaptationProblem._validate_selection_types(selection_types=selection_types)
Esempio n. 20
0
 def test_validate_mutation_types__invalid_value(self, mutation_types):
     with pytest.raises(ValueError):
         EvolutionaryAlgorithmAdaptationProblem._validate_mutation_types(mutation_types=mutation_types)
Esempio n. 21
0
 def test_validate_mutation_types__valid(self, mutation_types):
     assert EvolutionaryAlgorithmAdaptationProblem._validate_mutation_types(
         mutation_types=mutation_types) is None
Esempio n. 22
0
 def test_get_additional_decision_variables__valid(self, additional_params, default_min_tournament_group_size,
                                                   default_max_tournament_group_size,
                                                   default_min_ranking_bias, default_max_ranking_bias,
                                                   default_min_roulette_bias, default_max_roulette_bias):
     with pytest.raises(ValueError):
         EvolutionaryAlgorithmAdaptationProblem._get_additional_decision_variables(**additional_params)
Esempio n. 23
0
 def test_create_objective_function__valid(self, adaptation_type, solutions_percentile, solutions_number):
     objective = EvolutionaryAlgorithmAdaptationProblem._create_objective_function(
         adaptation_type=adaptation_type,
         solutions_percentile=solutions_percentile,
         solutions_number=solutions_number)
     assert callable(objective)
Esempio n. 24
0
 def test_validate_mutation_chance_boundaries__invalid_type(self, mutation_chance_boundaries):
     with pytest.raises(TypeError):
         EvolutionaryAlgorithmAdaptationProblem._validate_mutation_chance_boundaries(
             self=self.mock_adaptation_problem_object,
             mutation_chance_boundaries=mutation_chance_boundaries)
Esempio n. 25
0
 def test_validate_crossover_types__valid(self, crossover_types):
     assert EvolutionaryAlgorithmAdaptationProblem._validate_crossover_types(
         crossover_types=crossover_types) is None