Permutation-encoded genetic algorithm#

namespace gapp

class PermutationGene#

#include <encoding/permutation.hpp>
using gapp::PermutationGene = std::size_t#

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

See also

PermutationGA

class GaTraits<PermutationGene>#

#include <encoding/permutation.hpp>
template<>
struct GaTraits<PermutationGene>#

Public Types

using DefaultCrossover = crossover::perm::Order2#
using DefaultMutation = mutation::perm::Inversion#

Public Static Functions

static inline constexpr Probability defaultMutationRate(size_t) noexcept#

class PermutationGA#

#include <encoding/permutation.hpp>
class PermutationGA : public gapp::GA<PermutationGene>#

Permutation-encoded genetic algorithm class. This is the main solver that should be used for combinatorial problems.

The chromosome of a candidate solution encodes a permutation. Every gene of a chromosome is a unique unsigned integer in the closed interval of [0, chrom_len - 1],

Without any loss of generality, the first and last elements of the permutations are assumed to be unrelated, eg. the permutation A-B-C-D will not be considered equal to the permutation B-C-D-A by the GA. The fitness function should also be written with this in mind.

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.