int main(int argc, char *argv[]) { // create parent individuals: auto a = base.create(10); auto b = base.create(10); for(ea::sequence_len_t i = 0; i < 10; ++i) { base.set(a, i, i); base.set(b, i, 9 - i); } // create children: std::vector<Sequence*> children; auto adapter = ea::make_output_adapter(children); ea::CycleCrossover<ea::Int32PGenomeBase<Fitness>> crossover; std::size_t n = crossover.crossover(a, b, adapter); std::cout << "number of created children: " << n << std::endl; std::for_each(begin(children), end(children), [](Sequence* seq) { print_genome(seq); }); // cleanup: ea::dispose(base, { a, b }); ea::dispose(base, begin(children), end(children)); return 0; }
int main(int argc, char *argv[]) { ea::AnsiRandomNumberGenerator g; // create parent individuals: std::vector<Sequence*> population; for(ea::sequence_len_t i = 0; i < 10; ++i) { auto seq = base.create(10); int32_t genes[10]; g.get_unique_int32_seq(0, 9, genes, 10); for(ea::sequence_len_t j = 0; j < 10; ++j) { base.set(seq, j, genes[j]); } population.push_back(seq); } // create input adapter: auto input = ea::make_input_adapter(population); // print parent individuals: std::for_each(begin(population), end(population), [](Sequence* seq) { print_genome(seq); }); std::cout << std::endl; // select & print individuals: std::vector<std::size_t> children; auto output = ea::make_output_adapter(children); ea::TournamentSelection<ea::Int32PGenomeBase<Fitness>> sel; sel.select(input, 5, output); std::for_each(begin(children), end(children), [&population](uint32_t index) { std::cout << "selected child: " << index << " ==> "; print_genome(population[index]); }); // cleanup: ea::dispose(base, begin(population), end(population)); return 0; }