X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=src%2Fgeneration.h;h=88942ec0d9fd2a0cac8e19b3762bee8cef227da8;hb=5e4a04634f1d31d4c774b44184cf08d3faf4d02a;hp=8ca0eb841a975cb1c9fc2dfe3f8cc8bbf66d181c;hpb=ec0bd5c9a9350200f58ec7b84707bca822d145ed;p=genetic.git diff --git a/src/generation.h b/src/generation.h index 8ca0eb8..88942ec 100644 --- a/src/generation.h +++ b/src/generation.h @@ -9,25 +9,65 @@ 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 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()) { + : chromosomes(generation.chromosomes) { } - vector<_Chromosome> get() const { - return this->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]; } }; }