NonDominatedFronts { protected List<Collection<Individual>> generateFronts(Collection<Individual> individuals) { List<Collection<Individual>> fronts = new ArrayList<>(); Map<Individual, Integer> indexMap = new HashMap<>(); int index = 0; for (Individual individual : individuals) { indexMap.put(individual, index++); } Map<Individual, List<Individual>> dominatedIndividualsMap = new HashMap<>(); int[] dominatingIndividualNumber = new int[individuals.size()]; for (Individual e : individuals) { dominatedIndividualsMap.put(e, new ArrayList<>()); dominatingIndividualNumber[indexMap.get(e)] = 0; } determineDomination(individuals, dominatedIndividualsMap, dominatingIndividualNumber, indexMap); List<Individual> f1 = new ArrayList<>(); for (Individual i : individuals) { if (dominatingIndividualNumber[indexMap.get(i)] == 0) { f1.add(i); } } fronts.add(f1); List<Individual> currentFront = f1; while (!currentFront.isEmpty()) { List<Individual> nextFront = getNextFront(currentFront, dominatedIndividualsMap, dominatingIndividualNumber, indexMap); if (!nextFront.isEmpty()) { fronts.add(nextFront); } currentFront = nextFront; } return fronts; } NonDominatedFronts(Collection<Individual> individuals); Collection<Individual> getFrontAtIndex(int index); int getFrontNumber();  }
@Test public void testGenerateFronts() { NonDominatedFronts fronts = new NonDominatedFronts(getIndividualSet()); assertEquals(4, fronts.getFrontNumber()); assertEquals(3, fronts.getFrontAtIndex(0).size()); assertTrue(fronts.getFrontAtIndex(0).contains(first)); assertTrue(fronts.getFrontAtIndex(0).contains(second)); assertTrue(fronts.getFrontAtIndex(0).contains(third)); assertEquals(1, fronts.getFrontAtIndex(1).size()); assertTrue(fronts.getFrontAtIndex(1).contains(fourth)); assertEquals(1, fronts.getFrontAtIndex(2).size()); assertTrue(fronts.getFrontAtIndex(2).contains(fifth)); }