*/
@Override
public void performOperation(Random rnd, Genome[] parents, int parentIndex,
Genome[] offspring, int offspringIndex) {
IntegerArrayGenome mother = (IntegerArrayGenome)parents[parentIndex];
IntegerArrayGenome father = (IntegerArrayGenome)parents[parentIndex+1];
IntegerArrayGenome offspring1 = (IntegerArrayGenome)this.owner.getPopulation().getGenomeFactory().factor();
IntegerArrayGenome offspring2 = (IntegerArrayGenome)this.owner.getPopulation().getGenomeFactory().factor();
offspring[offspringIndex] = offspring1;
offspring[offspringIndex+1] = offspring2;
final int geneLength = mother.size();
// the chromosome must be cut at two positions, determine them
final int cutpoint1 = (int) (rnd.nextInt(geneLength - this.cutLength));
final int cutpoint2 = cutpoint1 + this.cutLength;
// keep track of which genes have been taken in each of the two
// offspring, defaults to false.
final Set<Integer> taken1 = new HashSet<Integer>();
final Set<Integer> taken2 = new HashSet<Integer>();
// handle cut section
for (int i = 0; i < geneLength; i++) {
if (!((i < cutpoint1) || (i > cutpoint2))) {
offspring1.copy(father,i,i);
offspring2.copy(mother,i,i);
taken1.add(father.getData()[i]);
taken2.add(mother.getData()[i]);
}
}
// handle outer sections
for (int i = 0; i < geneLength; i++) {
if ((i < cutpoint1) || (i > cutpoint2)) {
offspring1.getData()[i] = SpliceNoRepeat.getNotTaken(mother, taken1);
offspring2.getData()[i] = SpliceNoRepeat.getNotTaken(father, taken2);
}
}
}