CoevolutionNSGA2 extends CoevolutionMuLambda { @SuppressWarnings("rawtypes") @Override public ArrayList<Genotype> selection(int popIndex, int toKeep, ArrayList<Score> sourcePopulation) { return PopulationUtil.removeListGenotypeType(NSGA2.staticSelection(toKeep, NSGA2.staticNSGA2Scores(PopulationUtil.addListScoreType(sourcePopulation)))); }  @SuppressWarnings("rawtypes") // Each population can be a different type @Override ArrayList<Genotype> selection(int popIndex, int toKeep, ArrayList<Score> sourcePopulation);  }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void test() { CoevolutionNSGA2 ea = new CoevolutionNSGA2(); assertNotNull(ea); @SuppressWarnings("unused") ArrayList<Integer> s0, s1, s2, s3, s4, s5, s6, s7, s8, s9; ArrayList<Score> scores = new ArrayList<Score>(); scores.add(new Score(new BoundedIntegerValuedGenotype(s0 = ArrayUtil.intListFromArray(new int[] { 1, 5 })), new double[] { 1, 5 }, null)); scores.add(new Score(new BoundedIntegerValuedGenotype(s1 = ArrayUtil.intListFromArray(new int[] { 4, 4 })), new double[] { 4, 4 }, null)); scores.add(new Score(new BoundedIntegerValuedGenotype(s2 = ArrayUtil.intListFromArray(new int[] { 5, 1 })), new double[] { 5, 1 }, null)); scores.add(new Score(new BoundedIntegerValuedGenotype(s3 = ArrayUtil.intListFromArray(new int[] { 1, 4 })), new double[] { 1, 4 }, null)); scores.add(new Score(new BoundedIntegerValuedGenotype(s4 = ArrayUtil.intListFromArray(new int[] { 3, 3 })), new double[] { 3, 3 }, null)); scores.add(new Score(new BoundedIntegerValuedGenotype(s5 = ArrayUtil.intListFromArray(new int[] { 4, 1 })), new double[] { 4, 1 }, null)); scores.add(new Score(new BoundedIntegerValuedGenotype(s6 = ArrayUtil.intListFromArray(new int[] { 1, 3 })), new double[] { 1, 3 }, null)); scores.add(new Score(new BoundedIntegerValuedGenotype(s7 = ArrayUtil.intListFromArray(new int[] { 2, 2 })), new double[] { 2, 2 }, null)); scores.add(new Score(new BoundedIntegerValuedGenotype(s8 = ArrayUtil.intListFromArray(new int[] { 3, 1 })), new double[] { 3, 1 }, null)); scores.add(new Score(new BoundedIntegerValuedGenotype(s9 = ArrayUtil.intListFromArray(new int[] { 1, 1 })), new double[] { 1, 1 }, null)); Collections.shuffle(scores, RandomNumbers.randomGenerator); ArrayList<Genotype> front0 = (ea.selection(0, 3, scores)); ArrayList<ArrayList<Integer>> scores0 = justScores(front0); assertEquals(front0.size(), 3); assertTrue(scores0.contains(s0)); assertTrue(scores0.contains(s1)); assertTrue(scores0.contains(s2)); ArrayList<Genotype> front0and1 = (ea.selection(0, 6, scores)); ArrayList<ArrayList<Integer>> scores0and1 = justScores(front0and1); assertEquals(front0and1.size(), 6); assertTrue(scores0and1.contains(s0)); assertTrue(scores0and1.contains(s1)); assertTrue(scores0and1.contains(s2)); assertTrue(scores0and1.contains(s3)); assertTrue(scores0and1.contains(s4)); assertTrue(scores0and1.contains(s5)); ArrayList<Genotype> front0and1and2 = (ea.selection(0, 9, scores)); ArrayList<ArrayList<Integer>> scores0and1and2 = justScores(front0and1and2); assertEquals(front0and1and2.size(), 9); assertTrue(scores0and1and2.contains(s0)); assertTrue(scores0and1and2.contains(s1)); assertTrue(scores0and1and2.contains(s2)); assertTrue(scores0and1and2.contains(s3)); assertTrue(scores0and1and2.contains(s4)); assertTrue(scores0and1and2.contains(s5)); assertTrue(scores0and1and2.contains(s6)); assertTrue(scores0and1and2.contains(s7)); assertTrue(scores0and1and2.contains(s8)); }