Fix building and installing package.
[genetic.git] / include / generator / generator.h
diff --git a/include/generator/generator.h b/include/generator/generator.h
new file mode 100644 (file)
index 0000000..64f2720
--- /dev/null
@@ -0,0 +1,69 @@
+#ifndef __GENERATOR_GENERATOR_H
+#define __GENERATOR_GENERATOR_H
+
+#include <cstdlib>
+
+#include "../gene.h"
+#include "../chromosome.h"
+#include "../generation.h"
+
+using namespace std;
+
+namespace genetic {
+    namespace generator {
+        /**
+         * Generator for generating entire Generation of Chromosomes (individuals)
+         */
+        template < typename _Chromosome >
+        class Generator {
+        public:
+            /**
+             * Type representing Chromosome Gene
+             */
+            typedef typename _Chromosome::GeneType GeneType;
+        protected:
+            /**
+             * Size of the generation to generate
+             */
+            unsigned int generationSize;
+
+            /**
+             * Size of the chromosome to generate
+             */
+            unsigned int chromosomeSize;
+
+            /**
+             * Breeding calculations should be done here...
+             *
+             * @return newly breeded Generation
+             */
+            virtual ::genetic::Generation<_Chromosome> do_breed() = 0;
+
+        public:
+            /**
+             * Constructor. Initializes required variables and constants
+             *
+             * @param generationSize Indicates size of the generation
+             * @param chromosomeSize Indicates size of the chromosome
+             */
+            Generator(unsigned int generationSize, unsigned int chromosomeSize) {
+                this->generationSize = generationSize;
+                this->chromosomeSize = chromosomeSize;
+
+                time_t t;
+                srand((unsigned)time(&t));
+            }
+
+            /**
+             * Breeds new generation of chromosomes.
+             *
+             * @return ::genetic::Generation Generation of Chromosomes
+             */
+            ::genetic::Generation<_Chromosome> breed() {
+                return do_breed();
+            }
+        };
+    }
+}
+
+#endif /* __GENERATOR_GENERATOR_H */