AbstractArchive extends Archive { protected void removeArchiveDominated(List<Individual> candidates) { Iterator<Individual> i1; Iterator<Individual> i2; for (i1 = candidates.iterator(); i1.hasNext();) { Objectives o1 = i1.next().getObjectives(); for (i2 = this.iterator(); i2.hasNext();) { Objectives o2 = i2.next().getObjectives(); if (o2.weaklyDominates(o1)) { i1.remove(); break; } else if (o1.dominates(o2)) { i2.remove(); } } } }  @Override boolean update(Set<? extends Individual> individuals);  }
@Test public void removeArchiveDominatedTest() { Injector injector = Guice.createInjector(new MockProblemModule()); IndividualFactory factory = injector.getInstance(IndividualFactory.class); Objective o0 = new Objective("o0"); Objective o1 = new Objective("o1"); Individual iArchived0 = factory.create(); Objectives objectivesA0 = new Objectives(); objectivesA0.add(o0, 2); objectivesA0.add(o1, 3); iArchived0.setObjectives(objectivesA0); Individual iArchived1 = factory.create(); Objectives objectivesA1 = new Objectives(); objectivesA1.add(o0, 3); objectivesA1.add(o1, 2); iArchived1.setObjectives(objectivesA1); TestArchive archive = new TestArchive(); archive.addAll(iArchived0, iArchived1); 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.removeArchiveDominated(list); Assert.assertEquals(2, list.size()); Assert.assertTrue(list.contains(i0)); Assert.assertTrue(list.contains(i1)); Assert.assertTrue(archive.isEmpty()); }
@Test public void removeArchiveDominatedTest2() { Injector injector = Guice.createInjector(new MockProblemModule()); IndividualFactory factory = injector.getInstance(IndividualFactory.class); Objective o0 = new Objective("o0"); Objective o1 = new Objective("o1"); Individual iArchived0 = factory.create(); Objectives objectivesA0 = new Objectives(); objectivesA0.add(o0, 2); objectivesA0.add(o1, 3); iArchived0.setObjectives(objectivesA0); Individual iArchived1 = factory.create(); Objectives objectivesA1 = new Objectives(); objectivesA1.add(o0, 3); objectivesA1.add(o1, 2); iArchived1.setObjectives(objectivesA1); TestArchive archive = new TestArchive(); archive.addAll(iArchived0, iArchived1); Individual i0 = factory.create(); Objectives objectives0 = new Objectives(); objectives0.add(o0, 4); objectives0.add(o1, 4); i0.setObjectives(objectives0); List<Individual> list = new ArrayList<>(); list.add(i0); archive.removeArchiveDominated(list); Assert.assertTrue(list.isEmpty()); Assert.assertEquals(2, archive.size()); }
@Test public void removeArchiveDominatedTest3() { Injector injector = Guice.createInjector(new MockProblemModule()); IndividualFactory factory = injector.getInstance(IndividualFactory.class); Objective o0 = new Objective("o0"); Objective o1 = new Objective("o1"); Individual iArchived0 = factory.create(); Objectives objectivesA0 = new Objectives(); objectivesA0.add(o0, 0); objectivesA0.add(o1, 0); iArchived0.setObjectives(objectivesA0); TestArchive archive = new TestArchive(); archive.add(iArchived0); Individual i0 = factory.create(); Objectives objectives0 = new Objectives(); objectives0.add(o0, 0); objectives0.add(o1, 0); i0.setObjectives(objectives0); List<Individual> list = new ArrayList<>(); list.add(i0); archive.removeArchiveDominated(list); Assert.assertEquals(0, list.size()); Assert.assertFalse(list.contains(i0)); Assert.assertEquals(1, archive.size()); Assert.assertTrue(archive.contains(iArchived0)); }