Grail (C++)  1.3.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
EvoParam.hh
1 // Copyright QED Software 2023.
2 
3 #ifndef GRAIL_IEVO_PARAM_H
4 #define GRAIL_IEVO_PARAM_H
5 
6 #include <random>
7 #include <string>
8 
9 namespace grail
10 {
11 namespace evolution
12 {
16  class EvoParam
17  {
18  protected:
22  const size_t domainLength = {1};
26  size_t positionIndex;
27 
32  EvoParam(size_t domainLength);
33 
34  public:
35  //Helper methods for implementing mutations and crossover
36 
41  void Randomize(std::mt19937_64& rand_gen);
42 
44  const EvoParam* SetNext();
45 
47  const EvoParam* SetPrev();
48 
50  const EvoParam* SetNextClamped();
51 
53  const EvoParam* SetPrevClamped();
54 
56  float GetNormalizedPositionWeight() const;
57 
59  size_t GetPositionIndex() const;
60 
65  void SetPositionIndex(size_t position);
66 
70  virtual std::string ToString() const;
71  };
72 }
73 }
74 #endif //GRAIL_IEVO_PARAM_H
grail::evolution::EvoParam
EvoParam - class that represents a parameter that is modifiable (optimizable) by evolutionary algorit...
Definition: EvoParam.hh:16
grail::evolution::EvoParam::SetNext
const EvoParam * SetNext()
Sets to the next possible value in the domain (wrapped, i.e. last.next -> first) and returns itself.
Definition: EvoParam.cpp:14
grail::evolution::EvoParam::SetNextClamped
const EvoParam * SetNextClamped()
Sets to the next possible value in the domain (clamped, i.e. last.next -> last) and returns itself.
Definition: EvoParam.cpp:26
grail::evolution::EvoParam::SetPrevClamped
const EvoParam * SetPrevClamped()
Sets to the previous possible value in the domain (clamped, i.e. first.prev -> first) and returns its...
Definition: EvoParam.cpp:32
grail::evolution::EvoParam::EvoParam
EvoParam(size_t domainLength)
EvoParam - Constructor.
Definition: EvoParam.cpp:65
grail::evolution::EvoParam::Randomize
void Randomize(std::mt19937_64 &rand_gen)
Sets to a random possible value from a domain.
Definition: EvoParam.cpp:9
grail::evolution::EvoParam::GetNormalizedPositionWeight
float GetNormalizedPositionWeight() const
Returns the normalized position as [0.0, 1.0] floating point number.
Definition: EvoParam.cpp:45
grail::evolution::EvoParam::ToString
virtual std::string ToString() const
ToString - returns the string representation of the current value hold by the parameter.
Definition: EvoParam.cpp:60
grail::evolution::EvoParam::domainLength
const size_t domainLength
domainLength - the number of distinct values EvoParam may take.
Definition: EvoParam.hh:22
grail::evolution::EvoParam::SetPrev
const EvoParam * SetPrev()
Sets to the previous possible value in the domain (wrapped, i.e. first.prev -> last) and returns itse...
Definition: EvoParam.cpp:20
grail::evolution::EvoParam::GetPositionIndex
size_t GetPositionIndex() const
Returns the position of the parameter i.e. the index of the currently assigned element from the domai...
Definition: EvoParam.cpp:50
grail::evolution::EvoParam::positionIndex
size_t positionIndex
positionIndex - EvoParam uses positionIndex to point to an element from its domain.
Definition: EvoParam.hh:26
grail::evolution::EvoParam::SetPositionIndex
void SetPositionIndex(size_t position)
Sets the position of the parameter i.e. the index of the currently assigned element from the domain.
Definition: EvoParam.cpp:55