SinglePointCrossover extends CrossoverOperation { public void makeNewChromosome(final GEChromosome c1, final GEChromosome c2, final int p1maxXOPoint, final int p2maxXOPoint) { final int point1, point2; if (this.fixedCrossoverPoint) { point1 = getXoverPoint(p1maxXOPoint, p2maxXOPoint); int tmp1, tmp2; for (int i = 0; i < point1; i++) { tmp1 = c1.get(i); tmp2 = c2.get(i); c1.set(i, tmp2); c2.set(i, tmp1); } } else { point1 = this.rand.nextInt(p1maxXOPoint); point2 = this.rand.nextInt(p2maxXOPoint); int[] tmp1 = c1.toArray(); int[] tmp2 = c2.toArray(); c1.clear(); c2.clear(); for (int i = 0; i < point1; i++) { c1.add(tmp1[i]); } for (int i = point2; i < tmp2.length; i++) { c1.add(tmp2[i]); } for (int i = 0; i < point2; i++) { c2.add(tmp2[i]); } for (int i = point1; i < tmp1.length; i++) { c2.add(tmp1[i]); } } } @SuppressWarnings({"SameParameterValue"})  SinglePointCrossover(RandomNumberGenerator m, double prob);  SinglePointCrossover(RandomNumberGenerator m, Properties p); @Override void setProperties(Properties p); void doOperation(Individual operands); void doOperation(List<Individual> operands); void makeNewChromosome(final GEChromosome c1, final GEChromosome c2,
            final int p1maxXOPoint, final int p2maxXOPoint); boolean isFixedCrossoverPoint(); @SuppressWarnings({"SameParameterValue"}) void setFixedCrossoverPoint(boolean fixedCrossoverPoint); static void main(String[] args);  }
@Test public void testMakeNewChromosome() { System.out.println("*SinglePointCrossoverTest: makeNewChromosome"); MersenneTwisterFast mft = new MersenneTwisterFast(0); GEChromosome c1 = new GEChromosome(6); GEChromosome c2 = new GEChromosome(6); for (int i = 0; i < 6; i++) { c1.add(1); c2.add(2); } int[] ia = {1,1,1,1,2,2,2,2,2}; int[] ia2 = {2,1,1}; SinglePointCrossover instance = new SinglePointCrossover(mft, 1.0); instance.setFixedCrossoverPoint(false); instance.makeNewChromosome(c1, c2, c1.size(), c2.size()); JUnitHelper.checkArrays(ia, c1.toArray()); JUnitHelper.checkArrays(ia2, c2.toArray()); instance.setFixedCrossoverPoint(true); c1.clear(); c2.clear(); for(int i = 0; i < 6; i++) { c1.add(1); c2.add(2); } c1.add(1); int[] ia3 = {2,2,1,1,1,1,1}; int[] ia4 = {1,1,2,2,2,2}; instance.makeNewChromosome(c1, c2, c1.size(), c2.size()); JUnitHelper.checkArrays(ia3, c1.toArray()); JUnitHelper.checkArrays(ia4, c2.toArray()); }