<commit_before>/**
 *  \file
 *  \remark This file is part of VITA.
 *
 *  \copyright Copyright (C) 2011-2015 <NAME>.
 *
 *  \license
 *  This Source Code Form is subject to the terms of the Mozilla Public
 *  License, v. 2.0. If a copy of the MPL was not distributed with this file,
 *  You can obtain one at http://mozilla.org/MPL/2.0/
 */

#if !defined(VITA_SEARCH_H)
#define      VITA_SEARCH_H

#include "kernel/evolution.h"
#include "kernel/lambda_f.h"
#include "kernel/problem.h"

namespace vita
{
///
/// \brief Search drives the evolution
///
/// \tparam T the type of individual used
/// \tparam ES the adopted evolution strategy
///
/// The class is an interface for specific search strategies. The design
/// adheres to the NVI pattern ("Virtuality" in C/C++ Users Journal September
/// 2001 - <http://www.gotw.ca/publications/mill18.htm>).
///
/// \note
/// The "template template parameter" approach allows coordination between `T`
/// and `ES` to be handled by the search class, rather than in all the various
/// code that specializes search.
/// A very interesting description of this technique can be found in
/// "C++ Common Knowledge: Template Template Parameters" by <NAME>
/// (<http://www.informit.com/articles/article.aspx?p=376878>).
///
template<class T, template<class> class ES>
class search
{
public:
  explicit search(problem &);

  std::unique_ptr<lambda_f<T>> lambdify(const T &) const;

  summary<T> run(unsigned = 1);

  bool debug() const;

protected:  // Protected support methods
  void set_evaluator(std::unique_ptr<evaluator<T>>);
  void log(const summary<T> &, const distribution<fitness_t> &,
           const std::vector<unsigned> &, unsigned, unsigned) const;
  virtual void tune_parameters();

protected:  // Protected data members
  std::unique_ptr<evaluator<T>> active_eva_;

  // This is the environment actually used during the search (`prob_->env`
  // is used for compiling `env_` via the `tune_parameters` method).
  environment env_;

  // Problem we're working on.
  problem &prob_;

  std::function<void (unsigned)> shake_;
  std::function<bool (const summary<T> &)> stop_;

private:
  // Template methods for search::run() member function.
  virtual void preliminary_setup() {}
  virtual void after_evolution(summary<T> *) {}
  virtual void print_resume(const model_measurements &) const;

  // NVI template methods
  virtual bool debug_nvi() const { return true; }
  virtual void log_nvi(tinyxml2::XMLDocument *, const summary<T> &) const {}
};

#include "kernel/search.tcc"
}  // namespace vita

#endif  // Include guard
<commit_msg>[REF] search::set_evaluator is now public<commit_after>/**
 *  \file
 *  \remark This file is part of VITA.
 *
 *  \copyright Copyright (C) 2011-2015 EOS di <NAME>.
 *
 *  \license
 *  This Source Code Form is subject to the terms of the Mozilla Public
 *  License, v. 2.0. If a copy of the MPL was not distributed with this file,
 *  You can obtain one at http://mozilla.org/MPL/2.0/
 */

#if !defined(VITA_SEARCH_H)
#define      VITA_SEARCH_H

#include "kernel/evolution.h"
#include "kernel/lambda_f.h"
#include "kernel/problem.h"

namespace vita
{
///
/// \brief Search drives the evolution
///
/// \tparam T the type of individual used
/// \tparam ES the adopted evolution strategy
///
/// The class is an interface for specific search strategies. The design
/// adheres to the NVI pattern ("Virtuality" in C/C++ Users Journal September
/// 2001 - <http://www.gotw.ca/publications/mill18.htm>).
///
/// \note
/// The "template template parameter" approach allows coordination between `T`
/// and `ES` to be handled by the search class, rather than in all the various
/// code that specializes search.
/// A very interesting description of this technique can be found in
/// "C++ Common Knowledge: Template Template Parameters" by <NAME>
/// (<http://www.informit.com/articles/article.aspx?p=376878>).
///
template<class T, template<class> class ES>
class search
{
public:
  explicit search(problem &);

  std::unique_ptr<lambda_f<T>> lambdify(const T &) const;

  summary<T> run(unsigned = 1);

  void set_evaluator(std::unique_ptr<evaluator<T>>);

  bool debug() const;

protected:  // Protected support methods
  void log(const summary<T> &, const distribution<fitness_t> &,
           const std::vector<unsigned> &, unsigned, unsigned) const;
  virtual void tune_parameters();

protected:  // Protected data members
  std::unique_ptr<evaluator<T>> active_eva_;

  // This is the environment actually used during the search (`prob_->env`
  // is used for compiling `env_` via the `tune_parameters` method).
  environment env_;

  // Problem we're working on.
  problem &prob_;

  std::function<void (unsigned)> shake_;
  std::function<bool (const summary<T> &)> stop_;

private:
  // Template methods for search::run() member function.
  virtual void preliminary_setup() {}
  virtual void after_evolution(summary<T> *) {}
  virtual void print_resume(const model_measurements &) const;

  // NVI template methods
  virtual bool debug_nvi() const { return true; }
  virtual void log_nvi(tinyxml2::XMLDocument *, const summary<T> &) const {}
};

#include "kernel/search.tcc"
}  // namespace vita

#endif  // Include guard

{'fraction_non_alphanumeric': 0.12965093977752207, 'fraction_numerical': 0.009973149213655544, 'mean_word_length': 3.689748201438849, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4697246', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1569, 'n_words': 548}