fix: refactor foundry to be more dynamic than static
- Remove size template in favor of dynamic container: allow using the generic interface. - Using `operator=` was inducing slicing.
This commit is contained in:
parent
78be884270
commit
11ff72bdd9
5 changed files with 56 additions and 55 deletions
|
|
@ -65,10 +65,8 @@ eoAlgoFoundryEA<Bits>& make_foundry(eoFunctorStore& store, eoPopEvalFunc<Bits>&
|
|||
|
||||
// A basic PSO algorithm.
|
||||
std::pair< eoAlgo<Particle>*, eoPop<Particle>* >
|
||||
make_pso(eoFunctorStore& store, eoEvalFunc<Particle>& eval_foundry)
|
||||
make_pso(eoFunctorStore& store, eoEvalFoundryEA<Particle,Bits>& eval_foundry, size_t dim)
|
||||
{
|
||||
const size_t dim = eoAlgoFoundryEA<Bits>::dim;
|
||||
|
||||
auto& gen_pos = store.pack< eoUniformGenerator<double> >(0.1,0.9);
|
||||
auto& random_pos = store.pack< eoInitFixedLength<Particle> >(dim, gen_pos);
|
||||
|
||||
|
|
@ -133,13 +131,13 @@ int main(int /*argc*/, char** /*argv*/)
|
|||
|
||||
eoAlgo<Particle>* pso;
|
||||
eoPop<Particle>* pop_foundry;
|
||||
std::tie(pso, pop_foundry) = make_pso(store, eval_foundry);
|
||||
std::tie(pso, pop_foundry) = make_pso(store, eval_foundry, foundry.size());
|
||||
|
||||
// Perform the best algorithm configuration search.
|
||||
(*pso)(*pop_foundry);
|
||||
|
||||
// Print a glimpse of the best algorithm found.
|
||||
foundry = eval_foundry.decode(pop_foundry->best_element());
|
||||
foundry.select(eval_foundry.decode(pop_foundry->best_element()));
|
||||
std::cout << "Best algorithm: " << foundry.name() << std::endl;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ int main(int /*argc*/, char** /*argv*/)
|
|||
foundry.at(foundry.index_of.replacements) = i_rep;
|
||||
|
||||
// Or, if you know the order.
|
||||
foundry = {i_cont, i_cross, i_mut, i_sel, i_rep};
|
||||
foundry.select({i_cont, i_cross, i_mut, i_sel, i_rep});
|
||||
|
||||
// Actually perform a search
|
||||
foundry(pop);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue