Bigger values for testing results.
[genetic.git] / include / generator / bitGenerator.h
1 #ifndef __GENERATOR_BIT_H
2 #define __GENERATOR_BIT_H
3
4 #include <vector>
5 #include <cstdlib>
6
7 #include "gene.h"
8 #include "chromosome.h"
9 #include "generation.h"
10
11 #include "generator/generator.h"
12
13 using namespace std;
14
15 namespace genetic {
16     namespace generator {
17         /**
18          * Generator for generating entire Generation of Chromosomes (individuals)
19          */
20         template < typename _Chromosome >
21         class BitGenerator : public Generator<_Chromosome> {
22         public:
23             /**
24              * Type representing Chromosome Gene
25              */
26             typedef typename _Chromosome::GeneType GeneType;
27
28         protected:
29             /**
30              * Breeds new generation of chromosomes.
31              *
32              * @return ::genetic::Generation Generation of Chromosomes
33              */
34             virtual ::genetic::Generation<_Chromosome> do_breed() {
35                 vector<_Chromosome> chromosomes;
36
37                 for (unsigned int i = 0; i < this->generationSize; i++) {
38                     vector<GeneType> genes;
39                     for (unsigned int j = 0; j < this->chromosomeSize; j++) {
40                         GeneType gene(rand() % 2);
41                         genes.push_back(gene);
42                     }
43                     chromosomes.push_back(genes);
44                 }
45
46                 return ::genetic::Generation<_Chromosome>(chromosomes);
47             }
48         public:
49             /**
50              * Constructor. Initializes required variables and constants
51              *
52              * @param generationSize Indicates size of the generation
53              * @param chromosomeSize Indicates size of the chromosome
54              */
55             BitGenerator(unsigned int generationSize, unsigned int chromosomeSize)
56                 : Generator<_Chromosome>(generationSize, chromosomeSize) {
57             }
58         };
59     }
60 }
61
62 #endif /* __GENERATOR_GENERATOR_H */