56 template <
typename GeneArray,
typename Compare = std::less<GeneArray>>
59 template <
typename GeneArray,
typename Compare>
66 std::vector<std::shared_ptr<GeneArray>>
children;
80 children.assign(size,
nullptr);
99 children.reserve(size);
101 for (
size_t i = 0; i < size; i++)
103 GeneArray *ptr =
new GeneArray(*geneArray);
106 std::random_shuffle(ptr->begin(), ptr->end());
108 children.emplace_back(ptr);
119 std::shared_ptr<GeneArray> best = children[0];
121 for (
size_t i = 1; i < children.size(); i++)
122 if (Compare()(*children[i], *best) ==
true)
auto fitTest() const -> std::shared_ptr< GeneArray >
Test fitness of each GeneArray in the population.
GAPopulation(size_t size)
Private Constructor with population.
A population in a generation in G.A.
A genetic algorithm class.
std::vector< std::shared_ptr< GeneArray > > children
Genes representing the population.
GAPopulation(std::shared_ptr< GeneArray > geneArray, size_t size)
Construct from a GeneArray and size of the population.