From d2e7b1e9359bad68f591096949974bac668346ba Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Sun, 22 Mar 2015 15:32:35 +0100 Subject: [PATCH] Cleanup code. --- src/chromosome.h | 11 ++++++++++- src/gene.h | 5 ++++- src/generation.h | 3 +++ src/generator/generation.h | 6 +++++- src/main.cpp | 5 ----- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/chromosome.h b/src/chromosome.h index d37569f..ebed835 100644 --- a/src/chromosome.h +++ b/src/chromosome.h @@ -8,14 +8,23 @@ using namespace std; namespace genetic { + /** + * Chromosome of given Genes. + */ template < typename _Gene > class Chromosome { public: typedef _Gene GeneType; protected: + /** + * Genes of the chromosome + */ vector<_Gene> genes; public: + /** + * Default constructor + */ Chromosome() {} Chromosome(vector<_Gene> genes) { @@ -37,4 +46,4 @@ namespace genetic { }; } -#endif /* __CHROMOSOME_H */ \ No newline at end of file +#endif /* __CHROMOSOME_H */ diff --git a/src/gene.h b/src/gene.h index 618f887..9786587 100644 --- a/src/gene.h +++ b/src/gene.h @@ -3,6 +3,9 @@ namespace genetic { + /** + * Gene. + */ template < typename Type > class Gene { protected: @@ -27,4 +30,4 @@ namespace genetic { }; } -#endif /* __GENE_H */ \ No newline at end of file +#endif /* __GENE_H */ diff --git a/src/generation.h b/src/generation.h index 8ca0eb8..d36cd90 100644 --- a/src/generation.h +++ b/src/generation.h @@ -9,6 +9,9 @@ using namespace std; namespace genetic { + /** + * Generation of given Chromosomes. + */ template < typename _Chromosome > class Generation { protected: diff --git a/src/generator/generation.h b/src/generator/generation.h index c90a376..a561d8e 100644 --- a/src/generator/generation.h +++ b/src/generator/generation.h @@ -2,6 +2,7 @@ #define __GENERATOR_GENERATION_H #include +#include #include "../gene.h" #include "../chromosome.h" @@ -34,7 +35,7 @@ namespace genetic { public: /** - * Constructor. + * Constructor. Initializes required variables and constans * * @param generationSize Indicates size of the generation * @param generationSize Indicates size of the chromosome @@ -42,6 +43,9 @@ namespace genetic { Generation(unsigned int generationSize, unsigned int chromosomeSize) { this->generationSize = generationSize; this->chromosomeSize = chromosomeSize; + + time_t t; + srand((unsigned)time(&t)); } /** diff --git a/src/main.cpp b/src/main.cpp index 38bbf42..793df44 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,8 +1,6 @@ #include #include -#include - #include "gene.h" #include "chromosome.h" #include "generation.h" @@ -20,9 +18,6 @@ int main() { const int chromosomeSize = 11; const int generationSize = 20; - time_t t; - srand((unsigned)time(&t)); - generator::Generation<_Chromosome> generationGenerator(generationSize, chromosomeSize); Generation<_Chromosome> generation = generationGenerator.breed(); -- 2.30.2