Added bounds to the real operators in make_XXX (and hence in t-eoReal)
This commit is contained in:
parent
7b8999b205
commit
a7042bffee
16 changed files with 330 additions and 181 deletions
|
|
@ -48,7 +48,7 @@ template <class EOT>
|
|||
eoPop<EOT>& do_make_pop(eoParser & _parser, eoState& _state, eoInit<EOT> & _init)
|
||||
{
|
||||
eoValueParam<uint32>& seedParam = _parser.createParam(uint32(time(0)), "seed", "Random number seed", 'S');
|
||||
eoValueParam<unsigned>& popSize = _parser.createParam(unsigned(20), "PopSize", "Population Size", 'P', "initialization");
|
||||
eoValueParam<unsigned>& popSize = _parser.createParam(unsigned(20), "popSize", "Population Size", 'P', "initialization");
|
||||
|
||||
// Either load or initialize
|
||||
// create an empty pop and let the state handle the memory
|
||||
|
|
|
|||
|
|
@ -6,14 +6,12 @@
|
|||
|
||||
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_op_real.cpp \
|
||||
make_pop_real.cpp \
|
||||
make_run_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_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
|
||||
|
||||
CPPFLAGS = -Wall
|
||||
CXXFLAGS = -g
|
||||
libeoincdir = $(includedir)/eo/es
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoRealOp.h
|
||||
// (c) EEAAX 2000 - Maarten Keijzer 2000
|
||||
// (c) Maarten Keijzer 2000 - Marc Schoenauer 2001
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
|
|
@ -52,17 +52,37 @@ template<class EOT> class eoUniformMutation: public eoMonOp<EOT>
|
|||
* @param _epsilon the range for uniform nutation
|
||||
* @param _p_change the probability to change a given coordinate
|
||||
*/
|
||||
eoUniformMutation(const double& _epsilon, const double& _p_change = 1.0):
|
||||
bounds(eoDummyVectorNoBounds), epsilon(_epsilon), p_change(_p_change) {}
|
||||
eoUniformMutation(const unsigned _size, const double& _epsilon,
|
||||
const double& _p_change = 1.0):
|
||||
bounds(eoDummyVectorNoBounds), epsilon(_size, _epsilon),
|
||||
p_change(_size, _p_change) {}
|
||||
|
||||
/**
|
||||
* Constructor with bounds
|
||||
* @param _bounds an eoRealVectorBounds that contains the bounds
|
||||
* @param _epsilon the range for uniform nutation
|
||||
* @param _p_change the probability to change a given coordinate
|
||||
* @param _epsilon the range for uniform mutation - a double to be scaled
|
||||
* @param _p_change the one probability to change all coordinates
|
||||
*/
|
||||
eoUniformMutation(eoRealVectorBounds & _bounds,
|
||||
const double& _epsilon, const double& _p_change = 1.0):
|
||||
bounds(_bounds), epsilon(_bounds.size(), _epsilon),
|
||||
p_change(_bounds.size(), _p_change)
|
||||
{
|
||||
// scale to the range - if any
|
||||
for (unsigned i=0; i<bounds.size(); i++)
|
||||
if (bounds.isBounded(i))
|
||||
epsilon[i] *= _epsilon*bounds.range(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with bounds
|
||||
* @param _bounds an eoRealVectorBounds that contains the bounds
|
||||
* @param _epsilon the VECTOR of ranges for uniform mutation
|
||||
* @param _p_change the VECTOR of probabilities for each coordinates
|
||||
*/
|
||||
eoUniformMutation(eoRealVectorBounds & _bounds,
|
||||
const vector<double>& _epsilon,
|
||||
const vector<double>& _p_change):
|
||||
bounds(_bounds), epsilon(_epsilon), p_change(_p_change) {}
|
||||
|
||||
/// The class name.
|
||||
|
|
@ -70,18 +90,22 @@ template<class EOT> class eoUniformMutation: public eoMonOp<EOT>
|
|||
|
||||
/**
|
||||
* Do it!
|
||||
* @param _eo The cromosome undergoing the mutation
|
||||
* @param _eo The indi undergoing the mutation
|
||||
*/
|
||||
bool operator()(EOT& _eo)
|
||||
{
|
||||
// sanity check ?
|
||||
if (_eo.size() != bounds.size())
|
||||
throw runtime_error("Invalid size of indi in eoUniformMutation");
|
||||
|
||||
bool hasChanged=false;
|
||||
for (unsigned lieu=0; lieu<_eo.size(); lieu++)
|
||||
{
|
||||
if (rng.flip(p_change))
|
||||
if (rng.flip(p_change[lieu]))
|
||||
{
|
||||
// check the bounds
|
||||
double emin = _eo[lieu]-epsilon;
|
||||
double emax = _eo[lieu]+epsilon;
|
||||
double emin = _eo[lieu]-epsilon[lieu];
|
||||
double emax = _eo[lieu]+epsilon[lieu];
|
||||
if (bounds.isMinBounded(lieu))
|
||||
emin = max(bounds.minimum(lieu), emin);
|
||||
if (bounds.isMaxBounded(lieu))
|
||||
|
|
@ -95,8 +119,8 @@ template<class EOT> class eoUniformMutation: public eoMonOp<EOT>
|
|||
|
||||
private:
|
||||
eoRealVectorBounds & bounds;
|
||||
double epsilon;
|
||||
double p_change;
|
||||
vector<double> epsilon;
|
||||
vector<double> p_change;
|
||||
};
|
||||
|
||||
/** eoDetUniformMutation --> changes exactly k values of the vector
|
||||
|
|
@ -113,36 +137,63 @@ template<class EOT> class eoDetUniformMutation: public eoMonOp<EOT>
|
|||
* @param _epsilon the range for uniform nutation
|
||||
* @param number of coordinate to modify
|
||||
*/
|
||||
eoDetUniformMutation(const double& _epsilon, const unsigned& _no = 1):
|
||||
bounds(eoDummyVectorNoBounds), epsilon(_epsilon), no(_no) {}
|
||||
eoDetUniformMutation(const unsigned _size, const double& _epsilon,
|
||||
const unsigned& _no = 1):
|
||||
bounds(eoDummyVectorNoBounds), epsilon(_size, _epsilon), no(_no) {}
|
||||
|
||||
/**
|
||||
* Constructor with bounds
|
||||
* @param _bounds an eoRealVectorBounds that contains the bounds
|
||||
* @param _epsilon the range for uniform nutation
|
||||
* @param _epsilon the range for uniform nutation (to be scaled if necessary)
|
||||
* @param number of coordinate to modify
|
||||
*/
|
||||
eoDetUniformMutation(eoRealVectorBounds & _bounds,
|
||||
const double& _epsilon, const unsigned& _no = 1):
|
||||
bounds(_bounds), epsilon(_epsilon), no(_no) {}
|
||||
bounds(_bounds), epsilon(_bounds.size(), _epsilon), no(_no)
|
||||
{
|
||||
// scale to the range - if any
|
||||
for (unsigned i=0; i<bounds.size(); i++)
|
||||
if (bounds.isBounded(i))
|
||||
epsilon[i] *= _epsilon*bounds.range(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with bounds and full vector of epsilon
|
||||
* @param _bounds an eoRealVectorBounds that contains the bounds
|
||||
* @param _epsilon the VECTOR of ranges for uniform mutation
|
||||
* @param number of coordinate to modify
|
||||
*/
|
||||
eoDetUniformMutation(eoRealVectorBounds & _bounds,
|
||||
const vector<double>& _epsilon,
|
||||
const unsigned& _no = 1):
|
||||
bounds(_bounds), epsilon(_epsilon), no(_no)
|
||||
{
|
||||
// scale to the range - if any
|
||||
for (unsigned i=0; i<bounds.size(); i++)
|
||||
if (bounds.isBounded(i))
|
||||
epsilon[i] *= _epsilon*bounds.range(i);
|
||||
}
|
||||
|
||||
/// The class name.
|
||||
string className() const { return "eoDetUniformMutation"; }
|
||||
|
||||
/**
|
||||
* Do it!
|
||||
* @param _eo The cromosome undergoing the mutation
|
||||
* @param _eo The indi undergoing the mutation
|
||||
*/
|
||||
bool operator()(EOT& _eo)
|
||||
{
|
||||
// sanity check ?
|
||||
if (_eo.size() != bounds.size())
|
||||
throw runtime_error("Invalid size of indi in eoDetUniformMutation");
|
||||
for (unsigned i=0; i<no; i++)
|
||||
{
|
||||
unsigned lieu = rng.random(_eo.size());
|
||||
// actually, we should test that we don't re-modify same variable!
|
||||
|
||||
// check the bounds
|
||||
double emin = _eo[lieu]-epsilon;
|
||||
double emax = _eo[lieu]+epsilon;
|
||||
double emin = _eo[lieu]-epsilon[lieu];
|
||||
double emax = _eo[lieu]+epsilon[lieu];
|
||||
if (bounds.isMinBounded(lieu))
|
||||
emin = max(bounds.minimum(lieu), emin);
|
||||
if (bounds.isMaxBounded(lieu))
|
||||
|
|
@ -155,7 +206,7 @@ template<class EOT> class eoDetUniformMutation: public eoMonOp<EOT>
|
|||
|
||||
private:
|
||||
eoRealVectorBounds & bounds;
|
||||
double epsilon;
|
||||
vector<double> epsilon;
|
||||
unsigned no;
|
||||
};
|
||||
|
||||
|
|
@ -405,4 +456,3 @@ template<class EOT> class eoRealUxOver: public eoQuadOp<EOT>
|
|||
//-----------------------------------------------------------------------------
|
||||
//@}
|
||||
#endif eoRealOp_h
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** This file contains all ***INSTANCIATED*** declarations of all components
|
||||
* of the library for ***REAL_VALUED*** evolution inside EO.
|
||||
* of the library for ***ES-like gnptype*** evolution inside EO.
|
||||
* It should be included in the file that calls any of the corresponding fns
|
||||
*
|
||||
* The corresponding ***INSTANCIATED*** definitions are contained in
|
||||
|
|
@ -33,7 +33,9 @@
|
|||
* while the TEMPLATIZED code is define in the different make_XXX.h files
|
||||
* either in hte src/do dir for representation independant functions,
|
||||
* or in the src/es dir for representation dependent stuff.
|
||||
* Note that
|
||||
*
|
||||
* See also real.h for the similar declarations of eoReal genotypes
|
||||
* i.e. ***without*** mutation parameters attached to individuals
|
||||
*
|
||||
* Unlike most EO .h files, it does not (and should not) contain any code,
|
||||
* just declarations
|
||||
|
|
@ -51,44 +53,77 @@
|
|||
#include <eoGenOp.h>
|
||||
#include <eoPop.h>
|
||||
|
||||
#include <es/eoReal.h>
|
||||
#include <es/eoEsSimple.h> // one Sigma per individual
|
||||
#include <es/eoEsStdev.h> // one sigmal per object variable
|
||||
#include <es/eoEsFull.h> // full correlation matrix per indi
|
||||
|
||||
//Representation dependent - rewrite everything anew for each representation
|
||||
//////////////////////////
|
||||
|
||||
/*
|
||||
// the genotypes
|
||||
eoInit<eoReal<double> > & make_genotype(eoParameterLoader& _parser, eoState& _state, double _d);
|
||||
eoInit<eoReal<eoMinimizingFitness> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoMinimizingFitness _d);
|
||||
eoInit<eoEsSimple<double> > & make_genotype(eoParameterLoader& _parser, eoState& _state, double _d);
|
||||
eoInit<eoEsSimple<eoMinimizingFitness> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoMinimizingFitness _d);
|
||||
|
||||
// the operators
|
||||
eoGenOp<eoReal<double> >& make_op(eoParameterLoader& _parser, eoState& _state, eoInit<eoReal<double> >& _init);
|
||||
eoGenOp<eoReal<eoMinimizingFitness> >& make_op(eoParameterLoader& _parser, eoState& _state, eoInit<eoReal<eoMinimizingFitness> >& _init);
|
||||
eoGenOp<eoEsStdev<double> >& make_op(eoParameterLoader& _parser, eoState& _state, eoInit<eoEsStdev<double> >& _init);
|
||||
eoGenOp<eoEsStdev<eoMinimizingFitness> >& make_op(eoParameterLoader& _parser, eoState& _state, eoInit<eoEsStdev<eoMinimizingFitness> >& _init);
|
||||
*/
|
||||
|
||||
//Representation INdependent
|
||||
////////////////////////////
|
||||
// you don't need to modify that part even if you use your own representation
|
||||
|
||||
// init pop
|
||||
eoPop<eoReal<double> >& make_pop(eoParser& _parser, eoState& _state, eoInit<eoReal<double> >&);
|
||||
eoPop<eoReal<eoMinimizingFitness> >& make_pop(eoParser& _parser, eoState& _state, eoInit<eoReal<eoMinimizingFitness> >&);
|
||||
eoPop<eoEsSimple<double> >& make_pop(eoParser& _parser, eoState& _state, eoInit<eoEsSimple<double> >&);
|
||||
eoPop<eoEsSimple<eoMinimizingFitness> >& make_pop(eoParser& _parser, eoState& _state, eoInit<eoEsSimple<eoMinimizingFitness> >&);
|
||||
|
||||
eoPop<eoEsStdev<double> >& make_pop(eoParser& _parser, eoState& _state, eoInit<eoEsStdev<double> >&);
|
||||
eoPop<eoEsStdev<eoMinimizingFitness> >& make_pop(eoParser& _parser, eoState& _state, eoInit<eoEsStdev<eoMinimizingFitness> >&);
|
||||
|
||||
eoPop<eoEsFull<double> >& make_pop(eoParser& _parser, eoState& _state, eoInit<eoEsFull<double> >&);
|
||||
eoPop<eoEsFull<eoMinimizingFitness> >& make_pop(eoParser& _parser, eoState& _state, eoInit<eoEsFull<eoMinimizingFitness> >&);
|
||||
|
||||
// the continue's
|
||||
eoContinue<eoReal<double> >& make_continue(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoReal<double> > & _eval);
|
||||
eoContinue<eoReal<eoMinimizingFitness> >& make_continue(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoReal<eoMinimizingFitness> > & _eval);
|
||||
eoContinue<eoEsSimple<double> >& make_continue(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoEsSimple<double> > & _eval);
|
||||
eoContinue<eoEsSimple<eoMinimizingFitness> >& make_continue(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoEsSimple<eoMinimizingFitness> > & _eval);
|
||||
|
||||
eoContinue<eoEsStdev<double> >& make_continue(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoEsStdev<double> > & _eval);
|
||||
eoContinue<eoEsStdev<eoMinimizingFitness> >& make_continue(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoEsStdev<eoMinimizingFitness> > & _eval);
|
||||
|
||||
eoContinue<eoEsFull<double> >& make_continue(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoEsFull<double> > & _eval);
|
||||
eoContinue<eoEsFull<eoMinimizingFitness> >& make_continue(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoEsFull<eoMinimizingFitness> > & _eval);
|
||||
|
||||
// the checkpoint
|
||||
eoCheckPoint<eoReal<double> >& make_checkpoint(eoParameterLoader& _parser, eoState& _state, eoEvalFuncCounter<eoReal<double> >& _eval, eoContinue<eoReal<double> >& _continue);
|
||||
eoCheckPoint<eoReal<eoMinimizingFitness> >& make_checkpoint(eoParameterLoader& _parser, eoState& _state, eoEvalFuncCounter<eoReal<eoMinimizingFitness> >& _eval, eoContinue<eoReal<eoMinimizingFitness> >& _continue);
|
||||
eoCheckPoint<eoEsSimple<double> >& make_checkpoint(eoParameterLoader& _parser, eoState& _state, eoEvalFuncCounter<eoEsSimple<double> >& _eval, eoContinue<eoEsSimple<double> >& _continue);
|
||||
eoCheckPoint<eoEsSimple<eoMinimizingFitness> >& make_checkpoint(eoParameterLoader& _parser, eoState& _state, eoEvalFuncCounter<eoEsSimple<eoMinimizingFitness> >& _eval, eoContinue<eoEsSimple<eoMinimizingFitness> >& _continue);
|
||||
|
||||
eoCheckPoint<eoEsStdev<double> >& make_checkpoint(eoParameterLoader& _parser, eoState& _state, eoEvalFuncCounter<eoEsStdev<double> >& _eval, eoContinue<eoEsStdev<double> >& _continue);
|
||||
eoCheckPoint<eoEsStdev<eoMinimizingFitness> >& make_checkpoint(eoParameterLoader& _parser, eoState& _state, eoEvalFuncCounter<eoEsStdev<eoMinimizingFitness> >& _eval, eoContinue<eoEsStdev<eoMinimizingFitness> >& _continue);
|
||||
|
||||
eoCheckPoint<eoEsFull<double> >& make_checkpoint(eoParameterLoader& _parser, eoState& _state, eoEvalFuncCounter<eoEsFull<double> >& _eval, eoContinue<eoEsFull<double> >& _continue);
|
||||
eoCheckPoint<eoEsFull<eoMinimizingFitness> >& make_checkpoint(eoParameterLoader& _parser, eoState& _state, eoEvalFuncCounter<eoEsFull<eoMinimizingFitness> >& _eval, eoContinue<eoEsFull<eoMinimizingFitness> >& _continue);
|
||||
|
||||
|
||||
// the algo
|
||||
eoAlgo<eoReal<double> >& make_algo_scalar(eoParameterLoader& _parser, eoState& _state, eoEvalFunc<eoReal<double> >& _eval, eoContinue<eoReal<double> >& _ccontinue, eoGenOp<eoReal<double> >& _op);
|
||||
eoAlgo<eoEsSimple<double> >& make_algo_scalar(eoParameterLoader& _parser, eoState& _state, eoEvalFunc<eoEsSimple<double> >& _eval, eoContinue<eoEsSimple<double> >& _ccontinue, eoGenOp<eoEsSimple<double> >& _op);
|
||||
eoAlgo<eoEsSimple<eoMinimizingFitness> >& make_algo_scalar(eoParameterLoader& _parser, eoState& _state, eoEvalFunc<eoEsSimple<eoMinimizingFitness> >& _eval, eoContinue<eoEsSimple<eoMinimizingFitness> >& _ccontinue, eoGenOp<eoEsSimple<eoMinimizingFitness> >& _op);
|
||||
|
||||
eoAlgo<eoReal<eoMinimizingFitness> >& make_algo_scalar(eoParameterLoader& _parser, eoState& _state, eoEvalFunc<eoReal<eoMinimizingFitness> >& _eval, eoContinue<eoReal<eoMinimizingFitness> >& _ccontinue, eoGenOp<eoReal<eoMinimizingFitness> >& _op);
|
||||
eoAlgo<eoEsStdev<double> >& make_algo_scalar(eoParameterLoader& _parser, eoState& _state, eoEvalFunc<eoEsStdev<double> >& _eval, eoContinue<eoEsStdev<double> >& _ccontinue, eoGenOp<eoEsStdev<double> >& _op);
|
||||
eoAlgo<eoEsStdev<eoMinimizingFitness> >& make_algo_scalar(eoParameterLoader& _parser, eoState& _state, eoEvalFunc<eoEsStdev<eoMinimizingFitness> >& _eval, eoContinue<eoEsStdev<eoMinimizingFitness> >& _ccontinue, eoGenOp<eoEsStdev<eoMinimizingFitness> >& _op);
|
||||
|
||||
eoAlgo<eoEsFull<double> >& make_algo_scalar(eoParameterLoader& _parser, eoState& _state, eoEvalFunc<eoEsFull<double> >& _eval, eoContinue<eoEsFull<double> >& _ccontinue, eoGenOp<eoEsFull<double> >& _op);
|
||||
eoAlgo<eoEsFull<eoMinimizingFitness> >& make_algo_scalar(eoParameterLoader& _parser, eoState& _state, eoEvalFunc<eoEsFull<eoMinimizingFitness> >& _eval, eoContinue<eoEsFull<eoMinimizingFitness> >& _ccontinue, eoGenOp<eoEsFull<eoMinimizingFitness> >& _op);
|
||||
|
||||
// run
|
||||
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<eoEsSimple<double> >& _ga, eoPop<eoEsSimple<double> >& _pop);
|
||||
void run_ea(eoAlgo<eoEsSimple<eoMinimizingFitness> >& _ga, eoPop<eoEsSimple<eoMinimizingFitness> >& _pop);
|
||||
|
||||
void run_ea(eoAlgo<eoEsStdev<double> >& _ga, eoPop<eoEsStdev<double> >& _pop);
|
||||
void run_ea(eoAlgo<eoEsStdev<eoMinimizingFitness> >& _ga, eoPop<eoEsStdev<eoMinimizingFitness> >& _pop);
|
||||
|
||||
void run_ea(eoAlgo<eoEsFull<double> >& _ga, eoPop<eoEsFull<double> >& _pop);
|
||||
void run_ea(eoAlgo<eoEsFull<eoMinimizingFitness> >& _ga, eoPop<eoEsFull<eoMinimizingFitness> >& _pop);
|
||||
|
||||
// end of parameter input (+ .status + help)
|
||||
// that one is not templatized, but is here for completeness
|
||||
|
|
|
|||
|
|
@ -33,9 +33,6 @@
|
|||
* 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
|
||||
|
|
|
|||
|
|
@ -33,9 +33,6 @@
|
|||
* 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
|
||||
|
|
|
|||
|
|
@ -33,9 +33,6 @@
|
|||
* 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
|
||||
|
|
|
|||
|
|
@ -53,10 +53,10 @@ 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");
|
||||
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");
|
||||
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>
|
||||
|
|
|
|||
|
|
@ -35,8 +35,9 @@
|
|||
// combinations of simple eoOps (eoMonOp and eoQuadOp)
|
||||
#include <eoProportionalCombinedOp.h>
|
||||
|
||||
// the specialized GA stuff
|
||||
// the specialized Real stuff
|
||||
#include <es/eoReal.h>
|
||||
#include <es/eoRealInitBounded.h>
|
||||
#include <es/eoRealOp.h>
|
||||
#include <es/eoNormalMutation.h>
|
||||
// also need the parser and param includes
|
||||
|
|
@ -66,14 +67,56 @@
|
|||
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
|
||||
// First, decide whether the objective variables are bounded
|
||||
eoValueParam<eoParamParamType>& boundsParam = _parser.createParam(eoParamParamType("(0,1)"), "objectBounds", "Bounds for variables", 'B', "Genetic Operators");
|
||||
|
||||
// get initisalizer size == vector size
|
||||
// eoRealInitBounded<EOT> * realInit = (eoRealInitBounded<EOT>*)(&_init);
|
||||
// unsigned vecSize = realInit->theBounds().size();
|
||||
|
||||
// get vector size: safer???
|
||||
EOT eoTmp;
|
||||
_init(eoTmp);
|
||||
unsigned vecSize = eoTmp.size();
|
||||
|
||||
// the bounds pointer
|
||||
eoRealVectorBounds * ptBounds;
|
||||
if (_parser.isItThere(boundsParam)) // otherwise, no bounds
|
||||
{
|
||||
/////Warning: this code should probably be replaced by creating
|
||||
///// some eoValueParam<eoRealVectorBounds> with specific implementation
|
||||
//// in eoParser.cpp. At the moemnt, it is there (cf also make_genotype
|
||||
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
|
||||
if (v.size() == 2) // a min and a max for all variables
|
||||
ptBounds = new eoRealVectorBounds(vecSize, 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
|
||||
/////////// end of temporary code
|
||||
}
|
||||
else // no param for bounds was given
|
||||
ptBounds = new eoRealVectorNoBounds(vecSize); // DON'T USE eoDummyVectorNoBounds
|
||||
// as it does not have any dimension
|
||||
|
||||
// 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");
|
||||
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");
|
||||
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
|
||||
|
|
@ -81,119 +124,119 @@ eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit<EO
|
|||
// 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>& 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");
|
||||
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>& 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");
|
||||
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;
|
||||
}
|
||||
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;
|
||||
// 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());
|
||||
if (bCross)
|
||||
{
|
||||
// segment crossover for bitstring - pass it the bounds
|
||||
ptQuad = new eoSegmentCrossover<EOT>(*ptBounds);
|
||||
_state.storeFunctor(ptQuad);
|
||||
ptCombinedQuadOp = new eoPropCombinedQuadOp<EOT>(*ptQuad, segmentRateParam.value());
|
||||
|
||||
// arithmetic crossover
|
||||
ptQuad = new eoArithmeticCrossover<EOT>;
|
||||
_state.storeFunctor(ptQuad);
|
||||
ptCombinedQuadOp->add(*ptQuad, arithmeticRateParam.value());
|
||||
ptQuad = new eoArithmeticCrossover<EOT>(*ptBounds);
|
||||
_state.storeFunctor(ptQuad);
|
||||
ptCombinedQuadOp->add(*ptQuad, arithmeticRateParam.value());
|
||||
|
||||
// don't forget to store the CombinedQuadOp
|
||||
_state.storeFunctor(ptCombinedQuadOp);
|
||||
}
|
||||
// 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");
|
||||
// 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> & 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> & 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");
|
||||
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!!!");
|
||||
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;
|
||||
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());
|
||||
if (bMut)
|
||||
{
|
||||
// uniform mutation on all components:
|
||||
// offspring(i) uniformly chosen in [parent(i)-epsilon, parent(i)+epsilon]
|
||||
ptMon = new eoUniformMutation<EOT>(*ptBounds, 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());
|
||||
ptMon = new eoDetUniformMutation<EOT>(*ptBounds, 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);
|
||||
}
|
||||
// mutate all component using Gaussian mutation
|
||||
ptMon = new eoNormalMutation<EOT>(*ptBounds, 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
|
||||
|
|
|
|||
|
|
@ -33,9 +33,6 @@
|
|||
* 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
|
||||
|
|
|
|||
|
|
@ -33,9 +33,6 @@
|
|||
* 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
|
||||
|
|
|
|||
|
|
@ -169,6 +169,9 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
// one object for all - see eoRealBounds.cpp
|
||||
extern eoRealNoBounds eoDummyRealNoBounds;
|
||||
|
||||
/**
|
||||
* fully bounded eoRealBound == interval
|
||||
*/
|
||||
|
|
@ -414,10 +417,9 @@ public:
|
|||
// virtual desctructor (to avoid warning?)
|
||||
virtual ~eoRealVectorBounds(){}
|
||||
|
||||
/** Default Ctor
|
||||
/** Default Ctor. I don't like it, as it leaves NULL pointers around
|
||||
*/
|
||||
eoRealVectorBounds() :
|
||||
vector<eoRealBounds *>(0) {}
|
||||
eoRealVectorBounds(unsigned _dim=0) : vector<eoRealBounds *>(_dim) {}
|
||||
|
||||
/** Simple bounds = minimum and maximum (allowed)
|
||||
*/
|
||||
|
|
@ -590,14 +592,19 @@ public:
|
|||
class eoRealVectorNoBounds: public eoRealVectorBounds
|
||||
{
|
||||
public:
|
||||
// virtual desctructor (to avoid warining?)
|
||||
// virtual desctructor (to avoid warning?)
|
||||
virtual ~eoRealVectorNoBounds(){}
|
||||
|
||||
/**
|
||||
Simple bounds = minimum and maximum (allowed)
|
||||
*/
|
||||
// Ctor: nothing to do!
|
||||
eoRealVectorNoBounds(unsigned _dim=0) {}
|
||||
* Ctor: nothing to do, but beware of dimension: call base class ctor
|
||||
*/
|
||||
eoRealVectorNoBounds(unsigned _dim=0) : eoRealVectorBounds(_dim)
|
||||
{
|
||||
// avoid NULL pointers, even though they shoudl (at the moment) never be used!
|
||||
if (_dim)
|
||||
for (unsigned i=0; i<_dim; i++)
|
||||
operator[](i)=&eoDummyRealNoBounds;
|
||||
}
|
||||
|
||||
|
||||
virtual bool isBounded(unsigned) {return false;}
|
||||
|
|
@ -651,7 +658,6 @@ public:
|
|||
|
||||
};
|
||||
|
||||
// one object for all
|
||||
extern eoRealNoBounds eoDummyRealNoBounds;
|
||||
// one object for all - see eoRealBounds.cpp
|
||||
extern eoRealVectorNoBounds eoDummyVectorNoBounds;
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -2,17 +2,17 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
/** Just a simple function that takes an eoEsBase<float> and sets the fitnes
|
||||
/** Just a simple function that takes an eoEsBase<double> and sets the fitnes
|
||||
to sphere
|
||||
@param _ind A floatingpoint vector
|
||||
@param _ind vector<double>
|
||||
*/
|
||||
|
||||
double real_value(const std::vector<double>& _ind)
|
||||
{
|
||||
double sum = 0; /* compute in double format, even if return a float */
|
||||
double sum = 0;
|
||||
for (unsigned i = 0; i < _ind.size(); i++)
|
||||
sum += _ind[i] * _ind[i];
|
||||
return sum;
|
||||
return sqrt(sum);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ typedef eoMinimizingFitness FitT;
|
|||
template <class EOT>
|
||||
void runAlgorithm(EOT, eoParser& _parser, eoState& _state, eoRealVectorBounds& _bounds, eoValueParam<string> _load_name);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main_function(int argc, char *argv[])
|
||||
{
|
||||
// Create the command-line parser
|
||||
eoParser parser( argc, argv, "Basic EA for vector<float> with adaptive mutations");
|
||||
|
|
@ -83,6 +83,30 @@ int main(int argc, char *argv[])
|
|||
return 0;
|
||||
}
|
||||
|
||||
// A main that catches the exceptions
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
// rng.reseed(42);
|
||||
int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);
|
||||
flag |= _CRTDBG_LEAK_CHECK_DF;
|
||||
_CrtSetDbgFlag(flag);
|
||||
// _CrtSetBreakAlloc(100);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
template <class EOT>
|
||||
void runAlgorithm(EOT, eoParser& _parser, eoState& _state, eoRealVectorBounds& _bounds, eoValueParam<string> _load_name)
|
||||
{
|
||||
|
|
@ -90,8 +114,8 @@ void runAlgorithm(EOT, eoParser& _parser, eoState& _state, eoRealVectorBounds& _
|
|||
eoEvalFuncPtr<EOT, double, const vector<double>&> eval( real_value );
|
||||
|
||||
// population parameters, unfortunately these can not be altered in the state file
|
||||
eoValueParam<unsigned> mu = _parser.createParam(unsigned(50), "mu","Size of the population");
|
||||
eoValueParam<float>lambda_rate = _parser.createParam(float(7.0), "lambda_rate", "Factor of children to produce");
|
||||
eoValueParam<unsigned> mu = _parser.createParam(unsigned(7), "mu","Size of the population");
|
||||
eoValueParam<double>lambda_rate = _parser.createParam(double(7.0), "lambda_rate", "Factor of children to produce");
|
||||
|
||||
if (lambda_rate.value() < 1.0f)
|
||||
{
|
||||
|
|
@ -133,11 +157,19 @@ void runAlgorithm(EOT, eoParser& _parser, eoState& _state, eoRealVectorBounds& _
|
|||
checkpoint.add(monitor);
|
||||
checkpoint.add(average);
|
||||
|
||||
// only mutation (== with rate 1.0)
|
||||
eoMonGenOp<EOT> op(mutate);
|
||||
|
||||
// the selection: sequential selection
|
||||
eoSequentialSelect<EOT> select;
|
||||
// the general breeder (lambda is a rate -> true)
|
||||
eoGeneralBreeder<EOT> breed(select, op, lambda_rate.value(), true);
|
||||
|
||||
eoProportionalGOpSel<EOT> opSel;
|
||||
opSel.addOp(mutate, 1.0);
|
||||
// the replacement - hard-coded Comma replacement
|
||||
eoCommaReplacement<EOT> replace;
|
||||
|
||||
eoEvolutionStrategy<EOT> es(checkpoint, eval, opSel, lambda_rate.value(), eoEvolutionStrategy<EOT>::comma_strategy());
|
||||
// now the eoEasyEA
|
||||
eoEasyEA<EOT> es(checkpoint, eval, breed, replace);
|
||||
|
||||
es(pop);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include <iostream>
|
||||
|
||||
#include <es/es.h>
|
||||
#include <es/real.h>
|
||||
#include "real_value.h"
|
||||
#include <apply.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ and to</font></b></center>
|
|||
<h1>
|
||||
<font color="#FF0000">EO Tutorial</font></h1></center>
|
||||
|
||||
<center><font color="#FF0000">Version 0.94 - Feb. 18 2001</font></center>
|
||||
<center><font color="#FF0000">Version 0.95 - Apr. 27 2001</font></center>
|
||||
|
||||
<p>Welcome to EO tutorial/on-line documentation.
|
||||
<p>Please note that <b><font color="#FF6600">this tutorial is not supposed
|
||||
|
|
|
|||
Reference in a new issue