Install eoPropGAGenOp.h

Add #include <cmath> in eoEsChromInit.h in order to make gcc-4.0 happy.
This commit is contained in:
kuepper 2005-08-29 07:32:13 +00:00
commit d418459a01
3 changed files with 51 additions and 44 deletions

View file

@ -71,6 +71,7 @@ pkginclude_HEADERS = eo \
eoPopEvalFunc.h \ eoPopEvalFunc.h \
eoPopulator.h \ eoPopulator.h \
eoPrintable.h \ eoPrintable.h \
eoPropGAGenOp.h \
eoProportionalCombinedOp.h \ eoProportionalCombinedOp.h \
eoProportionalSelect.h \ eoProportionalSelect.h \
eoRandomSelect.h \ eoRandomSelect.h \

View file

@ -27,6 +27,7 @@
#ifndef _eoEsChromInit_H #ifndef _eoEsChromInit_H
#define _eoEsChromInit_H #define _eoEsChromInit_H
#include <cmath>
#include <es/eoRealInitBounded.h> #include <es/eoRealInitBounded.h>
#include <es/eoEsSimple.h> #include <es/eoEsSimple.h>
#include <es/eoEsStdev.h> #include <es/eoEsStdev.h>
@ -62,16 +63,17 @@ public:
typedef typename EOT::Fitness FitT; typedef typename EOT::Fitness FitT;
/** Ctor: @param /** Ctor:
* eoRealVectorBounds& _bounds : bounds for uniform initialization
* double _sigma : initial value for the stddev @param eoRealVectorBounds& _bounds : bounds for uniform initialization
* bool _to_scale : wether sigma should be multiplied by the range of each variable @param _sigma : initial value for the stddev
* added December 2004 - MS (together with the whole comment :-) @param _to_scale : wether sigma should be multiplied by the range of each variable
*/ added December 2004 - MS (together with the whole comment :-)
eoEsChromInit(eoRealVectorBounds& _bounds, double _sigma = 0.3, bool _to_scale=false) : */
eoRealInitBounded<EOT>(_bounds) eoEsChromInit(eoRealVectorBounds& _bounds, double _sigma = 0.3, bool _to_scale=false)
{ : eoRealInitBounded<EOT>(_bounds)
// a bit of pre-computations, to ave time later (even if some are useless) {
// a bit of pre-computations, to save time later (even if some are useless)
// first, the case of one unique sigma // first, the case of one unique sigma
if (_to_scale) // sigma is scaled by the average range (if that means anything!) if (_to_scale) // sigma is scaled by the average range (if that means anything!)
@ -96,7 +98,7 @@ public:
} }
else else
lesSigmas[i] = _sigma; lesSigmas[i] = _sigma;
} }
void operator()(EOT& _eo) void operator()(EOT& _eo)
{ {

View file

@ -37,12 +37,14 @@
#include <strstream> #include <strstream>
#endif #endif
#include <es/eoReal.h> #include <iostream>
#include <es/eoEsChromInit.h>
#include <utils/eoRealVectorBounds.h> #include "es/eoReal.h"
#include "es/eoEsChromInit.h"
#include "utils/eoRealVectorBounds.h"
// also need the parser and param includes // also need the parser and param includes
#include <utils/eoParser.h> #include "utils/eoParser.h"
#include <utils/eoState.h> #include "utils/eoState.h"
/* /*
@ -71,30 +73,35 @@
template <class EOT> template <class EOT>
eoEsChromInit<EOT> & do_make_genotype(eoParser& _parser, eoState& _state, EOT) eoEsChromInit<EOT> & do_make_genotype(eoParser& _parser, eoState& _state, EOT)
{ {
// the fitness type // the fitness type
typedef typename EOT::Fitness FitT; typedef typename EOT::Fitness FitT;
// for eoReal, only thing needed is the size - but might have been created elswhere ...
eoValueParam<unsigned>& vecSize = _parser.getORcreateParam(unsigned(10), "vecSize", "The number of variables ", 'n',"Genotype Initialization");
// for eoReal, only thing needed is the size - but might have been created elswhere ...
eoValueParam<unsigned>& vecSize
= _parser.getORcreateParam(unsigned(10), "vecSize",
"The number of variables ",
'n',"Genotype Initialization");
// to build an eoReal Initializer, we need bounds: [-1,1] by default // to build an eoReal Initializer, we need bounds: [-1,1] by default
eoValueParam<eoRealVectorBounds>& boundsParam = _parser.getORcreateParam(eoRealVectorBounds(vecSize.value(),-1,1), "initBounds", "Bounds for initialization (MUST be bounded)", 'B', "Genotype Initialization"); eoValueParam<eoRealVectorBounds>& boundsParam
= _parser.getORcreateParam(eoRealVectorBounds(vecSize.value(), -1, 1),
// now some initial value for sigmas - even if useless? "initBounds",
// shoudl be used in Normal mutation "Bounds for initialization (MUST be bounded)",
std::string & sigmaString = _parser.getORcreateParam(std::string("0.3"), "sigmaInit", 'B', "Genotype Initialization");
"Initial value for Sigmas (with a '%' -> scaled by the range of each variable)", // now some initial value for sigmas - even if useless?
// shoudl be used in Normal mutation
std::string& sigmaString
= _parser.getORcreateParam(std::string("0.3"), "sigmaInit",
"Initial value for Sigmas (with a '%' -> scaled by the range of each variable)",
's',"Genotype Initialization").value(); 's',"Genotype Initialization").value();
// check for % // check for %
bool to_scale = false; // == no % bool to_scale = false;
size_t pos = sigmaString.find('%'); size_t pos = sigmaString.find('%');
if (pos < sigmaString.size()) // found a % if (pos < sigmaString.size())
{ {
// found a % - use scaling and get rid of '%'
to_scale = true; to_scale = true;
sigmaString.resize(pos); // get rid of % sigmaString.resize(pos);
} }
#ifdef HAVE_SSTREAM #ifdef HAVE_SSTREAM
std::istringstream is(sigmaString); std::istringstream is(sigmaString);
#else #else
@ -102,16 +109,13 @@ eoEsChromInit<EOT> & do_make_genotype(eoParser& _parser, eoState& _state, EOT)
#endif #endif
double sigma; double sigma;
is >> sigma; is >> sigma;
// minimum check // minimum check
if ( (sigma < 0) ) if ( (sigma < 0) )
throw std::runtime_error("Negative sigma in make_genotype"); throw std::runtime_error("Negative sigma in make_genotype");
eoEsChromInit<EOT> * init = new eoEsChromInit<EOT>(boundsParam.value(), sigma, to_scale);
eoEsChromInit<EOT> * init = // store in state
new eoEsChromInit<EOT>(boundsParam.value(), sigma, to_scale); _state.storeFunctor(init);
// satore in state return *init;
_state.storeFunctor(init);
return *init;
} }
#endif #endif