1 #ifndef __GENERATOR_GENERATION_H
2 #define __GENERATOR_GENERATION_H
8 #include "../chromosome.h"
9 #include "../generation.h"
16 * Generator for generating entire Generation of Chromosomes (individuals)
18 template < typename _Chromosome >
22 * Type of used Genes in Chromosome
24 typedef typename _Chromosome::GeneType GeneType;
27 * Size of the generation to generate
29 unsigned int generationSize;
32 * Size of the chromosome to generate
34 unsigned int chromosomeSize;
38 * Constructor. Initializes required variables and constans
40 * @param generationSize Indicates size of the generation
41 * @param generationSize Indicates size of the chromosome
43 Generation(unsigned int generationSize, unsigned int chromosomeSize) {
44 this->generationSize = generationSize;
45 this->chromosomeSize = chromosomeSize;
48 srand((unsigned)time(&t));
52 * Breeds new generation of chromosomes.
54 * @return ::genetic::Generation Generation of Chromosomes
56 ::genetic::Generation<_Chromosome> breed() {
57 vector<_Chromosome> chromosomes;
59 for (unsigned int i = 0; i < generationSize; i++) {
60 vector<GeneType> genes;
61 for (unsigned int j = 0; j < chromosomeSize; j++) {
62 GeneType gene(rand() % 2);
63 genes.push_back(gene);
65 chromosomes.push_back(genes);
68 return ::genetic::Generation<_Chromosome>(chromosomes);
74 #endif /* __GENERATOR_GENERATION_H */