Some changes in names, before too many users have to modify their code :-)

Changed ga.h in src/ga into make_ga.h (was ambiguous with src/ga.h)
Chenged 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!)
This commit is contained in:
evomarc 2001-04-30 12:26:31 +00:00
commit 1c75344197
4 changed files with 24 additions and 18 deletions

View file

@ -17,4 +17,4 @@ libga_a_SOURCES = make_algo_scalar_ga.cpp \
CPPFLAGS = -Wall
CXXFLAGS = -g
libeoincdir = $(includedir)/eo/ga
libeoinc_HEADERS = eoBit.h eoBitOp.h eoBitOpFactory.h ga.h
libeoinc_HEADERS = eoBit.h eoBitOp.h eoBitOpFactory.h make_ga.h

92
eo/src/ga/make_ga.h Normal file
View file

@ -0,0 +1,92 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// ga.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
*/
//-----------------------------------------------------------------------------
/** This file contains all ***INSTANCIATED*** declarations of all components
* of the library for ***BISTRING*** evolution inside EO.
* It should be included in the file that calls any of the corresponding fns
*
* The corresponding ***INSTANCIATED*** definitions are contained in ga.cpp
* while the TEMPLATIZED code is define in the different makeXXX.h files
*
* Unlike most EO .h files, it does not (and should not) contain any code,
* just declarations
*/
#ifndef ga_h
#define ga_h
#include <eoAlgo.h>
#include <eoScalarFitness.h>
#include <utils/eoParser.h>
#include <eoEvalFuncCounter.h>
#include <utils/eoCheckPoint.h>
#include <eoGenOp.h>
#include <eoPop.h>
#include <ga/eoBit.h>
//Representation dependent - rewrite everything anew for each representation
//////////////////////////
// the genotypes
eoInit<eoBit<double> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoBit<double> _eo);
eoInit<eoBit<eoMinimizingFitness> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoBit<eoMinimizingFitness> _eo);
// the operators
eoGenOp<eoBit<double> >& make_op(eoParameterLoader& _parser, eoState& _state, eoInit<eoBit<double> >& _init);
eoGenOp<eoBit<eoMinimizingFitness> >& make_op(eoParameterLoader& _parser, eoState& _state, eoInit<eoBit<eoMinimizingFitness> >& _init);
//Representation INdependent
////////////////////////////
// if you use your own representation, simply change the types of templates
// init pop
eoPop<eoBit<double> >& make_pop(eoParser& _parser, eoState& _state, eoInit<eoBit<double> >&);
eoPop<eoBit<eoMinimizingFitness> >& make_ga(eoParser& _parser, eoState& _state, eoInit<eoBit<eoMinimizingFitness> >&);
// the continue's
eoContinue<eoBit<double> >& make_continue(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoBit<double> > & _eval);
eoContinue<eoBit<eoMinimizingFitness> >& make_continue(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoBit<eoMinimizingFitness> > & _eval);
// the checkpoint
eoCheckPoint<eoBit<double> >& make_checkpoint(eoParameterLoader& _parser, eoState& _state, eoEvalFuncCounter<eoBit<double> >& _eval, eoContinue<eoBit<double> >& _continue);
eoCheckPoint<eoBit<eoMinimizingFitness> >& make_checkpoint(eoParameterLoader& _parser, eoState& _state, eoEvalFuncCounter<eoBit<eoMinimizingFitness> >& _eval, eoContinue<eoBit<eoMinimizingFitness> >& _continue);
// the algo
eoAlgo<eoBit<double> >& make_algo_scalar(eoParameterLoader& _parser, eoState& _state, eoEvalFunc<eoBit<double> >& _eval, eoContinue<eoBit<double> >& _ccontinue, eoGenOp<eoBit<double> >& _op);
eoAlgo<eoBit<eoMinimizingFitness> >& make_algo_scalar(eoParameterLoader& _parser, eoState& _state, eoEvalFunc<eoBit<eoMinimizingFitness> >& _eval, eoContinue<eoBit<eoMinimizingFitness> >& _ccontinue, eoGenOp<eoBit<eoMinimizingFitness> >& _op);
// run
void run_ea(eoAlgo<eoBit<double> >& _ga, eoPop<eoBit<double> >& _pop);
void run_ea(eoAlgo<eoBit<eoMinimizingFitness> >& _ga, eoPop<eoBit<eoMinimizingFitness> >& _pop);
// end of parameter input (+ .status + help)
// that one is not templatized, but is here for the sake of completeness
void make_help(eoParser & _parser);
#endif

View file

@ -31,23 +31,20 @@
* files that you just need to link with your own main and fitness code).
*
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
* in make_genotype_ga.h
* while the TEMPLATIZED code is define in make_genotype.h in the ga dir
*
* Unlike most EO .h files, it does not (and should not) contain any code,
* just declarations
* in ga.h in src/ga dir
* while the TEMPLATIZED code is define in make_genotype_ga.h
*/
// the templatized code
#include <ga/make_genotype.h>
#include <ga/make_genotype_ga.h>
/// The following function merely call the templatized do_* functions above
eoInit<eoBit<double> > & make_genotype(eoParameterLoader& _parser, eoState& _state, double _d)
eoInit<eoBit<double> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoBit<double> _eo)
{
return do_make_genotype(_parser, _state, _d);
return do_make_genotype(_parser, _state, _eo);
}
eoInit<eoBit<eoMinimizingFitness> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoMinimizingFitness _d)
eoInit<eoBit<eoMinimizingFitness> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoBit<eoMinimizingFitness> _eo)
{
return do_make_genotype(_parser, _state, _d);
return do_make_genotype(_parser, _state, _eo);
}

View file

@ -0,0 +1,77 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// make_genotype.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
*/
//-----------------------------------------------------------------------------
#ifndef _make_genotype_h
#define _make_genotype_h
#include <ga/eoBit.h>
#include <eoInit.h>
// also need the parser and param includes
#include <utils/eoParser.h>
#include <utils/eoState.h>
/////////////////// the bitstring ////////////////
/*
* This fuciont 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.
* 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 is instanciated in ga/ga.cpp - and incorporated in the ga/libga.a
*
* It returns an eoInit<eoBit<FitT> > 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 <class EOT>
eoInit<EOT> & do_make_genotype(eoParameterLoader& _parser, eoState& _state, EOT)
{
// for bitstring, only thing needed is the size
eoValueParam<unsigned>& chromSize = _parser.createParam(unsigned(10), "ChromSize", "The length of the bitstrings", 'n',"initialization");
// Then we can built a bitstring random initializer
// based on boolean_generator class (see utils/rnd_generator.h)
eoBooleanGenerator * gen = new eoBooleanGenerator;
_state.storeFunctor(gen);
eoInitFixedLength<EOT>* init = new eoInitFixedLength<EOT>(chromSize.value(), *gen);
// store in state
_state.storeFunctor(init);
return *init;
}
#endif