AbstractNPointCrossoverReproductionOperator extends AbstractCrossoverReproductionOperator { protected boolean[] makeCutPointFlags(int numCrossings, int arrayLength){ int[] indexes = new int[numCrossings]; if ((numCrossings + 1) == arrayLength){ for (int i = 0; i < numCrossings; i++){ indexes[i] = i + 1; } } else { Set<Integer> indexSet = new TreeSet<Integer>(); while (indexSet.size() < numCrossings){ indexSet.add(this.randomGenerator.nextInt(1, arrayLength)); } int idx = 0; for (Integer integer : indexSet){ indexes[idx++] = integer; } } boolean[] flagArray = new boolean[arrayLength]; boolean flag = true; int index = 0; for (int i = 0; i < arrayLength; i++){ if (index < numCrossings && indexes[index] == i){ flag = !flag; index++; } flagArray[i] = flag; } return flagArray; }  @Override void checkConsistency(Population[] populations); Population[] reproduce(Population[] populations); int getCrossPointCount(); void setCrossPointCount(int crossPointCount);  }
@Test public void testMakeCutPointFlags1() throws Exception { for (int cutPoints = 1; cutPoints < 10; cutPoints++){ boolean[] flags = this.operator.makeCutPointFlags(cutPoints,cutPoints+1); int flips = countFlips(flags); assertTrue(flips == cutPoints); } }
@Test public void testMakeCutPointFlags2() throws Exception { for (int cutPoints = 1; cutPoints < 10; cutPoints++){ int totalLength = cutPoints * 4; boolean[] flags = this.operator.makeCutPointFlags(cutPoints, totalLength); int flips = countFlips(flags); assertEquals(cutPoints, flips); } }