Ejemplo n.º 1
0
    def test_should_the_solution_change_if_the_probability_is_one(self):
        operator = UniformMutation(1.0, 3.0)
        solution = FloatSolution([-5, -5, -5], [5, 5, 5], 1)
        solution.variables = [1.0, 2.0, 3.0]

        mutated_solution = operator.execute(solution)
        self.assertNotEqual([1.0, 2.0, 3.0], mutated_solution.variables)
Ejemplo n.º 2
0
    def test_should_the_solution_remain_unchanged_if_the_probability_is_zero(
            self):
        operator = UniformMutation(0.0, 3.0)
        solution = FloatSolution(3, 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)
Ejemplo n.º 3
0
    def test_should_the_solution_change_between_max_and_min_value(self):
        operator = UniformMutation(1.0, 5)
        solution = FloatSolution([-1, 12, -3, -5], [1, 17, 3, -2], 1)
        solution.variables = [-7.0, 3.0, 12.0, 13.4]

        mutated_solution = operator.execute(solution)
        for i in range(solution.number_of_variables):
            self.assertGreaterEqual(mutated_solution.variables[i],
                                    solution.lower_bound[i])
            self.assertLessEqual(mutated_solution.variables[i],
                                 solution.upper_bound[i])