Integer-encoded genetic algorithm#

namespace gapp

class IntegerGene#

#include <encoding/integer.hpp>
using gapp::IntegerGene = std::int64_t#

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

See also

IntegerGA

class GaTraits<IntegerGene>#

#include <encoding/integer.hpp>
template<>
struct GaTraits<IntegerGene>#

Public Types

using DefaultCrossover = crossover::integer::TwoPoint#
using DefaultMutation = mutation::integer::Uniform#

Public Static Functions

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

class IntegerGA#

#include <encoding/integer.hpp>
class IntegerGA : public gapp::GA<IntegerGene>#

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

Similar to the binary-encoded GA, but the values of a genes can be any integer in a closed interval, not just 0 or 1. The particular interval is specified by the gene bounds.

See also

BinaryGA

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>
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>
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>
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.