From: Rafał Długołęcki Date: Sun, 22 Mar 2015 12:06:24 +0000 (+0100) Subject: Fix Copy constructor. X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=46357591de1336612d4c26170cd59c13543b5169;p=genetic.git Fix Copy constructor. --- diff --git a/src/chromosome.h b/src/chromosome.h index 7582af0..a20c793 100644 --- a/src/chromosome.h +++ b/src/chromosome.h @@ -21,7 +21,9 @@ namespace genetic { } /** Copy constructor */ - Chromosome(const Chromosome& chromosome) : genes(chromosome.get()) {} + Chromosome(const Chromosome& chromosome) + : genes(chromosome.get()) { + } Chromosome& operator=(const Chromosome&){ return *this; diff --git a/src/fitness/wsti.h b/src/fitness/wsti.h index 068590d..028c322 100644 --- a/src/fitness/wsti.h +++ b/src/fitness/wsti.h @@ -34,10 +34,8 @@ namespace genetic { return span_start + (span_end - span_start) * this->fenotype() / power2N; } public: - WSTI(_Chromosome& chromosome, float start, float end) { - this->chromosome = chromosome; - this->span_start = start; - this->span_end = end; + WSTI(_Chromosome& _chromosome, float start, float end) + : chromosome(_chromosome.get()), span_start(start), span_end(end) { } double calculate() { diff --git a/src/main.cpp b/src/main.cpp index 958c241..60ea330 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,7 +20,7 @@ int main() { vector<_Gene> genes; - for (int i = 0; i < 20; i++) { + for (int i = 0; i < 11; i++) { _Gene gene(rand() % 2); cout << "Generated gene: " << (int)gene.get() << "\n"; genes.push_back(gene); @@ -29,13 +29,13 @@ int main() { _Chromosome chromosome(genes); cout << "Entire chromosome: "; - for (int i = 0; i < 20; i++) { + for (unsigned int i = 0; i < chromosome.get().size(); i++) { cout << chromosome.get()[i].get(); } cout << endl; WSTI<_Chromosome> fitness(chromosome, 0.5, 2.5); - cout << "Fitness is equal to: " << (double)fitness.calculate() << "\n"; + cout << "Fitness is equal to: " << fitness.calculate() << "\n"; return 0; }