<commit_before>/**
 *  \file
 *  \remark This file is part of VITA.
 *
 *  \copyright Copyright (C) 2011-2021 <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_EVALUATOR_PROXY_H)
#  error "Don't include this file directly, include the specific .h instead"
#endif

#if !defined(VITA_EVALUATOR_PROXY_TCC)
#define      VITA_EVALUATOR_PROXY_TCC

///
/// \param[in] eva pointer that lets the proxy access the real evaluator
/// \param[in] ts  `2^ts` is the number of elements of the cache
///
template<class T, class E>
evaluator_proxy<T, E>::evaluator_proxy(E eva, unsigned ts)
  : eva_(std::move(eva)), cache_(ts)
{
  Expects(ts > 6);
}

///
/// \param[in] prg the program (individual/team) whose fitness we want to know
/// \return        the fitness of `prg`
///
template<class T, class E>
fitness_t evaluator_proxy<T, E>::operator()(const T &prg)
{
  fitness_t f(cache_.find(prg.signature()));

  if (f.size())
  {
    assert(cache_.hits());

    // Hash collision checking code can slow down the program very much.
#if !defined(NDEBUG)
    const fitness_t f1(eva_(prg));
    if (!almost_equal(f[0], f1[0]))
      std::cerr << "********* COLLISION ********* [" << f << " != " << f1
                << "]\n";

    // In the above comparison we consider only the first component of the
    // fitness otherwise we can have false positives.
    // For example if the fitness is a 2D vector (where the first component
    // is the "score" on the training set and the second one is the effective
    // length of the program), then the following two programs:
    //
    // PROGRAM A                 PROGRAM B
    // ------------------        ------------------
    // [000] FADD 001 002        [000] FADD 001 001
    // [001] X1                  [001] X1
    // [002] X1
    //
    // have the same signature, the same stored "score" but distinct
    // effective size and so distinct fitnesses.
#endif
  }
  else  // not found in cache
  {
    f = eva_(prg);

    cache_.insert(prg.signature(), f);

#if !defined(NDEBUG)<commit_msg>[FIX] Compilation error in debug mode<commit_after>/**
 *  \file
 *  \remark This file is part of VITA.
 *
 *  \copyright Copyright (C) 2011-2021 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_EVALUATOR_PROXY_H)
#  error "Don't include this file directly, include the specific .h instead"
#endif

#if !defined(VITA_EVALUATOR_PROXY_TCC)
#define      VITA_EVALUATOR_PROXY_TCC

///
/// \param[in] eva pointer that lets the proxy access the real evaluator
/// \param[in] ts  `2^ts` is the number of elements of the cache
///
template<class T, class E>
evaluator_proxy<T, E>::evaluator_proxy(E eva, unsigned ts)
  : eva_(std::move(eva)), cache_(ts)
{
  Expects(ts > 6);
}

///
/// \param[in] prg the program (individual/team) whose fitness we want to know
/// \return        the fitness of `prg`
///
template<class T, class E>
fitness_t evaluator_proxy<T, E>::operator()(const T &prg)
{
  fitness_t f(cache_.find(prg.signature()));

  if (f.size())
  {
    // Hash collision checking code can slow down the program very much.
#if !defined(NDEBUG)
    const fitness_t f1(eva_(prg));
    if (!almost_equal(f[0], f1[0]))
      std::cerr << "********* COLLISION ********* [" << f << " != " << f1
                << "]\n";

    // In the above comparison we consider only the first component of the
    // fitness otherwise we can have false positives.
    // For example if the fitness is a 2D vector (where the first component
    // is the "score" on the training set and the second one is the effective
    // length of the program), then the following two programs:
    //
    // PROGRAM A                 PROGRAM B
    // ------------------        ------------------
    // [000] FADD 001 002        [000] FADD 001 001
    // [001] X1                  [001] X1
    // [002] X1
    //
    // have the same signature, the same stored "score" but distinct
    // effective size and so distinct fitnesses.
#endif
  }
  else  // not found in cache
  {
    f = eva_(prg);

    cache_.insert(prg.signature(), f);

#if !defined(NDEBUG)
{'fraction_non_alphanumeric': 0.14736842105263157, 'fraction_numerical': 0.022396416573348264, 'mean_word_length': 2.4539829853054913, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3603819', 'n_tokens_mistral': 1536, 'n_tokens_neox': 1449, 'n_words': 519}