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;
56 shared_ptr<Travel> travel;
61 struct GAParameters gaParameters;
73 this->travel = make_shared<Travel>();
74 this->gaParameters = {.03, 50, 100, 300};
80 Scheduler(shared_ptr<Travel> travel,
const struct GAParameters &gaParameteres)
83 this->travel = travel;
84 this->gaParameters = gaParameteres;
87 virtual ~Scheduler() =
default;
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));
108 auto optimize() -> shared_ptr<Travel>
110 GeneticAlgorithm<Travel> geneticAlgorithm
113 gaParameters.mutationRate,
114 gaParameters.tournament
118 geneticAlgorithm.evolveGeneArray
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++)
165 travel->emplace_back(
new GeometryPoint(i + 1));
168 struct GAParameters gaParameters = {.03, 30, 400, 400};
170 Scheduler scheduler(travel, gaParameters);
171 travel = scheduler.optimize();
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);
Top level namespace of products built from samchon.