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

#if !defined(VITA_EVOLUTION_STRATEGY_TCC)
#define      VITA_EVOLUTION_STRATEGY_TCC

///
/// \param[out] env environment
/// \return         a strategy-specific environment
///
/// \remark For standard evolution we only need one layer.
///
template<class T>
environment std_es<T>::shape(environment env)
{
  env.layers = 1;
  return env;
}

///
/// \return `true` when evolution must be stopped
///
/// We use an accelerated stop condition when:
/// - after `max_stuck_time` generations the situation doesn't change;
/// - all the individuals have the same fitness.
///
template<class T>
bool std_es<T>::stop_condition() const
{
  const auto &env(this->pop_.get_problem().env);
  Expects(env.max_stuck_time.has_value());

  if (this->sum_->gen > this->sum_->last_imp + *env.max_stuck_time
      && issmall(this->sum_->az.fit_dist().variance()))
    return true;

  return false;
}

///
/// \param[out] env environemnt
/// \return         a strategy-specific environment
///
/// \remark ALPS requires more than one layer.
///
template<class T, template<class> class CS>
environment basic_alps_es<T, CS>::shape(environment env)
{<commit_msg>[FIX] stop_condition could ignore stuck_time<commit_after>/**
 *  \file
 *  \remark This file is part of VITA.
 *
 *  \copyright Copyright (C) 2013-2017 EOS <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_EVOLUTION_STRATEGY_H)
#  error "Don't include this file directly, include the specific .h instead"
#endif

#if !defined(VITA_EVOLUTION_STRATEGY_TCC)
#define      VITA_EVOLUTION_STRATEGY_TCC

///
/// \param[out] env environment
/// \return         a strategy-specific environment
///
/// \remark For standard evolution we only need one layer.
///
template<class T>
environment std_es<T>::shape(environment env)
{
  env.layers = 1;
  return env;
}

///
/// \return `true` when evolution must be stopped
///
/// We use an accelerated stop condition when:
/// - after `max_stuck_time` generations the situation doesn't change;
/// - all the individuals have the same fitness.
///
template<class T>
bool std_es<T>::stop_condition() const
{
  const auto &env(this->pop_.get_problem().env);
  Expects(env.max_stuck_time.has_value());

  const auto &sum(this->sum_);
  Expects(sum->gen >= sum->last_imp);

  // Pay attention to `env.max_stuck_time`: it can be a large number and cause
  // overflow. E.g. `sum->gen > sum->last_imp + *env.max_stuck_time`

  if (sum->gen - sum->last_imp > *env.max_stuck_time
      && issmall(sum->az.fit_dist().variance()))
    return true;

  return false;
}

///
/// \param[out] env environemnt
/// \return         a strategy-specific environment
///
/// \remark ALPS requires more than one layer.
///
template<class T, template<class> class CS>
environment basic_alps_es<T, CS>::shape(environment env)
{
{'fraction_non_alphanumeric': 0.13875181422351235, 'fraction_numerical': 0.007547169811320755, 'mean_word_length': 3.280745341614907, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 39, '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': '4492457', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1118, 'n_words': 349}