Binary-encoded genetic algorithm#

namespace gapp#

class BinaryGene#

#include <encoding/binary.hpp>
using gapp::BinaryGene = std::uint8_t#

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

See also

BinaryGA

class GaTraits<BinaryGene>#

#include <encoding/binary.hpp>
template<>
struct GaTraits<BinaryGene>#

Public Types

using DefaultCrossover = crossover::binary::TwoPoint#
using DefaultMutation = mutation::binary::Flip#

Public Static Functions

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

class BinaryGA#

#include <encoding/binary.hpp>
class BinaryGA : public gapp::GA<BinaryGene>#

Binary-encoded genetic algorithm class. This is the main solver that should be used for binary-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.