AbstractArchive extends Archive { protected void removeDominatedCandidates(List<Individual> candidates) { for (int i = 0; i < candidates.size() - 1; i++) { Objectives o1 = candidates.get(i).getObjectives(); for (int j = i + 1; j < candidates.size(); j++) { Objectives o2 = candidates.get(j).getObjectives(); if (o2.weaklyDominates(o1)) { candidates.remove(i); i--; break; } else if (o1.weaklyDominates(o2)) { candidates.remove(j); j--; } } } }  @Override boolean update(Set<? extends Individual> individuals);  }
@Test public void removeDominatedCandidatesTest() { Injector injector = Guice.createInjector(new MockProblemModule()); IndividualFactory factory = injector.getInstance(IndividualFactory.class); Objective o0 = new Objective("o0"); Objective o1 = new Objective("o1"); TestArchive archive = new TestArchive(); Individual i0 = factory.create(); Objectives objectives0 = new Objectives(); objectives0.add(o0, 1); objectives0.add(o1, 0); i0.setObjectives(objectives0); Individual i1 = factory.create(); Objectives objectives1 = new Objectives(); objectives1.add(o0, 0); objectives1.add(o1, 1); i1.setObjectives(objectives1); List<Individual> list = new ArrayList<>(); list.add(i0); list.add(i1); archive.removeDominatedCandidates(list); Assert.assertEquals(2, list.size()); Assert.assertTrue(list.contains(i0)); Assert.assertTrue(list.contains(i1)); }
@Test public void removeDominatedCandidatesTest2() { Injector injector = Guice.createInjector(new MockProblemModule()); IndividualFactory factory = injector.getInstance(IndividualFactory.class); Objective o0 = new Objective("o0"); Objective o1 = new Objective("o1"); TestArchive archive = new TestArchive(); Individual i0 = factory.create(); Objectives objectives0 = new Objectives(); objectives0.add(o0, 0); objectives0.add(o1, 0); i0.setObjectives(objectives0); Individual i1 = factory.create(); Objectives objectives1 = new Objectives(); objectives1.add(o0, 1); objectives1.add(o1, 1); i1.setObjectives(objectives1); List<Individual> list = new ArrayList<>(); list.add(i0); list.add(i1); archive.removeDominatedCandidates(list); Assert.assertEquals(1, list.size()); Assert.assertTrue(list.contains(i0)); list.clear(); list.add(i1); list.add(i0); archive.removeDominatedCandidates(list); Assert.assertEquals(1, list.size()); Assert.assertTrue(list.contains(i0)); }