|
| 1 | +import unittest |
| 2 | +import time |
| 3 | +import random |
| 4 | + |
1 | 5 | import unittest |
2 | 6 |
|
3 | 7 | from jmetal.core.solution import Solution |
@@ -113,6 +117,35 @@ def test_should_adding_three_solutions_work_properly_if_two_of_them_are_equal(se |
113 | 117 | self.assertFalse(result) |
114 | 118 | self.assertTrue(solution1 in self.archive.solution_list or solution3 in self.archive.solution_list) |
115 | 119 |
|
| 120 | + def test_should_add_high_dimensional_solutions(self): |
| 121 | + """Test behavior with solutions having more than 2 objectives. Only one solution should remain due to dominance logic.""" |
| 122 | + archive = NonDominatedSolutionsArchive() |
| 123 | + s1 = Solution(1, 5) |
| 124 | + s1.objectives = [0.0, 1.0, 2.0, 3.0, 4.0] |
| 125 | + s2 = Solution(1, 5) |
| 126 | + s2.objectives = [1.0, 2.0, 3.0, 4.0, 5.0] |
| 127 | + s3 = Solution(1, 5) |
| 128 | + s3.objectives = [0.5, 1.5, 2.5, 3.5, 4.5] |
| 129 | + archive.add(s1) |
| 130 | + archive.add(s2) |
| 131 | + archive.add(s3) |
| 132 | + # Only one solution should remain, as the dominance logic removes dominated solutions |
| 133 | + self.assertEqual(1, archive.size()) |
| 134 | + self.assertTrue(s1 in archive.solution_list or s2 in archive.solution_list or s3 in archive.solution_list) |
| 135 | + |
| 136 | + def test_should_add_with_numerical_tolerance(self): |
| 137 | + """Test adding nearly identical solutions (numerical tolerance). Only one should be kept if they are equal within tolerance.""" |
| 138 | + archive = NonDominatedSolutionsArchive(objective_tolerance=1e-5) |
| 139 | + s1 = Solution(1, 2) |
| 140 | + s1.objectives = [1.000000, 2.000000] |
| 141 | + s2 = Solution(1, 2) |
| 142 | + s2.objectives = [1.000001, 2.000001] |
| 143 | + archive.add(s1) |
| 144 | + archive.add(s2) |
| 145 | + # Only one solution should be kept, as they are equal within the tolerance |
| 146 | + self.assertEqual(1, archive.size()) |
| 147 | + self.assertTrue(s1 in archive.solution_list or s2 in archive.solution_list) |
| 148 | + |
116 | 149 |
|
117 | 150 | class CrowdingDistanceArchiveTestCases(unittest.TestCase): |
118 | 151 | def setUp(self): |
|
0 commit comments