예제 #1
0
    def test_should_the_solution_change_if_the_probability_is_one(self):
        operator = SimpleRandomMutation(1.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)
예제 #2
0
    def test_should_the_solution_remain_unchanged_if_the_probability_is_zero(
            self):
        operator = SimpleRandomMutation(0.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)
예제 #3
0
    def test_should_the_solution_change_between_max_and_min_value(self):
        operator = SimpleRandomMutation(1.0)
        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])
예제 #4
0
 def test_should_constructor_raise_an_exception_if_the_probability_is_lower_than_zero(
         self):
     with self.assertRaises(Exception):
         SimpleRandomMutation(-12)
예제 #5
0
 def test_should_constructor_create_a_valid_operator(self):
     operator = SimpleRandomMutation(0.5)
     self.assertEqual(0.5, operator.probability)
예제 #6
0
 def test_should_constructor_create_a_non_null_object(self):
     operator = SimpleRandomMutation(1.0)
     self.assertIsNotNone(operator)
예제 #7
0
 def test_should_constructor_raises_an_exception_is_probability_is_higher_than_one(
         self) -> None:
     with self.assertRaises(Exception):
         SimpleRandomMutation(1.01)
예제 #8
0
 def test_should_constructor_raises_an_exception_is_probability_is_negative(
         self) -> None:
     with self.assertRaises(Exception):
         SimpleRandomMutation(-1)