Grail (C++)  1.3.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
Mutation.hh
1 // Copyright QED Software 2023.
2 
3 #ifndef GRAIL_MUTATION_H
4 #define GRAIL_MUTATION_H
5 
6 #include <memory>
7 #include <random>
8 #include <vector>
9 
10 namespace grail
11 {
12 namespace evolution
13 {
14  class EvoScript;
15  class EvoParam;
16 
20  struct Mutation
21  {
22  public:
27  {
36  };
37 
45  Mutation(double mutationPhaseRate = 1.0,
46  double mutateIndividualRate = 0.09,
47  double mutateChromosomeRate = 0.5,
48  bool mutateBothParentsAndChildren = true,
49  std::mt19937_64::result_type seed = std::random_device{}());
50  virtual ~Mutation();
51 
57  virtual void Perform(const std::vector<std::unique_ptr<EvoScript>>& parentPopulation,
58  const std::vector<std::unique_ptr<EvoScript>>& childrenPopulation);
59 
60  std::vector<std::unique_ptr<EvoScript>> populationAfter{};
61 
63  double MutationPhaseRate = 0.0;
64 
67  double MutateIndividualRate = 0.0;
68 
71  double MutateChromosomeRate = 0.0;
72 
75 
76  protected:
77  std::mt19937_64 randGen;
78  MutationSelectionType RandomResolutionTypeForIndividual = MutationSelectionType::SELECT_P_OF_N;
79  MutationSelectionType RandomResolutionTypeForChromosome = MutationSelectionType::SELECT_P_OF_N;
80 
81  protected:
82  virtual void MutateIndividual(EvoScript& individual);
83  virtual void MutateChromosome(EvoScript& individual, EvoParam& chromosome);
84  };
85 }
86 }
87 
88 #endif
grail::evolution::Mutation::MutateChromosomeRate
double MutateChromosomeRate
Probability that a chromosome of an individual will be considered for mutation (randomResolutionTypeF...
Definition: Mutation.hh:71
grail::evolution::EvoParam
EvoParam - class that represents a parameter that is modifiable (optimizable) by evolutionary algorit...
Definition: EvoParam.hh:16
grail::evolution::Mutation::MutationSelectionType::ITERATE_AND_TEST_P
@ ITERATE_AND_TEST_P
ITERATE_AND_TEST_P -
grail::evolution::Mutation::MutationSelectionType
MutationSelectionType
Predefined ways in which individuals are selected from the population for mutation....
Definition: Mutation.hh:26
grail::evolution::EvoScript
EvoScript - a class that holds a collection of EvoParams (through them) is optimizable....
Definition: EvoScript.hh:18
grail::evolution::Mutation::MutateBothParentsAndChildren
bool MutateBothParentsAndChildren
If true: both the previous population and children can be mutated; if false: only the individuals aft...
Definition: Mutation.hh:74
grail::evolution::Mutation::MutationSelectionType::SELECT_P_OF_N
@ SELECT_P_OF_N
SELECT_P_OF_N -
grail::evolution::Mutation::Mutation
Mutation(double mutationPhaseRate=1.0, double mutateIndividualRate=0.09, double mutateChromosomeRate=0.5, bool mutateBothParentsAndChildren=true, std::mt19937_64::result_type seed=std::random_device{}())
Mutation - Constructor.
Definition: Mutation.cpp:10
grail::evolution::Mutation
The Mutation structure that encapsulates the mutation operation and its configuration in evolutionary...
Definition: Mutation.hh:20
grail::evolution::Mutation::MutateIndividualRate
double MutateIndividualRate
Probability that an individual will be considered for mutation (randomResolutionTypeForIndividual == ...
Definition: Mutation.hh:67
grail::evolution::Mutation::MutationPhaseRate
double MutationPhaseRate
Probability of a mutation phase to happen (globally). If a mutation is included in the algorithm,...
Definition: Mutation.hh:63
grail::evolution::Mutation::Perform
virtual void Perform(const std::vector< std::unique_ptr< EvoScript >> &parentPopulation, const std::vector< std::unique_ptr< EvoScript >> &childrenPopulation)
Perform - Attempts to mutate the entire population. The umber of individuals mutates is based on muta...
Definition: Mutation.cpp:27