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> EOT;
00045 typedef edoNormalMulti< EOT > 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 double selection_rate = parser.createParam((double)0.5, "selection_rate", "Selection Rate", 'R', section).value();
00061
00062 eoSelect< EOT >* selector = new eoDetSelect< EOT >( selection_rate );
00063 state.storeFunctor(selector);
00064
00065 edoEstimator< Distrib >* estimator = new edoEstimatorNormalMulti< EOT >();
00066 state.storeFunctor(estimator);
00067
00068 eoEvalFunc< EOT >* plainEval = new Rosenbrock< EOT >();
00069 state.storeFunctor(plainEval);
00070
00071 unsigned long max_eval = parser.getORcreateParam((unsigned long)0, "maxEval", "Maximum number of evaluations (0 = none)", 'E', "Stopping criterion").value();
00072 eoEvalFuncCounterBounder< EOT > eval(*plainEval, max_eval);
00073
00074 eoRndGenerator< double >* gen = new eoUniformGenerator< double >(-5, 5);
00075 state.storeFunctor(gen);
00076
00077 unsigned int dimension_size = parser.createParam((unsigned int)10, "dimension-size", "Dimension size", 'd', section).value();
00078
00079 eoInitFixedLength< EOT >* init = new eoInitFixedLength< EOT >( dimension_size, *gen );
00080 state.storeFunctor(init);
00081
00082
00083
00084
00085
00086
00087 eoPop< EOT >& pop = do_make_pop(parser, state, *init);
00088
00089
00090 apply(eval, pop);
00091
00092
00093
00094 edoBounder< EOT >* bounder =
00095 new edoBounderRng< EOT >( EOT(dimension_size, -5), EOT(dimension_size, 5), *gen);
00096 state.storeFunctor(bounder);
00097
00098
00099 edoSampler< Distrib >* sampler = new edoSamplerNormalMulti< EOT >( *bounder );
00100 state.storeFunctor(sampler);
00101
00102
00103
00104 eoContinue< EOT >& eo_continue = do_make_continue(parser, state, eval);
00105
00106
00107 eoCheckPoint< EOT >& pop_continue = do_make_checkpoint(parser, state, eval, eo_continue);
00108
00109
00110 edoDummyContinue< Distrib >* dummy_continue = new edoDummyContinue< Distrib >();
00111 state.storeFunctor(dummy_continue);
00112
00113 edoCheckPoint< Distrib >* distribution_continue = new edoCheckPoint< Distrib >( *dummy_continue );
00114 state.storeFunctor(distribution_continue);
00115
00116
00117
00118 eoReplacement< EOT >* replacor = new eoEPReplacement< EOT >(pop.size());
00119 state.storeFunctor(replacor);
00120
00121
00122 make_verbose(parser);
00123 make_help(parser);
00124
00125
00126 if (parser.userNeedsHelp())
00127 {
00128 parser.printHelp(std::cout);
00129 exit(1);
00130 }
00131
00132
00133
00134
00135
00136 edoPopStat< EOT >* popStat = new edoPopStat<EOT>;
00137 state.storeFunctor(popStat);
00138 pop_continue.add(*popStat);
00139
00140 edoFileSnapshot* fileSnapshot = new edoFileSnapshot("EDA_ResPop");
00141 state.storeFunctor(fileSnapshot);
00142 fileSnapshot->add(*popStat);
00143 pop_continue.add(*fileSnapshot);
00144
00145
00146 edoDistribStat< Distrib >* distrib_stat = new edoStatNormalMulti< EOT >();
00147 state.storeFunctor(distrib_stat);
00148
00149 distribution_continue->add( *distrib_stat );
00150
00151
00152
00153
00154
00155
00156 eoFileMonitor* file_monitor = new eoFileMonitor("eda_distribution_bounds.txt");
00157 state.storeFunctor(file_monitor);
00158 file_monitor->add(*distrib_stat);
00159 distribution_continue->add( *file_monitor );
00160
00161 eoPopLoopEval<EOT> popEval( eval );
00162
00163
00164 edoAlgo< Distrib >* algo = new edoAlgoStateless< Distrib >
00165 (popEval, *selector, *estimator, *sampler, *replacor,
00166 pop_continue, *distribution_continue );
00167
00168
00169 try {
00170 do_run(*algo, pop);
00171
00172 } catch (eoEvalFuncCounterBounderException& e) {
00173 eo::log << eo::warnings << "warning: " << e.what() << std::endl;
00174
00175 } catch (std::exception& e) {
00176 eo::log << eo::errors << "error: " << e.what() << std::endl;
00177 exit(EXIT_FAILURE);
00178 }
00179 return 0;
00180 }