Fix building and installing package.
[genetic.git] / include / generator / bitGenerator.h
diff --git a/include/generator/bitGenerator.h b/include/generator/bitGenerator.h
new file mode 100644 (file)
index 0000000..8e92521
--- /dev/null
@@ -0,0 +1,62 @@
+#ifndef __GENERATOR_BIT_H
+#define __GENERATOR_BIT_H
+
+#include <vector>
+#include <cstdlib>
+
+#include "gene.h"
+#include "chromosome.h"
+#include "generation.h"
+
+#include "generator/generator.h"
+
+using namespace std;
+
+namespace genetic {
+    namespace generator {
+        /**
+         * Generator for generating entire Generation of Chromosomes (individuals)
+         */
+        template < typename _Chromosome >
+        class BitGenerator : public Generator<_Chromosome> {
+        public:
+            /**
+             * Type representing Chromosome Gene
+             */
+            typedef typename _Chromosome::GeneType GeneType;
+
+        protected:
+            /**
+             * Breeds new generation of chromosomes.
+             *
+             * @return ::genetic::Generation Generation of Chromosomes
+             */
+            virtual ::genetic::Generation<_Chromosome> do_breed() {
+                vector<_Chromosome> chromosomes;
+
+                for (unsigned int i = 0; i < this->generationSize; i++) {
+                    vector<GeneType> genes;
+                    for (unsigned int j = 0; j < this->chromosomeSize; j++) {
+                        GeneType gene(rand() % 2);
+                        genes.push_back(gene);
+                    }
+                    chromosomes.push_back(genes);
+                }
+
+                return ::genetic::Generation<_Chromosome>(chromosomes);
+            }
+        public:
+            /**
+             * Constructor. Initializes required variables and constants
+             *
+             * @param generationSize Indicates size of the generation
+             * @param chromosomeSize Indicates size of the chromosome
+             */
+            BitGenerator(unsigned int generationSize, unsigned int chromosomeSize)
+                : Generator<_Chromosome>(generationSize, chromosomeSize) {
+            }
+        };
+    }
+}
+
+#endif /* __GENERATOR_GENERATOR_H */