Stop conditions#

namespace stopping#

Early-stop conditions that can be used to control when the GA stops.

class StopCondition#

#include <stopping/stop_condition_base.hpp>
class StopCondition#

The base class used for all of the early-stop conditions. The stop condition will be evaluated once at the end of every generation, and it should return true when the GA should stop running.

New stop conditions should be derived from this class, and there are 2 virtual methods that should be implemented by them:

  • initialize (optional) : Initialize the stop condition at the start of a run. Does nothing by default.

  • stop_condition : Evaluate the stop condition and return true when the GA should stop running.

Subclassed by gapp::stopping::FitnessBestStall, gapp::stopping::FitnessEvals, gapp::stopping::FitnessMeanStall, gapp::stopping::FitnessValue, gapp::stopping::Lambda, gapp::stopping::NoEarlyStop, gapp::stopping::dtl::AND< Left, Right >, gapp::stopping::dtl::NOT< Base >, gapp::stopping::dtl::OR< Left, Right >

Public Functions

inline virtual void initialize(const GaInfo&)#

Initialize the stop condition. This method will be called exactly once at the start of each run. The default implementation does nothing.

Parameters:

ga – The genetic algorithm the stop condition is used in.

bool operator()(const GaInfo &ga)#

Evaluate the stop condition and return true if the GA should be stopped. This method will be called exactly once at the end of each generation of a run.

Implemented by stop_condition().

Parameters:

ga – The genetic algorithm the stop condition is used in.

Returns:

True when the genetic algorithm should stop running.

virtual ~StopCondition() = default#

Destructor.

Private Functions

virtual bool stop_condition(const GaInfo &ga) = 0#

The implementation of the early-stop condition. This method will be called exactly once at the end of each generation of a run, and it should return true when the GA should be stopped.

Parameters:

ga – The genetic algorithm the stop condition is used in.

Returns:

True when genetic algorithm should stop running.

class FitnessEvals#

#include <stopping/stop_condition.hpp>
class FitnessEvals : public gapp::stopping::StopCondition#

Early stop condition based on the number of fitness function evaluations performed.

The GA will stop early if a set maximum number of objective function evaluations have been performed.

Note

The stop condition is only checked once at the end of each generation, so the actual number objective function evaluations might be higher than the limit that was set for this stop condition.

Public Functions

inline explicit constexpr FitnessEvals(size_t max_fitness_evals) noexcept#

Create an early-stop condition based on the number of objective function evaluations performed.

Parameters:

max_fitness_evals – The maximum number of fitness function evaluations that should be performed.

inline constexpr void max_fitness_evals(size_t max_fitness_evals) noexcept#

Set the maximum number of fitness function evaluations allowed in the GA. The actual number of evaluations might be somewhat higher, as the stop condition is only checked once at the end of each generation.

Parameters:

max_fitness_evals – The maximum number of objective function evaluations that should be performed.

inline constexpr size_t max_fitness_evals() const noexcept#
Returns:

The maximum number of fitness function evaluations allowed.

class FitnessValue#

#include <stopping/stop_condition.hpp>
class FitnessValue : public gapp::stopping::StopCondition#

Early stop condition based on the fitness of the best solution discovered so far.

The GA will stop early if a solution is found that is equal to or better than a fitness threshold vector (assuming maximization).

Public Functions

inline explicit FitnessValue(FitnessVector fitness_threshold) noexcept#

Create an early-stop condition that is based on reaching a fitness threshold. Assumes fitness maximization.

Parameters:

fitness_threshold – The fitness threshold vector used. The size of this vector should be the same as the size of the fitness vectors of the population (ie. the number of objectives should match).

inline void fitness_threshold(FitnessVector threshold) noexcept#

Set the fitness threshold vector.

Parameters:

fitness_threshold – The fitness threshold vector used. The size of this vector should be the same as the size of the fitness vectors of the population (ie. the number of objectives should match).

