Samchon Framework for CPP  1.0.0
GAParameters.hpp
1 #pragma once
2 #include <samchon/API.hpp>
3 
4 #include <samchon/protocol/Entity.hpp>
5 
6 namespace samchon
7 {
8 namespace library
9 {
26  : public protocol::Entity
27  {
28  private:
29  typedef protocol::Entity super;
30 
31  protected:
35  size_t generation;
36 
40  size_t population;
41 
45  size_t tournament;
46 
59  double mutationRate;
60 
61  public:
62  /* ===========================================================
63  CONSTRUCTORS & SETTERS
64  ==============================================================
65  CONSTRUCTORS
66  ----------------------------------------------------------- */
71  : GAParameters(1000, 200, 50, .05)
72  {
73  };
74 
78  GAParameters(size_t generation, size_t population, size_t tournament, double mutationRate)
79  : super()
80  {
81  this->generation = generation;
82  this->population = population;
83  this->tournament = tournament;
84  this->mutationRate = mutationRate;
85  };
86 
87  virtual void construct(std::shared_ptr<XML> xml) override
88  {
89  generation = xml->getProperty<size_t>("generation");
90  population = xml->getProperty<size_t>("population");
91  tournament = xml->getProperty<size_t>("tournament");
92  mutationRate = xml->getProperty<double>("mutationRate");
93  };
94 
95  /* -----------------------------------------------------------
96  SETTERS
97  ----------------------------------------------------------- */
101  void setGeneration(size_t val)
102  {
103  generation = val;
104  }
105 
109  void setPopulation(size_t val)
110  {
111  population = val;
112  }
113 
117  void setTournament(size_t val)
118  {
119  tournament = val;
120  }
121 
125  void setMutationRate(double val)
126  {
127  mutationRate = val;
128  }
129 
130  /* -----------------------------------------------------------
131  GETTERS
132  ----------------------------------------------------------- */
136  auto getGeneration() const -> size_t
137  {
138  return generation;
139  };
140 
144  auto getPopulation() const -> size_t
145  {
146  return population;
147  };
148 
152  auto getTournament() const -> size_t
153  {
154  return tournament;
155  };
156 
160  auto getMutationRate() const -> double
161  {
162  return mutationRate;
163  };
164 
165  /* -----------------------------------------------------------
166  EXPORTERS
167  ----------------------------------------------------------- */
168  virtual auto TAG() const -> std::string
169  {
170  return "gaParameters";
171  };
172  virtual auto toXML() const -> std::shared_ptr<library::XML> override
173  {
174  std::shared_ptr<XML> &xml = super::toXML();
175  xml->setProperty("generation", generation);
176  xml->setProperty("population", population);
177  xml->setProperty("tournament", tournament);
178  xml->setProperty("mutationRate", mutationRate);
179 
180  return xml;
181  };
182  };
183 };
184 }
double mutationRate
Rate of mutate ocurrence.
auto getPopulation() const -> size_t
An entity, a standard data class.
Definition: Entity.hpp:48
virtual auto toXML() const -> std::shared_ptr< library::XML >
Get an XML object represents the Entity.
Definition: Entity.cpp:30
auto getTournament() const -> size_t
auto getGeneration() const -> size_t
Definition: RWMutex.hpp:4
size_t generation
A number of generation of evolution.
virtual auto toXML() const -> std::shared_ptr< library::XML > override
Get an XML object represents the Entity.
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)
virtual auto TAG() const -> std::string
A tag name when represented by XML.
A structure containing parameters of genetic algorithm.
XML is a class representing xml object.
Definition: XML.hpp:72
Top level namespace of products built from samchon.
Definition: ByteArray.hpp:7
size_t population
A number of population in a generation.