Mutations#

namespace mutation#

Mutation operators used in the GAs.

class Mutation#

#include <crossover/mutation_base.hpp>
template<typename T>
class Mutation#

The base class used for the mutation operators of the GAs. Mutation operators take a candidate solution, and modify it in some way with a given probability. This probability can be interpreted either per-candidate or per-gene depending on how the particular operator is defined.

New mutation operators should be derived from this class, and they should implement the following virtual method:

  • mutate : Perform the mutation on a single candidate’s chromosome.

Template Parameters:

T – The gene type the mutation operator is defined for.

Subclassed by gapp::mutation::Lambda< T >

Public Types

using GeneType = T#

The gene type the mutation operator is defined for.

Public Functions

inline explicit constexpr Mutation(Probability pm) noexcept#

Create a mutation operator.

Parameters:

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

inline constexpr void mutation_rate(Probability pm) noexcept#

Set the mutation rate used by the operator.

Parameters:

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

inline constexpr Probability mutation_rate() const noexcept#
Returns:

The mutation rate set for the operator.

inline virtual constexpr virtual bool allow_variable_chrom_length () const noexcept

This method specifies whether the mutation operator supports variable chromosome lengths 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.

This method will return false by default. If a particular mutation method allows variable chromosome lengths, it should override this method to return true.

Returns:

True if the mutation operator support variable chromosome lengths.

void operator()(const GA<T> &ga, Candidate<T> &candidate) const#

Perform mutation on a candidate using the set mutation probability. Implemented by mutate().

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

  • candidate – The candidate to mutate.

virtual ~Mutation() = default#

Destructor.

Private Functions

virtual void mutate(
const GA<T> &ga,
const Candidate<T> &candidate,
Chromosome<T> &chromosome,
) const = 0#

The implementation of the mutation operator. Performs the mutation on the given chromosome in-place with the set probability. This function must handle the mutation probability properly as part of its implementation. The mutated chromosome should be valid candidate solution for the given problem and GA.

This method will be called exactly once for each child solution in every population.

The function must be thread-safe if parallel execution is enabled for the GAs (which is true by default).

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

  • candidate – The candidate solution that will be mutated.

  • chromosome – The chromosome to mutate. This is the chromosome of candidate.