From: Rafał Długołęcki Date: Sun, 22 Mar 2015 14:32:35 +0000 (+0100) Subject: Cleanup code. X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;ds=sidebyside;h=d2e7b1e9359bad68f591096949974bac668346ba;p=genetic.git Cleanup code. --- 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();