Beispiel #1
0
    def test_should_compute_density_estimator_work_properly_case3(self):
        """ Case 3: The archive contains two solutions.
        """
        archive = CrowdingDistanceArchive(4)

        solution1 = Solution(2, 2)
        solution1.objectives = [0.0, 3.0]
        solution2 = Solution(2, 2)
        solution2.objectives = [1.0, 2.0]
        solution3 = Solution(2, 2)
        solution3.objectives = [2.0, 1.5]

        archive.add(solution1)
        archive.add(solution2)
        archive.add(solution3)

        archive.compute_density_estimator()

        self.assertEqual(3, archive.size())
        self.assertEqual(float("inf"),
                         solution1.attributes["crowding_distance"])
        self.assertEqual(float("inf"),
                         solution3.attributes["crowding_distance"])
        self.assertTrue(
            solution2.attributes["crowding_distance"] < float("inf"))
Beispiel #2
0
    def test_should_compute_density_estimator_work_properly_case1(self):
        """ Case 1: The archive contains one solution.
        """
        archive = CrowdingDistanceArchive(4)

        solution1 = Solution(2, 2)
        solution1.objectives = [0.0, 3.0]
        archive.add(solution1)

        archive.compute_density_estimator()

        self.assertEqual(1, archive.size())
        self.assertEqual(float("inf"), solution1.attributes["crowding_distance"])
Beispiel #3
0
    def test_should_compute_density_estimator_work_properly_case1(self):
        """ Case 1: The archive contains one solution.
        """
        archive = CrowdingDistanceArchive(4)

        solution1 = Solution(2, 2)
        solution1.objectives = [0.0, 3.0]
        archive.add(solution1)

        archive.compute_density_estimator()

        self.assertEqual(1, archive.size())
        self.assertEqual(float("inf"),
                         solution1.attributes["crowding_distance"])
Beispiel #4
0
    def test_should_add_work_properly_case7(self):
        """ Case 7: add a non-dominated solution when the archive is full should remove all the dominated solutions.
        """
        archive = CrowdingDistanceArchive(4)

        solution1 = Solution(2, 2)
        solution1.objectives = [0.0, 3.0]
        solution2 = Solution(2, 2)
        solution2.objectives = [1.0, 2.0]
        solution3 = Solution(2, 2)
        solution3.objectives = [2.0, 1.5]
        solution4 = Solution(2, 2)
        solution4.objectives = [3.0, 0.0]

        new_solution = Solution(2, 2)
        new_solution.objectives = [-1.0, -1.0]

        archive.add(solution1)
        archive.add(solution2)
        archive.add(solution3)
        archive.add(solution4)
        archive.add(new_solution)

        self.assertEqual(1, archive.size())
        self.assertTrue(new_solution in archive.solution_list)
Beispiel #5
0
    def test_should_add_work_properly_case6(self):
        """ Case 6: add a non-dominated solution when the archive is full should not include
        the solution if it has the highest distance crowding value.
        """
        archive = CrowdingDistanceArchive(4)

        solution1 = Solution(2, 2)
        solution1.objectives = [0.0, 3.0]
        solution2 = Solution(2, 2)
        solution2.objectives = [1.0, 2.0]
        solution3 = Solution(2, 2)
        solution3.objectives = [2.0, 1.5]
        solution4 = Solution(2, 2)
        solution4.objectives = [3.0, 0.0]

        new_solution = Solution(2, 2)
        new_solution.objectives = [1.1, 1.9]

        archive.add(solution1)
        archive.add(solution2)
        archive.add(solution3)
        archive.add(solution4)
        archive.add(new_solution)

        self.assertEqual(4, archive.size())
        self.assertTrue(new_solution not in archive.solution_list)
Beispiel #6
0
    def test_should_add_work_properly_case7(self):
        """ Case 7: add a non-dominated solution when the archive is full should remove all the dominated solutions.
        """
        archive = CrowdingDistanceArchive(4)

        solution1 = Solution(2, 2)
        solution1.objectives = [0.0, 3.0]
        solution2 = Solution(2, 2)
        solution2.objectives = [1.0, 2.0]
        solution3 = Solution(2, 2)
        solution3.objectives = [2.0, 1.5]
        solution4 = Solution(2, 2)
        solution4.objectives = [3.0, 0.0]

        new_solution = Solution(2, 2)
        new_solution.objectives = [-1.0, -1.0]

        archive.add(solution1)
        archive.add(solution2)
        archive.add(solution3)
        archive.add(solution4)
        archive.add(new_solution)

        self.assertEqual(1, archive.size())
        self.assertTrue(new_solution in archive.solution_list)
Beispiel #7
0
    def test_should_add_work_properly_case6(self):
        """ Case 6: add a non-dominated solution when the archive is full should not include
        the solution if it has the highest distance crowding value.
        """
        archive = CrowdingDistanceArchive(4)

        solution1 = Solution(2, 2)
        solution1.objectives = [0.0, 3.0]
        solution2 = Solution(2, 2)
        solution2.objectives = [1.0, 2.0]
        solution3 = Solution(2, 2)
        solution3.objectives = [2.0, 1.5]
        solution4 = Solution(2, 2)
        solution4.objectives = [3.0, 0.0]

        new_solution = Solution(2, 2)
        new_solution.objectives = [1.1, 1.9]

        archive.add(solution1)
        archive.add(solution2)
        archive.add(solution3)
        archive.add(solution4)
        archive.add(new_solution)

        self.assertEqual(4, archive.size())
        self.assertTrue(new_solution not in archive.solution_list)
Beispiel #8
0
    def test_should_compute_density_estimator_work_properly_case3(self):
        """ Case 3: The archive contains two solutions.
        """
        archive = CrowdingDistanceArchive(4)

        solution1 = Solution(2, 2)
        solution1.objectives = [0.0, 3.0]
        solution2 = Solution(2, 2)
        solution2.objectives = [1.0, 2.0]
        solution3 = Solution(2, 2)
        solution3.objectives = [2.0, 1.5]

        archive.add(solution1)
        archive.add(solution2)
        archive.add(solution3)

        archive.compute_density_estimator()

        self.assertEqual(3, archive.size())
        self.assertEqual(float("inf"), solution1.attributes["crowding_distance"])
        self.assertEqual(float("inf"), solution3.attributes["crowding_distance"])
        self.assertTrue(solution2.attributes["crowding_distance"] < float("inf"))