Пример #1
0
    def test_should_the_solution_remain_unchanged_if_the_probability_is_zero(
            self):
        operator = PolynomialMutation(0.0)
        solution = FloatSolution(2, 1, [-5, -5, -5], [5, 5, 5])
        solution.variables = [1.0, 2.0, 3.0]

        mutated_solution = operator.execute(solution)
        self.assertEqual([1.0, 2.0, 3.0], mutated_solution.variables)
Пример #2
0
    def test_should_the_solution_change__if_the_probability_is_one(self):
        operator = PolynomialMutation(1.0)
        solution = FloatSolution([-5, -5, -5], [5, 5, 5], 2)
        solution.variables = [1.0, 2.0, 3.0]

        mutated_solution = operator.execute(solution)

        self.assertNotEqual([1.0, 2.0, 3.0], mutated_solution.variables)
Пример #3
0
    def test_should_execute_work_with_a_solution_subclass_of_float_solution(
            self):
        class NewFloatSolution(FloatSolution):
            def __init__(self,
                         lower_bound: List[float],
                         upper_bound: List[float],
                         number_of_objectives: int,
                         number_of_constraints: int = 0):
                super(NewFloatSolution,
                      self).__init__(lower_bound, upper_bound,
                                     number_of_objectives,
                                     number_of_constraints)

        operator = PolynomialMutation(1.0)
        solution = NewFloatSolution([-5, -5, -5], [5, 5, 5], 2)
        solution.variables = [1.0, 2.0, 3.0]

        mutated_solution = operator.execute(solution)

        self.assertNotEqual([1.0, 2.0, 3.0], mutated_solution.variables)