Vita
ga/search.tcc
1/**
2 * \file
3 * \remark This file is part of VITA.
4 *
5 * \copyright Copyright (C) 2014-2022 EOS di Manlio Morini.
6 *
7 * \license
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/
11 */
12
13#if !defined(VITA_GA_SEARCH_H)
14# error "Don't include this file directly, include the specific .h instead"
15#endif
16
17#if !defined(VITA_GA_SEARCH_TCC)
18#define VITA_GA_SEARCH_TCC
19
20///
21/// Search class specialization for GAs / DE.
22///
23template<class T, template<class> class ES, class F>
24basic_ga_search<T, ES, F>::basic_ga_search(problem &pr, F f,
25 penalty_func_t<T> pf)
26 : search<T, ES>(pr)
27{
28 if (pf)
29 search<T, ES>::template training_evaluator<
30 constrained_evaluator<T, ga_evaluator<T, F>, penalty_func_t<T>>>(
31 ga_evaluator<T, F>(f), pf);
32 else
33 search<T, ES>::template training_evaluator<ga_evaluator<T, F>>(f);
34}
35
36///
37/// Tries to tune search parameters for the current function.
38///
39/// \see src_search::tune_parameters_nvi comments for further details.
40///
41template<class T, template<class> class ES, class F>
42void basic_ga_search<T, ES, F>::tune_parameters()
43{
44 search<T, ES>::tune_parameters();
45
46 if (this->prob_.env.min_individuals < 10)
47 this->prob_.env.min_individuals = 10;
48
49 Ensures(this->prob_.env.is_valid(true));
50}
51
52#endif // include guard