public List < Biomorph > apply ( List < Biomorph > selectedCandidates , Random rng ) { List < Biomorph > mutatedPopulation = new ArrayList < Biomorph > ( selectedCandidates . size ( ) ) ; int mutatedGene = 0 ; int mutation = 1 ; for ( Biomorph b : selectedCandidates ) { int [ ] genes = b . getGenotype ( ) ; mutation *= - 1 ; // Alternate between incrementing and decrementing. if ( mutation == 1 ) // After gene has been both incremented and decremented, move to next one. { mutatedGene = ( mutatedGene + 1 ) % Biomorph . GENE_COUNT ; } genes [ mutatedGene ] += mutation ; int min = mutatedGene == Biomorph . LENGTH_GENE_INDEX ? Biomorph . LENGTH_GENE_MIN : Biomorph . GENE_MIN ; int max = mutatedGene == Biomorph . LENGTH_GENE_INDEX ? Biomorph . LENGTH_GENE_MAX : Biomorph . GENE_MAX ; if ( genes [ mutatedGene ] > max ) { genes [ mutatedGene ] = min ; } else if ( genes [ mutatedGene ] < min ) { genes [ mutatedGene ] = max ; } mutatedPopulation . add ( new Biomorph ( genes ) ) ; } return mutatedPopulation ; }
Mutate a population of biomorphs non - randomly ensuring that each selected candidate is mutated differently .