X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=src%2Fmutation%2Fmutation.h;h=a35b312b60d637359e7e5d028c79be6bdd5a730e;hb=5e4a04634f1d31d4c774b44184cf08d3faf4d02a;hp=7b626ba1e63c54e07db72e0b70552191e787c046;hpb=1bef1f38888f19f83083d2f5bc1e1a90bb14291f;p=genetic.git diff --git a/src/mutation/mutation.h b/src/mutation/mutation.h index 7b626ba..a35b312 100644 --- a/src/mutation/mutation.h +++ b/src/mutation/mutation.h @@ -27,7 +27,7 @@ namespace genetic { typedef typename _Chromosome::GeneType GeneType; protected: /** - * Chance with which mutation can occur. + * Chance with which mutation can occur. (0 = 0%, 1 = 100%) */ MutationChanceType chance; @@ -49,21 +49,18 @@ namespace genetic { * @return new Generation of Chromosome's that passed the mutation */ Generation<_Chromosome> mutate(Generation<_Chromosome> _generation) { - const unsigned int generationSize = _generation.get().size(); - const unsigned int chromosomeSize = _generation.get()[0].get().size(); + const unsigned int generationSize = _generation.size(); + const unsigned int chromosomeSize = _generation[0].size(); vector<_Chromosome> newGeneration; for (unsigned int i = 0; i < generationSize; i++) { MutationChanceType random = (rand() % 10000) / 10000.0; - _Chromosome chromosome = _generation.get()[i]; + _Chromosome chromosome = _generation[i]; if (random < this->chance) { unsigned int mutatedGene = (rand() % chromosomeSize); - vector newChromosome = chromosome.get(); - newChromosome[mutatedGene] = GeneType(!newChromosome[mutatedGene].get()); - - chromosome = _Chromosome(newChromosome); + chromosome[mutatedGene] = GeneType(!chromosome[mutatedGene].get()); } newGeneration.push_back(chromosome); }