inline const FitnessVector &fitness_threshold() const & noexcept#
Returns:

The fitness threshold vector used.

class FitnessMeanStall#

#include <stopping/stop_condition.hpp>
class FitnessMeanStall : public gapp::stopping::StopCondition#

Early stop condition based on the mean fitness vector of the population.

The mean fitness values of the population are calculated separately for each objective, and the GA is stopped if the value hasn’t improved in any of the objectives for a certain number of generations.

For multi-objective problems, the mean fitness vector is considered improved if it’s better in at least one objective than the old one (assuming fitness maximization).

Public Functions

inline FitnessMeanStall() noexcept#

Create an early-stop condition based on the mean fitness values of the population.

inline explicit FitnessMeanStall(size_t patience, double delta = 1E-6) noexcept#

Create an early-stop condition based on the mean fitness values of the population.

Parameters:
  • patience – The number of generations to wait without stopping even if there is no improvement.

  • delta – The minimum fitness difference considered an improvement. Negative values may also be used.

inline constexpr void patience(size_t patience) noexcept#

Set the patience value used for the stop condition.

Note

The patiance counter is reset every time there is an improvement in the mean fitness vector.

Parameters:

patience – The number of generations to wait without stopping if there is no improvement.

inline constexpr size_t patience() const noexcept#
Returns:

The current patience value of the stop condition.

inline constexpr void delta(double delta) noexcept#

Set the delta parameter of the stop condition. The same delta value is used for every objective in the case of multi-objective problems.

Parameters:

delta – The minimum fitness difference considered an improvement. Negative values may also be used.

inline constexpr double delta() const noexcept#
Returns:

The value of the delta parameter.

virtual void initialize(const GaInfo &ga) override#

Initialize the stop condition. This method will be called exactly once at the start of each run. The default implementation does nothing.

Parameters:

ga – The genetic algorithm the stop condition is used in.

class FitnessBestStall#

#include <stopping/stop_condition.hpp>
class FitnessBestStall : public gapp::stopping::StopCondition#

Early stop condition based on the best fitness vector of the population.

The best fitness values of the population are calculated separately for each objective, and the GA is stopped if the best fitness value hasn’t improved in any of the objectives for a certain number of generations.

For multi-objective problems, the best fitness vector is considered improved if it’s better in at least one coordinate than the previous best (assuming fitness maximization).

Public Functions

inline FitnessBestStall() noexcept#

Create an early-stop condition based on the best fitness values of the population.

inline explicit FitnessBestStall(size_t patience, double delta = 1E-6) noexcept#

Create an early-stop condition based on the best fitness values of the population.

Parameters:
  • patience – The number of generations to wait before stopping even if there is no improvement.

  • delta – The minimum fitness difference considered an improvement. Negative values may also be used.

inline constexpr void patience(size_t patience) noexcept#

Set the patience value used for the stop condition.

Note

The patiance counter is reset every time there is an improvement in the mean fitness vector.

Parameters:

patience – The number of generations to wait before stopping if there is no improvement.

inline constexpr size_t patience() const noexcept#
Returns:

The current patience value of the stop condition.

inline constexpr void delta(double delta) noexcept#

Set the delta parameter of the stop condition. The same delta is used for every objective in the case of multi-objective problems.

Parameters:

delta – The minimum fitness difference considered an improvement. Negative values may also be used.

inline constexpr double delta() const noexcept#
Returns:

The value of the delta parameter.

virtual void initialize(const GaInfo &ga) override#

Initialize the stop condition. This method will be called exactly once at the start of each run. The default implementation does nothing.

Parameters:

ga – The genetic algorithm the stop condition is used in.

class NoEarlyStop#

#include <stopping/stop_condition.hpp>
class NoEarlyStop : public gapp::stopping::StopCondition#

This early-stop condition will always evaluate to false, so no early stopping will be used by the GA. This can be used to ensure that the GA will only stop upon reaching the maximum number of generations set for it.