diff --git a/edo/CMakeLists.txt b/edo/CMakeLists.txt index 9a07cd619..3cb182b3d 100644 --- a/edo/CMakeLists.txt +++ b/edo/CMakeLists.txt @@ -125,7 +125,7 @@ SET(SAMPLE_SRCS) ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(application) -ADD_SUBDIRECTORY(test) +#ADD_SUBDIRECTORY(test) ADD_SUBDIRECTORY(doc) ###################################################################################### diff --git a/edo/application/eda/main.cpp b/edo/application/eda/main.cpp index 075057186..6e024545b 100644 --- a/edo/application/eda/main.cpp +++ b/edo/application/eda/main.cpp @@ -161,7 +161,7 @@ int main(int ac, char** av) eoPopLoopEval popEval( eval ); // EDA algorithm configuration - edoAlgo< Distrib >* algo = new edoEDA< Distrib > + edoAlgo< Distrib >* algo = new edoAlgoStateless< Distrib > (popEval, *selector, *estimator, *sampler, *replacor, pop_continue, *distribution_continue ); diff --git a/edo/build_gcc_linux_release b/edo/build_gcc_linux_release index fb220d044..389d9b745 100755 --- a/edo/build_gcc_linux_release +++ b/edo/build_gcc_linux_release @@ -2,6 +2,7 @@ mkdir -p release cd release -cmake .. +cmake -DWITH_EIGEN=1 .. +#cmake -DWITH_BOOST=1 .. make cd .. diff --git a/edo/src/edo b/edo/src/edo index 0f7a06377..0da9ed9d4 100644 --- a/edo/src/edo +++ b/edo/src/edo @@ -30,17 +30,21 @@ Authors: #include "edoAlgo.h" //#include "edoEDASA.h" -#include "edoEDA.h" +#include "edoAlgoAdaptive.h" +#include "edoAlgoStateless.h" #include "edoDistrib.h" #include "edoUniform.h" #include "edoNormalMono.h" #include "edoNormalMulti.h" +#include "edoNormalAdaptive.h" #include "edoEstimator.h" #include "edoEstimatorUniform.h" #include "edoEstimatorNormalMono.h" #include "edoEstimatorNormalMulti.h" +#include "edoEstimatorAdaptive.h" +#include "edoEstimatorNormalAdaptive.h" #include "edoModifier.h" #include "edoModifierDispersion.h" @@ -53,6 +57,7 @@ Authors: #include "edoSamplerUniform.h" #include "edoSamplerNormalMono.h" #include "edoSamplerNormalMulti.h" +#include "edoSamplerNormalAdaptive.h" #include "edoVectorBounds.h" diff --git a/edo/src/edoAlgo.h b/edo/src/edoAlgo.h index b91a5c2ab..88ed3d63a 100644 --- a/edo/src/edoAlgo.h +++ b/edo/src/edoAlgo.h @@ -40,7 +40,7 @@ template < typename D > class edoAlgo : public eoAlgo< typename D::EOType > { //! Alias for the type - typedef typename D::EOType EOT; + typedef typename D::EOType EOType; // virtual R operator()(A1) = 0; (defined in eoUF) diff --git a/edo/src/edoEDA.h b/edo/src/edoEDA.h deleted file mode 100644 index f94e828f5..000000000 --- a/edo/src/edoEDA.h +++ /dev/null @@ -1,195 +0,0 @@ -/* -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 - Caner Candan -*/ - -#ifndef _edoEDA_h -#define _edoEDA_h - -#include -#include - -#include - -#include "edoAlgo.h" -#include "edoEstimator.h" -#include "edoModifierMass.h" -#include "edoSampler.h" -#include "edoContinue.h" - -//! edoEDA< D > - -template < typename D > -class edoEDA : public edoAlgo< D > -{ -public: - //! Alias for the type EOT - typedef typename D::EOType EOT; - - //! Alias for the atom type - typedef typename EOT::AtomType AtomType; - - //! Alias for the fitness - typedef typename EOT::Fitness Fitness; - -public: - - //! edoEDA constructor - /*! - Takes algo operators, all are mandatory - - \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 ( - 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) - {} - - //! edoEDA constructor without an edoContinue - /*! - Takes algo operators, all are mandatory - - \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); - - eoPop< EOT > current_pop; - eoPop< EOT > selected_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); - - // 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 ??? - - // (2) Estimation of the distribution parameters - distrib = _estimator(selected_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) ); - } - - // (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 - - } 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; - - //! A D sampler - edoSampler< D > & _sampler; - - //! 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/edoEDASA.h b/edo/src/edoEDASA.h index b2f0fe708..1966d54db 100644 --- a/edo/src/edoEDASA.h +++ b/edo/src/edoEDASA.h @@ -29,7 +29,7 @@ Authors: #define _edoEDASA_h #include -#include +//#include #include @@ -46,13 +46,13 @@ class edoEDASA : public edoAlgo< D > { public: //! Alias for the type EOT - typedef typename D::EOType EOT; + typedef typename D::EOType EOType; //! Alias for the atom type - typedef typename EOT::AtomType AtomType; + typedef typename EOType::AtomType AtomType; //! Alias for the fitness - typedef typename EOT::Fitness Fitness; + typedef typename EOType::Fitness Fitness; public: @@ -73,18 +73,18 @@ public: \param initial_temperature The initial temperature. \param replacor Population replacor */ - edoEDASA (eoSelect< EOT > & selector, + edoEDASA (eoSelect< EOType > & selector, edoEstimator< D > & estimator, - eoSelectOne< EOT > & selectone, + eoSelectOne< EOType > & selectone, edoModifierMass< D > & modifier, edoSampler< D > & sampler, - eoContinue< EOT > & pop_continue, + eoContinue< EOType > & pop_continue, edoContinue< D > & distribution_continue, - eoEvalFunc < EOT > & evaluation, - moContinuator< moDummyNeighbor > & sa_continue, - moCoolingSchedule & cooling_schedule, + eoEvalFunc < EOType > & evaluation, + moContinuator< moDummyNeighbor > & sa_continue, + moCoolingSchedule & cooling_schedule, double initial_temperature, - eoReplacement< EOT > & replacor + eoReplacement< EOType > & replacor ) : _selector(selector), _estimator(estimator), @@ -108,15 +108,15 @@ public: \param pop A population to improve. \return TRUE. */ - void operator ()(eoPop< EOT > & pop) + void operator ()(eoPop< EOType > & pop) { assert(pop.size() > 0); double temperature = _initial_temperature; - eoPop< EOT > current_pop; + eoPop< EOType > current_pop; - eoPop< EOT > selected_pop; + eoPop< EOType > selected_pop; //------------------------------------------------------------- @@ -165,7 +165,7 @@ public: // Init of a variable contening a point with the bestest fitnesses //------------------------------------------------------------- - EOT current_solution = _selectone(selected_pop); + EOType current_solution = _selectone(selected_pop); //------------------------------------------------------------- @@ -200,7 +200,7 @@ public: do { - EOT candidate_solution = _sampler(distrib); + EOType candidate_solution = _sampler(distrib); _evaluation( candidate_solution ); // TODO: verifier le critere d'acceptation @@ -232,14 +232,14 @@ public: private: - //! A EOT selector - eoSelect < EOT > & _selector; + //! A EOType selector + eoSelect < EOType > & _selector; - //! A EOT estimator. It is going to estimate distribution parameters. + //! A EOType estimator. It is going to estimate distribution parameters. edoEstimator< D > & _estimator; //! SelectOne - eoSelectOne< EOT > & _selectone; + eoSelectOne< EOType > & _selectone; //! A D modifier edoModifierMass< D > & _modifier; @@ -247,26 +247,26 @@ private: //! A D sampler edoSampler< D > & _sampler; - //! A EOT population continuator - eoContinue < EOT > & _pop_continue; + //! A EOType population continuator + eoContinue < EOType > & _pop_continue; //! A D continuator edoContinue < D > & _distribution_continue; //! A full evaluation function. - eoEvalFunc < EOT > & _evaluation; + eoEvalFunc < EOType > & _evaluation; //! Stopping criterion before temperature update - moContinuator< moDummyNeighbor > & _sa_continue; + moContinuator< moDummyNeighbor > & _sa_continue; //! The cooling schedule - moCoolingSchedule & _cooling_schedule; + moCoolingSchedule & _cooling_schedule; //! Initial temperature double _initial_temperature; - //! A EOT replacor - eoReplacement < EOT > & _replacor; + //! A EOType replacor + eoReplacement < EOType > & _replacor; }; #endif // !_edoEDASA_h diff --git a/edo/src/edoNormalMono.h b/edo/src/edoNormalMono.h index 4b015d120..4d21e0ca2 100644 --- a/edo/src/edoNormalMono.h +++ b/edo/src/edoNormalMono.h @@ -35,7 +35,11 @@ Authors: template < typename EOT > class edoNormalMono : public edoDistrib< EOT > { -public: +public: + edoNormalMono() + : _mean(EOT(1,0)), _variance(EOT(1,1)) + {} + edoNormalMono( const EOT& mean, const EOT& variance ) : _mean(mean), _variance(variance) { diff --git a/edo/src/edoNormalMulti.h b/edo/src/edoNormalMulti.h index db36810a0..0c32fad7e 100644 --- a/edo/src/edoNormalMulti.h +++ b/edo/src/edoNormalMulti.h @@ -45,6 +45,15 @@ class edoNormalMulti : public edoDistrib< EOT > public: typedef typename EOT::AtomType AtomType; + edoNormalMulti( unsigned int dim = 1 ) : + _mean( const ublas::vector(0,dim) ), + _varcovar( const ublas::identity_matrix(dim) ) + { + assert(_mean.size() > 0); + assert(_mean.size() == _varcovar.size1()); + assert(_mean.size() == _varcovar.size2()); + } + edoNormalMulti ( const ublas::vector< AtomType >& mean, @@ -86,6 +95,15 @@ public: typedef Eigen::Matrix< AtomType, Eigen::Dynamic, 1> Vector; typedef Eigen::Matrix< AtomType, Eigen::Dynamic, Eigen::Dynamic> Matrix; + edoNormalMulti( unsigned int dim = 1 ) : + _mean( Vector::Zero(dim) ), + _varcovar( Matrix::Identity(dim,dim) ) + { + assert(_mean.size() > 0); + assert(_mean.innerSize() == _varcovar.innerSize()); + assert(_mean.innerSize() == _varcovar.outerSize()); + } + edoNormalMulti( const Vector & mean, const Matrix & varcovar diff --git a/edo/src/edoSamplerNormalMulti.h b/edo/src/edoSamplerNormalMulti.h index 6420f0408..1f9fe990d 100644 --- a/edo/src/edoSamplerNormalMulti.h +++ b/edo/src/edoSamplerNormalMulti.h @@ -47,7 +47,7 @@ Authors: #include #include -template< class EOT, typename EOD = edoNormalMulti< EOT > > +template< typename EOT, typename EOD = edoNormalMulti< EOT > > class edoSamplerNormalMulti : public edoSampler< EOD > { public: @@ -91,7 +91,7 @@ protected: #else #ifdef WITH_EIGEN -template< class EOT, typename EOD = edoNormalMulti< EOT > > +template< typename EOT, typename EOD = edoNormalMulti< EOT > > class edoSamplerNormalMulti : public edoSampler< EOD > { public: diff --git a/edo/src/utils/edoStatNormalMulti.h b/edo/src/utils/edoStatNormalMulti.h index bc5066ac7..961fd7cba 100644 --- a/edo/src/utils/edoStatNormalMulti.h +++ b/edo/src/utils/edoStatNormalMulti.h @@ -31,7 +31,7 @@ Authors: #include #include "edoStat.h" -#include "edoNormalMulti.h" +#include "../edoNormalMulti.h" #ifdef WITH_BOOST @@ -50,7 +50,7 @@ template < typename EOT > class edoStatNormalMulti : public edoDistribStat< edoNormalMulti< EOT > > { public: - typedef typename EOT::AtomType AtomType; + // typedef typename EOT::AtomType AtomType; using edoDistribStat< edoNormalMulti< EOT > >::value; diff --git a/edo/test/t-edoEstimatorNormalMulti.cpp b/edo/test/t-edoEstimatorNormalMulti.cpp index 114f8fa17..5c47f5cf5 100644 --- a/edo/test/t-edoEstimatorNormalMulti.cpp +++ b/edo/test/t-edoEstimatorNormalMulti.cpp @@ -29,7 +29,7 @@ Authors: #include #include -#include +//#include #include diff --git a/edo/test/t-mean-distance.cpp b/edo/test/t-mean-distance.cpp index ae6de0eb3..4e184f5a8 100644 --- a/edo/test/t-mean-distance.cpp +++ b/edo/test/t-mean-distance.cpp @@ -33,7 +33,7 @@ Authors: #include #include -#include +//#include #include diff --git a/eo/NEWS b/eo/NEWS index f4625d6c3..369682af6 100644 --- a/eo/NEWS +++ b/eo/NEWS @@ -1,4 +1,22 @@ * current version + - features: + - delete the deprecated code parts (was marked as deprecated in the release 1.1) + - eoSignal: a class to handle signal with eoCheckpoint instances + - eoDetSingleBitFlip: bit flip mutation that changes exactly k bits while checking for duplicate + - eoFunctorStat: a wrapper to turn any stand-alone function and into an eoStat + - generilazed the output of an eoState: now you can change the format, comes with defaults formatting (latex and json) + - eoWrongParamTypeException: a new exception to handle cases where a wrong template is given to eoParser::valueOf + - added a getParam method to the eoParser, that raise an exception if the parameter has not been declared + - eoParserLogger features are now included in the default eoParser + - build system: + - improvements of the build architecture + - create PKGBUILD file for archlinux package manager + - a FindEO module for CMake + - bugfixes: + - fixed regression with gcc 4.7 + - fixed compilation issues in Microsoft Visual C++, related to time measurement + - added several asserts accross the framework (note: asserts are included only in debug mode) + - lot of small bugfixes :-) * release 1.2 (16. May. 2011) - fixed the incremental allocation issue in variation operators which were @@ -20,11 +38,11 @@ - GCC 4.3 compatibility - new versatile log system with several nested verbose levels - classes using intern verbose parameters marked as deprecated, please update your code accordingly if you use one of the following files: - eo/src/eoCombinedInit.h - eo/src/eoGenContinue.h - eo/src/eoProportionalCombinedOp.h - eo/src/utils/eoData.h - eo/src/utils/eoStdoutMonitor.h + eo/src/eoCombinedInit.h + eo/src/eoGenContinue.h + eo/src/eoProportionalCombinedOp.h + eo/src/utils/eoData.h + eo/src/utils/eoStdoutMonitor.h - an evaluator that throw an exception if a maximum eval numbers has been reached, independently of the number of generations - new monitor that can write on any ostream - new continuator that can catch POSIX system user signals diff --git a/eo/src/apply.h b/eo/src/apply.h index 01256e059..bbd30aa3a 100644 --- a/eo/src/apply.h +++ b/eo/src/apply.h @@ -58,14 +58,26 @@ void apply(eoUF& _proc, std::vector& _pop) if (!eo::parallel.isDynamic()) { #pragma omp parallel for if(eo::parallel.isEnabled()) //default(none) shared(_proc, _pop, size) +#ifdef _MSC_VER + //Visual Studio supports only OpenMP version 2.0 in which + //an index variable must be of a signed integral type + for (long long i = 0; i < size; ++i) { _proc(_pop[i]); } +#else // _MSC_VER for (size_t i = 0; i < size; ++i) { _proc(_pop[i]); } +#endif } else { #pragma omp parallel for schedule(dynamic) if(eo::parallel.isEnabled()) +#ifdef _MSC_VER + //Visual Studio supports only OpenMP version 2.0 in which + //an index variable must be of a signed integral type + for (long long i = 0; i < size; ++i) { _proc(_pop[i]); } +#else // _MSC_VER //doesnot work with gcc 4.1.2 //default(none) shared(_proc, _pop, size) for (size_t i = 0; i < size; ++i) { _proc(_pop[i]); } +#endif } if ( eo::parallel.enableResults() ) diff --git a/eo/src/eo b/eo/src/eo index 8cebd23a0..3a31daea4 100644 --- a/eo/src/eo +++ b/eo/src/eo @@ -102,6 +102,7 @@ #include // Embedding truncation selection #include +#include // the batch selection - from an eoSelectOne #include diff --git a/eo/src/eoDetSelect.h b/eo/src/eoDetSelect.h index 4a0858b6a..c89f41f69 100644 --- a/eo/src/eoDetSelect.h +++ b/eo/src/eoDetSelect.h @@ -34,7 +34,7 @@ #include //----------------------------------------------------------------------------- -/** eoDetSelect selects many individuals determinisctically +/** eoDetSelect selects many individuals deterministically * * @ingroup Selectors */ diff --git a/eo/src/eoEvalUserTimeThrowException.h b/eo/src/eoEvalUserTimeThrowException.h index 87e47ac54..2d9ccadd6 100644 --- a/eo/src/eoEvalUserTimeThrowException.h +++ b/eo/src/eoEvalUserTimeThrowException.h @@ -21,27 +21,30 @@ Authors: Johann Dréo */ -#ifndef __unix__ -#warning "Warning: class 'eoEvalUserTimeThrowException' is only available under UNIX systems (defining 'rusage' in 'sys/resource.h'), contributions for other systems are welcomed." -#else +#if !defined(__unix__) && !defined(_WINDOWS) +#warning "Warning: class 'eoEvalUserTimeThrowException' is only available under UNIX (defining 'rusage' in 'sys/resource.h') or Win32 (defining 'GetProcessTimes' in 'WinBase.h') systems, contributions for other systems are welcomed." +#else //!defined(__unix__) && !defined(_WINDOWS) #ifndef __EOEVALUSERTIMETHROWEXCEPTION_H__ #define __EOEVALUSERTIMETHROWEXCEPTION_H__ -#include -#include - -#include - /** Check at each evaluation if a given CPU user time contract has been reached. * * Throw an eoMaxTimeException if the given max time has been reached. * Usefull if you want to end the search independently of generations. - * This class uses (almost-)POSIX headers. + * This class uses (almost-)POSIX or Win32 headers, depending on the platform. * It uses a computation of the user time used on the CPU. For a wallclock time measure, see eoEvalTimeThrowException * * @ingroup Evaluation */ + +#include + +#ifdef __unix__ + +#include +#include + template< class EOT > class eoEvalUserTimeThrowException : public eoEvalFuncCounter< EOT > { @@ -58,7 +61,7 @@ public: if( current >= _max ) { throw eoMaxTimeException( current ); } else { - func(eo); + this->func(eo); } } } @@ -68,5 +71,41 @@ protected: struct rusage _usage; }; +#else +#ifdef _WINDOWS +//here _WINDOWS is defined + +#include + +template< class EOT > +class eoEvalUserTimeThrowException : public eoEvalFuncCounter< EOT > +{ +public: + eoEvalUserTimeThrowException( eoEvalFunc & func, const long max ) : eoEvalFuncCounter( func, "CPU-user"), _max(max) {} + + virtual void operator() ( EOT & eo ) + { + if( eo.invalid() ) { + FILETIME dummy; + GetProcessTimes(GetCurrentProcess(), &dummy, &dummy, &dummy, &_usage); + + ULARGE_INTEGER current; + current.LowPart = _usage.dwLowDateTime; + current.HighPart = _usage.dwHighDateTime; + if( current.QuadPart >= _max ) { + throw eoMaxTimeException( current.QuadPart ); + } else { + func(eo); + } + } + } + +protected: + const long _max; + FILETIME _usage; +}; + +#endif // _WINDOWS +#endif //__unix__ #endif // __EOEVALUSERTIMETHROWEXCEPTION_H__ -#endif // __UNIX__ +#endif //!defined(__unix__) && !defined(_WINDOWS)