64f2720820530fadb84d1b1fabc94deb76598864
[genetic.git] / include / generator / generator.h
1 #ifndef __GENERATOR_GENERATOR_H
2 #define __GENERATOR_GENERATOR_H
3
4 #include <cstdlib>
5
6 #include "../gene.h"
7 #include "../chromosome.h"
8 #include "../generation.h"
9
10 using namespace std;
11
12 namespace genetic {
13     namespace generator {
14         /**
15          * Generator for generating entire Generation of Chromosomes (individuals)
16          */
17         template < typename _Chromosome >
18         class Generator {
19         public:
20             /**
21              * Type representing Chromosome Gene
22              */
23             typedef typename _Chromosome::GeneType GeneType;
24         protected:
25             /**
26              * Size of the generation to generate
27              */
28             unsigned int generationSize;
29
30             /**
31              * Size of the chromosome to generate
32              */
33             unsigned int chromosomeSize;
34
35             /**
36              * Breeding calculations should be done here...
37              *
38              * @return newly breeded Generation
39              */
40             virtual ::genetic::Generation<_Chromosome> do_breed() = 0;
41
42         public:
43             /**
44              * Constructor. Initializes required variables and constants
45              *
46              * @param generationSize Indicates size of the generation
47              * @param chromosomeSize Indicates size of the chromosome
48              */
49             Generator(unsigned int generationSize, unsigned int chromosomeSize) {
50                 this->generationSize = generationSize;
51                 this->chromosomeSize = chromosomeSize;
52
53                 time_t t;
54                 srand((unsigned)time(&t));
55             }
56
57             /**
58              * Breeds new generation of chromosomes.
59              *
60              * @return ::genetic::Generation Generation of Chromosomes
61              */
62             ::genetic::Generation<_Chromosome> breed() {
63                 return do_breed();
64             }
65         };
66     }
67 }
68
69 #endif /* __GENERATOR_GENERATOR_H */