From d90286d890b9d871e8f1edc89d3b452adde2a12d Mon Sep 17 00:00:00 2001 From: evomarc Date: Mon, 30 Apr 2001 13:01:07 +0000 Subject: [PATCH] Some changes in names, before too many users have to modify their code :-) Changed es.h in src/es into make_es.h (was ambiguous with src/es.h) Changed the interface of make_genotype - now templatized by the EOT and not the fitness - this is mandatory for ES genoptypes as it allows to choose the type of gentype at run-time (from existing types, of course!) Also moved make_help.cpp into utils dir (otherwise you'd had to maintain a copy into each representation dir!). --- eo/src/do/make_help.cpp | 54 ------------------- eo/src/es/Makefile.am | 2 +- eo/src/es/{es.h => make_es.h} | 0 eo/src/es/make_genotype_real.cpp | 30 +++++++---- .../{make_genotype.h => make_genotype_real.h} | 29 ++++++---- eo/src/es/make_help.cpp | 54 ------------------- eo/src/es/{real.h => make_real.h} | 7 +-- eo/src/ga/Makefile.am | 1 - eo/src/ga/make_ga.h | 3 +- eo/src/ga/make_genotype_ga.h | 3 +- eo/src/utils/Makefile.am | 2 +- eo/test/t-eoGA.cpp | 4 +- eo/test/t-eoReal.cpp | 4 +- 13 files changed, 53 insertions(+), 140 deletions(-) delete mode 100644 eo/src/do/make_help.cpp rename eo/src/es/{es.h => make_es.h} (100%) rename eo/src/es/{make_genotype.h => make_genotype_real.h} (75%) delete mode 100644 eo/src/es/make_help.cpp rename eo/src/es/{real.h => make_real.h} (95%) diff --git a/eo/src/do/make_help.cpp b/eo/src/do/make_help.cpp deleted file mode 100644 index 31cb749f..00000000 --- a/eo/src/do/make_help.cpp +++ /dev/null @@ -1,54 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// make_help.h -// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001 -/* - 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 - Marc.Schoenauer@polytechnique.fr - mkeijzer@dhi.dk - */ -//----------------------------------------------------------------------------- -#include -#include - -/** Generation of the status file, and output of the help message if needed - * - * MUST be called after ALL parameters have been read in order to list them - * - * Warning: this is a plain .cpp file and shoudl NOT be included anywhere, - * but compiled separately and stored in a library. - */ -void make_help(eoParser & _parser) -{ - // name of the "status" file where all actual parameter values will be saved - string str_status = _parser.ProgramName() + ".status"; // default value - eoValueParam& statusParam = _parser.createParam(str_status, "status","Status file",'\0', "Persistence" ); - - // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED - // i.e. in case you need parameters somewhere else, postpone these - if (_parser.userNeedsHelp()) - { - _parser.printHelp(cout); - exit(1); - } - if (statusParam.value() != "") - { - ofstream os(statusParam.value().c_str()); - os << _parser; // and you can use that file as parameter file - } -} diff --git a/eo/src/es/Makefile.am b/eo/src/es/Makefile.am index 48c1b841..3ff39207 100644 --- a/eo/src/es/Makefile.am +++ b/eo/src/es/Makefile.am @@ -7,7 +7,7 @@ INCLUDES = -I$(top_builddir)/src lib_LIBRARIES = libes.a libes_a_SOURCES = make_algo_scalar_real.cpp make_checkpoint_real.cpp \ - make_continue_real.cpp make_genotype_real.cpp make_help.cpp \ + make_continue_real.cpp make_genotype_real.cpp \ make_op_real.cpp make_pop_real.cpp make_run_real.cpp \ make_algo_scalar_es.cpp make_checkpoint_es.cpp \ make_continue_es.cpp make_pop_es.cpp make_run_es.cpp diff --git a/eo/src/es/es.h b/eo/src/es/make_es.h similarity index 100% rename from eo/src/es/es.h rename to eo/src/es/make_es.h diff --git a/eo/src/es/make_genotype_real.cpp b/eo/src/es/make_genotype_real.cpp index e19ef54b..29775d24 100644 --- a/eo/src/es/make_genotype_real.cpp +++ b/eo/src/es/make_genotype_real.cpp @@ -30,23 +30,33 @@ * files that you just need to link with your own main and fitness code). * * The corresponding ***INSTANCIATED DECLARATIONS*** are contained - * in src/es/es.h - * while the TEMPLATIZED code is define in make_genotype_real.h in the src/es dir + * in src/es/make_real.h + * while the TEMPLATIZED code is define in make_genotype_real.h * - * Unlike most EO .h files, it does not (and should not) contain any code, - * just declarations - */ + * It is instanciated in src/es/make_genotype_real.cpp - + * and incorporated in the ga/libga.a + * + * It returns an eoInit that can later be used to initialize + * the population (see make_pop.h). + * + * It uses a parser (to get user parameters) and a state (to store the memory) + * the last argument is to disambiguate the call upon different instanciations. + * + * WARNING: that last argument will generally be the result of calling + * the default ctor of EOT, resulting in most cases in an EOT + * that is ***not properly initialized*** +*/ // the templatized code -#include +#include /// The following function merely call the templatized do_* functions -eoInit > & make_genotype(eoParameterLoader& _parser, eoState& _state, double _d) +eoInit > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoReal _eo) { - return do_make_genotype(_parser, _state, _d); + return do_make_genotype(_parser, _state, _eo); } -eoInit > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoMinimizingFitness _d) +eoInit > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoReal _eo) { - return do_make_genotype(_parser, _state, _d); + return do_make_genotype(_parser, _state, _eo); } diff --git a/eo/src/es/make_genotype.h b/eo/src/es/make_genotype_real.h similarity index 75% rename from eo/src/es/make_genotype.h rename to eo/src/es/make_genotype_real.h index 49e8738b..236f1e12 100644 --- a/eo/src/es/make_genotype.h +++ b/eo/src/es/make_genotype_real.h @@ -35,23 +35,34 @@ /* - * This function does the initialization of what's needed for a particular - * genotype (here, eoReal). - * It is templatized ***only on the fitness*** so it can be used to evolve - * eoReal with any fitness. - * It is instanciated in es/make_genotype_real.cpp - - * and incorporated in the es/libes.a + * This fuction does the initialization of what's needed for a particular + * genotype (here, vector == eoReal). + * It could be here tempatied only on the fitness, as it can be used to evolve + * bitstrings with any fitness. + * However, for consistency reasons, it was finally chosen, as in + * the rest of EO, to templatize by the full EOT, as this eventually + * allows to choose the type of genotype at run time (see in es dir) * - * It returns an eoInit > tha can later be used to initialize + * It is instanciated in src/es/make_genotyupe_real.cpp + * and incorporated in the src/es/libes.a + * + * It returns an eoInit tha can later be used to initialize * the population (see make_pop.h). * * It uses a parser (to get user parameters) and a state (to store the memory) * the last argument is to disambiguate the call upon different instanciations. + * + * WARNING: that last argument will generally be the result of calling + * the default ctor of EOT, resulting in most cases in an EOT + * that is ***not properly initialized*** */ -template -eoInit > & do_make_genotype(eoParameterLoader& _parser, eoState& _state, FitT) +template +eoInit & do_make_genotype(eoParameterLoader& _parser, eoState& _state, EOT) { + // the fitness type + typedef typename EOT::Fitness FitT; + // for eoReal, only thing needed is the size eoValueParam& vecSize = _parser.createParam(unsigned(10), "vecSize", "The number of variables ", 'n',"initialization"); diff --git a/eo/src/es/make_help.cpp b/eo/src/es/make_help.cpp deleted file mode 100644 index 31cb749f..00000000 --- a/eo/src/es/make_help.cpp +++ /dev/null @@ -1,54 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// make_help.h -// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001 -/* - 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 - Marc.Schoenauer@polytechnique.fr - mkeijzer@dhi.dk - */ -//----------------------------------------------------------------------------- -#include -#include - -/** Generation of the status file, and output of the help message if needed - * - * MUST be called after ALL parameters have been read in order to list them - * - * Warning: this is a plain .cpp file and shoudl NOT be included anywhere, - * but compiled separately and stored in a library. - */ -void make_help(eoParser & _parser) -{ - // name of the "status" file where all actual parameter values will be saved - string str_status = _parser.ProgramName() + ".status"; // default value - eoValueParam& statusParam = _parser.createParam(str_status, "status","Status file",'\0', "Persistence" ); - - // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED - // i.e. in case you need parameters somewhere else, postpone these - if (_parser.userNeedsHelp()) - { - _parser.printHelp(cout); - exit(1); - } - if (statusParam.value() != "") - { - ofstream os(statusParam.value().c_str()); - os << _parser; // and you can use that file as parameter file - } -} diff --git a/eo/src/es/real.h b/eo/src/es/make_real.h similarity index 95% rename from eo/src/es/real.h rename to eo/src/es/make_real.h index f5c8927d..3786b87c 100644 --- a/eo/src/es/real.h +++ b/eo/src/es/make_real.h @@ -59,8 +59,8 @@ ////////////////////////// // the genotypes -eoInit > & make_genotype(eoParameterLoader& _parser, eoState& _state, double _d); - eoInit > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoMinimizingFitness _d); +eoInit > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoReal _eo); + eoInit > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoReal _eo); // the operators eoGenOp >& make_op(eoParameterLoader& _parser, eoState& _state, eoInit >& _init); @@ -93,7 +93,8 @@ void run_ea(eoAlgo >& _ga, eoPop >& _pop); void run_ea(eoAlgo >& _ga, eoPop >& _pop); // end of parameter input (+ .status + help) -// that one is not templatized, but is here for completeness +// that one is not templatized +// Because of that, the source is in src/utils dir void make_help(eoParser & _parser); #endif diff --git a/eo/src/ga/Makefile.am b/eo/src/ga/Makefile.am index 08bc0498..b46bb017 100644 --- a/eo/src/ga/Makefile.am +++ b/eo/src/ga/Makefile.am @@ -10,7 +10,6 @@ libga_a_SOURCES = make_algo_scalar_ga.cpp \ make_checkpoint_ga.cpp \ make_continue_ga.cpp \ make_genotype_ga.cpp \ - make_help.cpp \ make_op_ga.cpp \ make_pop_ga.cpp \ make_run_ga.cpp diff --git a/eo/src/ga/make_ga.h b/eo/src/ga/make_ga.h index 861cbb77..ea7561f7 100644 --- a/eo/src/ga/make_ga.h +++ b/eo/src/ga/make_ga.h @@ -86,7 +86,8 @@ void run_ea(eoAlgo >& _ga, eoPop >& _pop); void run_ea(eoAlgo >& _ga, eoPop >& _pop); // end of parameter input (+ .status + help) -// that one is not templatized, but is here for the sake of completeness +// that one is not templatized +// Because of that, the source is in src/utils dir void make_help(eoParser & _parser); #endif diff --git a/eo/src/ga/make_genotype_ga.h b/eo/src/ga/make_genotype_ga.h index a0d5d92b..9a0fc6a8 100644 --- a/eo/src/ga/make_genotype_ga.h +++ b/eo/src/ga/make_genotype_ga.h @@ -36,7 +36,7 @@ /////////////////// the bitstring //////////////// /* - * This fuciont does the initialization of what's needed for a particular + * This fuction does the initialization of what's needed for a particular * genotype (here, bitstrings). * It could be here tempatied only on the fitness, as it can be used to evolve * bitstrings with any fitness. @@ -55,7 +55,6 @@ * WARNING: that last argument will generally be the result of calling * the default ctor of EOT, resulting in most cases in an EOT * that is ***not properly initialized*** - */ template diff --git a/eo/src/utils/Makefile.am b/eo/src/utils/Makefile.am index 2f1d0c4d..1b2484a8 100644 --- a/eo/src/utils/Makefile.am +++ b/eo/src/utils/Makefile.am @@ -7,7 +7,7 @@ INCLUDES = -I$(top_builddir)/src CPPFLAGS = -O2 -Wall lib_LIBRARIES = libeoutils.a -libeoutils_a_SOURCES = eoParser.cpp eoRNG.cpp eoState.cpp eoUpdater.cpp eoFileMonitor.cpp eoStdoutMonitor.cpp eoRealBounds.cpp +libeoutils_a_SOURCES = eoParser.cpp eoRNG.cpp eoState.cpp eoUpdater.cpp eoFileMonitor.cpp eoStdoutMonitor.cpp eoRealBounds.cpp make_help.cpp libeoincdir = $(includedir)/eo/utils libeoinc_HEADERS = checkpointing *.h diff --git a/eo/test/t-eoGA.cpp b/eo/test/t-eoGA.cpp index bba6d5cd..7d073d65 100644 --- a/eo/test/t-eoGA.cpp +++ b/eo/test/t-eoGA.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include "binary_value.h" #include @@ -25,7 +25,7 @@ int main(int argc, char* argv[]) eoEvalFuncCounter eval(mainEval); // the genotype - through a genotype initializer - eoInit& init = make_genotype(parser, state, double()); + eoInit& init = make_genotype(parser, state, EOT()); // Build the variation operator (any seq/prop construct) eoGenOp& op = make_op(parser, state, init); diff --git a/eo/test/t-eoReal.cpp b/eo/test/t-eoReal.cpp index 36dc6cd9..42d80a0c 100644 --- a/eo/test/t-eoReal.cpp +++ b/eo/test/t-eoReal.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include "real_value.h" #include @@ -26,7 +26,7 @@ int main(int argc, char* argv[]) eoEvalFuncCounter eval(mainEval); // the genotype - through a genotype initializer - eoInit& init = make_genotype(parser, state, eoMinimizingFitness()); + eoInit& init = make_genotype(parser, state, EOT()); // Build the variation operator (any seq/prop construct) eoGenOp& op = make_op(parser, state, init);