2 #include <samchon/protocol/Entity.hpp> 3 #include <samchon/example/tsp/Travel.hpp> 5 #include <samchon/library/GeneticAlgorithm.hpp> 18 using namespace library;
19 using namespace protocol;
73 this->travel = make_shared<Travel>();
74 this->gaParameters = {.03, 50, 100, 300};
83 this->travel = travel;
84 this->gaParameters = gaParameteres;
89 virtual void construct(shared_ptr<XML> xml)
override 91 super::construct(xml);
92 gaParameters.mutationRate = xml->getProperty<
double>(
"mutationRate");
93 gaParameters.tournament = xml->getProperty<
size_t>(
"tournament");
94 gaParameters.population = xml->getProperty<
size_t>(
"population");
95 gaParameters.generation = xml->getProperty<
size_t>(
"generation");
97 travel->construct(xml->get(travel->TAG())->at(0));
113 gaParameters.mutationRate,
114 gaParameters.tournament
121 gaParameters.population,
122 gaParameters.generation
128 auto calcDistance()
const ->
double 130 return travel->calcDistance();
136 virtual auto TAG() const ->
string override 141 virtual auto toXML() const -> shared_ptr<
XML>
override 143 shared_ptr<XML> &xml = super::toXML();
144 xml->setProperty(
"mutationRate", gaParameters.mutationRate);
145 xml->setProperty(
"tournament", gaParameters.tournament);
146 xml->setProperty(
"population", gaParameters.population);
147 xml->setProperty(
"generation", gaParameters.generation);
149 xml->push_back(travel->toXML());
153 auto toString()
const ->
string 155 return travel->toString();
163 shared_ptr<Travel> travel = make_shared<Travel>();
164 for(
int i = 0; i < 30; i++)
170 Scheduler scheduler(travel, gaParameters);
174 string &str = travel->toString();
181 static void toClipboard(
const string &str)
183 #if defined(_WINDOWS) || defined(_WIN32) || defined(_WIN64) 186 HGLOBAL hg = GlobalAlloc(GMEM_MOVEABLE, str.size());
193 memcpy(GlobalLock(hg), str.c_str(), str.size());
196 SetClipboardData(CF_TEXT, hg);
An entity, a standard data class.
virtual auto toXML() const -> shared_ptr< XML > override
Get an XML object represents the Entity.
Parameters for Genetic-Algorithm.
A genetic algorithm class.
shared_ptr< Travel > travel
A travel to optimize or optimized.
Scheduler()
Default Constructor.
Scheduler(shared_ptr< Travel > travel, const struct GAParameters &gaParameteres)
Construct from points and parameter of genetic algorithm.
A geometry coordinates (point)
XML is a class representing xml object.
auto optimize() -> shared_ptr< Travel >
Derive optimized schedule.
virtual auto TAG() const -> string override
A tag name when represented by XML.
Top level namespace of products built from samchon.
auto evolveGeneArray(std::shared_ptr< GeneArray > geneArray, size_t population, size_t generation) const -> std::shared_ptr< GeneArray >
Evolve a GeneArray.