Vita
population.h
Go to the documentation of this file.
1
13#if !defined(VITA_POPULATION_H)
14#define VITA_POPULATION_H
15
16#include <fstream>
17
18#include "kernel/environment.h"
19#include "kernel/log.h"
20#include "kernel/problem.h"
21#include "kernel/random.h"
22
23namespace vita
24{
35template<class T>
37{
38public:
39 explicit population(const problem &);
40
41 struct coord;
42 using layer_t = std::vector<T>;
43 T &operator[](coord);
44 const T &operator[](coord) const;
45
46 unsigned individuals() const;
47 unsigned individuals(unsigned) const;
48 unsigned allowed(unsigned) const;
49
50 void init_layer(unsigned);
51 void add_layer();
52 unsigned layers() const;
53 void add_to_layer(unsigned, const T &);
54 void pop_from_layer(unsigned);
55 void remove_layer(unsigned);
56 void set_allowed(unsigned, unsigned);
57
58 void inc_age();
59
60 const problem &get_problem() const;
61
62 bool is_valid() const;
63
64 // Iterators.
65 template<bool> class base_iterator;
68
69 const_iterator begin() const;
70 const_iterator end() const;
71
72 // Serialization.
73 bool load(std::istream &, const problem &);
74 bool save(std::ostream &) const;
75
76private:
77
78 const problem *prob_;
79
80 std::vector<layer_t> pop_;
81 std::vector<unsigned> allowed_;
82};
83
84template<class T> typename population<T>::coord pickup(const population<T> &);
85template<class T> typename population<T>::coord pickup(
86 const population<T> &, typename population<T>::coord);
87
88#include "kernel/population_coord.tcc"
89#include "kernel/population_iterator.tcc"
90#include "kernel/population.tcc"
91
92} // namespace vita
93
94#endif // include guard
A group of individuals which may interact together (for example by mating) producing offspring.
Definition: population.h:37
Aggregates the problem-related data needed by an evolutionary program.
Definition: problem.h:24
The main namespace for the project.