GenotypeUniformCrossoverReproductionOperator extends AbstractUniformCrossoverReproductionOperator { @Override protected void reproduceInternal(Individual[] firstChildren, Individual[] secondChildren, int retSize) { for (int i = 0; i < retSize; i++){ GenotypeRepresentation firstRepresentation = ((GenotypeRepresentation)firstChildren[i].getRepresentation()); GenotypeRepresentation secondRepresentation = ((GenotypeRepresentation)secondChildren[i].getRepresentation()); double parentFitness = Math.max(firstChildren[i].getFitness(), secondChildren[i].getFitness()); firstChildren[i].setParentFitness(parentFitness); secondChildren[i].setParentFitness(parentFitness); int totalLength = firstRepresentation.getTotalLength(); for (int j = 0; j < totalLength; j++){ if (this.crossoverProbability > 0.0 && this.randomGenerator.nextRandom() <= this.crossoverProbability){ firstRepresentation.swapGenes(secondRepresentation, j, j+1); } } } }  Class<? extends Representation> getAcceptableType();  }
@Test public void testReproduceInternal1() throws Exception { this.operator.setCreateBothChildren(true); this.operator.setCrossoverProbability(0.2); SimpleBinaryRepresentation repr1 = new SimpleBinaryRepresentation(new SimpleBinaryGenomeDescriptor()){ @Override public int getTotalLength() { this.genome = genome1; return super.getTotalLength(); } }; repr1.getTotalLength(); Individual first = new SimpleIndividual(1, 0.0, repr1); SimpleBinaryRepresentation repr2 = new SimpleBinaryRepresentation(new SimpleBinaryGenomeDescriptor()){ @Override public int getTotalLength() { this.genome = genome2; return super.getTotalLength(); } }; repr2.getTotalLength(); Individual second = new SimpleIndividual(1, 0.0, repr2); this.operator.reproduceInternal(new Individual[]{first}, new Individual[]{second}, 1); GenotypeRepresentation result1 = ((GenotypeRepresentation)first.getRepresentation()); GenotypeRepresentation result2 = ((GenotypeRepresentation)second.getRepresentation()); assertEquals(this.expectedGenome1.length, result1.getTotalLength()); assertEquals(this.expectedGenome2.length, result2.getTotalLength()); for (int i = 0; i < this.expectedGenome1.length; i++){ assertEquals("at index " + i, expectedGenome1[i], result1.getGeneAt(i)); } for (int i = 0; i < this.expectedGenome2.length; i++){ assertEquals("at index " + i, expectedGenome2[i], result2.getGeneAt(i)); } }