-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathIndividual.hpp
36 lines (28 loc) · 1.1 KB
/
Individual.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef __JM_GENETIC_ALGORITHM_INDIVIDUAL
#define __JM_GENETIC_ALGORITHM_INDIVIDUAL
#include <limits>
#include <vector>
#include "Gene.hpp"
class Individual {
public:
static void init(unsigned num_args, unsigned num_genes);
Individual();
Individual(const Individual& a, const Individual& b);
void fitness(const std::vector<double> &args, double expected);
void mutate(unsigned mutation_rate);
double getValue() const;
bool operator < (const Individual& ind) const;
Individual operator()() const;
friend std::ostream& operator<<(std::ostream& o, const Individual& ind);
private:
static unsigned m_num_args;
static unsigned m_num_genes;
unsigned m_num_evals;
double m_value = 0.0; // Fitness function needs this to be initialised to 0.
std::vector<Gene> m_genes;
// Converts an Individual (sub)tree into its flattened string representation.
std::string _flatten(unsigned idx = 0) const;
// Evaluates an Individual (sub)tree.
double _evaluate(const std::vector<double> &args, unsigned idx = 0) const;
};
#endif // __JM_GENETIC_ALGORITHM_INDIVIDUAL