X-Git-Url: https://git.dlugolecki.net.pl/?p=genetic.git;a=blobdiff_plain;f=include%2Fselection%2FrouletteSelection.h;h=afb3ac7f74828a4c0dfe8c1e28ef6b29aac354e3;hp=859e2531926fd8048f1890b4c57a75478b4cec29;hb=0c268e96035b65112e449c1c0df49f2be3eb184f;hpb=917440678dc4e920dfd5810da1274665acb17138 diff --git a/include/selection/rouletteSelection.h b/include/selection/rouletteSelection.h index 859e253..afb3ac7 100644 --- a/include/selection/rouletteSelection.h +++ b/include/selection/rouletteSelection.h @@ -4,8 +4,6 @@ #include #include // std::pair #include -#include -#include #include "chromosome.h" #include "selection.h" @@ -40,9 +38,9 @@ namespace genetic { * Generation. Values are set in the same order as they are in * the Generation. */ - vector calculateGenerationFitness( - Generation<_Chromosome> generation) { - vector generationFitness; + std::vector calculateGenerationFitness( + const Generation<_Chromosome>& generation) { + std::vector generationFitness; const unsigned int generationSize = generation.size(); for (unsigned int i = 0; i < generationSize; i++) { @@ -61,19 +59,19 @@ namespace genetic { * @return multimap containing normalized Fitness as a key and its * Chromosome as the value */ - multimap normalizeFitness( - vector generationFitness, + std::multimap normalizeFitness( + const std::vector& generationFitness, unsigned int chromosomeSize) { FitnessValueType min; FitnessValueType max; FitnessValueType offset; - unsigned int fitnessSize = generationFitness.size(); + const unsigned int fitnessSize = generationFitness.size(); /* we use multimap because it stores multiple values with the * same key */ - multimap normalizedFitness; + std::multimap normalizedFitness; min = max = generationFitness[0]; offset = 0; @@ -105,12 +103,12 @@ namespace genetic { * @return new Generation of Chromosome's that passed the Selection */ Generation<_Chromosome> spinRoulette( - multimap normalizedFitness) { + const std::multimap& normalizedFitness) { typedef typename std::multimap::iterator FitnessIterator; - vector<_Chromosome> selected; - multimap probabilities; + std::vector<_Chromosome> selected; + std::multimap probabilities; unsigned int size = this->generation.size(); const unsigned int power2N = 1 << this->generation[0].size(); @@ -169,7 +167,7 @@ namespace genetic { * @return new Generation of Chromosome's that passed the Selection */ Generation<_Chromosome> do_draw() { - multimap normalizedFitness; + std::multimap normalizedFitness; normalizedFitness = this->normalizeFitness( this->calculateGenerationFitness(this->generation), @@ -187,10 +185,8 @@ namespace genetic { * Selection * @param _fitness Fitness method to calculate fitness of Chromosomes */ - RouletteSelection(Generation<_Chromosome>& _generation, genetic::Fitness<_Chromosome>& _fitness) : + RouletteSelection(const Generation<_Chromosome>& _generation, genetic::Fitness<_Chromosome>& _fitness) : Selection<_Chromosome>(_generation, _fitness) { - this->generation = _generation; - this->fitness = _fitness; } }; // }