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"))
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"])
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"))