Mixed mutations#

namespace mutation

Mutation operators used in the GAs.

class Mixed#

#include <mutation/mixed.hpp>
template<typename ...Ts>
class Mixed : public gapp::mutation::Mutation<MixedGene<Ts::GeneType...>>#

The mixed mutation template that is used as the mutation operator in the MixedGene GAs.

The mixed mutation consists of a separate component mutation for each of the gene types in the mixed gene. These component mutations are applied separately to the appropriate chromosomes of the mixed gene candidates when performing the mutations.

The component mutations are independent of each other, and each of them must be a valid mutation operator that could be used for the given gene type.

Template Parameters:

Ts – The types of the component mutations. Must consist of mutations for unique gene types. None of the mutation types should be a mutation for some MixedGene<> type.

Public Functions

explicit constexpr Mixed() = default#

Create a mixed mutation operator by default constructing all of the component mutations.

explicit constexpr Mixed(Ts... mutations)#

Create a mixed mutation operator from the specified component mutations. The order of the component mutations must match the order of the gene types in the mixed gene type that the mixed mutation operator is going to be used for.

Parameters:

mutations – The component mutations that will comprise the mixed mutation.

constexpr void mutation_rates(Probability pm) noexcept override#

Set the mutation probability used for each of the component mutations to the same value.

Parameters:

pm – The mutation probability. Must be in the closed interval [0.0, 1.0].

constexpr void mutation_rates(
const std::array<Probability, N> &pms
) noexcept override#

Set the mutation probability used for each of the component mutations individually. The order of the probabilities should match the order of the component mutations.

Parameters:

pms – The mutation probabilities. They must all be in the closed interval [0.0, 1.0].

constexpr std::array<Probability, N> mutation_rates() const noexcept override#
Returns:

The mutation rates set for the component mutations. The order of the probabilities in the returned array will match the order of the component mutations.

Public Static Attributes

static constexpr size_t N = Base::N#

The number of component mutations the mixed mutation is composed of.

class Mutation<MixedGene>#

#include <mutation/mutation_base.hpp>
template<typename ...Ts>
class Mutation<MixedGene<Ts...>>#

The base class used for the mixed mutation operators. This is effectively the same as the primary template without the mutation probability.

Template Parameters:

Ts – The component gene types of the mixed gene type the mutation operator is defined for.

Public Types

using GeneType = MixedGene<Ts...>#

The mixed gene type the mutation operator is defined for.

Public Functions

template<typename GeneType>
constexpr void mutation_rate(
Probability pm
) noexcept#

Set the mutation probability of the component mutation associated with the specified GeneType.

Template Parameters:

GeneType – The gene type of the component mutation to set the probability of.

Parameters:

pm – The mutation probability. Must be in the closed interval [0.0, 1.0].

virtual constexpr void mutation_rates(Probability pm) noexcept = 0#

Set the mutation probability used for each of the component mutations to the same value.

Parameters:

pm – The mutation probability. Must be in the closed interval [0.0, 1.0].

virtual constexpr void mutation_rates(
const std::array<Probability, N> &pms
) noexcept = 0#

Set the mutation probability used for each of the component mutations individually. The order of the probabilities should match the order of the component mutations.

Parameters:

pms – The mutation probabilities. They must all be in the closed interval [0.0, 1.0].

template<typename GeneType>
constexpr Probability mutation_rate(
) const noexcept#
Template Parameters:

GeneType – The gene type of the component mutation to get the probability of.

Returns:

The mutation probability of the component mutation associated with the specified GeneType.

virtual constexpr std::array<Probability, N> mutation_rates(
) const noexcept = 0#
Returns:

The mutation rates set for the component mutations. The order of the probabilities in the returned array will match the order of the component mutations.

template<typename GeneType>
constexpr bool allow_variable_chrom_length(
) const noexcept#

This method specifies whether the mutation operator supports variable chromosome lengths for the specified gene type or not. If variable chromosome lengths are supported, the Candidates passed to the mutation operator are allowed to have chromosome lengths that are different from the chromosome length specified for the GA that the operator is used in. Otherwise the chromosome length of the given gene type must be the same for every Candidate.

Template Parameters:

The – gene type of the chromosome to check.

Returns:

True if the mutation operator support variable chromosome lengths for the specified gene type.

template<typename GeneType>
Mutation<GeneType> &component() & noexcept#
Template Parameters:

GeneType – The gene type of the component mutation to get.

Returns:

The component mutation associated with the specified gene type.

template<typename GeneType>
const Mutation<GeneType> &component(
) const & noexcept#
Template Parameters:

GeneType – The gene type of the component mutation to get.

Returns:

The component mutation associated with the specified gene type.

void operator()(const GaInfo &ga, Candidate<GeneType> &candidate) const#

Perform the mutation on a candidate solution. Implemented by mutate().

Parameters:
  • ga – The genetic algorithm the mutation operator is being used in.

  • candidate – The candidate to mutate.

virtual ~Mutation() = default#

Destructor.

Public Static Attributes

static constexpr size_t N = sizeof...(Ts)#

The number of component mutations the mixed mutation is composed of.