33 std::generate(genome_.begin(), genome_.end(),
36 return static_cast<value_type>(
37 p.sset.roulette_terminal(n++).init());
55 for (
const auto &g : genome_)
56 s <<
"g [label=" << g <<
", shape=circle];";
72 std::copy(ga.
begin(), ga.
end(), infix_iterator<i_ga::value_type>(s,
" "));
85unsigned i_ga::mutation(
double pgm,
const problem &prb)
94 if (random::boolean(pgm))
131 const auto cut1(random::sup(ps - 1));
132 const auto cut2(random::between(cut1 + 1, ps));
135 for (
auto i(cut1); i < cut2; ++i)
136 ret.genome_[i] = lhs[i];
138 ret.set_older_age(lhs.age());
139 ret.signature_ = ret.hash();
156 if (signature_.
empty())
173 const auto len(genome_.size() *
sizeof(genome_[0]));
186 const bool eq(genome_ == x.genome_);
188 assert(signature_.
empty() != x.signature_.
empty() ||
189 (signature_ == x.signature_) == eq);
204 for (
auto i(
decltype(cs){0}); i < cs; ++i)
205 if (genome_[i] != ind.genome_[i])
218 if (!genome_.empty())
220 vitaERROR <<
"Inconsistent internal status for empty individual";
224 if (!signature_.
empty())
226 vitaERROR <<
"Empty individual must empty signature";
233 if (!signature_.
empty() && signature_ !=
hash())
235 vitaERROR <<
"Wrong signature: " << signature_ <<
" should be " <<
hash();
250bool i_ga::load_impl(std::istream &in,
const symbol_set &)
256 decltype(genome_) v(sz);
270bool i_ga::save_impl(std::ostream &
out)
const
273 for (
const auto &g : genome_)
288 return in_line(ind, s);
297i_ga::operator std::vector<i_ga::value_type>()
const
An GA-individual optimized for combinatorial optimization.
std::size_t parameters() const
hash_t signature() const
The signature (hash value) of this individual.
void graphviz(std::ostream &) const
Produces a dot-language representation of this individual.
const_iterator begin() const
std::ostream & in_line(const i_ga &ga, std::ostream &s)
Prints the genes of the individual.
const_iterator end() const
std::ostream & operator<<(std::ostream &s, const i_ga &ind)
bool operator==(const i_ga &) const
unsigned distance(const i_ga &) const
i_ga crossover(const i_ga &lhs, const i_ga &rhs)
Two points crossover.
A single member of a population.
MurmurHash3 (https://github.com/aappleby/smhasher) by Austin Appleby.
static hash_t hash128(const void *const, std::size_t, std::uint32_t=1973)
Hashes a single message in one call, return 128-bit output.
Aggregates the problem-related data needed by an evolutionary program.
A container for the symbols used by the GP engine.
const terminal & roulette_terminal(category_t) const
virtual terminal_param_t init() const
Used to initialize the internal parameter of the terminal.
Contains flags and manipulators to control the output format of individuals.
The main namespace for the project.
std::size_t category_t
A category provide operations which supplement or supersede those of the domain but which are restric...
A 128bit unsigned integer used as individual's signature / hash table look-up key.
bool empty() const
We assume that a string of 128 zero bits means empty.