Added LinearRankSelection.
[genetic.git] / src / generation.h
index a37602897694cc6d5afabf80d59331ff74fadca5..88942ec0d9fd2a0cac8e19b3762bee8cef227da8 100644 (file)
@@ -20,6 +20,7 @@ namespace genetic {
          */
         vector<_Chromosome> chromosomes;
 
+        template<typename> friend class Generation;
     public:
         /**
          * Default constructor
@@ -37,14 +38,7 @@ namespace genetic {
 
         /** Copy constructor */
         Generation(const Generation& generation)
-            : chromosomes(generation.get()) {
-        }
-
-        /**
-         * Allows read-only access to Generation Chromosomes
-         */
-        vector<_Chromosome> get() const {
-            return this->chromosomes;
+            : chromosomes(generation.chromosomes) {
         }
 
         /**
@@ -54,9 +48,27 @@ namespace genetic {
          * @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];
+        }
     };
 }