Fix building and installing package.
[genetic.git] / include / generation.h
diff --git a/include/generation.h b/include/generation.h
new file mode 100644 (file)
index 0000000..88942ec
--- /dev/null
@@ -0,0 +1,75 @@
+#ifndef __GENERATION_H
+#define __GENERATION_H
+
+#include <vector>
+
+#include <gene.h>
+#include <chromosome.h>
+
+using namespace std;
+
+namespace genetic {
+    /**
+     * Class representing Generation of given Chromosomes.
+     */
+    template < typename _Chromosome >
+    class Generation {
+    protected:
+        /**
+         * Chromosomes in the given Generation
+         */
+        vector<_Chromosome> chromosomes;
+
+        template<typename> friend class Generation;
+    public:
+        /**
+         * Default constructor
+         */
+        Generation() {}
+
+        /**
+         * Class constructor. Initializes generation with the given chromosomes
+         *
+         * @param chromosomes vector containing Chromosomes to use in Generation
+         */
+        Generation(vector<_Chromosome> chromosomes) {
+            this->chromosomes = chromosomes;
+        }
+
+        /** Copy constructor */
+        Generation(const Generation& generation)
+            : chromosomes(generation.chromosomes) {
+        }
+
+        /**
+         * Copy operator.
+         *
+         * @param generation Generation from which the Chromosomes should be copied.
+         * @return Generation instance containing copied Chromosomes
+         */
+        Generation& operator=(const Generation& generation){
+            this->chromosomes = generation.chromosomes;
+            return *this;
+        }
+
+        /**
+         * Returns number of Chromosomes in current Generation
+         *
+         * @return number of Chromosomes in current Generation
+         */
+        unsigned int size() const {
+            return this->chromosomes.size();
+        }
+
+        /**
+         * Returns i-th Chromosome in the current Generation
+         *
+         * @return i-th Chromosome in the current Generation
+         */
+        _Chromosome& operator[](unsigned int i) {
+            return this->chromosomes[i];
+        }
+    };
+}
+
+#endif /* __GENERATION_H */