Adding all make_*_real.* - similar to ga stuff for eoReal (not ES yet)
This commit is contained in:
parent
4968d64b05
commit
538d91c601
10 changed files with 768 additions and 0 deletions
59
eo/src/es/make_algo_scalar_real.cpp
Normal file
59
eo/src/es/make_algo_scalar_real.cpp
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// make_algo_scalar_real.cpp
|
||||||
|
// (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 ***INSTANCIATED DEFINITIONS*** of select/replace fns
|
||||||
|
* of the library for evolution of ***eoReal*** inside EO.
|
||||||
|
* It should be included in the file that calls any of the corresponding fns
|
||||||
|
* Compiling this file allows one to generate part of the library (i.e. object
|
||||||
|
* files that you just need to link with your own main and fitness code).
|
||||||
|
*
|
||||||
|
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||||
|
* in src/es/real.h
|
||||||
|
* while the TEMPLATIZED code is define in make_algo_scalar.h in the src/do dir
|
||||||
|
*
|
||||||
|
* Unlike most EO .h files, it does not (and should not) contain any code,
|
||||||
|
* just declarations
|
||||||
|
*/
|
||||||
|
|
||||||
|
// The templatized code
|
||||||
|
#include <do/make_algo_scalar.h>
|
||||||
|
// the instanciating EOType
|
||||||
|
#include <es/eoReal.h>
|
||||||
|
|
||||||
|
/// The following function merely call the templatized do_* functions above
|
||||||
|
|
||||||
|
// Algo
|
||||||
|
///////
|
||||||
|
eoAlgo<eoReal<double> >& make_algo_scalar(eoParameterLoader& _parser, eoState& _state, eoEvalFunc<eoReal<double> >& _eval, eoContinue<eoReal<double> >& _continue, eoGenOp<eoReal<double> >& _op)
|
||||||
|
{
|
||||||
|
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
|
||||||
|
}
|
||||||
|
|
||||||
|
eoAlgo<eoReal<eoMinimizingFitness> >& make_algo_scalar(eoParameterLoader& _parser, eoState& _state, eoEvalFunc<eoReal<eoMinimizingFitness> >& _eval, eoContinue<eoReal<eoMinimizingFitness> >& _continue, eoGenOp<eoReal<eoMinimizingFitness> >& _op)
|
||||||
|
{
|
||||||
|
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
|
||||||
|
}
|
||||||
|
|
||||||
59
eo/src/es/make_checkpoint_real.cpp
Normal file
59
eo/src/es/make_checkpoint_real.cpp
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// make_checkpoint_real.cpp
|
||||||
|
// (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 ***INSTANCIATED DEFINITIONS*** of checkpoint fns
|
||||||
|
* of the library for evolution of ***eoReal*** inside EO.
|
||||||
|
* It should be included in the file that calls any of the corresponding fns
|
||||||
|
* Compiling this file allows one to generate part of the library (i.e. object
|
||||||
|
* files that you just need to link with your own main and fitness code).
|
||||||
|
*
|
||||||
|
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||||
|
* in src/es/real.h
|
||||||
|
* while the TEMPLATIZED code is define in make_checkpoint.h in the src/do dir
|
||||||
|
*
|
||||||
|
* Unlike most EO .h files, it does not (and should not) contain any code,
|
||||||
|
* just declarations
|
||||||
|
*/
|
||||||
|
|
||||||
|
// The templatized code
|
||||||
|
#include <do/make_checkpoint.h>
|
||||||
|
// the instanciating EOType
|
||||||
|
#include <es/eoReal.h>
|
||||||
|
|
||||||
|
/// The following function merely call the templatized do_* functions
|
||||||
|
|
||||||
|
// checkpoint
|
||||||
|
/////////////
|
||||||
|
eoCheckPoint<eoReal<double> >& make_checkpoint(eoParameterLoader& _parser, eoState& _state, eoEvalFuncCounter<eoReal<double> >& _eval, eoContinue<eoReal<double> >& _continue)
|
||||||
|
{
|
||||||
|
return do_make_checkpoint(_parser, _state, _eval, _continue);
|
||||||
|
}
|
||||||
|
eoCheckPoint<eoReal<eoMinimizingFitness> >& make_checkpoint(eoParameterLoader& _parser, eoState& _state, eoEvalFuncCounter<eoReal<eoMinimizingFitness> >& _eval, eoContinue<eoReal<eoMinimizingFitness> >& _continue)
|
||||||
|
{
|
||||||
|
return do_make_checkpoint(_parser, _state, _eval, _continue);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
59
eo/src/es/make_continue_real.cpp
Normal file
59
eo/src/es/make_continue_real.cpp
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// make_continue_real.cpp
|
||||||
|
// (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 ***INSTANCIATED DEFINITIONS*** of continuator fns
|
||||||
|
* of the library for evolution of ***REAL vectors*** inside EO.
|
||||||
|
* It should be included in the file that calls any of the corresponding fns
|
||||||
|
* Compiling this file allows one to generate part of the library (i.e. object
|
||||||
|
* files that you just need to link with your own main and fitness code).
|
||||||
|
*
|
||||||
|
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||||
|
* in src/es/real.h
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
// The templatized code
|
||||||
|
#include <do/make_continue.h>
|
||||||
|
// the instanciating EOType
|
||||||
|
#include <es/eoReal.h>
|
||||||
|
|
||||||
|
/// The following function merely call the templatized do_* functions
|
||||||
|
|
||||||
|
// continue
|
||||||
|
///////////
|
||||||
|
eoContinue<eoReal<double> >& make_continue(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoReal<double> > & _eval)
|
||||||
|
{
|
||||||
|
return do_make_continue(_parser, _state, _eval);
|
||||||
|
}
|
||||||
|
eoContinue<eoReal<eoMinimizingFitness> >& make_continue(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoReal<eoMinimizingFitness> > & _eval)
|
||||||
|
{
|
||||||
|
return do_make_continue(_parser, _state, _eval);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
87
eo/src/es/make_genotype.h
Normal file
87
eo/src/es/make_genotype.h
Normal file
|
|
@ -0,0 +1,87 @@
|
||||||
|
// -*- 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 <es/eoReal.h>
|
||||||
|
#include <eoRealInitBounded.h>
|
||||||
|
// also need the parser and param includes
|
||||||
|
#include <utils/eoParser.h>
|
||||||
|
#include <utils/eoState.h>
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* It returns an eoInit<eoReal<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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
template <class FitT>
|
||||||
|
eoInit<eoReal<FitT> > & do_make_genotype(eoParameterLoader& _parser, eoState& _state, FitT)
|
||||||
|
{
|
||||||
|
// for eoReal, only thing needed is the size
|
||||||
|
eoValueParam<unsigned>& vecSize = _parser.createParam(unsigned(10), "VecSize", "The number of variables ", 'n',"initialization");
|
||||||
|
|
||||||
|
// to build an eoReal Initializer, we need bounds
|
||||||
|
eoValueParam<eoParamParamType>& boundsParam = _parser.createParam(eoParamParamType("(0,1)"), "InitBounds", "Bounds for uniform initialization", 'B', "initialization");
|
||||||
|
|
||||||
|
eoParamParamType & ppBounds = boundsParam.value(); // pair<string,vector<string> >
|
||||||
|
// transform into a vector<double>
|
||||||
|
vector<double> v;
|
||||||
|
vector<string>::iterator it;
|
||||||
|
for (it=ppBounds.second.begin(); it<ppBounds.second.end(); it++)
|
||||||
|
{
|
||||||
|
istrstream is(it->c_str());
|
||||||
|
double r;
|
||||||
|
is >> r;
|
||||||
|
v.push_back(r);
|
||||||
|
}
|
||||||
|
// now create the eoRealVectorBounds object
|
||||||
|
eoRealVectorBounds * ptBounds = NULL;
|
||||||
|
if (v.size() == 2) // a min and a max for all variables
|
||||||
|
ptBounds = new eoRealVectorBounds(vecSize.value(), v[0], v[1]);
|
||||||
|
else // no time now
|
||||||
|
throw runtime_error("Sorry, only unique bounds for all variables implemented at the moment. Come back later");
|
||||||
|
// we need to give ownership of this pointer to somebody
|
||||||
|
|
||||||
|
eoRealInitBounded<FitT> * init =
|
||||||
|
new eoRealInitBounded<FitT>(*ptBounds);
|
||||||
|
// satore in state
|
||||||
|
_state.storeFunctor(init);
|
||||||
|
return *init;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
52
eo/src/es/make_genotype_real.cpp
Normal file
52
eo/src/es/make_genotype_real.cpp
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// make_genotype_real.cpp
|
||||||
|
// (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 ***INSTANCIATED DEFINITIONS*** of eoReal Init fns
|
||||||
|
* It should be included in the file that calls any of the corresponding fns
|
||||||
|
* Compiling this file allows one to generate part of the library (i.e. object
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* Unlike most EO .h files, it does not (and should not) contain any code,
|
||||||
|
* just declarations
|
||||||
|
*/
|
||||||
|
|
||||||
|
// the templatized code
|
||||||
|
#include <es/make_genotype.h>
|
||||||
|
|
||||||
|
/// The following function merely call the templatized do_* functions
|
||||||
|
|
||||||
|
eoInit<eoReal<double> > & make_genotype(eoParameterLoader& _parser, eoState& _state, double _d)
|
||||||
|
{
|
||||||
|
return do_make_genotype(_parser, _state, _d);
|
||||||
|
}
|
||||||
|
eoInit<eoReal<eoMinimizingFitness> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoMinimizingFitness _d)
|
||||||
|
{
|
||||||
|
return do_make_genotype(_parser, _state, _d);
|
||||||
|
}
|
||||||
54
eo/src/es/make_help.cpp
Normal file
54
eo/src/es/make_help.cpp
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
// -*- 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
|
||||||
|
}
|
||||||
|
}
|
||||||
223
eo/src/es/make_op.h
Normal file
223
eo/src/es/make_op.h
Normal file
|
|
@ -0,0 +1,223 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// make_op.h - the real-valued version
|
||||||
|
// (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_op_h
|
||||||
|
#define _make_op_h
|
||||||
|
|
||||||
|
// the operators
|
||||||
|
#include <eoOp.h>
|
||||||
|
#include <eoGenOp.h>
|
||||||
|
#include <eoCloneOps.h>
|
||||||
|
#include <eoOpContainer.h>
|
||||||
|
// combinations of simple eoOps (eoMonOp and eoQuadOp)
|
||||||
|
#include <eoProportionalCombinedOp.h>
|
||||||
|
|
||||||
|
// the specialized GA stuff
|
||||||
|
#include <es/eoReal.h>
|
||||||
|
#include <es/eoRealOp.h>
|
||||||
|
#include <es/eoNormalMutation.h>
|
||||||
|
// also need the parser and param includes
|
||||||
|
#include <utils/eoParser.h>
|
||||||
|
#include <utils/eoState.h>
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function builds the operators that will be applied to the eoReal
|
||||||
|
*
|
||||||
|
* It uses a parser (to get user parameters) and a state (to store the memory)
|
||||||
|
* the last argument is an individual, needed for 2 reasons
|
||||||
|
* it disambiguates the call after instanciations
|
||||||
|
* some operator might need some private information about the indis
|
||||||
|
*
|
||||||
|
* This is why the template is the complete EOT even though only the fitness
|
||||||
|
* is actually templatized here: the following only applies to bitstrings
|
||||||
|
*
|
||||||
|
* Note : the last parameter is an eoInit: if some operator needs some info
|
||||||
|
* about the gneotypes, the init has it all (e.g. bounds, ...)
|
||||||
|
* Simply do
|
||||||
|
* EOT myEO;
|
||||||
|
* _init(myEO);
|
||||||
|
* and myEO is then an ACTUAL object
|
||||||
|
*/
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit<EOT>& _init)
|
||||||
|
{
|
||||||
|
// this is a temporary version, while Maarten codes the full tree-structured
|
||||||
|
// general operator input
|
||||||
|
// BTW we must leave that simple version available somehow, as it is the one
|
||||||
|
// that 90% people use!
|
||||||
|
eoValueParam<string>& operatorParam = _parser.createParam(string("SGA"), "operator", "Description of the operator (SGA only now)", 'o', "Genetic Operators");
|
||||||
|
|
||||||
|
if (operatorParam.value() != string("SGA"))
|
||||||
|
throw runtime_error("Sorry, only SGA-like operator available right now\n");
|
||||||
|
|
||||||
|
// now we read Pcross and Pmut,
|
||||||
|
// the relative weights for all crossovers -> proportional choice
|
||||||
|
// the relative weights for all mutations -> proportional choice
|
||||||
|
// and create the eoGenOp that is exactly
|
||||||
|
// crossover with pcross + mutation with pmut
|
||||||
|
|
||||||
|
eoValueParam<double>& pCrossParam = _parser.createParam(0.6, "pCross", "Probability of Crossover", 'C', "Genetic Operators" );
|
||||||
|
// minimum check
|
||||||
|
if ( (pCrossParam.value() < 0) || (pCrossParam.value() > 1) )
|
||||||
|
throw runtime_error("Invalid pCross");
|
||||||
|
|
||||||
|
eoValueParam<double>& pMutParam = _parser.createParam(0.1, "pMut", "Probability of Mutation", 'M', "Genetic Operators" );
|
||||||
|
// minimum check
|
||||||
|
if ( (pMutParam.value() < 0) || (pMutParam.value() > 1) )
|
||||||
|
throw runtime_error("Invalid pMut");
|
||||||
|
|
||||||
|
// the crossovers
|
||||||
|
/////////////////
|
||||||
|
// the parameters
|
||||||
|
eoValueParam<double>& segmentRateParam = _parser.createParam(double(1.0), "segmentRate", "Relative rate for segment crossover", 's', "Genetic Operators" );
|
||||||
|
// minimum check
|
||||||
|
if ( (segmentRateParam.value() < 0) )
|
||||||
|
throw runtime_error("Invalid segmentRate");
|
||||||
|
|
||||||
|
eoValueParam<double>& arithmeticRateParam = _parser.createParam(double(2.0), "arithmeticRate", "Relative rate for arithmetic crossover", 'A', "Genetic Operators" );
|
||||||
|
// minimum check
|
||||||
|
if ( (arithmeticRateParam.value() < 0) )
|
||||||
|
throw runtime_error("Invalid arithmeticRate");
|
||||||
|
|
||||||
|
// minimum check
|
||||||
|
bool bCross = true;
|
||||||
|
if (segmentRateParam.value()+arithmeticRateParam.value()==0)
|
||||||
|
{
|
||||||
|
cerr << "Warning: no crossover" << endl;
|
||||||
|
bCross = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the CombinedQuadOp
|
||||||
|
eoPropCombinedQuadOp<EOT> *ptCombinedQuadOp = NULL;
|
||||||
|
eoQuadOp<EOT> *ptQuad = NULL;
|
||||||
|
|
||||||
|
if (bCross)
|
||||||
|
{
|
||||||
|
// segment crossover for bitstring
|
||||||
|
ptQuad = new eoSegmentCrossover<EOT>;
|
||||||
|
_state.storeFunctor(ptQuad);
|
||||||
|
ptCombinedQuadOp = new eoPropCombinedQuadOp<EOT>(*ptQuad, segmentRateParam.value());
|
||||||
|
|
||||||
|
// arithmetic crossover
|
||||||
|
ptQuad = new eoArithmeticCrossover<EOT>;
|
||||||
|
_state.storeFunctor(ptQuad);
|
||||||
|
ptCombinedQuadOp->add(*ptQuad, arithmeticRateParam.value());
|
||||||
|
|
||||||
|
// don't forget to store the CombinedQuadOp
|
||||||
|
_state.storeFunctor(ptCombinedQuadOp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// the mutations
|
||||||
|
/////////////////
|
||||||
|
// the parameters
|
||||||
|
eoValueParam<double> & epsilonParam = _parser.createParam(0.01, "epsilon", "Half-size of interval for Uniform Mutation", 'e', "Genetic Operators" );
|
||||||
|
// minimum check
|
||||||
|
if ( (epsilonParam.value() < 0) )
|
||||||
|
throw runtime_error("Invalid epsilon");
|
||||||
|
|
||||||
|
eoValueParam<double> & uniformMutRateParam = _parser.createParam(1.0, "uniformMutRate", "Relative rate for uniform mutation", 'u', "Genetic Operators" );
|
||||||
|
// minimum check
|
||||||
|
if ( (uniformMutRateParam.value() < 0) )
|
||||||
|
throw runtime_error("Invalid uniformMutRate");
|
||||||
|
|
||||||
|
eoValueParam<double> & detMutRateParam = _parser.createParam(1.0, "detMutRate", "Relative rate for deterministic uniform mutation", 'd', "Genetic Operators" );
|
||||||
|
// minimum check
|
||||||
|
if ( (detMutRateParam.value() < 0) )
|
||||||
|
throw runtime_error("Invalid detMutRate");
|
||||||
|
|
||||||
|
eoValueParam<double> & normalMutRateParam = _parser.createParam(1.0, "normalMutRate", "Relative rate for Gaussian mutation", 'd', "Genetic Operators" );
|
||||||
|
// minimum check
|
||||||
|
if ( (normalMutRateParam.value() < 0) )
|
||||||
|
throw runtime_error("Invalid normalMutRate");
|
||||||
|
// and the sigma
|
||||||
|
eoValueParam<double> & sigmaParam = _parser.createParam(1.0, "sigma", "Sigma (fixed) for Gaussian mutation", 'S', "Genetic Operators" );
|
||||||
|
// minimum check
|
||||||
|
if ( (sigmaParam.value() < 0) )
|
||||||
|
throw runtime_error("Invalid sigma");
|
||||||
|
|
||||||
|
// minimum check
|
||||||
|
bool bMut = true;
|
||||||
|
if (uniformMutRateParam.value()+detMutRateParam.value()+normalMutRateParam.value()==0)
|
||||||
|
{
|
||||||
|
cerr << "Warning: no mutation" << endl;
|
||||||
|
bMut = false;
|
||||||
|
}
|
||||||
|
if (!bCross && !bMut)
|
||||||
|
throw runtime_error("No operator called in SGA operator definition!!!");
|
||||||
|
|
||||||
|
// Create the CombinedMonOp
|
||||||
|
eoPropCombinedMonOp<EOT> *ptCombinedMonOp = NULL;
|
||||||
|
eoMonOp<EOT> *ptMon = NULL;
|
||||||
|
|
||||||
|
if (bMut)
|
||||||
|
{
|
||||||
|
// uniform mutation on all components:
|
||||||
|
// offspring(i) uniformly chosen in [parent(i)-epsilon, parent(i)+epsilon]
|
||||||
|
ptMon = new eoUniformMutation<EOT>(epsilonParam.value());
|
||||||
|
_state.storeFunctor(ptMon);
|
||||||
|
// create the CombinedMonOp
|
||||||
|
ptCombinedMonOp = new eoPropCombinedMonOp<EOT>(*ptMon, uniformMutRateParam.value());
|
||||||
|
|
||||||
|
// mutate exactly 1 component (uniformly) per individual
|
||||||
|
ptMon = new eoDetUniformMutation<EOT>(epsilonParam.value());
|
||||||
|
_state.storeFunctor(ptMon);
|
||||||
|
ptCombinedMonOp->add(*ptMon, detMutRateParam.value());
|
||||||
|
|
||||||
|
// mutate all component using Gaussian mutation
|
||||||
|
ptMon = new eoNormalMutation<EOT>(sigmaParam.value());
|
||||||
|
_state.storeFunctor(ptMon);
|
||||||
|
ptCombinedMonOp->add(*ptMon, normalMutRateParam.value());
|
||||||
|
_state.storeFunctor(ptCombinedMonOp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// now build the eoGenOp:
|
||||||
|
// to simulate SGA (crossover with proba pCross + mutation with proba pMut
|
||||||
|
// we must construct
|
||||||
|
// a sequential combination of
|
||||||
|
// with proba 1, a proportional combination of
|
||||||
|
// a QuadCopy and our crossover
|
||||||
|
// with proba pMut, our mutation
|
||||||
|
|
||||||
|
// the crossover - with probability pCross
|
||||||
|
eoProportionalOp<EOT> * cross = new eoProportionalOp<EOT> ;
|
||||||
|
_state.storeFunctor(cross);
|
||||||
|
ptQuad = new eoQuadCloneOp<EOT>;
|
||||||
|
_state.storeFunctor(ptQuad);
|
||||||
|
cross->add(*ptCombinedQuadOp, pCrossParam.value()); // user crossover
|
||||||
|
cross->add(*ptQuad, 1-pCrossParam.value()); // clone operator
|
||||||
|
|
||||||
|
// now the sequential
|
||||||
|
eoSequentialOp<EOT> *op = new eoSequentialOp<EOT>;
|
||||||
|
_state.storeFunctor(op);
|
||||||
|
op->add(*cross, 1.0); // always crossover (but clone with prob 1-pCross
|
||||||
|
op->add(*ptCombinedMonOp, pMutParam.value());
|
||||||
|
|
||||||
|
// that's it!
|
||||||
|
return *op;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
54
eo/src/es/make_op_real.cpp
Normal file
54
eo/src/es/make_op_real.cpp
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// make_op_real.cpp
|
||||||
|
// (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 ***INSTANCIATED DEFINITIONS*** of operators fns
|
||||||
|
* of the library for ***eoReal*** evolution inside EO.
|
||||||
|
* It should be included in the file that calls any of the corresponding fns
|
||||||
|
* Compiling this file allows one to generate part of the library (i.e. object
|
||||||
|
* files that you just need to link with your own main and fitness code).
|
||||||
|
*
|
||||||
|
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||||
|
* in es.h in src/es dir
|
||||||
|
* while the TEMPLATIZED code is define in make_op.h in the es dir
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Templatized code
|
||||||
|
#include <es/make_op.h>
|
||||||
|
|
||||||
|
/// The following function merely call the templatized do_* functions above
|
||||||
|
|
||||||
|
// oeprators
|
||||||
|
////////////
|
||||||
|
eoGenOp<eoReal<double> >& make_op(eoParameterLoader& _parser, eoState& _state, eoInit<eoReal<double> >& _init)
|
||||||
|
{
|
||||||
|
return do_make_op(_parser, _state, _init);
|
||||||
|
}
|
||||||
|
|
||||||
|
eoGenOp<eoReal<eoMinimizingFitness> >& make_op(eoParameterLoader& _parser, eoState& _state, eoInit<eoReal<eoMinimizingFitness> >& _init)
|
||||||
|
{
|
||||||
|
return do_make_op(_parser, _state, _init);
|
||||||
|
}
|
||||||
60
eo/src/es/make_pop_real.cpp
Normal file
60
eo/src/es/make_pop_real.cpp
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// make_pop_real.cpp
|
||||||
|
// (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 ***INSTANCIATED DEFINITIONS*** of pop. init. fns
|
||||||
|
* of the library for evolution of ***eoReal*** indis inside EO.
|
||||||
|
* It should be included in the file that calls any of the corresponding fns
|
||||||
|
* Compiling this file allows one to generate part of the library (i.e. object
|
||||||
|
* files that you just need to link with your own main and fitness code).
|
||||||
|
*
|
||||||
|
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||||
|
* in src/es/real.h
|
||||||
|
* while the TEMPLATIZED code is define in make_pop.h in the src/do dir
|
||||||
|
*
|
||||||
|
* Unlike most EO .h files, it does not (and should not) contain any code,
|
||||||
|
* just declarations
|
||||||
|
*/
|
||||||
|
|
||||||
|
// The templatized code
|
||||||
|
#include <do/make_pop.h>
|
||||||
|
// the instanciating EOType
|
||||||
|
#include <es/eoReal.h>
|
||||||
|
|
||||||
|
/// The following function merely call the templatized do_* functions above
|
||||||
|
|
||||||
|
// Init POP
|
||||||
|
///////////
|
||||||
|
eoPop<eoReal<double> >& make_pop(eoParser& _parser, eoState& _state, eoInit<eoReal<double> > & _init)
|
||||||
|
{
|
||||||
|
return do_make_pop(_parser, _state, _init);
|
||||||
|
}
|
||||||
|
|
||||||
|
eoPop<eoReal<eoMinimizingFitness> >& make_pop(eoParser& _parser, eoState& _state, eoInit<eoReal<eoMinimizingFitness> > & _init)
|
||||||
|
{
|
||||||
|
return do_make_pop(_parser, _state, _init);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
61
eo/src/es/make_run_real.cpp
Normal file
61
eo/src/es/make_run_real.cpp
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// make_run_real.cpp
|
||||||
|
// (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 ***INSTANCIATED DEFINITIONS*** of run funs
|
||||||
|
* of the library for evolution of ***eoReal*** inside EO.
|
||||||
|
* It should be included in the file that calls any of the corresponding fns
|
||||||
|
* Compiling this file allows one to generate part of the library (i.e. object
|
||||||
|
* files that you just need to link with your own main and fitness code).
|
||||||
|
*
|
||||||
|
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||||
|
* in src/es/real.h
|
||||||
|
* while the TEMPLATIZED code is define in make_run.h in the src/do dir
|
||||||
|
*
|
||||||
|
* Unlike most EO .h files, it does not (and should not) contain any code,
|
||||||
|
* just declarations
|
||||||
|
*/
|
||||||
|
|
||||||
|
// The templatized code
|
||||||
|
#include <do/make_run.h>
|
||||||
|
// the instanciating EOType
|
||||||
|
#include <es/eoReal.h>
|
||||||
|
// the instanciating fitnesses
|
||||||
|
#include <eoScalarFitness.h>
|
||||||
|
|
||||||
|
/// The following function merely call the templatized do_* functions above
|
||||||
|
|
||||||
|
// run
|
||||||
|
/////////
|
||||||
|
void run_ea(eoAlgo<eoReal<double> >& _ga, eoPop<eoReal<double> >& _pop)
|
||||||
|
{
|
||||||
|
do_run(_ga, _pop);
|
||||||
|
}
|
||||||
|
|
||||||
|
void run_ea(eoAlgo<eoReal<eoMinimizingFitness> >& _ga, eoPop<eoReal<eoMinimizingFitness> >& _pop)
|
||||||
|
{
|
||||||
|
do_run(_ga, _pop);
|
||||||
|
}
|
||||||
|
|
||||||
Reference in a new issue