int tries = this.train.getMaxOperationErrors();
do {
try {
// choose an evolutionary operation (i.e. crossover or a type of
// mutation) to use
final EvolutionaryOperator opp = this.train.getOperators()
.pickMaxParents(this.rnd,
this.species.getMembers().size());
this.children[0] = null;
// prepare for either sexual or asexual reproduction either way,
// we
// need at least
// one parent, which is the first parent.
//
// Chose the first parent, there must be at least one genome in
// this
// species
this.parents[0] = chooseParent();
// if the number of individuals in this species is only
// one then we can only clone and perhaps mutate, otherwise use
// the crossover probability to determine if we are to use
// sexual reproduction.
if (opp.parentsNeeded() > 1) {
int numAttempts = 5;
this.parents[1] = chooseParent();
while (this.parents[0] == this.parents[1]
&& numAttempts-- > 0) {
this.parents[1] = chooseParent();
}
// success, perform crossover
if (this.parents[0] != this.parents[1]) {
opp.performOperation(this.rnd, this.parents, 0,
this.children, 0);
}
} else {
// clone a child (asexual reproduction)
opp.performOperation(this.rnd, this.parents, 0,
this.children, 0);
this.children[0].setPopulation(this.parents[0]
.getPopulation());
}