Esempio n. 1
0
    def test_should_compare_works_properly_case4(self):
        """ Case 4: solution1.attribute > solution2.attribute (highest is best)
        """
        solution1 = Solution(1, 1)
        solution2 = Solution(1, 1)
        solution1.attributes["attribute"] = 1.0
        solution2.attributes["attribute"] = 0.0

        comparator = SolutionAttributeComparator("attribute", False)
        self.assertEqual(-1, comparator.compare(solution1, solution2))
Esempio n. 2
0
 def __init__(self, maximum_size: int, reference_point: List[float]):
     super(CrowdingDistanceArchiveWithReferencePoint, self).__init__(
         maximum_size=maximum_size,
         reference_point=reference_point,
         comparator=SolutionAttributeComparator("crowding_distance",
                                                lowest_is_best=False),
         density_estimator=CrowdingDistance())
Esempio n. 3
0
    def test_should_execute_work_properly_case1(self):
        solution1 = Solution(3, 2)
        solution1.objectives = [2, 3]
        solution2 = Solution(3, 2)
        solution2.objectives = [1, 4]
        solution1.attributes["dominance_ranking"] = 1
        solution2.attributes["dominance_ranking"] = 1

        solution_list = [solution1, solution2]
        operator = BinaryTournament2Selection[Solution](
            [SolutionAttributeComparator("key")])
        selection1 = operator.execute(solution_list)

        self.assertTrue(1, selection1.attributes["dominance_ranking"])
Esempio n. 4
0
 def setUp(self):
     self.comparator = SolutionAttributeComparator("attribute")
Esempio n. 5
0
class SolutionAttributeComparatorTestCases(unittest.TestCase):

    def setUp(self):
        self.comparator = SolutionAttributeComparator("attribute")

    def test_should_compare_return_zero_if_the_first_solution_has_no_the_attribute(self):
        solution1 = Solution(1, 1)
        solution2 = Solution(1, 1)
        solution2.attributes["attribute"] = 1.0

        self.assertEqual(0, self.comparator.compare(solution1, solution2))

    def test_should_compare_return_zero_if_the_second_solution_has_no_the_attribute(self):
        solution1 = Solution(1, 1)
        solution2 = Solution(1, 1)
        solution1.attributes["attribute"] = 1.0

        self.assertEqual(0, self.comparator.compare(solution1, solution2))

    def test_should_compare_return_zero_if_none_of_the_solutions_have_the_attribute(self):
        solution1 = Solution(1, 1)
        solution2 = Solution(1, 1)

        self.assertEqual(0, self.comparator.compare(solution1, solution2))

    def test_should_compare_return_zero_if_both_solutions_have_the_same_attribute_value(self):
        solution1 = Solution(1, 1)
        solution2 = Solution(1, 1)
        solution1.attributes["attribute"] = 1.0
        solution2.attributes["attribute"] = 1.0

        self.assertEqual(0, self.comparator.compare(solution1, solution2))

    def test_should_compare_works_properly_case1(self):
        """ Case 1: solution1.attribute < solution2.attribute (lowest is best)
        """
        solution1 = Solution(1, 1)
        solution2 = Solution(1, 1)
        solution1.attributes["attribute"] = 0.0
        solution2.attributes["attribute"] = 1.0

        self.assertEqual(-1, self.comparator.compare(solution1, solution2))

    def test_should_compare_works_properly_case2(self):
        """ Case 2: solution1.attribute > solution2.attribute (lowest is best)
        """
        solution1 = Solution(1, 1)
        solution2 = Solution(1, 1)
        solution1.attributes["attribute"] = 1.0
        solution2.attributes["attribute"] = 0.0

        self.assertEqual(1, self.comparator.compare(solution1, solution2))

    def test_should_compare_works_properly_case3(self):
        """ Case 3: solution1.attribute < solution2.attribute (highest is best)
        """
        comparator = SolutionAttributeComparator("attribute", False)
        solution1 = Solution(1, 1)
        solution2 = Solution(1, 1)
        solution1.attributes["attribute"] = 0.0
        solution2.attributes["attribute"] = 1.0

        self.assertEqual(1, comparator.compare(solution1, solution2))

    def test_should_compare_works_properly_case4(self):
        """ Case 4: solution1.attribute > solution2.attribute (highest is best)
        """
        solution1 = Solution(1, 1)
        solution2 = Solution(1, 1)
        solution1.attributes["attribute"] = 1.0
        solution2.attributes["attribute"] = 0.0

        comparator = SolutionAttributeComparator("attribute", False)
        self.assertEqual(-1, comparator.compare(solution1, solution2))
Esempio n. 6
0
 def __init__(self, maximum_size: int):
     super(CrowdingDistanceArchive, self).__init__(
         maximum_size=maximum_size,
         comparator=SolutionAttributeComparator("crowding_distance",
                                                lowest_is_best=False),
         density_estimator=CrowdingDistance())