1 #ifndef __GENERATOR_BIT_H
2 #define __GENERATOR_BIT_H
8 #include "chromosome.h"
9 #include "generation.h"
11 #include "generator/generator.h"
18 * Generator for generating entire Generation of Chromosomes (individuals)
20 template < typename _Chromosome >
21 class BitGenerator : public Generator<_Chromosome> {
24 * Type representing Chromosome Gene
26 typedef typename _Chromosome::GeneType GeneType;
30 * Breeds new generation of chromosomes.
32 * @return ::genetic::Generation Generation of Chromosomes
34 virtual ::genetic::Generation<_Chromosome> do_breed() {
35 vector<_Chromosome> chromosomes;
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);
43 chromosomes.push_back(genes);
46 return ::genetic::Generation<_Chromosome>(chromosomes);
50 * Constructor. Initializes required variables and constants
52 * @param generationSize Indicates size of the generation
53 * @param chromosomeSize Indicates size of the chromosome
55 BitGenerator(unsigned int generationSize, unsigned int chromosomeSize)
56 : Generator<_Chromosome>(generationSize, chromosomeSize) {
62 #endif /* __GENERATOR_GENERATOR_H */