3 * \remark This file is part of VITA.
5 * \copyright Copyright (C) 2015-2017, 2019 EOS di Manlio Morini.
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
10 * You can obtain one at http://mozilla.org/MPL/2.0/
13#if !defined(VITA_INDIVIDUAL_H)
14# error "Don't include this file directly, include the specific .h instead"
17#if !defined(VITA_INDIVIDUAL_TCC)
18#define VITA_INDIVIDUAL_TCC
21/// A measurement of the age of an individual (mainly used for ALPS).
23/// \return The individual's age
25/// This is a measure of how long an individual's family of genotypic
26/// material has been in the population. Randomly generated individuals,
27/// such as those that are created when the search algorithm are started,
28/// start with an age of `0`. Each generation that an individual stays in the
29/// population (such as through elitism) its age is increased by `1`.
30/// **Individuals that are created through mutation or recombination take the
31/// age of their oldest parent**.
34/// This differs from conventional measures of age, in which individuals
35/// created through applying some type of variation to an existing
36/// individual (e.g. mutation or recombination) start with an age of `0`.
37template<class Derived>
38inline unsigned individual<Derived>::age() const
44/// Increments the individual's age.
46template<class Derived>
47inline void individual<Derived>::inc_age()
53/// \param[in] ss active symbol set
54/// \param[in] in input stream
55/// \return `true` if the object has been loaded correctly
57/// \note If the load operation isn't successful the object isn't modified.
59template<class Derived>
60bool individual<Derived>::load(std::istream &in, const symbol_set &ss)
62 decltype(age()) t_age;
66 if (!static_cast<Derived *>(this)->load_impl(in, ss))
71 // We don't save/load signature: it can be easily calculated on the fly.
78/// \param[out] out output stream
79/// \return `true` if the object has been saved correctly
81template<class Derived>
82bool individual<Derived>::save(std::ostream &out) const
86 return static_cast<const Derived *>(this)->save_impl(out);
90/// Updates the age of this individual if it's smaller than `rhs_age`.
92/// \param[in] rhs_age the age of an individual
94template<class Derived>
95void individual<Derived>::set_older_age(unsigned rhs_age)
101#endif // include guard