Grail (C++)  1.4.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
grail::evolution::Mutation Struct Reference

The Mutation structure that encapsulates the mutation operation and its configuration in evolutionary algorithm. More...

#include <Mutation.hh>

Public Types

enum  MutationSelectionType { MutationSelectionType::ITERATE_AND_TEST_P, MutationSelectionType::SELECT_P_OF_N }
 Predefined ways in which individuals are selected from the population for mutation. Please refer to enum values for details about each of them. More...
 

Public Member Functions

 Mutation (double mutationPhaseRate=1.0, double mutateIndividualRate=0.09, double mutateGeneRate=0.5, bool mutateBothParentsAndChildren=true, MutationSelectionType randomResolutionTypeForIndividual=MutationSelectionType::SELECT_P_OF_N, MutationSelectionType randomResolutionTypeForGene=MutationSelectionType::SELECT_P_OF_N, std::mt19937_64::result_type seed=std::random_device{}())
 Mutation - Constructor. More...
 
virtual void Perform (const std::vector< std::unique_ptr< Individual >> &parentPopulation, const std::vector< std::unique_ptr< Individual >> &childrenPopulation)
 Perform - Attempts to mutate the entire population. The umber of individuals mutates is based on mutation phase rate and mutate individual rate. More...
 

Public Attributes

double MutationPhaseRate = 1.0
 Probability of a mutation phase to happen (globally). If a mutation is included in the algorithm, this value should most likely be equal to 1.0.
 
double MutateIndividualRate = 0.09
 Probability that an individual will be considered for mutation [if (randomResolutionTypeForIndividual == ITERATE_AND_TEST_P)]; or the portion of individuals chosen for mutation [if (randomResolutionTypeForIndividual == SELECT_P_OF_N)].
 
double MutateGeneRate = 0.5
 Probability that a gene of an individual will be considered for mutation [if (randomResolutionTypeForGene == ITERATE_AND_TEST_P)]; or the portion of genes within an individual chosen for mutation [if (randomResolutionTypeForGene == SELECT_P_OF_N)].
 
bool MutateBothParentsAndChildren = false
 If true: both the previous population and children can be mutated; if false: only the individuals after crossover can be mutated.
 
MutationSelectionType RandomResolutionTypeForIndividual = MutationSelectionType::SELECT_P_OF_N
 Specifies how individuals for mutations are chosen. See MutationSelectionType enum.
 
MutationSelectionType RandomResolutionTypeForGene = MutationSelectionType::SELECT_P_OF_N
 Specifies how genes in an individual (already chosen for mutation) are chosen for mutation. See MutationSelectionType enum.
 

Protected Member Functions

virtual void MutateIndividual (Individual &individual)
 The function that performs the mutation operation of one individual. More...
 
virtual void MutateGene (Individual &individual, BaseEvoParam &gene)
 The function that performs the mutation operation of a single parameter within the mutated individual. More...
 

Protected Attributes

std::mt19937_64 randGen
 

Friends

class EAOptimizer
 

Detailed Description

The Mutation structure that encapsulates the mutation operation and its configuration in evolutionary algorithm.

Member Enumeration Documentation

◆ MutationSelectionType

Predefined ways in which individuals are selected from the population for mutation. Please refer to enum values for details about each of them.

Enumerator
ITERATE_AND_TEST_P 

ITERATE_AND_TEST_P - a random test whether to mutate an individual will be performed for each individual in a loop.

SELECT_P_OF_N 

SELECT_P_OF_N - upfront, the PopulationSize*MutationIndividualRate of individuals will be randomly chosen for mutation. This ensures that the expected number of individuals will be mutated, regardless of RNG.

Constructor & Destructor Documentation

◆ Mutation()

grail::evolution::Mutation::Mutation ( double  mutationPhaseRate = 1.0,
double  mutateIndividualRate = 0.09,
double  mutateGeneRate = 0.5,
bool  mutateBothParentsAndChildren = true,
MutationSelectionType  randomResolutionTypeForIndividual = MutationSelectionType::SELECT_P_OF_N,
MutationSelectionType  randomResolutionTypeForGene = MutationSelectionType::SELECT_P_OF_N,
std::mt19937_64::result_type  seed = std::random_device{}() 
)

Mutation - Constructor.

Parameters
mutationPhaseRate- the probability of a mutation phase to happen (globally). If a mutation is included in the algorithm, this value should most likely be equal to 1.0.
mutateIndividualRate- the probability that an individual will be considered for mutation [if (randomResolutionTypeForIndividual == ITERATE_AND_TEST_P)]; or represents the portion of individuals chosen for mutation [if (randomResolutionTypeForIndividual == SELECT_P_OF_N)].
mutateGeneRate- the probability that a gene of an individual will be considered for mutation [if (randomResolutionTypeForGene == ITERATE_AND_TEST_P)]; or the portion of genes within an individual chosen for mutation [if (randomResolutionTypeForGene == SELECT_P_OF_N)].
mutateBothParentsAndChildren- if true: both the previous population and children can be mutated; if false: only the individuals after crossover can be mutated.
randomResolutionTypeForIndividual- specifies how individuals for mutations are chosen. See MutationSelectionType enum.
randomResolutionTypeForGene- specifies how genes in an individual (already chosen for mutation) are chosen for mutation. See MutationSelectionType enum.
seed- the initial seed for random numbers generator.

Member Function Documentation

◆ MutateGene()

void grail::evolution::Mutation::MutateGene ( Individual individual,
BaseEvoParam gene 
)
protectedvirtual

The function that performs the mutation operation of a single parameter within the mutated individual.

Parameters
individual- the individual to be mutated.
gene- the parameter of the individual to be mutated.

◆ MutateIndividual()

void grail::evolution::Mutation::MutateIndividual ( Individual individual)
protectedvirtual

The function that performs the mutation operation of one individual.

Parameters
individual- the individual to be mutated.

◆ Perform()

void grail::evolution::Mutation::Perform ( const std::vector< std::unique_ptr< Individual >> &  parentPopulation,
const std::vector< std::unique_ptr< Individual >> &  childrenPopulation 
)
virtual

Perform - Attempts to mutate the entire population. The umber of individuals mutates is based on mutation phase rate and mutate individual rate.

Parameters
parentPopulationParent population - before the mutation.
childrenPopulationChildren population - after the mutation.

The documentation for this struct was generated from the following files: