From: Rafał Długołęcki Date: Sun, 5 Apr 2015 15:46:54 +0000 (+0200) Subject: Additional optimization. Removed get() method from Generation. X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=4ec0abc15ad6868ae7b154db026336e8a2c90249;p=genetic.git Additional optimization. Removed get() method from Generation. --- diff --git a/src/generation.h b/src/generation.h index f195d7e..88942ec 100644 --- a/src/generation.h +++ b/src/generation.h @@ -20,6 +20,7 @@ namespace genetic { */ vector<_Chromosome> chromosomes; + template friend class Generation; public: /** * Default constructor @@ -37,14 +38,7 @@ namespace genetic { /** Copy constructor */ Generation(const Generation& generation) - : chromosomes(generation.get()) { - } - - /** - * Allows read-only access to Generation Chromosomes - */ - vector<_Chromosome> get() const { - return this->chromosomes; + : chromosomes(generation.chromosomes) { } /** @@ -54,7 +48,7 @@ namespace genetic { * @return Generation instance containing copied Chromosomes */ Generation& operator=(const Generation& generation){ - this->chromosomes = generation.get(); + this->chromosomes = generation.chromosomes; return *this; } diff --git a/src/selection/roulette.h b/src/selection/roulette.h index b5c1f33..f1b10c5 100644 --- a/src/selection/roulette.h +++ b/src/selection/roulette.h @@ -44,8 +44,8 @@ namespace genetic { Generation<_Chromosome> generation) { vector generationFitness; - for (unsigned int i = 0; i < generation.get().size(); i++) { - generationFitness.push_back(this->checkChromosomeFitness(generation.get()[i])); + for (unsigned int i = 0; i < generation.size(); i++) { + generationFitness.push_back(this->checkChromosomeFitness(generation[i])); } return generationFitness; @@ -88,7 +88,7 @@ namespace genetic { offset = (max - min) / (chromosomeSize - 1) - min; for (unsigned int i = 0; i < generationFitness.size(); i++) { - normalizedFitness.insert(std::make_pair(generationFitness[i] + offset, this->generation.get()[i])); + normalizedFitness.insert(std::make_pair(generationFitness[i] + offset, this->generation[i])); } return normalizedFitness;