00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <eo>
00029
00030
00031 #include <eoEvalFuncCounterBounder.h>
00032
00033 #include <do/make_pop.h>
00034 #include <do/make_run.h>
00035 #include <do/make_continue.h>
00036 #include <do/make_checkpoint.h>
00037
00038 #include <edo>
00039
00040 #include "Rosenbrock.h"
00041 #include "Sphere.h"
00042
00043
00044 typedef eoReal<eoMinimizingFitness> RealVec;
00045 typedef edoNormalAdaptive< RealVec > Distrib;
00046
00047
00048 int main(int ac, char** av)
00049 {
00050 eoParser parser(ac, av);
00051
00052
00053
00054
00055 std::string section("Algorithm parameters");
00056
00057 eoState state;
00058
00059
00060
00061
00062 unsigned long max_eval = parser.getORcreateParam((unsigned long)0, "maxEval", "Maximum number of evaluations (0 = none)", 'E', "Stopping criterion").value();
00063
00064 unsigned int dim = parser.createParam((unsigned int)10, "dimension-size", "Dimension size", 'd', section).value();
00065
00066
00067 double mu = dim / 2;
00068
00069
00070 edoNormalAdaptive<RealVec> distribution(dim);
00071
00072 eoSelect< RealVec >* selector = new eoRankMuSelect< RealVec >( mu );
00073 state.storeFunctor(selector);
00074
00075 edoEstimator< Distrib >* estimator = new edoEstimatorNormalAdaptive<RealVec>( distribution );
00076 state.storeFunctor(estimator);
00077
00078 eoEvalFunc< RealVec >* plainEval = new Rosenbrock< RealVec >();
00079 state.storeFunctor(plainEval);
00080
00081 eoEvalFuncCounterBounder< RealVec > eval(*plainEval, max_eval);
00082
00083 eoRndGenerator< double >* gen = new eoUniformGenerator< double >(-5, 5);
00084 state.storeFunctor(gen);
00085
00086
00087 eoInitFixedLength< RealVec >* init = new eoInitFixedLength< RealVec >( dim, *gen );
00088 state.storeFunctor(init);
00089
00090
00091
00092
00093
00094
00095 eoPop< RealVec >& pop = do_make_pop(parser, state, *init);
00096
00097
00098 apply(eval, pop);
00099
00100
00101
00102 edoBounder< RealVec >* bounder =
00103 new edoBounderRng< RealVec >( RealVec(dim, -5), RealVec(dim, 5), *gen);
00104 state.storeFunctor(bounder);
00105
00106
00107 edoSampler< Distrib >* sampler = new edoSamplerNormalAdaptive< RealVec >( *bounder );
00108 state.storeFunctor(sampler);
00109
00110
00111
00112 eoContinue< RealVec >& eo_continue = do_make_continue(parser, state, eval);
00113
00114
00115 eoCheckPoint< RealVec >& pop_continue = do_make_checkpoint(parser, state, eval, eo_continue);
00116
00117
00118 edoDummyContinue< Distrib >* dummy_continue = new edoDummyContinue< Distrib >();
00119 state.storeFunctor(dummy_continue);
00120
00121 edoCheckPoint< Distrib >* distribution_continue = new edoCheckPoint< Distrib >( *dummy_continue );
00122 state.storeFunctor(distribution_continue);
00123
00124
00125
00126 eoReplacement< RealVec >* replacor = new eoEPReplacement< RealVec >(pop.size());
00127 state.storeFunctor(replacor);
00128
00129
00130 if (parser.userNeedsHelp())
00131 {
00132 parser.printHelp(std::cout);
00133 exit(1);
00134 }
00135
00136
00137 make_verbose(parser);
00138 make_help(parser);
00139
00140 eoPopLoopEval<RealVec> popEval( eval );
00141
00142
00143 edoAlgo< Distrib >* algo = new edoAlgoAdaptive< Distrib >
00144 (distribution, popEval, *selector, *estimator, *sampler, *replacor,
00145 pop_continue, *distribution_continue );
00146
00147
00148
00149 try {
00150 do_run(*algo, pop);
00151
00152 } catch (eoEvalFuncCounterBounderException& e) {
00153 eo::log << eo::warnings << "warning: " << e.what() << std::endl;
00154
00155 } catch (std::exception& e) {
00156 eo::log << eo::errors << "error: " << e.what() << std::endl;
00157 exit(EXIT_FAILURE);
00158 }
00159 return 0;
00160 }