3 * \remark This file is part of VITA.
5 * \copyright Copyright (C) 2014-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_CONSTRAINED_EVALUATOR_H)
14# error "Don't include this file directly, include the specific .h instead"
17#if !defined(VITA_CONSTRAINED_EVALUATOR_TCC)
18#define VITA_CONSTRAINED_EVALUATOR_TCC
21/// \param[in] e the base evaluator
22/// \param[in] p the penalty function (as described in "An Efficient Constraint
23/// Handling Method for Genetic Algorithms" - Kalyanmoy Deb)
25template<class T, class E, class P>
26constrained_evaluator<T, E, P>::constrained_evaluator(E e, P p)
27 : eva_(std::move(e)), penalty_(std::move(p))
32/// \param[in] prg the program (individual/team) whose fitness we want to know
33/// \return the fitness of `ind`
35template<class T, class E, class P>
36fitness_t constrained_evaluator<T, E, P>::operator()(const T &prg)
38 return combine(fitness_t{static_cast<fitness_t::value_type>(-penalty_(prg))},
43/// \param[in] prg a program (individual/team)
44/// \return the an approximation of the fitness of `prg`
46template<class T, class E, class P>
47fitness_t constrained_evaluator<T, E, P>::fast(const T &prg)
49 return combine(fitness_t{static_cast<fitness_t::value_type>(-penalty_(prg))},
54/// \param[in] prg a program (individual/team)
55/// \return a pointer to the executable version of `prg`
57template<class T, class E, class P>
58std::unique_ptr<basic_lambda_f> constrained_evaluator<T, E, P>::lambdify(
61 return eva_.lambdify(prg);
64#endif // include guard