Fitness functions#
-
namespace gapp
class FitnessFunction#
#include <core/fitness_function.hpp>
-
template<typename T, size_t ChromLen>
class FitnessFunction : public gapp::FitnessFunctionBase<T># The base class of the fitness functions used in the algorithms. The fitness functions take a candidate solution (chromosome) as a parameter and return a fitness vector after evaluating the chromosome.
This should only be used as the base class for fitness functions if the chromosome length is known at compile time. If the chromosome length is not known at compile, use FitnessFunctionBase as the base class instead.
- Template Parameters:
T – The gene type expected by the fitness function.
ChromLen – The length of the chromosomes expected by the fitness function. Must be at least 1. For variable chromosome length problems, this value will only be used during the generation of the initial population.
Public Functions
-
inline constexpr FitnessFunction(Type type = Type::Static) noexcept#
Create a fitness function.
- Parameters:
type – The type of the fitness function. The value should be either Type::Static or Type::Dynamic, based on whether the fitness function always returns the same fitness vector for a solution (static) or not (dynamic).
class FitnessFunctionBase#
#include <core/fitness_function.hpp>
-
template<typename T>
class FitnessFunctionBase : public gapp::FitnessFunctionInfo# The base class of the fitness functions used in the GAs. The fitness functions take a candidate solution (chromosome) as a parameter and return a fitness vector after evaluating the chromosome.
This should be used as the base class for fitness functions if the chromosome length is not known at compile time. If the chromosome length is known at compile, use FitnessFunction as the base class instead.
- Template Parameters:
T – The gene type expected by the fitness function.
Subclassed by gapp::problems::BenchmarkFunction< IntegerGene >, gapp::problems::BenchmarkFunction< PermutationGene >, gapp::problems::BenchmarkFunction< BinaryGene >, gapp::FitnessFunction< T, ChromLen >, gapp::detail::FitnessLambda< T >, gapp::problems::BenchmarkFunction< T >
Public Types
Public Functions
-
inline FitnessVector operator()(const Chromosome<T> &chrom) const#
Compute the fitness value of a chromosome.
The size of the chromosome must be equal to the chromosome length set for the fitness function, unless variable chromosome lengths are allowed.
- Parameters:
chrom – The chromosome to evaluate.
- Returns:
The fitness vector of the chromosome, with a size equal to the number of objectives.
- inline constexpr FitnessFunctionInfo(
- Positive<size_t> chrom_len,
- Type type = Type::Static,
Create a fitness function.
- Parameters:
chrom_len – The chromosome length that is expected by the fitness function, and will be used for the candidate solutions in the GA. Must be at least 1, and a value must be specified even if the chromosome length is variable, as it will still be used to generate the initial population.
type – The type of the fitness function. The value should be either Type::Static or Type::Dynamic, based on whether the fitness function always returns the same fitness vector for a solution (static) or not (dynamic).
Private Functions
-
virtual FitnessVector invoke(const Chromosome<T> &chrom) const = 0#
The implementation of the fitness function. Should be thread-safe.
class FitnessFunctionInfo#
#include <core/fitness_function.hpp>
-
class FitnessFunctionInfo#
The base class of the fitness functions used in the GAs. Contains all of the properties of a fitness function that are not dependent on the gene type.
Fitness function implementations should not be derived directly from this class, but instead from FitnessFunctionBase or FitnessFunction.
Subclassed by gapp::FitnessFunctionBase< BinaryGene >, gapp::FitnessFunctionBase< IntegerGene >, gapp::FitnessFunctionBase< PermutationGene >, gapp::FitnessFunctionBase< RealGene >, gapp::FitnessFunctionBase< T >
Public Functions
- inline constexpr FitnessFunctionInfo(
- Positive<size_t> chrom_len,
- Type type = Type::Static,
Create a fitness function.
- Parameters:
chrom_len – The chromosome length that is expected by the fitness function, and will be used for the candidate solutions in the GA. Must be at least 1, and a value must be specified even if the chromosome length is variable, as it will still be used to generate the initial population.
type – The type of the fitness function. The value should be either Type::Static or Type::Dynamic, based on whether the fitness function always returns the same fitness vector for a solution (static) or not (dynamic).
-
inline constexpr size_t chrom_len() const noexcept#
- Returns:
The chromosome length the fitness function expects.
-
inline constexpr bool is_dynamic() const noexcept#
- Returns:
True if the fitness function is dynamic.
-
virtual ~FitnessFunctionInfo() = default#
Destructor.