Additional optimization. Removed get() method from Generation.
[genetic.git] / src / generation.h
1 #ifndef __GENERATION_H
2 #define __GENERATION_H
3
4 #include <vector>
5
6 #include <gene.h>
7 #include <chromosome.h>
8
9 using namespace std;
10
11 namespace genetic {
12     /**
13      * Class representing Generation of given Chromosomes.
14      */
15     template < typename _Chromosome >
16     class Generation {
17     protected:
18         /**
19          * Chromosomes in the given Generation
20          */
21         vector<_Chromosome> chromosomes;
22
23         template<typename> friend class Generation;
24     public:
25         /**
26          * Default constructor
27          */
28         Generation() {}
29
30         /**
31          * Class constructor. Initializes generation with the given chromosomes
32          *
33          * @param chromosomes vector containing Chromosomes to use in Generation
34          */
35         Generation(vector<_Chromosome> chromosomes) {
36             this->chromosomes = chromosomes;
37         }
38
39         /** Copy constructor */
40         Generation(const Generation& generation)
41             : chromosomes(generation.chromosomes) {
42         }
43
44         /**
45          * Copy operator.
46          *
47          * @param generation Generation from which the Chromosomes should be copied.
48          * @return Generation instance containing copied Chromosomes
49          */
50         Generation& operator=(const Generation& generation){
51             this->chromosomes = generation.chromosomes;
52             return *this;
53         }
54
55         /**
56          * Returns number of Chromosomes in current Generation
57          *
58          * @return number of Chromosomes in current Generation
59          */
60         unsigned int size() const {
61             return this->chromosomes.size();
62         }
63
64         /**
65          * Returns i-th Chromosome in the current Generation
66          *
67          * @return i-th Chromosome in the current Generation
68          */
69         _Chromosome& operator[](unsigned int i) {
70             return this->chromosomes[i];
71         }
72     };
73 }
74
75 #endif /* __GENERATION_H */