Example #1
0
    def test_should_the_solution_remain_unchanged_if_the_probability_is_zero(
            self):
        operator = BitFlipMutation(0.0)
        solution = BinarySolution(number_of_variables=1,
                                  number_of_objectives=1)
        solution.variables[0] = [True, True, False, False, True, False]

        mutated_solution = operator.execute(solution)
        self.assertEqual([True, True, False, False, True, False],
                         mutated_solution.variables[0])
Example #2
0
    def test_should_the_solution_change_all_the_bits_if_the_probability_is_one(
            self):
        operator = BitFlipMutation(1.0)
        solution = BinarySolution(number_of_variables=2,
                                  number_of_objectives=1)
        solution.variables[0] = [True, True, False, False, True, False]
        solution.variables[1] = [False, True, True, False, False, True]

        mutated_solution = operator.execute(solution)
        self.assertEqual([False, False, True, True, False, True],
                         mutated_solution.variables[0])
        self.assertEqual([True, False, False, True, True, False],
                         mutated_solution.variables[1])