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!).
This commit is contained in:
evomarc 2001-04-30 13:01:07 +00:00
commit d90286d890
13 changed files with 53 additions and 140 deletions

View file

@ -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 <utils/eoParser.h>
#include <fstream.h>
/** 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<string>& 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
}
}

View file

@ -7,7 +7,7 @@
INCLUDES = -I$(top_builddir)/src INCLUDES = -I$(top_builddir)/src
lib_LIBRARIES = libes.a lib_LIBRARIES = libes.a
libes_a_SOURCES = make_algo_scalar_real.cpp make_checkpoint_real.cpp \ 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_op_real.cpp make_pop_real.cpp make_run_real.cpp \
make_algo_scalar_es.cpp make_checkpoint_es.cpp \ make_algo_scalar_es.cpp make_checkpoint_es.cpp \
make_continue_es.cpp make_pop_es.cpp make_run_es.cpp make_continue_es.cpp make_pop_es.cpp make_run_es.cpp

View file

@ -30,23 +30,33 @@
* files that you just need to link with your own main and fitness code). * files that you just need to link with your own main and fitness code).
* *
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained * The corresponding ***INSTANCIATED DECLARATIONS*** are contained
* in src/es/es.h * in src/es/make_real.h
* while the TEMPLATIZED code is define in make_genotype_real.h in the src/es dir * 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, * It is instanciated in src/es/make_genotype_real.cpp -
* just declarations * and incorporated in the ga/libga.a
*
* It returns an eoInit<EOT> 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 // the templatized code
#include <es/make_genotype.h> #include <es/make_genotype_real.h>
/// The following function merely call the templatized do_* functions /// The following function merely call the templatized do_* functions
eoInit<eoReal<double> > & make_genotype(eoParameterLoader& _parser, eoState& _state, double _d) eoInit<eoReal<double> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoReal<double> _eo)
{ {
return do_make_genotype(_parser, _state, _d); return do_make_genotype(_parser, _state, _eo);
} }
eoInit<eoReal<eoMinimizingFitness> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoMinimizingFitness _d) eoInit<eoReal<eoMinimizingFitness> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoReal<eoMinimizingFitness> _eo)
{ {
return do_make_genotype(_parser, _state, _d); return do_make_genotype(_parser, _state, _eo);
} }

View file

@ -35,23 +35,34 @@
/* /*
* This function does the initialization of what's needed for a particular * This fuction does the initialization of what's needed for a particular
* genotype (here, eoReal). * genotype (here, vector<double> == eoReal).
* It is templatized ***only on the fitness*** so it can be used to evolve * It could be here tempatied only on the fitness, as it can be used to evolve
* eoReal with any fitness. * bitstrings with any fitness.
* It is instanciated in es/make_genotype_real.cpp - * However, for consistency reasons, it was finally chosen, as in
* and incorporated in the es/libes.a * 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<eoReal<FitT> > 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<EOT> tha can later be used to initialize
* the population (see make_pop.h). * the population (see make_pop.h).
* *
* It uses a parser (to get user parameters) and a state (to store the memory) * 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. * 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 <class FitT> template <class EOT>
eoInit<eoReal<FitT> > & do_make_genotype(eoParameterLoader& _parser, eoState& _state, FitT) eoInit<EOT> & do_make_genotype(eoParameterLoader& _parser, eoState& _state, EOT)
{ {
// the fitness type
typedef typename EOT::Fitness FitT;
// for eoReal, only thing needed is the size // for eoReal, only thing needed is the size
eoValueParam<unsigned>& vecSize = _parser.createParam(unsigned(10), "vecSize", "The number of variables ", 'n',"initialization"); eoValueParam<unsigned>& vecSize = _parser.createParam(unsigned(10), "vecSize", "The number of variables ", 'n',"initialization");

View file

@ -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 <utils/eoParser.h>
#include <fstream.h>
/** 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<string>& 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
}
}

View file

@ -59,8 +59,8 @@
////////////////////////// //////////////////////////
// the genotypes // the genotypes
eoInit<eoReal<double> > & make_genotype(eoParameterLoader& _parser, eoState& _state, double _d); eoInit<eoReal<double> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoReal<double> _eo);
eoInit<eoReal<eoMinimizingFitness> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoMinimizingFitness _d); eoInit<eoReal<eoMinimizingFitness> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoReal<eoMinimizingFitness> _eo);
// the operators // the operators
eoGenOp<eoReal<double> >& make_op(eoParameterLoader& _parser, eoState& _state, eoInit<eoReal<double> >& _init); eoGenOp<eoReal<double> >& make_op(eoParameterLoader& _parser, eoState& _state, eoInit<eoReal<double> >& _init);
@ -93,7 +93,8 @@ void run_ea(eoAlgo<eoReal<double> >& _ga, eoPop<eoReal<double> >& _pop);
void run_ea(eoAlgo<eoReal<eoMinimizingFitness> >& _ga, eoPop<eoReal<eoMinimizingFitness> >& _pop); void run_ea(eoAlgo<eoReal<eoMinimizingFitness> >& _ga, eoPop<eoReal<eoMinimizingFitness> >& _pop);
// end of parameter input (+ .status + help) // 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); void make_help(eoParser & _parser);
#endif #endif

View file

@ -10,7 +10,6 @@ libga_a_SOURCES = make_algo_scalar_ga.cpp \
make_checkpoint_ga.cpp \ make_checkpoint_ga.cpp \
make_continue_ga.cpp \ make_continue_ga.cpp \
make_genotype_ga.cpp \ make_genotype_ga.cpp \
make_help.cpp \
make_op_ga.cpp \ make_op_ga.cpp \
make_pop_ga.cpp \ make_pop_ga.cpp \
make_run_ga.cpp make_run_ga.cpp

View file

@ -86,7 +86,8 @@ void run_ea(eoAlgo<eoBit<double> >& _ga, eoPop<eoBit<double> >& _pop);
void run_ea(eoAlgo<eoBit<eoMinimizingFitness> >& _ga, eoPop<eoBit<eoMinimizingFitness> >& _pop); void run_ea(eoAlgo<eoBit<eoMinimizingFitness> >& _ga, eoPop<eoBit<eoMinimizingFitness> >& _pop);
// end of parameter input (+ .status + help) // 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); void make_help(eoParser & _parser);
#endif #endif

View file

@ -36,7 +36,7 @@
/////////////////// the bitstring //////////////// /////////////////// 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). * genotype (here, bitstrings).
* It could be here tempatied only on the fitness, as it can be used to evolve * It could be here tempatied only on the fitness, as it can be used to evolve
* bitstrings with any fitness. * bitstrings with any fitness.
@ -55,7 +55,6 @@
* WARNING: that last argument will generally be the result of calling * WARNING: that last argument will generally be the result of calling
* the default ctor of EOT, resulting in most cases in an EOT * the default ctor of EOT, resulting in most cases in an EOT
* that is ***not properly initialized*** * that is ***not properly initialized***
*/ */
template <class EOT> template <class EOT>

