diff --git a/edo/CMakeLists.txt b/edo/CMakeLists.txt index 563437043..ab4333ef6 100644 --- a/edo/CMakeLists.txt +++ b/edo/CMakeLists.txt @@ -42,7 +42,6 @@ INCLUDE_DIRECTORIES( LINK_DIRECTORIES( ${EO_LIBRARY_DIRS} - ${MO_LIBRARY_DIRS} ) ###################################################################################### @@ -77,6 +76,7 @@ ENDIF() ### 6) Prepare some variables for CMAKE usage ###################################################################################### +# Empty source files, because we want to build a library SET(SAMPLE_SRCS) ###################################################################################### diff --git a/edo/application/eda/CMakeLists.txt b/edo/application/eda/CMakeLists.txt index 2f1a52a57..2dfe5774c 100644 --- a/edo/application/eda/CMakeLists.txt +++ b/edo/application/eda/CMakeLists.txt @@ -24,4 +24,4 @@ FILE(GLOB SOURCES *.cpp) SET(EXECUTABLE_OUTPUT_PATH ${EDO_BINARY_DIR}) ADD_EXECUTABLE(${PROJECT_NAME} ${SOURCES}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} edo edoutils ${EO_LIBRARIES} ${MO_LIBRARIES} ${Boost_LIBRARIES}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} edo edoutils ${EO_LIBRARIES} ${Boost_LIBRARIES}) diff --git a/edo/application/eda/main.cpp b/edo/application/eda/main.cpp index 4208580e5..250e6bf1e 100644 --- a/edo/application/eda/main.cpp +++ b/edo/application/eda/main.cpp @@ -52,32 +52,19 @@ int main(int ac, char** av) // Letters used by the following declarations: // a d i p t - std::string section("Algorithm parameters"); - - // FIXME: default value to check - //double initial_temperature = parser.createParam((double)10e5, "temperature", "Initial temperature", 'i', section).value(); // i + std::string section("Algorithm parameters"); eoState state; - - //----------------------------------------------------------------------------- // Instantiate all needed parameters for EDA algorithm - //----------------------------------------------------------------------------- - 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); - edoEstimator< Distrib >* estimator = new edoEstimatorNormalMulti< EOT >(); + edoEstimator< Distrib >* estimator = new edoEstimatorNormalMulti< EOT >(); state.storeFunctor(estimator); - eoSelectOne< EOT >* selectone = new eoDetTournamentSelect< EOT >( 2 ); - state.storeFunctor(selectone); - - edoModifierMass< Distrib >* modifier = new edoNormalMultiCenter< EOT >(); - state.storeFunctor(modifier); - eoEvalFunc< EOT >* plainEval = new Rosenbrock< EOT >(); state.storeFunctor(plainEval); @@ -87,159 +74,65 @@ int main(int ac, char** av) eoRndGenerator< double >* gen = new eoUniformGenerator< double >(-5, 5); state.storeFunctor(gen); - unsigned int dimension_size = parser.createParam((unsigned int)10, "dimension-size", "Dimension size", 'd', section).value(); // d eoInitFixedLength< EOT >* init = new eoInitFixedLength< EOT >( dimension_size, *gen ); state.storeFunctor(init); - //----------------------------------------------------------------------------- - - //----------------------------------------------------------------------------- // (1) Population init and sampler - //----------------------------------------------------------------------------- - // Generation of population from do_make_pop (creates parameters, manages persistance and so on...) // ... and creates the parameters: L P r S - - // this first sampler creates a uniform distribution independently from our distribution (it does not use doUniform). - + // this first sampler creates a uniform distribution independently from our distribution (it does not use edoUniform). eoPop< EOT >& pop = do_make_pop(parser, state, *init); - //----------------------------------------------------------------------------- - - - //----------------------------------------------------------------------------- // (2) First evaluation before starting the research algorithm - //----------------------------------------------------------------------------- - apply(eval, pop); - //----------------------------------------------------------------------------- - - - //----------------------------------------------------------------------------- // Prepare bounder class to set bounds of sampling. - // This is used by doSampler. - //----------------------------------------------------------------------------- - - edoBounder< EOT >* bounder = new edoBounderRng< EOT >(EOT(pop[0].size(), -5), - EOT(pop[0].size(), 5), - *gen); + // This is used by edoSampler. + edoBounder< EOT >* bounder = + new edoBounderRng< EOT >( EOT(pop[0].size(), -5), EOT(pop[0].size(), 5), *gen); // FIXME do not use hard-coded bounds state.storeFunctor(bounder); - //----------------------------------------------------------------------------- - - - //----------------------------------------------------------------------------- // Prepare sampler class with a specific distribution - //----------------------------------------------------------------------------- - edoSampler< Distrib >* sampler = new edoSamplerNormalMulti< EOT >( *bounder ); state.storeFunctor(sampler); - - //----------------------------------------------------------------------------- - - - //----------------------------------------------------------------------------- - // Metropolis sample parameters - //----------------------------------------------------------------------------- - - //unsigned int popSize = parser.getORcreateParam((unsigned int)20, "popSize", "Population Size", 'P', "Evolution Engine").value(); - - //moContinuator< moDummyNeighbor >* sa_continue = new moIterContinuator< moDummyNeighbor >( popSize ); - //state.storeFunctor(sa_continue); - - //----------------------------------------------------------------------------- - - - //----------------------------------------------------------------------------- - // SA parameters - //----------------------------------------------------------------------------- - - //double threshold_temperature = parser.createParam((double)0.1, "threshold", "Minimal temperature at which stop", 't', section).value(); // t - //double alpha = parser.createParam((double)0.1, "alpha", "Temperature decrease rate", 'a', section).value(); // a - - //moCoolingSchedule* cooling_schedule = new moSimpleCoolingSchedule(initial_temperature, alpha, 0, threshold_temperature); - //state.storeFunctor(cooling_schedule); - - //----------------------------------------------------------------------------- - - - //----------------------------------------------------------------------------- + // stopping criteria // ... and creates the parameter letters: C E g G s T - //----------------------------------------------------------------------------- - eoContinue< EOT >& eo_continue = do_make_continue(parser, state, eval); - - //----------------------------------------------------------------------------- - - - //----------------------------------------------------------------------------- + // population output - //----------------------------------------------------------------------------- - eoCheckPoint< EOT >& pop_continue = do_make_checkpoint(parser, state, eval, eo_continue); - - //----------------------------------------------------------------------------- - - - //----------------------------------------------------------------------------- + // distribution output - //----------------------------------------------------------------------------- - edoDummyContinue< Distrib >* dummy_continue = new edoDummyContinue< Distrib >(); state.storeFunctor(dummy_continue); edoCheckPoint< Distrib >* distribution_continue = new edoCheckPoint< Distrib >( *dummy_continue ); state.storeFunctor(distribution_continue); - //----------------------------------------------------------------------------- - - - //----------------------------------------------------------------------------- // eoEPRemplacement causes the using of the current and previous // sample for sampling. - //----------------------------------------------------------------------------- - eoReplacement< EOT >* replacor = new eoEPReplacement< EOT >(pop.size()); - - // Below, use eoGenerationalReplacement to sample only on the current sample - - //eoReplacement< EOT >* replacor = new eoGenerationalReplacement< EOT >(); // FIXME: to define the size - state.storeFunctor(replacor); - - //----------------------------------------------------------------------------- - - - //----------------------------------------------------------------------------- + // Some stuff to display helper when we are using -h option - //----------------------------------------------------------------------------- - if (parser.userNeedsHelp()) - { - parser.printHelp(std::cout); - exit(1); - } + { + parser.printHelp(std::cout); + exit(1); + } // Help + Verbose routines - make_verbose(parser); make_help(parser); - //----------------------------------------------------------------------------- - - - //----------------------------------------------------------------------------- // population output (after helper) // - // FIXME: theses objects are instanciate there in order to avoid a folder - // removing as doFileSnapshot does within ctor. - //----------------------------------------------------------------------------- - + // FIXME: theses objects are instanciated there in order to avoid a folder + // removing as edoFileSnapshot does within ctor. edoPopStat< EOT >* popStat = new edoPopStat; state.storeFunctor(popStat); pop_continue.add(*popStat); @@ -249,13 +142,7 @@ int main(int ac, char** av) fileSnapshot->add(*popStat); pop_continue.add(*fileSnapshot); - //----------------------------------------------------------------------------- - - - //----------------------------------------------------------------------------- // distribution output (after helper) - //----------------------------------------------------------------------------- - edoDistribStat< Distrib >* distrib_stat = new edoStatNormalMulti< EOT >(); state.storeFunctor(distrib_stat); @@ -271,42 +158,24 @@ int main(int ac, char** av) file_monitor->add(*distrib_stat); distribution_continue->add( *file_monitor ); - //----------------------------------------------------------------------------- + eoPopLoopEval popEval( eval ); - - //----------------------------------------------------------------------------- // EDA algorithm configuration - //----------------------------------------------------------------------------- - edoAlgo< Distrib >* algo = new edoEDA< Distrib > - (*selector, *estimator, *selectone, *modifier, *sampler, - pop_continue, *distribution_continue, - eval, - //*sa_continue, *cooling_schedule, initial_temperature, - *replacor); + (*selector, *estimator, *sampler, + pop_continue, *distribution_continue, + popEval, *replacor); - //----------------------------------------------------------------------------- - - - //----------------------------------------------------------------------------- // Beginning of the algorithm call - //----------------------------------------------------------------------------- + try { + do_run(*algo, pop); - try - { - do_run(*algo, pop); - } - catch (eoEvalFuncCounterBounderException& e) - { - eo::log << eo::warnings << "warning: " << e.what() << std::endl; - } - catch (std::exception& e) - { - eo::log << eo::errors << "error: " << e.what() << std::endl; - exit(EXIT_FAILURE); - } - - //----------------------------------------------------------------------------- + } catch (eoEvalFuncCounterBounderException& e) { + eo::log << eo::warnings << "warning: " << e.what() << std::endl; + } catch (std::exception& e) { + eo::log << eo::errors << "error: " << e.what() << std::endl; + exit(EXIT_FAILURE); + } return 0; } diff --git a/edo/install.cmake-dist b/edo/install.cmake-dist index bd07be7c8..99d4166ba 100644 --- a/edo/install.cmake-dist +++ b/edo/install.cmake-dist @@ -8,7 +8,7 @@ SET(MO_DIR "<>" CACHE PATH "MO directory" FORCE) SET(EO_INCLUDE_DIRS "${EO_DIR}/src" CACHE PATH "EO include directory" FORCE) SET(EO_LIBRARY_DIRS "${EO_DIR}/release/lib" CACHE PATH "EO library directory" FORCE) -SET(EO_LIBRARIES "eoutils eo es ga cma gcov") +SET(EO_LIBRARIES eoutils eo es ga cma gcov) # do not use quotes around this list or it will fail SET(MO_INCLUDE_DIRS "${MO_DIR}/src" CACHE PATH "MO include directory" FORCE) SET(MO_LIBRARY_DIRS "${MO_DIR}/release/lib" CACHE PATH "MO library directory" FORCE) diff --git a/edo/src/edo b/edo/src/edo index 1a6a2c682..69f13f116 100644 --- a/edo/src/edo +++ b/edo/src/edo @@ -56,10 +56,14 @@ Authors: #include "edoVectorBounds.h" +#include "edoRepairer.h" +#include "edoRepairerDispatcher.h" +#include "edoRepairerRound.h" #include "edoBounder.h" #include "edoBounderNo.h" #include "edoBounderBound.h" #include "edoBounderRng.h" +#include "edoBounderUniform.h" #include "edoContinue.h" #include "utils/edoCheckPoint.h" diff --git a/edo/src/edoAlgo.h b/edo/src/edoAlgo.h index db0c7fe52..b91a5c2ab 100644 --- a/edo/src/edoAlgo.h +++ b/edo/src/edoAlgo.h @@ -31,14 +31,19 @@ Authors: #include -//! edoAlgo< D > - +/** An EDO algorithm difffers from a canonical EO algorithm because it is + * templatized on a Distribution rather than just an EOT. + * + * Derivating from an eoAlgo, it should define an operator()( EOT sol ) + */ template < typename D > class edoAlgo : public eoAlgo< typename D::EOType > { //! Alias for the type typedef typename D::EOType EOT; + // virtual R operator()(A1) = 0; (defined in eoUF) + public: virtual ~edoAlgo(){} }; diff --git a/edo/src/edoBounder.h b/edo/src/edoBounder.h index 0ab5f275c..8f418aa8d 100644 --- a/edo/src/edoBounder.h +++ b/edo/src/edoBounder.h @@ -28,19 +28,26 @@ Authors: #ifndef _edoBounder_h #define _edoBounder_h -#include - -//! edoBounder< EOT > +#include +/** The interface of a set of classes that modifies a solution so as to respect + * a given set of bounds (typically an hypercube). + * + * @ingroup Repairers + */ template < typename EOT > -class edoBounder : public eoUF< EOT&, void > +class edoBounder : public edoRepairer< EOT > { public: - edoBounder( EOT min = EOT(1, 0), EOT max = EOT(1, 0) ) - : _min(min), _max(max) + edoBounder() + {} + + + edoBounder( EOT min/* = EOT(1, 0)*/, EOT max/* = EOT(1, 1)*/ ) + : _min(min), _max(max) { - assert(_min.size() > 0); - assert(_min.size() == _max.size()); + assert(_min.size() > 0); + assert(_min.size() == _max.size()); } // virtual void operator()( EOT& ) = 0 (provided by eoUF< A1, R >) diff --git a/edo/src/edoBounderBound.h b/edo/src/edoBounderBound.h index 31a4e5867..36ad53144 100644 --- a/edo/src/edoBounderBound.h +++ b/edo/src/edoBounderBound.h @@ -30,34 +30,36 @@ Authors: #include "edoBounder.h" -//! edoBounderBound< EOT > - +/** A bounder that correct an incorrect variable by setting it to the min/max + * + * @ingroup Repairers + */ template < typename EOT > class edoBounderBound : public edoBounder< EOT > { public: edoBounderBound( EOT min, EOT max ) - : edoBounder< EOT >( min, max ) + : edoBounder< EOT >( min, max ) {} void operator()( EOT& x ) { - unsigned int size = x.size(); - assert(size > 0); + unsigned int size = x.size(); + assert(size > 0); - for (unsigned int d = 0; d < size; ++d) // browse all dimensions - { - if (x[d] < this->min()[d]) - { - x[d] = this->min()[d]; - continue; - } + for (unsigned int d = 0; d < size; ++d) // browse all dimensions + { + if (x[d] < this->min()[d]) + { + x[d] = this->min()[d]; + continue; + } - if (x[d] > this->max()[d]) - { - x[d] = this->max()[d]; - } - } + if (x[d] > this->max()[d]) + { + x[d] = this->max()[d]; + } + } } }; diff --git a/edo/src/edoBounderNo.h b/edo/src/edoBounderNo.h index f0e45454b..33416d56d 100644 --- a/edo/src/edoBounderNo.h +++ b/edo/src/edoBounderNo.h @@ -30,8 +30,10 @@ Authors: #include "edoBounder.h" -//! edoBounderNo< EOT > - +/** A bounder that does nothing. + * + * @ingroup Repairers + */ template < typename EOT > class edoBounderNo : public edoBounder< EOT > { diff --git a/edo/src/edoBounderRng.h b/edo/src/edoBounderRng.h index 2501a212c..bfe6cb712 100644 --- a/edo/src/edoBounderRng.h +++ b/edo/src/edoBounderRng.h @@ -30,31 +30,34 @@ Authors: #include "edoBounder.h" -//! edoBounderRng< EOT > - +/** A bounder that randomly draw new values for variables going out bounds, + * using an eoRng to do so. + * + * @ingroup Repairers + */ template < typename EOT > class edoBounderRng : public edoBounder< EOT > { public: edoBounderRng( EOT min, EOT max, eoRndGenerator< double > & rng ) - : edoBounder< EOT >( min, max ), _rng(rng) + : edoBounder< EOT >( min, max ), _rng(rng) {} void operator()( EOT& x ) { - unsigned int size = x.size(); - assert(size > 0); + unsigned int size = x.size(); + assert(size > 0); - for (unsigned int d = 0; d < size; ++d) // browse all dimensions - { + for (unsigned int d = 0; d < size; ++d) // browse all dimensions + { - // FIXME: attention: les bornes RNG ont les memes bornes quelque soit les dimensions idealement on voudrait avoir des bornes differentes pour chaque dimensions. + // FIXME: attention: les bornes RNG ont les memes bornes quelque soit les dimensions idealement on voudrait avoir des bornes differentes pour chaque dimensions. - if (x[d] < this->min()[d] || x[d] > this->max()[d]) - { - x[d] = _rng(); - } - } + if (x[d] < this->min()[d] || x[d] > this->max()[d]) + { + x[d] = _rng(); + } + } } private: diff --git a/edo/src/edoBounderUniform.h b/edo/src/edoBounderUniform.h index 6501a481d..c90317c7a 100644 --- a/edo/src/edoBounderUniform.h +++ b/edo/src/edoBounderUniform.h @@ -29,28 +29,35 @@ Authors: #include "edoBounder.h" -//! edoBounderUniform< EOT > - +/** A bounder that randomly draw new values for variables going out bounds, + * in a given uniform distribution. + * + * @ingroup Repairers + */ template < typename EOT > class edoBounderUniform : public edoBounder< EOT > { public: edoBounderUniform( EOT min, EOT max ) - : edoBounder< EOT >( min, max ) - {} + : edoBounder< EOT >( min, max ) + { + } void operator()( EOT& sol ) { - unsigned int size = sol.size(); - assert(size > 0); + assert( this->min().size() > 0 ); + assert( this->max().size() > 0 ); - for (unsigned int d = 0; d < size; ++d) { + assert( sol.size() > 0); - if ( sol[d] < this->min()[d] || sol[d] > this->max()[d]) { - // use EO's global "rng" - sol[d] = rng.uniform( this->min()[d], this->max()[d] ); - } - } // for d in size + unsigned int size = sol.size(); + for (unsigned int d = 0; d < size; ++d) { + + if ( sol[d] < this->min()[d] || sol[d] > this->max()[d]) { + // use EO's global "rng" + sol[d] = rng.uniform( this->min()[d], this->max()[d] ); + } + } // for d in size } }; diff --git a/edo/src/edoEDA.h b/edo/src/edoEDA.h index 51028efc9..f94e828f5 100644 --- a/edo/src/edoEDA.h +++ b/edo/src/edoEDA.h @@ -58,217 +58,138 @@ public: //! edoEDA constructor /*! - All the boxes used by a EDASA need to be given. + Takes algo operators, all are mandatory - \param selector Population Selector - \param estimator Distribution Estimator - \param selectone SelectOne - \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 Population replacor + \param evaluation Evaluate a population + \param selector Selection of the best candidate solutions in the population + \param estimator Estimation of the distribution parameters + \param sampler Generate feasible solutions using the distribution + \param replacor Replace old solutions by new ones + \param pop_continuator Stopping criterion based on the population features + \param distribution_continuator Stopping criterion based on the distribution features */ - edoEDA (eoSelect< EOT > & selector, - edoEstimator< D > & estimator, - eoSelectOne< EOT > & selectone, - edoModifierMass< D > & modifier, - edoSampler< D > & sampler, - eoContinue< EOT > & pop_continue, - edoContinue< D > & distribution_continue, - eoEvalFunc < EOT > & evaluation, - //moContinuator< moDummyNeighbor > & sa_continue, - //moCoolingSchedule & cooling_schedule, - //double initial_temperature, - eoReplacement< EOT > & replacor - ) - : _selector(selector), - _estimator(estimator), - _selectone(selectone), - _modifier(modifier), - _sampler(sampler), - _pop_continue(pop_continue), - _distribution_continue(distribution_continue), - _evaluation(evaluation), - //_sa_continue(sa_continue), - //_cooling_schedule(cooling_schedule), - //_initial_temperature(initial_temperature), - _replacor(replacor) - + edoEDA ( + eoPopEvalFunc < EOT > & evaluator, + eoSelect< EOT > & selector, + edoEstimator< D > & estimator, + edoSampler< D > & sampler, + eoReplacement< EOT > & replacor, + eoContinue< EOT > & pop_continuator, + edoContinue< D > & distribution_continuator + ) : + _evaluator(evaluator), + _selector(selector), + _estimator(estimator), + _sampler(sampler), + _replacor(replacor), + _pop_continuator(pop_continuator), + _dummy_continue(), + _distribution_continuator(distribution_continuator) {} - //! function that launches the EDASA algorithm. + //! edoEDA constructor without an edoContinue /*! - As a moTS or a moHC, the EDASA can be used for HYBRIDATION in an evolutionary algorithm. + Takes algo operators, all are mandatory - \param pop A population to improve. - \return TRUE. + \param evaluation Evaluate a population + \param selector Selection of the best candidate solutions in the population + \param estimator Estimation of the distribution parameters + \param sampler Generate feasible solutions using the distribution + \param replacor Replace old solutions by new ones + \param pop_continuator Stopping criterion based on the population features + */ + edoEDA ( + eoPopEvalFunc < EOT > & evaluator, + eoSelect< EOT > & selector, + edoEstimator< D > & estimator, + edoSampler< D > & sampler, + eoReplacement< EOT > & replacor, + eoContinue< EOT > & pop_continuator + ) : + _evaluator(evaluator), + _selector(selector), + _estimator(estimator), + _sampler(sampler), + _replacor(replacor), + _pop_continuator(pop_continuator), + _dummy_continue(), + _distribution_continuator( _dummy_continue ) + {} + + + /** A basic EDA algorithm that iterates over: + * selection, estimation, sampling, bounding, evaluation, replacement + * + * \param pop the population of candidate solutions + * \return void */ void operator ()(eoPop< EOT > & pop) { - assert(pop.size() > 0); + assert(pop.size() > 0); - //double temperature = _initial_temperature; + eoPop< EOT > current_pop; + eoPop< EOT > selected_pop; - eoPop< EOT > current_pop; + // FIXME one must instanciate a first distrib here because there is no empty constructor, see if it is possible to instanciate Distributions without parameters + D distrib = _estimator(pop); - eoPop< EOT > selected_pop; + // Evaluating a first time the candidate solutions + // The first pop is not supposed to be evaluated (@see eoPopLoopEval). + _evaluator( current_pop, pop ); + do { + // (1) Selection of the best points in the population + //selected_pop.clear(); // FIXME is it necessary to clear? + _selector(pop, selected_pop); + assert( selected_pop.size() > 0 ); + // TODO: utiliser selected_pop ou pop ??? - //------------------------------------------------------------- - // Estimating a first time the distribution parameter thanks - // to population. - //------------------------------------------------------------- + // (2) Estimation of the distribution parameters + distrib = _estimator(selected_pop); - D distrib = _estimator(pop); + // (3) sampling + // The sampler produces feasible solutions (@see edoSampler that + // encapsulate an edoBounder) + current_pop.clear(); + for( unsigned int i = 0; i < pop.size(); ++i ) { + current_pop.push_back( _sampler(distrib) ); + } - double size = distrib.size(); - assert(size > 0); + // (4) Evaluate new solutions + _evaluator( pop, current_pop ); - //------------------------------------------------------------- + // (5) Replace old solutions by new ones + _replacor(pop, current_pop); // e.g. copy current_pop in pop - - do - { - //------------------------------------------------------------- - // (3) Selection of the best points in the population - //------------------------------------------------------------- - - selected_pop.clear(); - - _selector(pop, selected_pop); - - assert( selected_pop.size() > 0 ); - - //------------------------------------------------------------- - - - //------------------------------------------------------------- - // (4) Estimation of the distribution parameters - //------------------------------------------------------------- - - distrib = _estimator(selected_pop); - - //------------------------------------------------------------- - - - // TODO: utiliser selected_pop ou pop ??? - - assert(selected_pop.size() > 0); - - - //------------------------------------------------------------- - // Init of a variable contening a point with the bestest fitnesses - //------------------------------------------------------------- - - EOT current_solution = _selectone(selected_pop); - - //------------------------------------------------------------- - - - //------------------------------------------------------------- - // Fit the current solution with the distribution parameters (bounds) - //------------------------------------------------------------- - - // FIXME: si besoin de modifier la dispersion de la distribution - // _modifier_dispersion(distribution, selected_pop); - _modifier(distrib, current_solution); - - //------------------------------------------------------------- - - - //------------------------------------------------------------- - // Evaluating a first time the current solution - //------------------------------------------------------------- - - _evaluation( current_solution ); - - //------------------------------------------------------------- - - - //------------------------------------------------------------- - // Building of the sampler in current_pop - //------------------------------------------------------------- - - //_sa_continue.init( current_solution ); - - current_pop.clear(); - - for ( unsigned int i = 0; i < pop.size(); ++i ) - //do - { - EOT candidate_solution = _sampler(distrib); - _evaluation( candidate_solution ); - - // TODO: verifier le critere d'acceptation - if ( candidate_solution.fitness() < current_solution.fitness() - // || rng.uniform() < exp( ::fabs(candidate_solution.fitness() - current_solution.fitness()) / temperature ) - ) - { - current_pop.push_back(candidate_solution); - current_solution = candidate_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 ( 1 ); - } + } while( _distribution_continuator( distrib ) && _pop_continuator( pop ) ); + } // operator() private: + //! A full evaluation function. + eoPopEvalFunc < EOT > & _evaluator; + //! A EOT selector eoSelect < EOT > & _selector; //! A EOT estimator. It is going to estimate distribution parameters. edoEstimator< D > & _estimator; - //! SelectOne - eoSelectOne< EOT > & _selectone; - - //! A D modifier - edoModifierMass< D > & _modifier; - //! A D sampler edoSampler< D > & _sampler; - //! A EOT population continuator - eoContinue < EOT > & _pop_continue; - - //! A D continuator - edoContinue < D > & _distribution_continue; - - //! A full evaluation function. - eoEvalFunc < EOT > & _evaluation; - - //! Stopping criterion before temperature update - //moContinuator< moDummyNeighbor > & _sa_continue; - - //! The cooling schedule - //moCoolingSchedule & _cooling_schedule; - - //! Initial temperature - //double _initial_temperature; - //! A EOT replacor eoReplacement < EOT > & _replacor; + + //! A EOT population continuator + eoContinue < EOT > & _pop_continuator; + + //! A D continuator that always return true + edoDummyContinue _dummy_continue; + + //! A D continuator + edoContinue < D > & _distribution_continuator; + }; #endif // !_edoEDA_h diff --git a/edo/src/edoEstimatorNormalMono.h b/edo/src/edoEstimatorNormalMono.h index 6a42114b5..c5ddade40 100644 --- a/edo/src/edoEstimatorNormalMono.h +++ b/edo/src/edoEstimatorNormalMono.h @@ -42,57 +42,57 @@ public: class Variance { public: - Variance() : _sumvar(0){} + Variance() : _sumvar(0){} - void update(AtomType v) - { - _n++; + void update(AtomType v) + { + _n++; - AtomType d = v - _mean; + AtomType d = v - _mean; - _mean += 1 / _n * d; - _sumvar += (_n - 1) / _n * d * d; - } + _mean += 1 / _n * d; + _sumvar += (_n - 1) / _n * d * d; + } - AtomType get_mean() const {return _mean;} - AtomType get_var() const {return _sumvar / (_n - 1);} - AtomType get_std() const {return sqrt( get_var() );} + AtomType get_mean() const {return _mean;} + AtomType get_var() const {return _sumvar / (_n - 1);} + AtomType get_std() const {return sqrt( get_var() );} private: - AtomType _n; - AtomType _mean; - AtomType _sumvar; + AtomType _n; + AtomType _mean; + AtomType _sumvar; }; public: edoNormalMono< EOT > operator()(eoPop& pop) { - unsigned int popsize = pop.size(); - assert(popsize > 0); + unsigned int popsize = pop.size(); + assert(popsize > 0); - unsigned int dimsize = pop[0].size(); - assert(dimsize > 0); + unsigned int dimsize = pop[0].size(); + assert(dimsize > 0); - std::vector< Variance > var( dimsize ); + std::vector< Variance > var( dimsize ); - for (unsigned int i = 0; i < popsize; ++i) - { - for (unsigned int d = 0; d < dimsize; ++d) - { - var[d].update( pop[i][d] ); - } - } + for (unsigned int i = 0; i < popsize; ++i) + { + for (unsigned int d = 0; d < dimsize; ++d) + { + var[d].update( pop[i][d] ); + } + } - EOT mean( dimsize ); - EOT variance( dimsize ); + EOT mean( dimsize ); + EOT variance( dimsize ); - for (unsigned int d = 0; d < dimsize; ++d) - { - mean[d] = var[d].get_mean(); - variance[d] = var[d].get_var(); - } + for (unsigned int d = 0; d < dimsize; ++d) + { + mean[d] = var[d].get_mean(); + variance[d] = var[d].get_var(); + } - return edoNormalMono< EOT >( mean, variance ); + return edoNormalMono< EOT >( mean, variance ); } }; diff --git a/edo/src/edoRepairer.h b/edo/src/edoRepairer.h new file mode 100644 index 000000000..8ea2366ab --- /dev/null +++ b/edo/src/edoRepairer.h @@ -0,0 +1,47 @@ +/* +The Evolving Distribution Objects framework (EDO) is a template-based, +ANSI-C++ evolutionary computation library which helps you to write your +own estimation of distribution algorithms. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Copyright (C) 2011 Thales group +*/ +/* +Authors: + Johann Dréo + Pierre Savéant +*/ + +#ifndef _edoRepairer_h +#define _edoRepairer_h + +#include + +/** The interface of a set of classes that modifies an unfeasible candidate + * solution so as to respect a given set of constraints and thus make a feasible + * solution. + * + * @ingroup Repairers + */ +template < typename EOT > +class edoRepairer : public eoUF< EOT&, void > +{ +public: + // virtual void operator()( EOT& ) = 0 (provided by eoUF< A1, R >) + virtual void operator()( EOT& ) {} +}; + +#endif // !_edoRepairer_h diff --git a/edo/src/edoRepairerDispatcher.h b/edo/src/edoRepairerDispatcher.h new file mode 100644 index 000000000..96c07da5d --- /dev/null +++ b/edo/src/edoRepairerDispatcher.h @@ -0,0 +1,115 @@ +/* +The Evolving Distribution Objects framework (EDO) is a template-based, +ANSI-C++ evolutionary computation library which helps you to write your +own estimation of distribution algorithms. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Copyright (C) 2011 Thales group +*/ +/* +Authors: + Johann Dréo + Pierre Savéant +*/ + +#ifndef _edoRepairerDispatcher_h +#define _edoRepairerDispatcher_h + +#include +#include +#include + +#include "edoRepairer.h" + +/** Repair a candidate solution by sequentially applying several repairers on + * subparts of the solution (subparts being defined by the corresponding set + * of indexes). + * + * Only work on EOT that implements the "push_back( EOT::AtomType )" and + * "operator[](uint)" and "at(uint)" methods. + * + * Expects _addresses_ of the repairer operators. + * + * @example t-dispatcher-round.cpp + * + * @ingroup Repairers + */ + +template < typename EOT > +class edoRepairerDispatcher + : public edoRepairer, + std::vector< + std::pair< std::set< unsigned int >, edoRepairer< EOT >* > + > +{ +public: + //! Empty constructor + edoRepairerDispatcher() : + std::vector< + std::pair< std::set< unsigned int >, edoRepairer< EOT >* > + >() + {} + + //! Constructor with a single index set and repairer operator + edoRepairerDispatcher( std::set idx, edoRepairer* op ) : + std::vector< + std::pair< std::set< unsigned int >, edoRepairer< EOT >* > + >() + { + this->add( idx, op ); + } + + //! Add more indexes set and their corresponding repairer operator address to the list + void add( std::set idx, edoRepairer* op ) + { + assert( idx.size() > 0 ); + assert( op != NULL ); + + this->push_back( std::make_pair(idx, op) ); + } + + //! Repair a solution by calling several repair operator on subset of indexes + virtual void operator()( EOT& sol ) + { + // ipair is an iterator that points on a pair + for( typename edoRepairerDispatcher::iterator ipair = this->begin(); ipair != this->end(); ++ipair ) { + // a partial copy of the sol + EOT partsol; + + // j is an iterator that points on an uint + for( std::set< unsigned int >::iterator j = ipair->first.begin(); j != ipair->first.end(); ++j ) { + partsol.push_back( sol.at(*j) ); + } // for j + + assert( partsol.size() > 0 ); + + // apply the repairer on the partial copy + // the repairer is a functor, thus second is callable + (*(ipair->second))( partsol ); + + { // copy back the repaired partial solution to sol + // browse partsol with uint k, and the idx set with an iterator (std::set is an associative tab) + unsigned int k=0; + for( std::set< unsigned int >::iterator j = ipair->first.begin(); j != ipair->first.end(); ++j ) { + sol[ *j ] = partsol[ k ]; + k++; + } // for j + } // context for k + } // for ipair + } +}; + +#endif // !_edoRepairerDispatcher_h diff --git a/edo/src/edoRepairerRound.h b/edo/src/edoRepairerRound.h new file mode 100644 index 000000000..032169424 --- /dev/null +++ b/edo/src/edoRepairerRound.h @@ -0,0 +1,68 @@ +/* +The Evolving Distribution Objects framework (EDO) is a template-based, +ANSI-C++ evolutionary computation library which helps you to write your +own estimation of distribution algorithms. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Copyright (C) 2011 Thales group +*/ +/* +Authors: + Johann Dréo + Pierre Savéant +*/ + +#ifndef _edoRepairerRound_h +#define _edoRepairerRound_h + +#include + +#include "edoRepairer.h" + +/** + * + * @ingroup Repairers + */ +template < typename EOT > +class edoRepairerFloor : public edoRepairer +{ +public: + virtual void operator()( EOT& sol ) + { + for( unsigned int i=0; i < sol.size(); ++i ) { + sol[i] = floor( sol[i] ); + } + } +}; + +/** + * + * @ingroup Repairers + */ +template < typename EOT > +class edoRepairerCeil : public edoRepairer +{ +public: + virtual void operator()( EOT& sol ) + { + for( unsigned int i=0; i < sol.size(); ++i ) { + sol[i] = ceil( sol[i] ); + } + } +}; + + +#endif // !_edoRepairerRound_h diff --git a/edo/src/edoSampler.h b/edo/src/edoSampler.h index 3e4dd0bde..bb0f8b6d0 100644 --- a/edo/src/edoSampler.h +++ b/edo/src/edoSampler.h @@ -30,7 +30,7 @@ Authors: #include -#include "edoBounder.h" +#include "edoRepairer.h" #include "edoBounderNo.h" //! edoSampler< D > @@ -41,47 +41,34 @@ class edoSampler : public eoUF< D&, typename D::EOType > public: typedef typename D::EOType EOType; - edoSampler(edoBounder< EOType > & bounder) - : /*_dummy_bounder(),*/ _bounder(bounder) + edoSampler(edoRepairer< EOType > & repairer) + : _dummy_repairer(), _repairer(repairer) {} - /* + edoSampler() - : _dummy_bounder(), _bounder( _dummy_bounder ) + : _dummy_repairer(), _repairer( _dummy_repairer ) {} - */ + // virtual EOType operator()( D& ) = 0 (provided by eoUF< A1, R >) EOType operator()( D& distrib ) { - unsigned int size = distrib.size(); - assert(size > 0); + unsigned int size = distrib.size(); + assert(size > 0); + // Point we want to sample to get higher a set of points + // (coordinates in n dimension) + // x = {x1, x2, ..., xn} + // the sample method is implemented in the derivated class + EOType solution(sample(distrib)); - //------------------------------------------------------------- - // Point we want to sample to get higher a set of points - // (coordinates in n dimension) - // x = {x1, x2, ..., xn} - // the sample method is implemented in the derivated class - //------------------------------------------------------------- + // Now we are bounding the distribution thanks to min and max + // parameters. + _repairer(solution); - EOType solution(sample(distrib)); - - //------------------------------------------------------------- - - - //------------------------------------------------------------- - // Now we are bounding the distribution thanks to min and max - // parameters. - //------------------------------------------------------------- - - _bounder(solution); - - //------------------------------------------------------------- - - - return solution; + return solution; } protected: @@ -89,10 +76,10 @@ protected: virtual EOType sample( D& ) = 0; private: - //edoBounderNo _dummy_bounder; + edoBounderNo _dummy_repairer; - //! Bounder functor - edoBounder< EOType > & _bounder; + //! repairer functor + edoRepairer< EOType > & _repairer; }; diff --git a/edo/src/edoSamplerNormalMono.h b/edo/src/edoSamplerNormalMono.h index b52ad2836..b3162f92f 100644 --- a/edo/src/edoSamplerNormalMono.h +++ b/edo/src/edoSamplerNormalMono.h @@ -39,52 +39,37 @@ Authors: * This class uses the NormalMono distribution parameters (bounds) to return * a random position used for population sampling. */ -template < typename EOT > -class edoSamplerNormalMono : public edoSampler< edoNormalMono< EOT > > +template < typename EOT, typename D = edoNormalMono< EOT > > +class edoSamplerNormalMono : public edoSampler< D > { public: typedef typename EOT::AtomType AtomType; - edoSamplerNormalMono( edoBounder< EOT > & bounder ) - : edoSampler< edoNormalMono< EOT > >( bounder ) - {} + edoSamplerNormalMono( edoRepairer & repairer ) : edoSampler< D >( repairer) {} EOT sample( edoNormalMono< EOT >& distrib ) { - unsigned int size = distrib.size(); - assert(size > 0); + unsigned int size = distrib.size(); + assert(size > 0); + // Point we want to sample to get higher a set of points + // (coordinates in n dimension) + // x = {x1, x2, ..., xn} + EOT solution; + + // Sampling all dimensions + for (unsigned int i = 0; i < size; ++i) + { + AtomType mean = distrib.mean()[i]; + AtomType variance = distrib.variance()[i]; + AtomType random = rng.normal(mean, variance); - //------------------------------------------------------------- - // Point we want to sample to get higher a set of points - // (coordinates in n dimension) - // x = {x1, x2, ..., xn} - //------------------------------------------------------------- + assert(variance >= 0); - EOT solution; + solution.push_back(random); + } - //------------------------------------------------------------- - - - //------------------------------------------------------------- - // Sampling all dimensions - //------------------------------------------------------------- - - for (unsigned int i = 0; i < size; ++i) - { - AtomType mean = distrib.mean()[i]; - AtomType variance = distrib.variance()[i]; - AtomType random = rng.normal(mean, variance); - - assert(variance >= 0); - - solution.push_back(random); - } - - //------------------------------------------------------------- - - - return solution; + return solution; } }; diff --git a/edo/src/edoSamplerNormalMulti.h b/edo/src/edoSamplerNormalMulti.h index 2601ea77e..7c08d22b5 100644 --- a/edo/src/edoSamplerNormalMulti.h +++ b/edo/src/edoSamplerNormalMulti.h @@ -34,142 +34,144 @@ Authors: //! edoSamplerNormalMulti< EOT > -template< class EOT > -class edoSamplerNormalMulti : public edoSampler< edoNormalMulti< EOT > > +template< class EOT, typename D = edoNormalMulti< EOT > > +class edoSamplerNormalMulti : public edoSampler< D > { public: typedef typename EOT::AtomType AtomType; + edoSamplerNormalMulti( edoRepairer & repairer ) : edoSampler< D >( repairer) {} + class Cholesky { public: - Cholesky( const ublas::symmetric_matrix< AtomType, ublas::lower >& V) - { - unsigned int Vl = V.size1(); + Cholesky( const ublas::symmetric_matrix< AtomType, ublas::lower >& V) + { + unsigned int Vl = V.size1(); - assert(Vl > 0); + assert(Vl > 0); - unsigned int Vc = V.size2(); + unsigned int Vc = V.size2(); - assert(Vc > 0); + assert(Vc > 0); - assert( Vl == Vc ); + assert( Vl == Vc ); - _L.resize(Vl); + _L.resize(Vl); - unsigned int i,j,k; + unsigned int i,j,k; - // first column - i=0; + // first column + i=0; - // diagonal - j=0; - _L(0, 0) = sqrt( V(0, 0) ); + // diagonal + j=0; + _L(0, 0) = sqrt( V(0, 0) ); - // end of the column - for ( j = 1; j < Vc; ++j ) - { - _L(j, 0) = V(0, j) / _L(0, 0); - } + // end of the column + for ( j = 1; j < Vc; ++j ) + { + _L(j, 0) = V(0, j) / _L(0, 0); + } - // end of the matrix - for ( i = 1; i < Vl; ++i ) // each column - { + // end of the matrix + for ( i = 1; i < Vl; ++i ) // each column + { - // diagonal - double sum = 0.0; + // diagonal + double sum = 0.0; - for ( k = 0; k < i; ++k) - { - sum += _L(i, k) * _L(i, k); - } + for ( k = 0; k < i; ++k) + { + sum += _L(i, k) * _L(i, k); + } - _L(i,i) = sqrt( fabs( V(i,i) - sum) ); + _L(i,i) = sqrt( fabs( V(i,i) - sum) ); - for ( j = i + 1; j < Vl; ++j ) // rows - { - // one element - sum = 0.0; + for ( j = i + 1; j < Vl; ++j ) // rows + { + // one element + sum = 0.0; - for ( k = 0; k < i; ++k ) - { - sum += _L(j, k) * _L(i, k); - } + for ( k = 0; k < i; ++k ) + { + sum += _L(j, k) * _L(i, k); + } - _L(j, i) = (V(j, i) - sum) / _L(i, i); - } - } - } + _L(j, i) = (V(j, i) - sum) / _L(i, i); + } + } + } - const ublas::symmetric_matrix< AtomType, ublas::lower >& get_L() const {return _L;} + const ublas::symmetric_matrix< AtomType, ublas::lower >& get_L() const {return _L;} private: - ublas::symmetric_matrix< AtomType, ublas::lower > _L; + ublas::symmetric_matrix< AtomType, ublas::lower > _L; }; edoSamplerNormalMulti( edoBounder< EOT > & bounder ) - : edoSampler< edoNormalMulti< EOT > >( bounder ) + : edoSampler< edoNormalMulti< EOT > >( bounder ) {} EOT sample( edoNormalMulti< EOT >& distrib ) { - unsigned int size = distrib.size(); + unsigned int size = distrib.size(); - assert(size > 0); + assert(size > 0); - //------------------------------------------------------------- - // Cholesky factorisation gererating matrix L from covariance - // matrix V. - // We must use cholesky.get_L() to get the resulting matrix. - // - // L = cholesky decomposition of varcovar - //------------------------------------------------------------- + //------------------------------------------------------------- + // Cholesky factorisation gererating matrix L from covariance + // matrix V. + // We must use cholesky.get_L() to get the resulting matrix. + // + // L = cholesky decomposition of varcovar + //------------------------------------------------------------- - Cholesky cholesky( distrib.varcovar() ); - ublas::symmetric_matrix< AtomType, ublas::lower > L = cholesky.get_L(); + Cholesky cholesky( distrib.varcovar() ); + ublas::symmetric_matrix< AtomType, ublas::lower > L = cholesky.get_L(); - //------------------------------------------------------------- + //------------------------------------------------------------- - //------------------------------------------------------------- - // T = vector of size elements drawn in N(0,1) rng.normal(1.0) - //------------------------------------------------------------- + //------------------------------------------------------------- + // T = vector of size elements drawn in N(0,1) rng.normal(1.0) + //------------------------------------------------------------- - ublas::vector< AtomType > T( size ); + ublas::vector< AtomType > T( size ); - for ( unsigned int i = 0; i < size; ++i ) - { - T( i ) = rng.normal( 1.0 ); - } + for ( unsigned int i = 0; i < size; ++i ) + { + T( i ) = rng.normal( 1.0 ); + } - //------------------------------------------------------------- + //------------------------------------------------------------- - //------------------------------------------------------------- - // LT = prod( L, T ) - //------------------------------------------------------------- + //------------------------------------------------------------- + // LT = prod( L, T ) + //------------------------------------------------------------- - ublas::vector< AtomType > LT = ublas::prod( L, T ); + ublas::vector< AtomType > LT = ublas::prod( L, T ); - //------------------------------------------------------------- + //------------------------------------------------------------- - //------------------------------------------------------------- - // solution = means + LT - //------------------------------------------------------------- + //------------------------------------------------------------- + // solution = means + LT + //------------------------------------------------------------- - ublas::vector< AtomType > mean = distrib.mean(); + ublas::vector< AtomType > mean = distrib.mean(); - ublas::vector< AtomType > ublas_solution = mean + LT; + ublas::vector< AtomType > ublas_solution = mean + LT; - EOT solution( size ); + EOT solution( size ); - std::copy( ublas_solution.begin(), ublas_solution.end(), solution.begin() ); + std::copy( ublas_solution.begin(), ublas_solution.end(), solution.begin() ); - //------------------------------------------------------------- + //------------------------------------------------------------- - return solution; + return solution; } }; diff --git a/edo/src/edoSamplerUniform.h b/edo/src/edoSamplerUniform.h index dbb8f4124..44a59ea87 100644 --- a/edo/src/edoSamplerUniform.h +++ b/edo/src/edoSamplerUniform.h @@ -38,58 +38,34 @@ Authors: * This class uses the Uniform distribution parameters (bounds) to return * a random position used for population sampling. */ -template < typename EOT, class D=edoUniform > // FIXME: D template name is there really used ?!? -class edoSamplerUniform : public edoSampler< edoUniform< EOT > > +template < typename EOT, class D = edoUniform > +class edoSamplerUniform : public edoSampler< D > { public: typedef D Distrib; - edoSamplerUniform(edoBounder< EOT > & bounder) - : edoSampler< edoUniform >(bounder) // FIXME: Why D is not used here ? - {} - - /* - edoSamplerUniform() - : edoSampler< edoUniform >() - {} - */ + edoSamplerUniform( edoRepairer & repairer ) : edoSampler< D >( repairer) {} EOT sample( edoUniform< EOT >& distrib ) { - unsigned int size = distrib.size(); - assert(size > 0); + unsigned int size = distrib.size(); + assert(size > 0); + // Point we want to sample to get higher a set of points + // (coordinates in n dimension) + // x = {x1, x2, ..., xn} + EOT solution; - //------------------------------------------------------------- - // Point we want to sample to get higher a set of points - // (coordinates in n dimension) - // x = {x1, x2, ..., xn} - //------------------------------------------------------------- + // Sampling all dimensions + for (unsigned int i = 0; i < size; ++i) + { + double min = distrib.min()[i]; + double max = distrib.max()[i]; + double random = rng.uniform(min, max); + solution.push_back(random); + } - EOT solution; - - //------------------------------------------------------------- - - - //------------------------------------------------------------- - // Sampling all dimensions - //------------------------------------------------------------- - - for (unsigned int i = 0; i < size; ++i) - { - double min = distrib.min()[i]; - double max = distrib.max()[i]; - double random = rng.uniform(min, max); - - assert(min <= random && random <= max); - - solution.push_back(random); - } - - //------------------------------------------------------------- - - - return solution; + return solution; } }; diff --git a/edo/src/edoUniform.h b/edo/src/edoUniform.h index 37bf065b8..3317e1afe 100644 --- a/edo/src/edoUniform.h +++ b/edo/src/edoUniform.h @@ -38,7 +38,7 @@ class edoUniform : public edoDistrib< EOT >, public edoVectorBounds< EOT > { public: edoUniform(EOT min, EOT max) - : edoVectorBounds< EOT >(min, max) + : edoVectorBounds< EOT >(min, max) {} }; diff --git a/edo/src/edoVectorBounds.h b/edo/src/edoVectorBounds.h index 635132cd4..4fc64aa68 100644 --- a/edo/src/edoVectorBounds.h +++ b/edo/src/edoVectorBounds.h @@ -35,10 +35,10 @@ class edoVectorBounds { public: edoVectorBounds(EOT min, EOT max) - : _min(min), _max(max) + : _min(min), _max(max) { - assert(_min.size() > 0); - assert(_min.size() == _max.size()); + assert(_min.size() > 0); + assert(_min.size() == _max.size()); } EOT min(){return _min;} @@ -46,8 +46,8 @@ public: unsigned int size() { - assert(_min.size() == _max.size()); - return _min.size(); + assert(_min.size() == _max.size()); + return _min.size(); } private: diff --git a/edo/test/CMakeLists.txt b/edo/test/CMakeLists.txt index aea8eaee2..acdabc7b7 100644 --- a/edo/test/CMakeLists.txt +++ b/edo/test/CMakeLists.txt @@ -38,6 +38,7 @@ SET(SOURCES t-bounderno t-uniform t-continue + t-dispatcher-round ) FOREACH(current ${SOURCES}) diff --git a/edo/test/t-dispatcher-round.cpp b/edo/test/t-dispatcher-round.cpp new file mode 100644 index 000000000..245a2e2cb --- /dev/null +++ b/edo/test/t-dispatcher-round.cpp @@ -0,0 +1,62 @@ +/* +The Evolving Distribution Objects framework (EDO) is a template-based, +ANSI-C++ evolutionary computation library which helps you to write your +own estimation of distribution algorithms. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Copyright (C) 2010 Thales group +*/ +/* +Authors: + Johann Dréo + Pierre Savéant +*/ + +#include +#include +#include + +typedef eoReal< eoMinimizingFitness > EOT; + +int main(void) +{ + EOT sol; + sol.push_back(1.1); + sol.push_back(1.1); + sol.push_back(3.9); + sol.push_back(3.9); + // we expect {1,2,3,4} + + edoRepairer* rep1 = new edoRepairerFloor(); + edoRepairer* rep2 = new edoRepairerCeil(); + + std::set indexes1; + indexes1.insert(0); + indexes1.insert(2); + + std::set indexes2; + indexes2.insert(1); + indexes2.insert(3); + + edoRepairerDispatcher repare( indexes1, rep1 ); + repare.add( indexes2, rep2 ); + + repare(sol); + + std::cout << sol << std::endl; + + return 0; +} diff --git a/eo/CMakeLists.txt b/eo/CMakeLists.txt index 5b8840017..d7ef8558a 100644 --- a/eo/CMakeLists.txt +++ b/eo/CMakeLists.txt @@ -1,3 +1,4 @@ + ###################################################################################### ### 0) If you want to set your variables in eo-conf.cmake and avoid the cmd line ###################################################################################### @@ -14,6 +15,9 @@ INCLUDE(eo-conf.cmake OPTIONAL) # set the project name and other variables PROJECT(EO) +# CMake > 2.8 is needed, because of the FindOpenMP feature +cmake_minimum_required(VERSION 2.8) + #SET(PROJECT_VERSION_MAJOR 1) #SET(PROJECT_VERSION_MINOR 1) #SET(PROJECT_VERSION_PATCH 1) @@ -26,9 +30,6 @@ SET(PACKAGE_NAME "Evolving Objects" CACHE STRING "Package name" FORCE) SET(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}"CACHE STRING "Package string full name" FORCE) SET(PACKAGE_TARNAME "eo" CACHE STRING "Package tar name" FORCE) -# check cmake version compatibility -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) - # regular expression checking INCLUDE_REGULAR_EXPRESSION("^.*$" "^$") diff --git a/website/index.html b/website/index.html index 5f6aaecac..09481644c 100644 --- a/website/index.html +++ b/website/index.html @@ -42,7 +42,8 @@
  • Download
  • Tutorial
  • FAQ
  • -
  • API documentation
  • +
  • EO documentation
  • +
  • EDO documentation
  • Project page
  • Contact us