Samchon Framework for CPP  1.0.0
GAParameters.hpp
1 #pragma once
2 #include <samchon/protocol/Entity.hpp>
3 
4 namespace samchon
5 {
6 namespace library
7 {
20  : public protocol::Entity<>
21  {
22  private:
23  typedef protocol::Entity<> super;
24 
25  protected:
29  size_t generation;
30 
34  size_t population;
35 
39  size_t tournament;
40 
53  double mutationRate;
54 
55  public:
56  /* ===========================================================
57  CONSTRUCTORS & SETTERS
58  ==============================================================
59  CONSTRUCTORS
60  ----------------------------------------------------------- */
65  : GAParameters(1000, 200, 50, .05)
66  {
67  };
68 
72  GAParameters(size_t generation, size_t population, size_t tournament, double mutationRate)
73  : super()
74  {
75  this->generation = generation;
76  this->population = population;
77  this->tournament = tournament;
78  this->mutationRate = mutationRate;
79  };
80 
81  virtual void construct(std::shared_ptr<XML> xml) override
82  {
83  generation = xml->getProperty<size_t>("generation");
84  population = xml->getProperty<size_t>("population");
85  tournament = xml->getProperty<size_t>("tournament");
86  mutationRate = xml->getProperty<double>("mutationRate");
87  };
88 
89  /* -----------------------------------------------------------
90  SETTERS
91  ----------------------------------------------------------- */
95  void setGeneration(size_t val)
96  {
97  generation = val;
98  }
99 
103  void setPopulation(size_t val)
104  {
105  population = val;
106  }
107 
111  void setTournament(size_t val)
112  {
113  tournament = val;
114  }
115 
119  void setMutationRate(double val)
120  {
121  mutationRate = val;
122  }
123 
124  /* -----------------------------------------------------------
125  GETTERS
126  ----------------------------------------------------------- */
130  auto getGeneration() const -> size_t
131  {
132  return generation;
133  };
134 
138  auto getPopulation() const -> size_t
139  {
140  return population;
141  };
142 
146  auto getTournament() const -> size_t
147  {
148  return tournament;
149  };
150 
154  auto getMutationRate() const -> double
155  {
156  return mutationRate;
157  };
158 
159  /* -----------------------------------------------------------
160  EXPORTERS
161  ----------------------------------------------------------- */
162  virtual auto TAG() const -> std::string
163  {
164  return "gaParameters";
165  };
166  virtual auto toXML() const -> std::shared_ptr<library::XML> override
167  {
168  std::shared_ptr<XML> &xml = super::toXML();
169  xml->setProperty("generation", generation);
170  xml->setProperty("population", population);
171  xml->setProperty("tournament", tournament);
172  xml->setProperty("mutationRate", mutationRate);
173 
174  return xml;
175  };
176  };
177 };
178 }
double mutationRate
Rate of mutate ocurrence.
auto getPopulation() const -> size_t
An entity, a standard data class.
Definition: Entity.hpp:115
auto getTournament() const -> size_t
auto getGeneration() const -> size_t
size_t generation
A number of generation of evolution.
size_t tournament
A number of tournament in a selection.
auto getMutationRate() const -> double
GAParameters(size_t generation, size_t population, size_t tournament, double mutationRate)
A structure containing parameters of genetic algorithm.
size_t population
A number of population in a generation.