X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=include%2Fgeneration.h;fp=include%2Fgeneration.h;h=88942ec0d9fd2a0cac8e19b3762bee8cef227da8;hb=2a8fc81203107eb3495a50fb2666803fda3e0517;hp=0000000000000000000000000000000000000000;hpb=169219566d08e4940d25b66ecdb68e80b90c090d;p=genetic.git diff --git a/include/generation.h b/include/generation.h new file mode 100644 index 0000000..88942ec --- /dev/null +++ b/include/generation.h @@ -0,0 +1,75 @@ +#ifndef __GENERATION_H +#define __GENERATION_H + +#include + +#include +#include + +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.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 */