int offspringIndex = getPopulation().getPopulationSize()
- offspringCount;
final int matingPopulationSize = (int) (getPopulation()
.getPopulationSize() * getMatingPopulation());
final TaskGroup group = EngineConcurrency.getInstance()
.createTaskGroup();
// mate and form the next generation
for (int i = 0; i < countToMate; i++) {
final Genome mother = getPopulation().getGenomes().get(i);
final int fatherInt = (int) (Math.random() * matingPopulationSize);
final Genome father = getPopulation().getGenomes().get(fatherInt);
final Genome child1 = getPopulation().getGenomes().get(
offspringIndex);
final Genome child2 = getPopulation().getGenomes().get(
offspringIndex + 1);
final MateWorker worker = new MateWorker(mother, father, child1,
child2);
if( this.isMultiThreaded() ) {
EngineConcurrency.getInstance().processTask(worker, group);
} else {
worker.run();
}
offspringIndex += 2;
}
if( this.isMultiThreaded() ) {
group.waitForComplete();
}
// sort the next generation
getPopulation().sort();
}