#include #include #include #include #include #include #include using R = eoReal; using CMA = edoNormalAdaptive; R::FitnessType sphere(const R& sol) { double sum = 0; for(auto x : sol) { sum += x * x; } return sum; } int main(int argc, char** argv) { eoParser parser(argc, argv); eoState state; size_t dim = parser.createParam(10, "dimension", "Dimension", 'd', "Problem").value(); size_t max_eval = parser.getORcreateParam(100 * dim, "maxEval", "Maximum number of evaluations", 'E', "Stopping criterion").value(); edoNormalAdaptive gaussian(dim); auto& obj_func = state.pack< eoEvalFuncPtr >(sphere); auto& eval = state.pack< eoEvalCounterThrowException >(obj_func, max_eval); auto& pop_eval = state.pack< eoPopLoopEval >(eval); auto& gen = state.pack< eoUniformGenerator >(-5, 5); auto& init = state.pack< eoInitFixedLength >(dim, gen); auto& pop = do_make_pop(parser, state, init); pop_eval(pop,pop); auto& eo_continue = do_make_continue( parser, state, eval); auto& pop_continue = do_make_checkpoint(parser, state, eval, eo_continue); auto& best = state.pack< eoBestIndividualStat >(); pop_continue.add( best ); auto& distrib_continue = state.pack< edoContAdaptiveFinite >(); auto& selector = state.pack< eoRankMuSelect >(dim/2); auto& estimator = state.pack< edoEstimatorNormalAdaptive >(gaussian); auto& bounder = state.pack< edoBounderRng >(R(dim, -5), R(dim, 5), gen); auto& sampler = state.pack< edoSamplerNormalAdaptive >(bounder); auto& replacor = state.pack< eoCommaReplacement >(); make_verbose(parser); make_help(parser); auto& algo = state.pack< edoAlgoAdaptive >( gaussian , pop_eval, selector, estimator, sampler , replacor, pop_continue, distrib_continue); try { algo(pop); } catch (eoMaxEvalException& e) { eo::log << eo::progress << "STOP" << std::endl; } std::cout << best.value() << std::endl; return 0; }