diff --git a/application/eda_sa/CMakeLists.txt b/application/eda_sa/CMakeLists.txt index e8ec6f133..25c077722 100644 --- a/application/eda_sa/CMakeLists.txt +++ b/application/eda_sa/CMakeLists.txt @@ -10,6 +10,7 @@ LINK_DIRECTORIES(${Boost_LIBRARY_DIRS}) SET(RESOURCES eda_sa.param plot.py + plot_on_ggobi.py ) FOREACH(file ${RESOURCES}) diff --git a/application/eda_sa/main.cpp b/application/eda_sa/main.cpp index b362529ca..023976ca0 100644 --- a/application/eda_sa/main.cpp +++ b/application/eda_sa/main.cpp @@ -4,6 +4,8 @@ #include #include +#include + #include #include #include @@ -14,12 +16,11 @@ #include "Rosenbrock.h" #include "Sphere.h" -typedef eoReal EOT; -//typedef doUniform< EOT > Distrib; -//typedef doNormalMono< EOT > Distrib; +typedef eoReal EOT; typedef doNormalMulti< EOT > Distrib; + int main(int ac, char** av) { eoParserLogger parser(ac, av); @@ -39,34 +40,27 @@ int main(int ac, char** av) // Instantiate all needed parameters for EDASA algorithm //----------------------------------------------------------------------------- - eoSelect< EOT >* selector = new eoDetSelect< EOT >(0.5); + double selection_rate = parser.createParam((double)0.5, "selection_rate", "Selection Rate", 'R', section).value(); // R + + eoSelect< EOT >* selector = new eoDetSelect< EOT >( selection_rate ); state.storeFunctor(selector); - doEstimator< Distrib >* estimator = - //new doEstimatorUniform< EOT >(); - //new doEstimatorNormalMono< EOT >(); - new doEstimatorNormalMulti< EOT >(); + doEstimator< Distrib >* estimator = new doEstimatorNormalMulti< EOT >(); state.storeFunctor(estimator); eoSelectOne< EOT >* selectone = new eoDetTournamentSelect< EOT >( 2 ); state.storeFunctor(selectone); - doModifierMass< Distrib >* modifier = - //new doUniformCenter< EOT >(); - //new doNormalMonoCenter< EOT >(); - new doNormalMultiCenter< EOT >(); + doModifierMass< Distrib >* modifier = new doNormalMultiCenter< EOT >(); state.storeFunctor(modifier); - eoEvalFunc< EOT >* plainEval = - new Rosenbrock< EOT >(); - //new Sphere< EOT >(); + eoEvalFunc< EOT >* plainEval = new Rosenbrock< EOT >(); state.storeFunctor(plainEval); unsigned long max_eval = parser.getORcreateParam((unsigned long)0, "maxEval", "Maximum number of evaluations (0 = none)", 'E', "Stopping criterion").value(); // E - eoEvalFuncCounter< EOT > eval(*plainEval, max_eval); + eoEvalFuncCounterBounder< EOT > eval(*plainEval, max_eval); eoRndGenerator< double >* gen = new eoUniformGenerator< double >(-5, 5); - //eoRndGenerator< double >* gen = new eoNormalGenerator< double >(0, 1); state.storeFunctor(gen); @@ -106,8 +100,6 @@ int main(int ac, char** av) // This is used by doSampler. //----------------------------------------------------------------------------- - - //doBounder< EOT >* bounder = new doBounderNo< EOT >(); doBounder< EOT >* bounder = new doBounderRng< EOT >(EOT(pop[0].size(), -5), EOT(pop[0].size(), 5), *gen); @@ -120,10 +112,7 @@ int main(int ac, char** av) // Prepare sampler class with a specific distribution //----------------------------------------------------------------------------- - doSampler< Distrib >* sampler = - //new doSamplerUniform< EOT >(); - //new doSamplerNormalMono< EOT >( *bounder ); - new doSamplerNormalMulti< EOT >( *bounder ); + doSampler< Distrib >* sampler = new doSamplerNormalMulti< EOT >( *bounder ); state.storeFunctor(sampler); //----------------------------------------------------------------------------- @@ -133,11 +122,9 @@ int main(int ac, char** av) // Metropolis sample parameters //----------------------------------------------------------------------------- - // FIXME: should I set the default value of rho to pop size ?!? + unsigned int popSize = parser.getORcreateParam((unsigned int)20, "popSize", "Population Size", 'P', "Evolution Engine").value(); - unsigned int rho = parser.createParam((unsigned int)0, "rho", "Rho: metropolis sample size", 'p', section).value(); // p - - moGenSolContinue< EOT >* sa_continue = new moGenSolContinue< EOT >(rho); + moGenSolContinue< EOT >* sa_continue = new moGenSolContinue< EOT >( popSize ); state.storeFunctor(sa_continue); //----------------------------------------------------------------------------- @@ -170,7 +157,16 @@ int main(int ac, char** av) // general output //----------------------------------------------------------------------------- - eoCheckPoint< EOT >& monitoring_continue = do_make_checkpoint(parser, state, eval, eo_continue); + eoCheckPoint< EOT >& pop_continue = do_make_checkpoint(parser, state, eval, eo_continue); + + doPopStat< EOT >* popStat = new doPopStat; + state.storeFunctor(popStat); + pop_continue.add(*popStat); + + doFileSnapshot* fileSnapshot = new doFileSnapshot("ResPop"); + state.storeFunctor(fileSnapshot); + fileSnapshot->add(*popStat); + pop_continue.add(*fileSnapshot); //----------------------------------------------------------------------------- @@ -179,17 +175,6 @@ int main(int ac, char** av) // population output //----------------------------------------------------------------------------- - eoCheckPoint< EOT >* pop_continue = new eoCheckPoint< EOT >( eo_continue ); - state.storeFunctor(pop_continue); - - doPopStat< EOT >* popStat = new doPopStat; - state.storeFunctor(popStat); - pop_continue->add(*popStat); - - doFileSnapshot* fileSnapshot = new doFileSnapshot("ResPop"); - state.storeFunctor(fileSnapshot); - fileSnapshot->add(*popStat); - pop_continue->add(*fileSnapshot); //----------------------------------------------------------------------------- @@ -244,7 +229,7 @@ int main(int ac, char** av) doAlgo< Distrib >* algo = new doEDASA< Distrib > (*selector, *estimator, *selectone, *modifier, *sampler, - monitoring_continue, *pop_continue, *distribution_continue, + pop_continue, *distribution_continue, eval, *sa_continue, *cooling_schedule, initial_temperature, *replacor); @@ -273,13 +258,13 @@ int main(int ac, char** av) { do_run(*algo, pop); } - catch (eoReachedThresholdException& e) - { - eo::log << eo::warnings << e.what() << std::endl; - } + catch (eoEvalFuncCounterBounderException& e) + { + eo::log << eo::warnings << "warning: " << e.what() << std::endl; + } catch (std::exception& e) { - eo::log << eo::errors << "exception: " << e.what() << std::endl; + eo::log << eo::errors << "error: " << e.what() << std::endl; exit(EXIT_FAILURE); } diff --git a/src/do b/src/do index bcd43e19f..1f91d3923 100644 --- a/src/do +++ b/src/do @@ -52,3 +52,7 @@ #include "utils/doPopStat.h" #endif // !_do_ + +// Local Variables: +// mode: C++ +// End: diff --git a/src/doEDASA.h b/src/doEDASA.h index ae2e39cd9..05c8cc1c9 100644 --- a/src/doEDASA.h +++ b/src/doEDASA.h @@ -38,23 +38,24 @@ public: /*! All the boxes used by a EDASA need to be given. - \param selector The EOT selector - \param estomator The EOT selector + \param selector Population Selector + \param estimator Distribution Estimator \param selectone SelectOne - \param modifier The D modifier - \param sampler The D sampler - \param evaluation The evaluation function. - \param continue The stopping criterion. - \param cooling_schedule The cooling schedule, describes how the temperature is modified. + \param modifier Distribution Modifier + \param sampler Distribution Sampler + \param pop_continue Population Continuator + \param distribution_continue Distribution Continuator + \param evaluation Evaluation function. + \param sa_continue Stopping criterion. + \param cooling_schedule Cooling schedule, describes how the temperature is modified. \param initial_temperature The initial temperature. - \param replacor The EOT replacor + \param replacor Population replacor */ doEDASA (eoSelect< EOT > & selector, doEstimator< D > & estimator, eoSelectOne< EOT > & selectone, doModifierMass< D > & modifier, doSampler< D > & sampler, - eoContinue< EOT > & monitoring_continue, eoContinue< EOT > & pop_continue, doContinue< D > & distribution_continue, eoEvalFunc < EOT > & evaluation, @@ -68,7 +69,6 @@ public: _selectone(selectone), _modifier(modifier), _sampler(sampler), - _monitoring_continue(monitoring_continue), _pop_continue(pop_continue), _distribution_continue(distribution_continue), _evaluation(evaluation), @@ -91,7 +91,7 @@ public: double temperature = _initial_temperature; - eoPop< EOT > current_pop = pop; + eoPop< EOT > current_pop; eoPop< EOT > selected_pop; @@ -111,19 +111,12 @@ public: do { - if (pop != current_pop) - { - _replacor(pop, current_pop); - } - - current_pop.clear(); - selected_pop.clear(); - - //------------------------------------------------------------- // (3) Selection of the best points in the population //------------------------------------------------------------- + selected_pop.clear(); + _selector(pop, selected_pop); assert( selected_pop.size() > 0 ); @@ -172,6 +165,8 @@ public: // Building of the sampler in current_pop //------------------------------------------------------------- + current_pop.clear(); + do { EOT candidate_solution = _sampler(distrib); @@ -189,14 +184,20 @@ public: current_solution = candidate_solution; } } - while ( _sa_continue( current_solution) ); + while ( _sa_continue( current_solution) ); + + _replacor(pop, current_pop); // copy current_pop in pop + + pop.sort(); + + if ( ! _cooling_schedule( temperature ) ){ eo::log << eo::debug << "_cooling_schedule" << std::endl; break; } + + if ( ! _distribution_continue( distrib ) ){ eo::log << eo::debug << "_distribution_continue" << std::endl; break; } + + if ( ! _pop_continue( pop ) ){ eo::log << eo::debug << "_pop_continue" << std::endl; break; } } - while ( _cooling_schedule( temperature ) && - _distribution_continue( distrib ) && - _pop_continue( current_pop ) && - _monitoring_continue( selected_pop ) - ); + while ( 1 ); } private: @@ -216,9 +217,6 @@ private: //! A D sampler doSampler< D > & _sampler; - //! A EOT monitoring continuator - eoContinue < EOT > & _monitoring_continue; - //! A EOT population continuator eoContinue < EOT > & _pop_continue;