Added LinearRankSelection.
[genetic.git] / src / generation.h
index 39b9577bc4f7c855da8acdb0c2413de7dffe5721..88942ec0d9fd2a0cac8e19b3762bee8cef227da8 100644 (file)
@@ -10,33 +10,65 @@ using namespace std;
 
 namespace genetic {
     /**
-     * Generation of given Chromosomes.
+     * 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.get()) {
-        }
-
-        vector<_Chromosome> get() const {
-            return this->chromosomes;
+            : 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.get();
+            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];
+        }
     };
 }