View file

@ -7,7 +7,7 @@
INCLUDES = -I$(top_builddir)/src INCLUDES = -I$(top_builddir)/src
CPPFLAGS = -O2 -Wall CPPFLAGS = -O2 -Wall
lib_LIBRARIES = libeoutils.a 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 libeoincdir = $(includedir)/eo/utils
libeoinc_HEADERS = checkpointing *.h libeoinc_HEADERS = checkpointing *.h

View file

@ -1,6 +1,6 @@
#include <iostream> #include <iostream>
#include <ga/ga.h> #include <ga/make_ga.h>
#include "binary_value.h" #include "binary_value.h"
#include <apply.h> #include <apply.h>
@ -25,7 +25,7 @@ int main(int argc, char* argv[])
eoEvalFuncCounter<EOT> eval(mainEval); eoEvalFuncCounter<EOT> eval(mainEval);
// the genotype - through a genotype initializer // the genotype - through a genotype initializer
eoInit<EOT>& init = make_genotype(parser, state, double()); eoInit<EOT>& init = make_genotype(parser, state, EOT());
// Build the variation operator (any seq/prop construct) // Build the variation operator (any seq/prop construct)
eoGenOp<EOT>& op = make_op(parser, state, init); eoGenOp<EOT>& op = make_op(parser, state, init);

View file

@ -1,6 +1,6 @@
#include <iostream> #include <iostream>
#include <es/real.h> #include <es/make_real.h>
#include "real_value.h" #include "real_value.h"
#include <apply.h> #include <apply.h>
@ -26,7 +26,7 @@ int main(int argc, char* argv[])
eoEvalFuncCounter<EOT> eval(mainEval); eoEvalFuncCounter<EOT> eval(mainEval);
// the genotype - through a genotype initializer // the genotype - through a genotype initializer
eoInit<EOT>& init = make_genotype(parser, state, eoMinimizingFitness()); eoInit<EOT>& init = make_genotype(parser, state, EOT());
// Build the variation operator (any seq/prop construct) // Build the variation operator (any seq/prop construct)
eoGenOp<EOT>& op = make_op(parser, state, init); eoGenOp<EOT>& op = make_op(parser, state, init);