From 0d5bf295cb6e8bf1e163220e097eb19f54fe17bc Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Tue, 1 May 2012 20:49:29 +0200 Subject: [PATCH 01/21] * commented unused function params --- eo/src/eoInitializer.h | 2 +- eo/src/eoPeriodicContinue.h | 2 +- eo/src/eoProportionalSelect.h | 2 +- eo/src/eoSyncEasyPSO.h | 2 +- eo/src/eoVelocity.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/eo/src/eoInitializer.h b/eo/src/eoInitializer.h index 506fcf73..9e5cd5ca 100644 --- a/eo/src/eoInitializer.h +++ b/eo/src/eoInitializer.h @@ -129,7 +129,7 @@ private : class eoDummyEval : public eoPopEvalFunc { public: - void operator()(eoPop &,eoPop &_pop) + void operator()(eoPop &,eoPop &/*_pop*/) {} } dummyEval; diff --git a/eo/src/eoPeriodicContinue.h b/eo/src/eoPeriodicContinue.h index a6f968e9..1a3f9d0d 100644 --- a/eo/src/eoPeriodicContinue.h +++ b/eo/src/eoPeriodicContinue.h @@ -39,7 +39,7 @@ public: /** It returns 'true' only if the current number of generations modulo the period doen't equal to zero. */ - bool operator () (const eoPop & pop) + bool operator () (const eoPop & /*pop*/) { return ((++ counter) % period) != 0 ; } diff --git a/eo/src/eoProportionalSelect.h b/eo/src/eoProportionalSelect.h index daa4428d..ec1243ce 100644 --- a/eo/src/eoProportionalSelect.h +++ b/eo/src/eoProportionalSelect.h @@ -46,7 +46,7 @@ template class eoProportionalSelect: public eoSelectOne { public: /// Sanity check - eoProportionalSelect(const eoPop& pop = eoPop()) + eoProportionalSelect(const eoPop& /*pop*/ = eoPop()) { if (minimizing_fitness()) throw std::logic_error("eoProportionalSelect: minimizing fitness"); diff --git a/eo/src/eoSyncEasyPSO.h b/eo/src/eoSyncEasyPSO.h index f05f15f6..a3b4f36e 100644 --- a/eo/src/eoSyncEasyPSO.h +++ b/eo/src/eoSyncEasyPSO.h @@ -241,7 +241,7 @@ private: { public: eoDummyFlight () {} - void operator () (POT & _po) {} + void operator () (POT & /*_po*/) {} }dummyFlight; // if the initializer does not need to be used, use the dummy one instead diff --git a/eo/src/eoVelocity.h b/eo/src/eoVelocity.h index 753c6af2..5bbdb7c5 100644 --- a/eo/src/eoVelocity.h +++ b/eo/src/eoVelocity.h @@ -57,7 +57,7 @@ public: /** * Update the neighborhood of the given particle. */ - virtual void updateNeighborhood(POT & ,unsigned _indice){} + virtual void updateNeighborhood(POT & ,unsigned /*_indice*/){} /** From cd94be695709ea26caa8dc47f34346017b053ee9 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Tue, 1 May 2012 20:59:45 +0200 Subject: [PATCH 02/21] * fixed gcc 4.7 errors: ambigious calls to super class methods --- eo/src/eoFlight.h | 2 +- eo/src/eoParticleBestInit.h | 2 +- eo/src/eoSelectFromWorth.h | 2 +- eo/src/eoVelocity.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/eo/src/eoFlight.h b/eo/src/eoFlight.h index 9af813a2..4c46d8e9 100644 --- a/eo/src/eoFlight.h +++ b/eo/src/eoFlight.h @@ -46,7 +46,7 @@ public: { for (unsigned i = 0; i < _pop.size (); i++) { - operator ()(_pop[i]); + this->operator ()(_pop[i]); } } diff --git a/eo/src/eoParticleBestInit.h b/eo/src/eoParticleBestInit.h index 050fbc9c..b203c824 100644 --- a/eo/src/eoParticleBestInit.h +++ b/eo/src/eoParticleBestInit.h @@ -46,7 +46,7 @@ public: { for (unsigned i = 0; i < _pop.size (); i++) { - operator ()(_pop[i]); + this->operator ()(_pop[i]); } } diff --git a/eo/src/eoSelectFromWorth.h b/eo/src/eoSelectFromWorth.h index a2fd5ed2..342be9da 100644 --- a/eo/src/eoSelectFromWorth.h +++ b/eo/src/eoSelectFromWorth.h @@ -217,7 +217,7 @@ public: #ifndef NDEBUG // check whether the stuff is still in sync - check_sync(index, _pop[index]); + this->check_sync(index, _pop[index]); #endif return _pop[index]; diff --git a/eo/src/eoVelocity.h b/eo/src/eoVelocity.h index 5bbdb7c5..e388078c 100644 --- a/eo/src/eoVelocity.h +++ b/eo/src/eoVelocity.h @@ -49,7 +49,7 @@ public: { for (unsigned i = 0; i < _pop.size (); i++) { - operator ()(_pop[i],i); + this->operator ()(_pop[i],i); } } From 0d92a48d8969196c258de4317eaa834d55016f04 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Thu, 14 Jun 2012 01:05:27 +0200 Subject: [PATCH 03/21] + added eoFunctorStat class --- eo/src/utils/eoFuncPtrStat.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/eo/src/utils/eoFuncPtrStat.h b/eo/src/utils/eoFuncPtrStat.h index 316b7f42..c7728157 100644 --- a/eo/src/utils/eoFuncPtrStat.h +++ b/eo/src/utils/eoFuncPtrStat.h @@ -4,6 +4,8 @@ #include #include + + /** Wrapper to turn any stand-alone function and into an eoStat. * * The function should take an eoPop as argument. @@ -41,4 +43,38 @@ eoFuncPtrStat& makeFuncPtrStat( T (*func)(const eoPop&), eoFunctorS ); } +/** Wrapper to turn any stand-alone function and into an eoStat. + * + * The function should take an eoPop as argument. + * + * @ingroup Stats + */ +template +class eoFunctorStat : public eoStat +{ +public : + eoFunctorStat(eoUF< const eoPop&, T >& f, std::string _description = "functor") + : eoStat(T(), _description), func(f) + {} + + using eoStat::value; + + void operator()(const eoPop& pop) { + value() = func(pop); + } + +private: + eoUF< const eoPop&, T >& func; +}; + +/** + * @ingroup Stats + */ +template +eoFunctorStat& makeFunctorStat( eoUF< const eoPop&, T >& func, eoFunctorStore& store, std::string description = "func") { + return store.storeFunctor( + new eoFunctorStat( func, description) + ); +} + #endif From 138706d1253a0f954a9e29649acecee8f7e854ab Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Thu, 14 Jun 2012 01:06:38 +0200 Subject: [PATCH 04/21] * checkpoint main header file: just added license and multi-inclusion protection --- eo/src/utils/checkpointing | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/eo/src/utils/checkpointing b/eo/src/utils/checkpointing index 5d49e589..7e3c34a6 100644 --- a/eo/src/utils/checkpointing +++ b/eo/src/utils/checkpointing @@ -1,3 +1,29 @@ +/* + ----------------------------------------------------------------------------- + checkpointing + + (c) Maarten Keijzer (mak@dhi.dk) and GeNeura Team, 1999, 2000 + + 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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact: todos@geneura.ugr.es, http://geneura.ugr.es + */ + +#ifndef _CHECKPOINTING_ +#define _CHECKPOINTING_ + #include #include #include @@ -21,3 +47,9 @@ // and make_help - any better suggestion to include it? void make_help(eoParser & _parser); + +#endif // !_CHECKPOINTING_ + +// Local Variables: +// mode: C++ +// End: From 44d80d002009eef7a20f2ee1c3cd44d997a86fb2 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Thu, 14 Jun 2012 01:08:26 +0200 Subject: [PATCH 05/21] * eoBitOp.h: added eoDetSingleBitFlip class --- eo/src/ga/eoBitOp.h | 58 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/eo/src/ga/eoBitOp.h b/eo/src/ga/eoBitOp.h index d1247020..15d77434 100644 --- a/eo/src/ga/eoBitOp.h +++ b/eo/src/ga/eoBitOp.h @@ -56,7 +56,7 @@ template class eoOneBitFlip: public eoMonOp bool operator()(Chrom& chrom) { unsigned i = eo::rng.random(chrom.size()); - chrom[i] = (chrom[i]) ? false : true; + chrom[i] = !chrom[i]; return true; } }; @@ -85,11 +85,11 @@ template class eoDetBitFlip: public eoMonOp */ bool operator()(Chrom& chrom) { - // does not check for duplicate: if someone volunteers .... + // for duplicate checking see eoDetSingleBitFlip for (unsigned k=0; k class eoDetBitFlip: public eoMonOp }; +/** eoDetSingleBitFlip --> changes exactly k bits with checking for duplicate +\class eoDetSingleBitFlip eoBitOp.h ga/eoBitOp.h +\ingroup bitstring +*/ + +template class eoDetSingleBitFlip: public eoMonOp +{ + public: + /** + * (Default) Constructor. + * @param _num_bit The number of bits to change + * default is one - equivalent to eoOneBitFlip then + */ + eoDetSingleBitFlip(const unsigned& _num_bit = 1): num_bit(_num_bit) {} + + /// The class name. + virtual std::string className() const { return "eoDetSingleBitFlip"; } + + /** + * Change num_bit bits. + * @param chrom The cromosome which one bit is going to be changed. + */ + bool operator()(Chrom& chrom) + { + std::vector< unsigned > selected; + + // check for duplicate + for (unsigned k=0; k classical mutation \class eoBitMutation eoBitOp.h ga/eoBitOp.h \ingroup bitstring From 6051ccb27490c936218bedf3905c4e8b0ef4491b Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Thu, 14 Jun 2012 01:50:16 +0200 Subject: [PATCH 06/21] edoNormalMulti.h: added missing license header --- edo/src/edoNormalMulti.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/edo/src/edoNormalMulti.h b/edo/src/edoNormalMulti.h index 463f0bc8..be0e7d00 100644 --- a/edo/src/edoNormalMulti.h +++ b/edo/src/edoNormalMulti.h @@ -1,4 +1,24 @@ -// (c) Thales group, 2010 +/* +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 Dreo From 461edcf3cf277c7d0744bb081a7295af0b23077b Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Thu, 14 Jun 2012 15:30:13 +0200 Subject: [PATCH 07/21] * eoReduceSplit.h: useless comparaision fixed since it was: unsigned < 0 --- eo/src/eoReduceSplit.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo/src/eoReduceSplit.h b/eo/src/eoReduceSplit.h index ce22d027..4b21aa25 100644 --- a/eo/src/eoReduceSplit.h +++ b/eo/src/eoReduceSplit.h @@ -104,7 +104,7 @@ public: unsigned eliminated = howMany(popSize); if (!eliminated) // nothing to do return ; - unsigned newsize = popSize - eliminated; + long newsize = static_cast(popSize) - static_cast(eliminated); if (newsize < 0) throw std::logic_error("eoLinearTruncateSplit: Cannot truncate to a larger size!\n"); From a183a1c6d1de14dd67c45a873fc8385b2e82ce9a Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Thu, 14 Jun 2012 15:30:41 +0200 Subject: [PATCH 08/21] * make_op.h, eoLogger.cpp: disabled not used variables. should I remove them ? --- eo/src/ga/make_op.h | 8 ++++---- eo/src/utils/eoLogger.cpp | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/eo/src/ga/make_op.h b/eo/src/ga/make_op.h index 8c46549f..045148ec 100644 --- a/eo/src/ga/make_op.h +++ b/eo/src/ga/make_op.h @@ -115,11 +115,11 @@ eoGenOp & do_make_op(eoParser& _parser, eoState& _state, eoInit& _init throw std::runtime_error("Invalid uRate"); // minimum check - bool bCross = true; + // bool bCross = true; // not used ? if (onePointRateParam.value()+twoPointsRateParam.value()+uRateParam.value()==0) { std::cerr << "Warning: no crossover" << std::endl; - bCross = false; + // bCross = false; } // Create the CombinedQuadOp @@ -162,11 +162,11 @@ eoGenOp & do_make_op(eoParser& _parser, eoState& _state, eoInit& _init throw std::runtime_error("Invalid oneBitRate"); // minimum check - bool bMut = true; + // bool bMut = true; // not used ? if (bitFlipRateParam.value()+oneBitRateParam.value()==0) { std::cerr << "Warning: no mutation" << std::endl; - bMut = false; + // bMut = false; } // Create the CombinedMonOp diff --git a/eo/src/utils/eoLogger.cpp b/eo/src/utils/eoLogger.cpp index e478ba09..f052d795 100644 --- a/eo/src/utils/eoLogger.cpp +++ b/eo/src/utils/eoLogger.cpp @@ -194,8 +194,7 @@ int eoLogger::outbuf::overflow(int_type c) { if (_fd >= 0 && c != EOF) { - size_t num; - num = ::write(_fd, &c, 1); + ::write(_fd, &c, 1); } } return c; From 0cfab9208b4786bab9be46968adc40e8dc83a775 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Thu, 14 Jun 2012 15:31:23 +0200 Subject: [PATCH 09/21] * install_symlink.py.cmake compatible with python3 --- eo/install_symlink.py.cmake | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/eo/install_symlink.py.cmake b/eo/install_symlink.py.cmake index 145d67a1..fd71d68b 100755 --- a/eo/install_symlink.py.cmake +++ b/eo/install_symlink.py.cmake @@ -9,8 +9,8 @@ PREFIX = "/usr" DATA = { 'dirs': [ "%s/share/%s" % (PREFIX, NAME) ], 'links': [ ("%s/src" % SOURCE, "%s/include/%s" % (PREFIX, NAME)), - ("%s/doc" % BINARY, "%s/share/%s/doc" % (PREFIX, NAME)), - ("%s/%s.pc" % (BINARY, NAME), "%s/lib/pkgconfig/%s.pc" % (PREFIX, NAME)), + ("%s/doc" % BINARY, "%s/share/%s/doc" % (PREFIX, NAME)), + ("%s/%s.pc" % (BINARY, NAME), "%s/lib/pkgconfig/%s.pc" % (PREFIX, NAME)), ] } @@ -21,19 +21,19 @@ import os, sys def isroot(): if os.getuid() != 0: - print '[WARNING] you have to be root' - return False + print('[WARNING] you have to be root') + return False return True def uninstall(): for dummy, link in DATA['links']: os.remove(link) for dirname in DATA['dirs']: os.rmdir(dirname) - print 'All symlinks have been removed.' + print('All symlinks have been removed.') def install(): for dirname in DATA['dirs']: os.mkdir(dirname) for src, dst in DATA['links']: os.symlink(src, dst) - print 'All symlinks have been installed.' + print('All symlinks have been installed.') def data(): from pprint import pprint @@ -41,11 +41,11 @@ def data(): if __name__ == '__main__': if not isroot(): - sys.exit() + sys.exit() if len(sys.argv) < 2: - print 'Usage: %s [install|uninstall|data]' % sys.argv[0] - sys.exit() + print(('Usage: %s [install|uninstall|data]' % sys.argv[0])) + sys.exit() if sys.argv[1] == 'install': install() elif sys.argv[1] == 'uninstall': uninstall() From 699a6c18585a7e5da34c96be22098ad3391a58cd Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Sun, 17 Jun 2012 14:21:55 +0200 Subject: [PATCH 10/21] =?UTF-8?q?*=C2=A0eo/src/pyeo/test/run=5Ftests.sh:?= =?UTF-8?q?=20removed=20ambigious=20use=20of=20python=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eo/src/pyeo/test/run_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo/src/pyeo/test/run_tests.sh b/eo/src/pyeo/test/run_tests.sh index b06c61b0..8a2ebca1 100755 --- a/eo/src/pyeo/test/run_tests.sh +++ b/eo/src/pyeo/test/run_tests.sh @@ -2,6 +2,6 @@ for i in *.py do - python $i > /dev/null + python2 $i > /dev/null done From 6637535020b607aed9fb27e5649b08b703bd441e Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Sun, 17 Jun 2012 20:59:21 +0200 Subject: [PATCH 11/21] * cmakelists.txt: minimum version checker --- eo/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/eo/CMakeLists.txt b/eo/CMakeLists.txt index c10ac3c5..63de5b22 100644 --- a/eo/CMakeLists.txt +++ b/eo/CMakeLists.txt @@ -1,3 +1,4 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) ###################################################################################### ### 0) If you want to set your variables in eo-conf.cmake and avoid the cmd line From f962a7942bc6e8c3c48ab2abff8dfb60a063f88a Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Sun, 17 Jun 2012 21:01:16 +0200 Subject: [PATCH 12/21] * we can now disable deprecated messages --- eo/eo-conf.cmake | 1 + eo/src/eoCombinedContinue.h | 5 +++++ eo/src/eoProportionalCombinedOp.h | 3 +++ eo/src/utils/eoOStreamMonitor.h | 5 +++-- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/eo/eo-conf.cmake b/eo/eo-conf.cmake index e8f285cb..9d3d5c3a 100644 --- a/eo/eo-conf.cmake +++ b/eo/eo-conf.cmake @@ -5,3 +5,4 @@ SET(PROJECT_VERSION_MINOR 3) SET(PROJECT_VERSION_PATCH 0) SET(PROJECT_VERSION_MISC "-edge") +# ADD_DEFINITIONS(-DDEPRECATED_MESSAGES) # disable warning deprecated function messages diff --git a/eo/src/eoCombinedContinue.h b/eo/src/eoCombinedContinue.h index 5226e28d..dfb70f67 100644 --- a/eo/src/eoCombinedContinue.h +++ b/eo/src/eoCombinedContinue.h @@ -61,7 +61,9 @@ public: eoCombinedContinue( eoContinue& _cont1, eoContinue& _cont2) : eoContinue(), std::vector* >() { +#ifndef DEPRECATED_MESSAGES #pragma message "The double continuators constructor of eocombinedContinue is deprecated and will be removed in the next release." +#endif // !DEPRECATED_MESSAGES this->push_back(&_cont1); this->push_back(&_cont2); @@ -74,7 +76,10 @@ public: void removeLast(void) { +#ifndef DEPRECATED_MESSAGES #pragma message "The removeLast method of eocombinedContinue is deprecated and will be removed in the next release, use pop_back instead." +#endif // !DEPRECATED_MESSAGES + this->pop_back(); } diff --git a/eo/src/eoProportionalCombinedOp.h b/eo/src/eoProportionalCombinedOp.h index 4fea77e5..60c47890 100644 --- a/eo/src/eoProportionalCombinedOp.h +++ b/eo/src/eoProportionalCombinedOp.h @@ -188,8 +188,11 @@ public: virtual void add(eoQuadOp & _op, const double _rate, bool _verbose) { +#ifndef DEPRECATED_MESSAGES #pragma message "The use of the verbose parameter in eoPropCombinedQuadOp::add is deprecated and will be removed in the next release." eo::log << eo::warnings << "WARNING: the use of the verbose parameter in eoPropCombinedQuadOp::add is deprecated and will be removed in the next release." << std::endl; +#endif // !DEPRECATED_MESSAGES + add(_op,_rate); } diff --git a/eo/src/utils/eoOStreamMonitor.h b/eo/src/utils/eoOStreamMonitor.h index cb4c476a..b941b05f 100644 --- a/eo/src/utils/eoOStreamMonitor.h +++ b/eo/src/utils/eoOStreamMonitor.h @@ -44,12 +44,13 @@ Authors: class eoOStreamMonitor : public eoMonitor { public : - eoOStreamMonitor( std::ostream & _out, bool _verbose=true, std::string _delim = "\t", unsigned int _width=20, char _fill=' ' ) : + eoOStreamMonitor( std::ostream & _out, bool /*_verbose*/=true, std::string _delim = "\t", unsigned int _width=20, char _fill=' ' ) : out(_out), delim(_delim), width(_width), fill(_fill), firsttime(true) { - (void)_verbose; +#ifndef DEPRECATED_MESSAGES eo::log << eo::warnings << "WARNING: the use of the verbose parameter in eoOStreamMonitor constructor is deprecated and will be removed in the next release" << std::endl; #pragma message "WARNING: the use of the verbose parameter in eoOStreamMonitor constructor is deprecated and will be removed in the next release" +#endif // !DEPRECATED_MESSAGES } eoOStreamMonitor( std::ostream & _out, std::string _delim = "\t", unsigned int _width=20, char _fill=' ' ) : From 5c85bbdeded5fa7ce8cedf189a6e87b155d99591 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Fri, 22 Jun 2012 15:35:16 +0200 Subject: [PATCH 13/21] * eoStdoutMonitor.h: warning message should be disabled --- eo/src/utils/eoStdoutMonitor.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/eo/src/utils/eoStdoutMonitor.h b/eo/src/utils/eoStdoutMonitor.h index a1979b5d..07c5a02f 100644 --- a/eo/src/utils/eoStdoutMonitor.h +++ b/eo/src/utils/eoStdoutMonitor.h @@ -46,7 +46,9 @@ public : eoStdoutMonitor(bool _verbose, std::string _delim = "\t", unsigned int _width=20, char _fill=' ' ) : eoOStreamMonitor( std::cout, _verbose, _delim, _width, _fill) { - eo::log << eo::warnings << "WARNING: the use of the verbose parameter in eoStdutMonitor constructor is deprecated and will be removed in the next release" << std::endl; +#ifndef DEPRECATED_MESSAGES + eo::log << eo::warnings << "WARNING: the use of the verbose parameter in eoStdoutMonitor constructor is deprecated and will be removed in the next release" << std::endl; +#endif // !DEPRECATED_MESSAGES } eoStdoutMonitor(std::string _delim = "\t", unsigned int _width=20, char _fill=' ' ) : From 4d2931b810f3e3d2a1eda952018f5d5a7671ddfd Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Fri, 22 Jun 2012 15:35:54 +0200 Subject: [PATCH 14/21] * eoCtrlCContinue.h: signal c++ header file --- eo/src/eoCtrlCContinue.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo/src/eoCtrlCContinue.h b/eo/src/eoCtrlCContinue.h index 9bbcf9c0..e239f736 100644 --- a/eo/src/eoCtrlCContinue.h +++ b/eo/src/eoCtrlCContinue.h @@ -30,7 +30,7 @@ #ifndef eoCtrlCContinue_h #define eoCtrlCContinue_h -#include +#include #include /** From ba45bac06c6ad0c598b4ea770f345936e72aec5c Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Fri, 22 Jun 2012 15:36:19 +0200 Subject: [PATCH 15/21] * make_continue_ga.cpp: typo --- eo/src/ga/make_continue_ga.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo/src/ga/make_continue_ga.cpp b/eo/src/ga/make_continue_ga.cpp index 1b25a0c8..fb4662c3 100644 --- a/eo/src/ga/make_continue_ga.cpp +++ b/eo/src/ga/make_continue_ga.cpp @@ -37,7 +37,7 @@ * * The corresponding ***INSTANCIATED DECLARATIONS*** are contained * in ga.h - * while the TEMPLATIZED code is define in make_contninue.h in the src/do dir + * while the TEMPLATIZED code is define in make_continue.h in the src/do dir * * Unlike most EO .h files, it does not (and should not) contain any code, * just declarations From afc0bb6f9ba1cc1f22db9c3f0fa4b53e9c0e1846 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Fri, 22 Jun 2012 15:37:51 +0200 Subject: [PATCH 16/21] + eoSignal: to handle signal with eoCheckpoint instances --- eo/src/utils/CMakeLists.txt | 1 + eo/src/utils/eoSignal.cpp | 36 ++++++++++++++ eo/src/utils/eoSignal.h | 96 +++++++++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 eo/src/utils/eoSignal.cpp create mode 100644 eo/src/utils/eoSignal.h diff --git a/eo/src/utils/CMakeLists.txt b/eo/src/utils/CMakeLists.txt index 010c6d41..5224f652 100644 --- a/eo/src/utils/CMakeLists.txt +++ b/eo/src/utils/CMakeLists.txt @@ -29,6 +29,7 @@ SET(EOUTILS_SOURCES pipecom.cpp eoLogger.cpp eoParallel.cpp + eoSignal.cpp ) ADD_LIBRARY(eoutils STATIC ${EOUTILS_SOURCES}) diff --git a/eo/src/utils/eoSignal.cpp b/eo/src/utils/eoSignal.cpp new file mode 100644 index 00000000..745d21bd --- /dev/null +++ b/eo/src/utils/eoSignal.cpp @@ -0,0 +1,36 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +/** + 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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact: http://eodev.sourceforge.net + + Autors: todos@geneura.ugr.es, http://geneura.ugr.es + Marc.Schoenauer@polytechnique.fr + mak@dhi.dk + Caner.Candan@univ-angers.fr +*/ + +#include + +/** + * @addtogroup Continuators + * @{ + */ + +// --- Global variables - but don't know what else to do - MS --- +std::map< int, bool > signals_called; + +/** @} */ diff --git a/eo/src/utils/eoSignal.h b/eo/src/utils/eoSignal.h new file mode 100644 index 00000000..7eeafe3c --- /dev/null +++ b/eo/src/utils/eoSignal.h @@ -0,0 +1,96 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +/** + 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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact: http://eodev.sourceforge.net + + Authors: todos@geneura.ugr.es, http://geneura.ugr.es + Marc.Schoenauer@polytechnique.fr + mak@dhi.dk + Caner.Candan@univ-angers.fr +*/ + +#ifndef _eoSignal_h +#define _eoSignal_h + +#include +#include +#include + +#include +#include + +/** + * @addtogroup Continuators + * @{ + */ + +extern std::map< int, bool > signals_called; + +/** eoSignal inherits from eoCheckPoint including signals handling (see signal(7)) + * + * @ingroup Utilities + */ +template +class eoSignal : public eoCheckPoint +{ +public : + + eoSignal( int sig = SIGINT ) : eoCheckPoint( _dummyContinue ), _sig( sig ) + { + ::signals_called[_sig] = false; + ::signal( _sig, handler ); + } + + eoSignal( eoContinue& _cont, int sig = SIGINT ) : eoCheckPoint( _cont ), _sig( sig ) + { + ::signals_called[_sig] = false; + ::signal( _sig, handler ); + } + + bool operator()( const eoPop& _pop ) + { + bool& called = ::signals_called[_sig]; + if ( called ) + { + eo::log << eo::logging << "Signal granted…" << std::endl ; + called = false; + return this->eoCheckPoint::operator()( _pop ); + } + return true; + } + + virtual std::string className(void) const { return "eoSignal"; } + + static void handler( int sig ) + { + ::signals_called[sig] = true; + eo::log << eo::logging << "Signal wished…" << std::endl ; + } + +private: + class DummyContinue : public eoContinue + { + public: + bool operator() ( const eoPop& ) { return true; } + } _dummyContinue; + + int _sig; +}; + +/** @} */ + +#endif // !_eoSignal_h From 48a90633127584bf6c5df5f44c8a299c58a9b3e3 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Fri, 22 Jun 2012 16:55:40 +0200 Subject: [PATCH 17/21] * make_checkpoint.h: too much empty lines removed --- eo/src/do/make_checkpoint.h | 571 ++++++++++-------------------------- 1 file changed, 157 insertions(+), 414 deletions(-) diff --git a/eo/src/do/make_checkpoint.h b/eo/src/do/make_checkpoint.h index 7958ed5b..74145d84 100644 --- a/eo/src/do/make_checkpoint.h +++ b/eo/src/do/make_checkpoint.h @@ -1,45 +1,32 @@ // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - - //----------------------------------------------------------------------------- - // make_checkpoint.h - // (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2000 - /* - 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 of the License, or (at your option) any later version. + 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 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. + 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Contact: todos@geneura.ugr.es, http://geneura.ugr.es - - Marc.Schoenauer@polytechnique.fr - - mkeijzer@dhi.dk - - */ + 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Contact: todos@geneura.ugr.es, http://geneura.ugr.es + Marc.Schoenauer@polytechnique.fr + mkeijzer@dhi.dk +*/ //----------------------------------------------------------------------------- - - #ifndef _make_checkpoint_h - #define _make_checkpoint_h - #ifdef HAVE_CONFIG_H #include #endif @@ -52,521 +39,277 @@ #include #include - - // at the moment, in utils/make_help.cpp - // this should become some eoUtils.cpp with corresponding eoUtils.h - bool testDirRes(std::string _dirName, bool _erase); - /////////////////// The checkpoint and other I/O ////////////// - - - /** * * CHANGE (March 2008): now receiving an eoValueParam instead of an eoEvalFuncCounter. This function is just interested * in the value of the parameter calculated on the evaluation function, not in the actual function itself!! * * @ingroup Builders -*/ + */ template eoCheckPoint& do_make_checkpoint(eoParser& _parser, eoState& _state, eoValueParam& _eval, eoContinue& _continue) { + // first, create a checkpoint from the eoContinue + eoCheckPoint *checkpoint = new eoCheckPoint(_continue); - // first, create a checkpoint from the eoContinue - eoCheckPoint *checkpoint = new eoCheckPoint(_continue); + _state.storeFunctor(checkpoint); - _state.storeFunctor(checkpoint); + /////////////////// + // Counters + ////////////////// + // is nb Eval to be used as counter? + eoValueParam& useEvalParam = _parser.createParam(true, "useEval", "Use nb of eval. as counter (vs nb of gen.)", '\0', "Output"); + eoValueParam& useTimeParam = _parser.createParam(true, "useTime", "Display time (s) every generation", '\0', "Output"); + // if we want the time, we need an eoTimeCounter + eoTimeCounter * tCounter = NULL; + // Create anyway a generation-counter + // Recent change (03/2002): it is now an eoIncrementorParam, both + // a parameter AND updater so you can store it into the eoState + eoIncrementorParam *generationCounter = new eoIncrementorParam("Gen."); - /////////////////// - - // Counters - - ////////////////// - - // is nb Eval to be used as counter? - - eoValueParam& useEvalParam = _parser.createParam(true, "useEval", "Use nb of eval. as counter (vs nb of gen.)", '\0', "Output"); - - eoValueParam& useTimeParam = _parser.createParam(true, "useTime", "Display time (s) every generation", '\0', "Output"); - - - - // if we want the time, we need an eoTimeCounter - - eoTimeCounter * tCounter = NULL; - - - - // Create anyway a generation-counter - - // Recent change (03/2002): it is now an eoIncrementorParam, both - - // a parameter AND updater so you can store it into the eoState - - eoIncrementorParam *generationCounter = new eoIncrementorParam("Gen."); - - // store it in the state - - _state.storeFunctor(generationCounter); - - // And add it to the checkpoint, - - checkpoint->add(*generationCounter); - + // store it in the state + _state.storeFunctor(generationCounter); + // And add it to the checkpoint, + checkpoint->add(*generationCounter); // dir for DISK output - eoValueParam& dirNameParam = _parser.createParam(std::string("Res"), "resDir", "Directory to store DISK outputs", '\0', "Output - Disk"); // shoudl we empty it if exists - eoValueParam& eraseParam = _parser.createParam(true, "eraseDir", "erase files in dirName if any", '\0', "Output - Disk"); bool dirOK = false; // not tested yet - - ///////////////////////////////////////// - // now some statistics on the population: - ///////////////////////////////////////// /** - * existing stats as of today, April 10. 2001 - * - * eoBestFitnessStat : best value in pop - type EOT::Fitness - * eoAverageStat : average value in pop - type EOT::Fitness - * eoSecondMomentStat: average + stdev - type std::pair - * eoSortedPopStat : whole population - type std::string (!!) - * eoScalarFitnessStat: the fitnesses - type std::vector - */ - - // Best fitness in population - //--------------------------- - eoValueParam& printBestParam = _parser.createParam(true, "printBestStat", "Print Best/avg/stdev every gen.", '\0', "Output"); - eoValueParam& plotBestParam = _parser.createParam(false, "plotBestStat", "Plot Best/avg Stat", '\0', "Output - Graphical"); - eoValueParam& fileBestParam = _parser.createParam(false, "fileBestStat", "Output bes/avg/std to file", '\0', "Output - Disk"); - - eoBestFitnessStat *bestStat = NULL; - if ( printBestParam.value() || plotBestParam.value() || fileBestParam.value() ) - - // we need the bestStat for at least one of the 3 above - - { - - bestStat = new eoBestFitnessStat; - - // store it - - _state.storeFunctor(bestStat); - - // add it to the checkpoint - - checkpoint->add(*bestStat); - - } - - + // we need the bestStat for at least one of the 3 above + { + bestStat = new eoBestFitnessStat; + // store it + _state.storeFunctor(bestStat); + // add it to the checkpoint + checkpoint->add(*bestStat); + } // Average fitness alone - //---------------------- - eoAverageStat *averageStat = NULL; // do we need averageStat? - if ( plotBestParam.value() ) // we need it for gnuplot output - - { - - averageStat = new eoAverageStat; - - // store it - - _state.storeFunctor(averageStat); - - // add it to the checkpoint - - checkpoint->add(*averageStat); - - } - - + { + averageStat = new eoAverageStat; + // store it + _state.storeFunctor(averageStat); + // add it to the checkpoint + checkpoint->add(*averageStat); + } // Second moment stats: average and stdev - //--------------------------------------- - eoSecondMomentStats *secondStat = NULL; - - if ( printBestParam.value() || fileBestParam.value() ) // we need it for screen output or file output - - { - - secondStat = new eoSecondMomentStats; - - // store it - - _state.storeFunctor(secondStat); - - // add it to the checkpoint - - checkpoint->add(*secondStat); - - } - - - - + if ( printBestParam.value() || fileBestParam.value() ) // we need it for screen output or file output + { + secondStat = new eoSecondMomentStats; + // store it + _state.storeFunctor(secondStat); + // add it to the checkpoint + checkpoint->add(*secondStat); + } // Dump of the whole population - //----------------------------- - eoSortedPopStat *popStat = NULL; - eoValueParam& printPopParam = _parser.createParam(false, "printPop", "Print sorted pop. every gen.", '\0', "Output"); if ( printPopParam.value() ) // we do want pop dump - - { - - popStat = new eoSortedPopStat; - - // store it - - _state.storeFunctor(popStat); - - // add it to the checkpoint - - checkpoint->add(*popStat); - - } - - - - + { + popStat = new eoSortedPopStat; + // store it + _state.storeFunctor(popStat); + // add it to the checkpoint + checkpoint->add(*popStat); + } // do we wnat some histogram of fitnesses snpashots? - eoValueParam plotHistogramParam = _parser.createParam(false, "plotHisto", "Plot histogram of fitnesses", '\0', "Output - Graphical"); - - /////////////// - // The monitors - /////////////// // do we want an eoStdoutMonitor? - bool needStdoutMonitor = printBestParam.value() - || printPopParam.value() ; - - // The Stdout monitor will print parameters to the screen ... - if ( needStdoutMonitor ) + { + eoStdoutMonitor *monitor = new eoStdoutMonitor(false); + _state.storeFunctor(monitor); - { + // when called by the checkpoint (i.e. at every generation) + checkpoint->add(*monitor); - eoStdoutMonitor *monitor = new eoStdoutMonitor(false); + // the monitor will output a series of parameters: add them + monitor->add(*generationCounter); - _state.storeFunctor(monitor); - - - - // when called by the checkpoint (i.e. at every generation) - - checkpoint->add(*monitor); - - - - // the monitor will output a series of parameters: add them - - monitor->add(*generationCounter); - - if (useEvalParam.value()) // we want nb of evaluations - - monitor->add(_eval); - - if (useTimeParam.value()) // we want time - - { - - tCounter = new eoTimeCounter; - - _state.storeFunctor(tCounter); - - checkpoint->add(*tCounter); - - monitor->add(*tCounter); - - } - - if (printBestParam.value()) - - { - - monitor->add(*bestStat); - - monitor->add(*secondStat); - - } - - if ( printPopParam.value()) - - monitor->add(*popStat); - - } + if (useEvalParam.value()) // we want nb of evaluations + monitor->add(_eval); + if (useTimeParam.value()) // we want time + { + tCounter = new eoTimeCounter; + _state.storeFunctor(tCounter); + checkpoint->add(*tCounter); + monitor->add(*tCounter); + } + if (printBestParam.value()) + { + monitor->add(*bestStat); + monitor->add(*secondStat); + } + if ( printPopParam.value()) + monitor->add(*popStat); + } // first handle the dir test - if we need at least one file - if ( ( fileBestParam.value() || plotBestParam.value() || - plotHistogramParam.value() ) - && !dirOK ) // just in case we add something before - - dirOK = testDirRes(dirNameParam.value(), eraseParam.value()); // TRUE - - + dirOK = testDirRes(dirNameParam.value(), eraseParam.value()); // TRUE if (fileBestParam.value()) // A file monitor for best & secondMoment - - { - + { #ifdef _MSVC - - std::string stmp = dirNameParam.value() + "\best.xg"; - + std::string stmp = dirNameParam.value() + "\best.xg"; #else - - std::string stmp = dirNameParam.value() + "/best.xg"; - + std::string stmp = dirNameParam.value() + "/best.xg"; #endif - - eoFileMonitor *fileMonitor = new eoFileMonitor(stmp); - - // save and give to checkpoint - - _state.storeFunctor(fileMonitor); - - checkpoint->add(*fileMonitor); - - // and feed with some statistics - - fileMonitor->add(*generationCounter); - - fileMonitor->add(_eval); - - if (tCounter) // we want the time as well - - { - - // std::cout << "On met timecounter\n"; - - fileMonitor->add(*tCounter); - - } - - fileMonitor->add(*bestStat); - - fileMonitor->add(*secondStat); - - } - - + eoFileMonitor *fileMonitor = new eoFileMonitor(stmp); + // save and give to checkpoint + _state.storeFunctor(fileMonitor); + checkpoint->add(*fileMonitor); + // and feed with some statistics + fileMonitor->add(*generationCounter); + fileMonitor->add(_eval); + if (tCounter) // we want the time as well + { + // std::cout << "On met timecounter\n"; + fileMonitor->add(*tCounter); + } + fileMonitor->add(*bestStat); + fileMonitor->add(*secondStat); + } #if defined(HAVE_GNUPLOT) - if (plotBestParam.value()) // an eoGnuplot1DMonitor for best & average - - { - - std::string stmp = dirNameParam.value() + "/gnu_best.xg"; - - eoGnuplot1DMonitor *gnuMonitor = new eoGnuplot1DMonitor(stmp,minimizing_fitness()); - - // save and give to checkpoint - - _state.storeFunctor(gnuMonitor); - - checkpoint->add(*gnuMonitor); - - // and feed with some statistics - - if (useEvalParam.value()) // do we want eval as X coordinate - - gnuMonitor->add(_eval); - - else if (tCounter) // or time? - - gnuMonitor->add(*tCounter); - - else // default: generation - - gnuMonitor->add(*generationCounter); - - gnuMonitor->add(*bestStat); - - gnuMonitor->add(*averageStat); - - } - - + { + std::string stmp = dirNameParam.value() + "/gnu_best.xg"; + eoGnuplot1DMonitor *gnuMonitor = new eoGnuplot1DMonitor(stmp,minimizing_fitness()); + // save and give to checkpoint + _state.storeFunctor(gnuMonitor); + checkpoint->add(*gnuMonitor); + // and feed with some statistics + if (useEvalParam.value()) // do we want eval as X coordinate + gnuMonitor->add(_eval); + else if (tCounter) // or time? + gnuMonitor->add(*tCounter); + else // default: generation + gnuMonitor->add(*generationCounter); + gnuMonitor->add(*bestStat); + gnuMonitor->add(*averageStat); + } // historgram? - if (plotHistogramParam.value()) // want to see how the fitness is spread? - - { - - eoScalarFitnessStat *fitStat = new eoScalarFitnessStat; - - _state.storeFunctor(fitStat); - - checkpoint->add(*fitStat); - - // a gnuplot-based monitor for snapshots: needs a dir name - - eoGnuplot1DSnapshot *fitSnapshot = new eoGnuplot1DSnapshot(dirNameParam.value()); - - _state.storeFunctor(fitSnapshot); - - // add any stat that is a std::vector to it - - fitSnapshot->add(*fitStat); - - // and of course add it to the checkpoint - - checkpoint->add(*fitSnapshot); - - } + { + eoScalarFitnessStat *fitStat = new eoScalarFitnessStat; + _state.storeFunctor(fitStat); + checkpoint->add(*fitStat); + // a gnuplot-based monitor for snapshots: needs a dir name + eoGnuplot1DSnapshot *fitSnapshot = new eoGnuplot1DSnapshot(dirNameParam.value()); + _state.storeFunctor(fitSnapshot); + // add any stat that is a std::vector to it + fitSnapshot->add(*fitStat); + // and of course add it to the checkpoint + checkpoint->add(*fitSnapshot); + } #endif ////////////////////////////////// - // State savers - ////////////////////////////// - - // feed the state to state savers - // save state every N generation - eoValueParam& saveFrequencyParam = _parser.createParam(unsigned(0), "saveFrequency", "Save every F generation (0 = only final state, absent = never)", '\0', "Persistence" ); - - if (_parser.isItThere(saveFrequencyParam)) + { + // first make sure dirName is OK + if (! dirOK ) + dirOK = testDirRes(dirNameParam.value(), eraseParam.value()); // TRUE - { - - // first make sure dirName is OK - - if (! dirOK ) - - dirOK = testDirRes(dirNameParam.value(), eraseParam.value()); // TRUE - - - - unsigned freq = (saveFrequencyParam.value()>0 ? saveFrequencyParam.value() : UINT_MAX ); - + unsigned freq = (saveFrequencyParam.value()>0 ? saveFrequencyParam.value() : UINT_MAX ); #ifdef _MSVC - - std::string stmp = dirNameParam.value() + "\generations"; - + std::string stmp = dirNameParam.value() + "\generations"; #else - - std::string stmp = dirNameParam.value() + "/generations"; - + std::string stmp = dirNameParam.value() + "/generations"; #endif - - eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp); - - _state.storeFunctor(stateSaver1); - - checkpoint->add(*stateSaver1); - - } - - + eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp); + _state.storeFunctor(stateSaver1); + checkpoint->add(*stateSaver1); + } // save state every T seconds - eoValueParam& saveTimeIntervalParam = _parser.createParam(unsigned(0), "saveTimeInterval", "Save every T seconds (0 or absent = never)", '\0',"Persistence" ); - if (_parser.isItThere(saveTimeIntervalParam) && saveTimeIntervalParam.value()>0) - - { - - // first make sure dirName is OK - - if (! dirOK ) - - dirOK = testDirRes(dirNameParam.value(), eraseParam.value()); // TRUE - - + { + // first make sure dirName is OK + if (! dirOK ) + dirOK = testDirRes(dirNameParam.value(), eraseParam.value()); // TRUE #ifdef _MSVC - - std::string stmp = dirNameParam.value() + "\time"; - + std::string stmp = dirNameParam.value() + "\time"; #else - - std::string stmp = dirNameParam.value() + "/time"; - + std::string stmp = dirNameParam.value() + "/time"; #endif - - eoTimedStateSaver *stateSaver2 = new eoTimedStateSaver(saveTimeIntervalParam.value(), _state, stmp); - - _state.storeFunctor(stateSaver2); - - checkpoint->add(*stateSaver2); - - } - - + eoTimedStateSaver *stateSaver2 = new eoTimedStateSaver(saveTimeIntervalParam.value(), _state, stmp); + _state.storeFunctor(stateSaver2); + checkpoint->add(*stateSaver2); + } // and that's it for the (control and) output - return *checkpoint; - } - - #endif From 46b3f77d9c8687bcf016fd91c45514a55763fd96 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Fri, 22 Jun 2012 17:41:46 +0200 Subject: [PATCH 18/21] * make_checkpoint.h: added --monitor_with_CtrlC option in order to monitor only when Ctrl-C is pressed --- eo/src/do/make_checkpoint.h | 44 ++++++++++++++++++++++++++++++++++--- eo/src/utils/checkpointing | 1 + eo/src/utils/eoSignal.h | 10 +++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/eo/src/do/make_checkpoint.h b/eo/src/do/make_checkpoint.h index 74145d84..8e529511 100644 --- a/eo/src/do/make_checkpoint.h +++ b/eo/src/do/make_checkpoint.h @@ -59,6 +59,24 @@ eoCheckPoint& do_make_checkpoint(eoParser& _parser, eoState& _state, eoValu _state.storeFunctor(checkpoint); + //////////////////// + // Signal monitoring + //////////////////// + +#ifndef _MSC_VER + // the CtrlC monitoring interception + eoSignal *mon_ctrlCCont; + eoValueParam& mon_ctrlCParam = _parser.createParam(false, "monitor-with-CtrlC", "Monitor current generation upon Ctrl C",0, "Stopping criterion"); + if (mon_ctrlCParam.value()) + { + mon_ctrlCCont = new eoSignal; + // store + _state.storeFunctor(mon_ctrlCCont); + // add to checkpoint + checkpoint->add(*mon_ctrlCCont); + } +#endif + /////////////////// // Counters ////////////////// @@ -117,18 +135,24 @@ eoCheckPoint& do_make_checkpoint(eoParser& _parser, eoState& _state, eoValu _state.storeFunctor(bestStat); // add it to the checkpoint checkpoint->add(*bestStat); + // check if monitoring with signal + if ( mon_ctrlCParam.value() ) + mon_ctrlCCont->add(*bestStat); } // Average fitness alone //---------------------- eoAverageStat *averageStat = NULL; // do we need averageStat? - if ( plotBestParam.value() ) // we need it for gnuplot output + if ( printBestParam.value() || plotBestParam.value() || fileBestParam.value() ) // we need it for gnuplot output { averageStat = new eoAverageStat; // store it _state.storeFunctor(averageStat); // add it to the checkpoint checkpoint->add(*averageStat); + // check if monitoring with signal + if ( mon_ctrlCParam.value() ) + mon_ctrlCCont->add(*averageStat); } // Second moment stats: average and stdev @@ -141,6 +165,9 @@ eoCheckPoint& do_make_checkpoint(eoParser& _parser, eoState& _state, eoValu _state.storeFunctor(secondStat); // add it to the checkpoint checkpoint->add(*secondStat); + // check if monitoring with signal + if ( mon_ctrlCParam.value() ) + mon_ctrlCCont->add(*secondStat); } // Dump of the whole population @@ -155,6 +182,9 @@ eoCheckPoint& do_make_checkpoint(eoParser& _parser, eoState& _state, eoValu _state.storeFunctor(popStat); // add it to the checkpoint checkpoint->add(*popStat); + // check if monitoring with signal + if ( mon_ctrlCParam.value() ) + mon_ctrlCCont->add(*popStat); } // do we wnat some histogram of fitnesses snpashots? @@ -175,7 +205,11 @@ eoCheckPoint& do_make_checkpoint(eoParser& _parser, eoState& _state, eoValu _state.storeFunctor(monitor); // when called by the checkpoint (i.e. at every generation) - checkpoint->add(*monitor); + // check if monitoring with signal + if ( ! mon_ctrlCParam.value() ) + checkpoint->add(*monitor); + else + mon_ctrlCCont->add(*monitor); // the monitor will output a series of parameters: add them monitor->add(*generationCounter); @@ -186,7 +220,11 @@ eoCheckPoint& do_make_checkpoint(eoParser& _parser, eoState& _state, eoValu { tCounter = new eoTimeCounter; _state.storeFunctor(tCounter); - checkpoint->add(*tCounter); + // check if monitoring with signal + if ( ! mon_ctrlCParam.value() ) + checkpoint->add(*tCounter); + else + mon_ctrlCCont->add(*tCounter); monitor->add(*tCounter); } diff --git a/eo/src/utils/checkpointing b/eo/src/utils/checkpointing index 7e3c34a6..f7fd0e55 100644 --- a/eo/src/utils/checkpointing +++ b/eo/src/utils/checkpointing @@ -36,6 +36,7 @@ #include #endif #include +#include #include #include #include diff --git a/eo/src/utils/eoSignal.h b/eo/src/utils/eoSignal.h index 7eeafe3c..9a89cb19 100644 --- a/eo/src/utils/eoSignal.h +++ b/eo/src/utils/eoSignal.h @@ -52,13 +52,23 @@ public : eoSignal( int sig = SIGINT ) : eoCheckPoint( _dummyContinue ), _sig( sig ) { ::signals_called[_sig] = false; + +#ifndef _WINDOWS +#ifdef SIGQUIT ::signal( _sig, handler ); +#endif // !SIGQUIT +#endif // !_WINDOWS } eoSignal( eoContinue& _cont, int sig = SIGINT ) : eoCheckPoint( _cont ), _sig( sig ) { ::signals_called[_sig] = false; + +#ifndef _WINDOWS +#ifdef SIGQUIT ::signal( _sig, handler ); +#endif // !SIGQUIT +#endif // !_WINDOWS } bool operator()( const eoPop& _pop ) From d44a696e2168a98e4430f49bde0aa33d24113fd7 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Sat, 23 Jun 2012 13:39:17 +0200 Subject: [PATCH 19/21] * fixed regression with gcc 4.7 --- eo/src/eoScalarFitnessAssembled.h | 2 +- eo/src/gp/eoParseTree.h | 4 ++-- eo/test/CMakeLists.txt | 2 +- eo/test/t-openmp.cpp | 2 ++ 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/eo/src/eoScalarFitnessAssembled.h b/eo/src/eoScalarFitnessAssembled.h index 95168ec6..50e9038d 100644 --- a/eo/src/eoScalarFitnessAssembled.h +++ b/eo/src/eoScalarFitnessAssembled.h @@ -212,7 +212,7 @@ public: //! Print term values and descriptions void printAll(std::ostream& os) const { for (size_type i=0; i < size(); ++i ) - os << FitnessTraits::getDescription(i) << " = " << operator[](i) << " "; + os << FitnessTraits::getDescription(i) << " = " << this->operator[](i) << " "; } //! Comparison, using less by default diff --git a/eo/src/gp/eoParseTree.h b/eo/src/gp/eoParseTree.h index 11ec105e..88737d91 100644 --- a/eo/src/gp/eoParseTree.h +++ b/eo/src/gp/eoParseTree.h @@ -94,7 +94,7 @@ public: while (size() > _size) { - back() = operator[](size()-2); + back() = this->operator[](size()-2); } } @@ -150,7 +150,7 @@ public: v[i] = node; } parse_tree tmp(v.begin(), v.end()); - swap(tmp); + this->swap(tmp); /* * old code which caused problems for paradisEO diff --git a/eo/test/CMakeLists.txt b/eo/test/CMakeLists.txt index 4e68b02a..c4fcc8db 100644 --- a/eo/test/CMakeLists.txt +++ b/eo/test/CMakeLists.txt @@ -66,7 +66,7 @@ SET (TEST_LIST t-eoLogger t-eoIQRStat t-eoParallel - t-openmp + #t-openmp # does not work anymore since functions used in this test were removed from EO #t-eoDualFitness t-eoParser ) diff --git a/eo/test/t-openmp.cpp b/eo/test/t-openmp.cpp index a1d68087..d2f4cf3b 100644 --- a/eo/test/t-openmp.cpp +++ b/eo/test/t-openmp.cpp @@ -39,6 +39,8 @@ Caner Candan #include +#include + #include "real_value.h" //----------------------------------------------------------------------------- From 1809120d34faddda61aa99949f3c541ca3fba13b Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Mon, 25 Jun 2012 02:17:32 +0200 Subject: [PATCH 20/21] =?UTF-8?q?*=20ga/make=5Fga:=C2=A0eoBooleanGeneratio?= =?UTF-8?q?n=20is=20now=20settable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eo/src/ga/make_ga.h | 4 ++-- eo/src/ga/make_genotype_ga.cpp | 8 ++++---- eo/src/ga/make_genotype_ga.h | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/eo/src/ga/make_ga.h b/eo/src/ga/make_ga.h index ce594903..20609488 100644 --- a/eo/src/ga/make_ga.h +++ b/eo/src/ga/make_ga.h @@ -57,8 +57,8 @@ */ // the genotypes -eoInit > & make_genotype(eoParser& _parser, eoState& _state, eoBit _eo); - eoInit > & make_genotype(eoParser& _parser, eoState& _state, eoBit _eo); +eoInit > & make_genotype(eoParser& _parser, eoState& _state, eoBit _eo, float _bias=0.5); + eoInit > & make_genotype(eoParser& _parser, eoState& _state, eoBit _eo, float _bias=0.5); // the operators eoGenOp >& make_op(eoParser& _parser, eoState& _state, eoInit >& _init); diff --git a/eo/src/ga/make_genotype_ga.cpp b/eo/src/ga/make_genotype_ga.cpp index 4f9e69ef..3344a8d8 100644 --- a/eo/src/ga/make_genotype_ga.cpp +++ b/eo/src/ga/make_genotype_ga.cpp @@ -45,11 +45,11 @@ /// The following function merely call the templatized do_* functions above -eoInit > & make_genotype(eoParser& _parser, eoState& _state, eoBit _eo) +eoInit > & make_genotype(eoParser& _parser, eoState& _state, eoBit _eo, float _bias) { - return do_make_genotype(_parser, _state, _eo); + return do_make_genotype(_parser, _state, _eo, _bias); } -eoInit > & make_genotype(eoParser& _parser, eoState& _state, eoBit _eo) +eoInit > & make_genotype(eoParser& _parser, eoState& _state, eoBit _eo, float _bias) { - return do_make_genotype(_parser, _state, _eo); + return do_make_genotype(_parser, _state, _eo, _bias); } diff --git a/eo/src/ga/make_genotype_ga.h b/eo/src/ga/make_genotype_ga.h index ea1b2005..fad4f756 100644 --- a/eo/src/ga/make_genotype_ga.h +++ b/eo/src/ga/make_genotype_ga.h @@ -60,7 +60,7 @@ * @ingroup Builders */ template -eoInit & do_make_genotype(eoParser& _parser, eoState& _state, EOT) +eoInit & do_make_genotype(eoParser& _parser, eoState& _state, EOT, float _bias=0.5) { // for bitstring, only thing needed is the size // but it might have been already read in the definition fo the performance @@ -68,7 +68,7 @@ eoInit & do_make_genotype(eoParser& _parser, eoState& _state, EOT) // Then we can built a bitstring random initializer // based on boolean_generator class (see utils/rnd_generator.h) - eoBooleanGenerator * gen = new eoBooleanGenerator; + eoBooleanGenerator * gen = new eoBooleanGenerator(_bias); _state.storeFunctor(gen); eoInitFixedLength* init = new eoInitFixedLength(theSize, *gen); // store in state From 29e31fb6df78f7eb79614547a3876e8510edc6b0 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Mon, 25 Jun 2012 02:18:15 +0200 Subject: [PATCH 21/21] =?UTF-8?q?*=20ga/make=5Fop:=C2=A0added=20kbit=20fli?= =?UTF-8?q?p=20mutation,=20disabled=20by=20default?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eo/src/ga/make_op.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/eo/src/ga/make_op.h b/eo/src/ga/make_op.h index 045148ec..2035a4f8 100644 --- a/eo/src/ga/make_op.h +++ b/eo/src/ga/make_op.h @@ -156,11 +156,23 @@ eoGenOp & do_make_op(eoParser& _parser, eoState& _state, eoInit& _init if ( (bitFlipRateParam.value() < 0) ) throw std::runtime_error("Invalid bitFlipRate"); + // oneBitFlip eoValueParam & oneBitRateParam = _parser.createParam(0.01, "oneBitRate", "Relative rate for deterministic bit-flip mutation", 'd', "Variation Operators" ); // minimum check if ( (oneBitRateParam.value() < 0) ) throw std::runtime_error("Invalid oneBitRate"); + // kBitFlip + eoValueParam & kBitParam = _parser.createParam((unsigned)1, "kBit", "Number of bit for deterministic k bit-flip mutation", 0, "Variation Operators" ); + // minimum check + if ( ! kBitParam.value() ) + throw std::runtime_error("Invalid kBit"); + + eoValueParam & kBitRateParam = _parser.createParam(0.0, "kBitRate", "Relative rate for deterministic k bit-flip mutation", 0, "Variation Operators" ); + // minimum check + if ( (kBitRateParam.value() < 0) ) + throw std::runtime_error("Invalid kBitRate"); + // minimum check // bool bMut = true; // not used ? if (bitFlipRateParam.value()+oneBitRateParam.value()==0) @@ -184,6 +196,11 @@ eoGenOp & do_make_op(eoParser& _parser, eoState& _state, eoInit& _init _state.storeFunctor(ptMon); ptCombinedMonOp->add(*ptMon, oneBitRateParam.value()); + // mutate exactly k bit per individual + ptMon = new eoDetBitFlip(kBitParam.value()); + _state.storeFunctor(ptMon); + ptCombinedMonOp->add(*ptMon, kBitRateParam.value()); + _state.storeFunctor(ptCombinedMonOp); // now build the eoGenOp: