2 #include <samchon/protocol/Entity.hpp> 3 #include <samchon/examples/tsp/Travel.hpp> 6 #include <samchon/library/GeneticAlgorithm.hpp> 16 using namespace library;
17 using namespace protocol;
71 this->travel = make_shared<Travel>();
72 this->gaParameters = {.03, 50, 100, 300};
81 this->travel = travel;
82 this->gaParameters = gaParameteres;
87 virtual void construct(shared_ptr<XML> xml)
override 89 gaParameters.mutationRate = xml->getProperty<
double>(
"mutationRate");
90 gaParameters.tournament = xml->getProperty<
size_t>(
"tournament");
91 gaParameters.population = xml->getProperty<
size_t>(
"population");
92 gaParameters.generation = xml->getProperty<
size_t>(
"generation");
94 travel->construct(xml->get(travel->TAG())->at(0));
110 gaParameters.mutationRate,
111 gaParameters.tournament
118 gaParameters.population,
119 gaParameters.generation
125 auto calcDistance()
const ->
double 127 return travel->calcDistance();
133 virtual auto TAG()
const ->
string override 138 virtual auto toXML()
const -> shared_ptr<XML>
override 140 shared_ptr<XML> &xml = super::toXML();
141 xml->setProperty(
"mutationRate", gaParameters.mutationRate);
142 xml->setProperty(
"tournament", gaParameters.tournament);
143 xml->setProperty(
"population", gaParameters.population);
144 xml->setProperty(
"generation", gaParameters.generation);
146 xml->push_back(travel->toXML());
150 auto toString()
const ->
string 152 return travel->toString();
160 shared_ptr<Travel> travel = make_shared<Travel>();
161 for(
int i = 0; i < 30; i++)
167 Scheduler scheduler(travel, gaParameters);
171 string &str = travel->toString();
An entity, a standard data class.
auto optimize() -> shared_ptr< Travel >
Derive optimized schedule.
A genetic algorithm class.
Scheduler(shared_ptr< Travel > travel, const struct GAParameters &gaParameteres)
Construct from points and parameter of genetic algorithm.
auto evolveGeneArray(std::shared_ptr< GeneArray > individual, size_t population, size_t generation) const -> std::shared_ptr< GeneArray >
Evolve a GeneArray.
Scheduler()
Default Constructor.
shared_ptr< Travel > travel
A travel to optimize or optimized.
A geometry coordinates (point)
Parameters for Genetic-Algorithm.