UniformDeterministicSelectionOperator extends AbstractSelectionOperator { public Population[] select(Population[] populations) { this.checkConsistency(populations); Individual[] inputIndividuals = this.concatenateIndividualsFromPopulations(populations, this.inputArity); int totalOutput = inputIndividuals.length * this.broodSize; List<Individual> outputList = new ArrayList<Individual>(); for (Individual individual : inputIndividuals){ for (int i = 0; i < this.broodSize; i++){ outputList.add(individual); } } this.individualsPerPopulation = totalOutput / this.outputArity; Population[] outputPopulations = this.createOutputPopulations(); Individual[][] outputIndividuals = this.createOutputIndividuals(); this.mapByColumns(outputList, outputIndividuals); this.assignIndividualsToPopulations(outputIndividuals, outputPopulations); return outputPopulations; } UniformDeterministicSelectionOperator(); Population[] select(Population[] populations); @Override void checkConsistency(Population[] inputPopulations); void setRandomGenerator(RandomGenerator randomGenerator); void resetGenerationCount(); void nextGeneration(); void setGeneration(int currentGeneration);  }
@Test public void testSelect1() throws Exception { SimplePopulation popIn1 = new SimplePopulation(); SimplePopulation popIn2 = new SimplePopulation(); Individual[] allIndividuals = new SimpleIndividual[10]; for (int i = 0; i < allIndividuals.length; i++){ allIndividuals[i] = new SimpleIndividual(0, i, new SimplePhenotypeRepresentation()); } Individual[] ind1 = new Individual[]{allIndividuals[0], allIndividuals[1], allIndividuals[2]}; popIn1.setIndividuals(ind1); Individual[] ind2 = new Individual[]{allIndividuals[3], allIndividuals[4]}; popIn2.setIndividuals(ind2); Population[] popsIn = new Population[]{popIn1, popIn2}; this.operator.setInputArity(1); this.operator.setIndividualsPerPopulation(6); this.operator.setOutputArity(1); Population[] popsOut = operator.select(popsIn); assertTrue(popsOut != null); assertTrue(popsOut.length == 1); Individual[] indOut1 = popsOut[0].getIndividuals(); assertTrue(indOut1.length == 6); assertSame(allIndividuals[0], indOut1[0]); assertSame(allIndividuals[0], indOut1[1]); assertSame(allIndividuals[1], indOut1[2]); assertSame(allIndividuals[1], indOut1[3]); assertSame(allIndividuals[2], indOut1[4]); assertSame(allIndividuals[2], indOut1[5]); }
@Test public void testSelect2() throws Exception { SimplePopulation popIn1 = new SimplePopulation(); SimplePopulation popIn2 = new SimplePopulation(); SimplePopulation popIn3 = new SimplePopulation(); Individual[] allIndividuals = new SimpleIndividual[10]; for (int i = 0; i < allIndividuals.length; i++){ allIndividuals[i] = new SimpleIndividual(0, i, new SimplePhenotypeRepresentation()); } Individual[] ind1 = new Individual[]{allIndividuals[0], allIndividuals[1], allIndividuals[2], allIndividuals[3]}; popIn1.setIndividuals(ind1); Individual[] ind2 = new Individual[]{allIndividuals[4], allIndividuals[5]}; popIn2.setIndividuals(ind2); Individual[] ind3 = new Individual[]{allIndividuals[6], allIndividuals[7]}; popIn3.setIndividuals(ind3); Population[] popsIn = new Population[]{popIn1, popIn2, popIn3}; this.operator.setInputArity(2); this.operator.setIndividualsPerPopulation(9); this.operator.setOutputArity(2); Population[] popsOut = operator.select(popsIn); assertTrue(popsOut != null); assertTrue(popsOut.length == 2); Individual[] indOut1 = popsOut[0].getIndividuals(); Individual[] indOut2 = popsOut[1].getIndividuals(); assertTrue(indOut1.length == 9); assertSame(allIndividuals[0], indOut1[0]); assertSame(allIndividuals[1], indOut2[1]); assertSame(allIndividuals[1], indOut2[2]); assertSame(allIndividuals[2], indOut1[4]); assertSame(allIndividuals[3], indOut2[5]); assertSame(allIndividuals[4], indOut1[6]); assertSame(allIndividuals[5], indOut2[7]); }