Real-encoded genetic algorithm#

namespace gapp

class RealGene#

#include <encoding/real.hpp>
using gapp::RealGene = double#

The gene type used in the real-encoded genetic algorithm.

See also

RCGA

class GaTraits<RealGene>#

#include <encoding/real.hpp>
template<>
struct GaTraits<RealGene>#

Public Types

using DefaultCrossover = crossover::real::Wright#
using DefaultMutation = mutation::real::Gauss#

Public Static Functions

static inline constexpr Probability defaultMutationRate(
size_t chrom_len,
) noexcept#

class RCGA#

#include <encoding/real.hpp>
class RCGA : public gapp::GA<RealGene>#

Real-encoded genetic algorithm class. This is the main solver that should be used for real-encoded objective functions.

Public Functions

GA(Positive<size_t> population_size = DEFAULT_POPSIZE)#

Create a genetic algorithm using the default genetic operators.

The algorithm used will be deduced from the number of objectives of the fitness function (single- or multi-objective), along with the mutation probability used, which will be deduced from the chromosome length.

Parameters:

population_size – The number of candidates in the population. Must be at least 1.

GA(
Positive<size_t> population_size,
std::unique_ptr<algorithm::Algorithm> algorithm,
)#

Create a genetic algorithm using the default genetic operators. The mutation probability used will be deduced from the chromosome length.

Parameters:
  • population_size – The number of candidates in the population. Must be at least 1.

  • algorithm – The algorithm to use. The default algorithm will be used if it’s a nullptr.

GA(
Positive<size_t> population_size,
std::unique_ptr<crossover::Crossover<T>> crossover,
std::unique_ptr<mutation::Mutation<T>> mutation,
std::unique_ptr<stopping::StopCondition> stop_condition = std::make_unique<stopping::NoEarlyStop>(),
)#

Create a genetic algorithm using the specified operators. The algorithm used will be deduced from the number of objectives of the fitness function (single- or multi-objective).

Parameters:
  • population_size – The number of candidates in the population. Must be at least 1.

  • crossover – The crossover operator to use. Can’t be a nullptr.

  • mutation – The mutation operator to use. Can’t be a nullptr.

  • stop_condition – The early-stop condition to use. No early-stopping will be used if it’s a nullptr.

GA(
Positive<size_t> population_size,
std::unique_ptr<algorithm::Algorithm> algorithm,
std::unique_ptr<crossover::Crossover<T>> crossover,
std::unique_ptr<mutation::Mutation<T>> mutation,
std::unique_ptr<stopping::StopCondition> stop_condition = std::make_unique<stopping::NoEarlyStop>(),
)#

Create a genetic algorithm using the specified algorithm and operators.

Parameters:
  • population_size – The number of candidates in the population. Must be at least 1.

  • algorithm – The algorithm to use. The default algorithm will be used if it’s a nullptr.

  • crossover – The crossover operator to use. Can’t be a nullptr.

  • mutation – The mutation operator to use. Can’t be a nullptr.

  • stop_condition – The early-stop condition to use. No early-stopping will be used if it’s a nullptr.

template<typename AlgorithmType>
requires std::derived_from<AlgorithmType, algorithm::Algorithm>
GA(
Positive<size_t> population_size,
AlgorithmType algorithm,
)#

Create a genetic algorithm using the default genetic operators. The mutation probability will be deduced from the chromosome length.

Parameters:
  • population_size – The number of candidates in the population. Must be at least 1.

  • algorithm – The algorithm to use.

template<typename CrossoverType, typename MutationType, typename StoppingType = stopping::NoEarlyStop>
requires std::derived_from<CrossoverType, crossover::Crossover<T>> && std::derived_from<MutationType, mutation::Mutation<T>> && std::derived_from<StoppingType, stopping::StopCondition>
GA(
Positive<size_t> population_size,
CrossoverType crossover,
MutationType mutation,
StoppingType stop_condition = {},
)#

Create a genetic algorithm using the specified operators. The algorithm used will be deduced from the number of objectives of the fitness function (single- or multi-objective).

Parameters:
  • population_size – The number of candidates in the population. Must be at least 1.

  • crossover – The crossover operator to use.

  • mutation – The mutation operator to use.

  • stop_condition – The early-stop condition to use.

template<typename AlgorithmType, typename CrossoverType, typename MutationType, typename StoppingType = stopping::NoEarlyStop>
requires std::derived_from<AlgorithmType, algorithm::Algorithm> && std::derived_from<CrossoverType, crossover::Crossover<T>> && std::derived_from<MutationType, mutation::Mutation<T>> && std::derived_from<StoppingType, stopping::StopCondition>
GA(
Positive<size_t> population_size,
AlgorithmType algorithm,
CrossoverType crossover,
MutationType mutation,
StoppingType stop_condition = {},
)#

Create a genetic algorithm using the specified algorithm and operators.

Parameters:
  • population_size – The number of candidates in the population. Must be at least 1.

  • algorithm – The algorithm to use.

  • crossover – The crossover operator to use.

  • mutation – The mutation operator to use.

  • stop_condition – The early-stop condition to use.