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 \
eoPopulator.h \
eoPrintable.h \
eoPropGAGenOp.h \
eoProportionalCombinedOp.h \
eoProportionalSelect.h \
eoRandomSelect.h \

View file

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

View file

@ -37,12 +37,14 @@
#include <strstream>
#endif
#include <es/eoReal.h>
#include <es/eoEsChromInit.h>
#include <utils/eoRealVectorBounds.h>
#include <iostream>
#include "es/eoReal.h"
#include "es/eoEsChromInit.h"
#include "utils/eoRealVectorBounds.h"
// also need the parser and param includes
#include <utils/eoParser.h>
#include <utils/eoState.h>
#include "utils/eoParser.h"
#include "utils/eoState.h"
/*
@ -71,30 +73,35 @@
template <class EOT>
eoEsChromInit<EOT> & do_make_genotype(eoParser& _parser, eoState& _state, EOT)
{
// the fitness type
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");
// the fitness type
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");
// 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");
// 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)",
eoValueParam<eoRealVectorBounds>& boundsParam
= _parser.getORcreateParam(eoRealVectorBounds(vecSize.value(), -1, 1),
"initBounds",
"Bounds for initialization (MUST be bounded)",
'B', "Genotype Initialization");
// 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();
// check for %
bool to_scale = false; // == no %
bool to_scale = false;
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;
sigmaString.resize(pos); // get rid of %
}
sigmaString.resize(pos);
}
#ifdef HAVE_SSTREAM
std::istringstream is(sigmaString);
#else
@ -102,16 +109,13 @@ eoEsChromInit<EOT> & do_make_genotype(eoParser& _parser, eoState& _state, EOT)
#endif
double sigma;
is >> sigma;
// minimum check
if ( (sigma < 0) )
throw std::runtime_error("Negative sigma in make_genotype");
eoEsChromInit<EOT> * init =
new eoEsChromInit<EOT>(boundsParam.value(), sigma, to_scale);
// satore in state
_state.storeFunctor(init);
return *init;
if ( (sigma < 0) )
throw std::runtime_error("Negative sigma in make_genotype");
eoEsChromInit<EOT> * init = new eoEsChromInit<EOT>(boundsParam.value(), sigma, to_scale);
// store in state
_state.storeFunctor(init);
return *init;
}
#endif