18 py::class_<Class> vary(m, name.data() );
21 Class variation(p, ss);
23 .def(
"mutate", &Class::mutate, py::return_value_policy::automatic)
24 .def(
"cross", &Class::cross, py::return_value_policy::automatic)
25 .def(
"vary_pop", [](Class &self,
28 if (individuals.size() != params.
pop_size) {
29 string msg =
"Individual vector has different number of "
30 "individuals than pop_size. When calling "
31 "variation, they should be the same. popsize is "+
33 "individuals is "+
to_string(individuals.size());
35 throw std::runtime_error(msg);
40 pop.init(individuals, params);
42 vector<br::Pop::Individual<PT>> pool;
45 for (
int island = 0; island < params.
num_islands; ++island)
49 vector<size_t> parents = pop.get_island_indexes(island);
53 pop.add_offspring_indexes(island);
55 self.vary(pop, island, parents);
58 vector<size_t> indices = pop.get_island_indexes(island);
59 int start = indices.size()/2;
60 for (
unsigned i = start; i<indices.size(); ++i)
63 pool.push_back(pop[indices.at(i)]);