예제 #1
0
    def test_crossover_same_level_4(self):
        individual_1 = Individual("(root S0)", Config.get_instance())
        individual_2 = Individual("(root S0)", Config.get_instance())

        try:
            new_ind_1, new_ind_2, _ = individual_1.crossover(individual_2)
            self.assertFalse(True,
                             "crossover with individual type 4 should fail")
        except OperationOverIndividualFail, ex:
            self.assertTrue(True)
예제 #2
0
    def test_crossover_same_level_0(self):
        individual_1 = Individual("(root (cos 5.046))", Config.get_instance())
        individual_2 = Individual("(root (cos 5.046))", Config.get_instance())

        new_ind_1, new_ind_2, _ = individual_1.crossover(individual_2)

        self._assert_individual(new_ind_1,
                                complexity=4,
                                value="(root (cos 5.046))",
                                formal="cos(5.046)")

        self._assert_individual(new_ind_2,
                                complexity=4,
                                value="(root (cos 5.046))",
                                formal="cos(5.046)")
예제 #3
0
    def test_crossover_same_level_2(self):
        individual_1 = Individual(
            "(root (cos (* (+ (* -1.912 -9.178) (cos S0)) 3.113)))",
            Config.get_instance())
        individual_2 = Individual(
            "(root (cos (* (+ (* -1.912 -9.178) (cos S0)) 3.113)))",
            Config.get_instance())
        new_ind_1, new_ind_2, _ = individual_1.crossover(individual_2)

        self._assert_individual(
            new_ind_1,
            complexity=8,
            value="(root (cos (* (* -1.912 -9.178) 3.113)))",
            formal="cos((((-1.912) .* (-9.178)) .* 3.113))")

        self._assert_individual(
            new_ind_2,
            complexity=18,
            value=
            "(root (cos (* (+ (+ (* -1.912 -9.178) (cos S0)) (cos S0)) 3.113)))",
            formal=
            "cos((((((-1.912) .* (-9.178)) + cos(S0)) + cos(S0)) .* 3.113))")