Bing change in eoRealBounds: it is now deriving from eoPersistent.
More important, the eoRealVectorBounds, vectorized version (a vector<eoRealBounds *> has also become an eoPersistent object and now derives from an eoRealBaseVectorBounds class. A useful consequence (and actual motivatino) was to be able to have soem eoValueParam<eoRealVectorBounds> with all possibilities for input (see doc for Lesson4 in the tutorial for the syntax).
This commit is contained in:
parent
42cb1981d5
commit
09388c8ed5
10 changed files with 779 additions and 412 deletions
|
|
@ -31,7 +31,7 @@
|
|||
#include <utils/eoRNG.h>
|
||||
#include <eoInit.h>
|
||||
#include <es/eoReal.h>
|
||||
#include <utils/eoRealBounds.h>
|
||||
#include <utils/eoRealVectorBounds.h>
|
||||
|
||||
/** Simple initialization for any EOT that derives from vector<double>
|
||||
* uniformly in some bounds
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
#include <algorithm> // swap_ranges
|
||||
#include <utils/eoRNG.h>
|
||||
#include <es/eoReal.h>
|
||||
#include <utils/eoRealBounds.h>
|
||||
#include <utils/eoRealVectorBounds.h>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include <es/eoReal.h>
|
||||
#include <eoEsChromInit.h>
|
||||
#include <utils/eoRealVectorBounds.h>
|
||||
// also need the parser and param includes
|
||||
#include <utils/eoParser.h>
|
||||
#include <utils/eoState.h>
|
||||
|
|
@ -66,27 +67,8 @@ eoEsChromInit<EOT> & do_make_genotype(eoParameterLoader& _parser, eoState& _stat
|
|||
// for eoReal, only thing needed is the size
|
||||
eoValueParam<unsigned>& vecSize = _parser.createParam(unsigned(10), "vecSize", "The number of variables ", 'n',"Genotype Initialization");
|
||||
|
||||
// to build an eoReal Initializer, we need bounds
|
||||
eoValueParam<eoParamParamType>& boundsParam = _parser.createParam(eoParamParamType("(0,1)"), "initBounds", "Bounds for uniform initialization", 'B', "Genotype 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
|
||||
// to build an eoReal Initializer, we need bounds: [-1,1] by default
|
||||
eoValueParam<eoRealVectorBounds>& boundsParam = _parser.createParam(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
|
||||
|
|
@ -97,7 +79,7 @@ eoEsChromInit<EOT> & do_make_genotype(eoParameterLoader& _parser, eoState& _stat
|
|||
throw runtime_error("Invalid sigma");
|
||||
|
||||
eoEsChromInit<EOT> * init =
|
||||
new eoEsChromInit<EOT>(*ptBounds, sigmaParam.value());
|
||||
new eoEsChromInit<EOT>(boundsParam.value(), sigmaParam.value());
|
||||
// satore in state
|
||||
_state.storeFunctor(init);
|
||||
return *init;
|
||||
|
|
|
|||
|
|
@ -70,41 +70,11 @@
|
|||
template <class EOT>
|
||||
eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoRealInitBounded<EOT>& _init)
|
||||
{
|
||||
// First, decide whether the objective variables are bounded
|
||||
eoValueParam<eoParamParamType>& boundsParam = _parser.createParam(eoParamParamType("(0,1)"), "objectBounds", "Bounds for variables (unbounded if absent)", 'B', "Variation Operators");
|
||||
|
||||
// get vector size
|
||||
unsigned vecSize = _init.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 moment, 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
|
||||
// First, decide whether the objective variables are bounded
|
||||
eoValueParam<eoRealVectorBounds>& boundsParam = _parser.createParam(eoRealVectorBounds(vecSize,eoDummyRealNoBounds), "objectBounds", "Bounds for variables", 'B', "Variation Operators");
|
||||
|
||||
// now we read Pcross and Pmut,
|
||||
eoValueParam<string>& operatorParam = _parser.createParam(string("SGA"), "operator", "Description of the operator (SGA only now)", 'o', "Variation Operators");
|
||||
|
|
@ -173,7 +143,7 @@ eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoRealIni
|
|||
// Proxy for the mutation parameters
|
||||
eoEsMutationInit mutateInit(_parser, "Variation Operators");
|
||||
|
||||
eoEsMutate<EOT> * ptMon = new eoEsMutate<EOT>(mutateInit, *ptBounds);
|
||||
eoEsMutate<EOT> * ptMon = new eoEsMutate<EOT>(mutateInit, boundsParam.value());
|
||||
_state.storeFunctor(ptMon);
|
||||
|
||||
// encapsulate into an eoGenop
|
||||
|
|
|
|||
|
|
@ -67,41 +67,11 @@
|
|||
template <class EOT>
|
||||
eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoRealInitBounded<EOT>& _init)
|
||||
{
|
||||
// First, decide whether the objective variables are bounded
|
||||
eoValueParam<eoParamParamType>& boundsParam = _parser.createParam(eoParamParamType("(0,1)"), "objectBounds", "Bounds for variables (unbounded if absent)", 'B', "Variation Operators");
|
||||
|
||||
// get vector size
|
||||
unsigned vecSize = _init.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
|
||||
// First, decide whether the objective variables are bounded
|
||||
eoValueParam<eoRealVectorBounds>& boundsParam = _parser.createParam(eoRealVectorBounds(vecSize,eoDummyRealNoBounds), "objectBounds", "Bounds for variables", 'B', "Variation Operators");
|
||||
|
||||
// this is a temporary version(!),
|
||||
// while Maarten codes the full tree-structured general operator input
|
||||
|
|
@ -167,12 +137,12 @@ eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoRealIni
|
|||
if (bCross)
|
||||
{
|
||||
// segment crossover for bitstring - pass it the bounds
|
||||
ptQuad = new eoSegmentCrossover<EOT>(*ptBounds, alphaParam.value());
|
||||
ptQuad = new eoSegmentCrossover<EOT>(boundsParam.value(), alphaParam.value());
|
||||
_state.storeFunctor(ptQuad);
|
||||
ptCombinedQuadOp = new eoPropCombinedQuadOp<EOT>(*ptQuad, segmentRateParam.value());
|
||||
|
||||
// hypercube crossover
|
||||
ptQuad = new eoHypercubeCrossover<EOT>(*ptBounds, alphaParam.value());
|
||||
ptQuad = new eoHypercubeCrossover<EOT>(boundsParam.value(), alphaParam.value());
|
||||
_state.storeFunctor(ptQuad);
|
||||
ptCombinedQuadOp->add(*ptQuad, hypercubeRateParam.value());
|
||||
|
||||
|
|
@ -228,18 +198,18 @@ eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoRealIni
|
|||
{
|
||||
// uniform mutation on all components:
|
||||
// offspring(i) uniformly chosen in [parent(i)-epsilon, parent(i)+epsilon]
|
||||
ptMon = new eoUniformMutation<EOT>(*ptBounds, epsilonParam.value());
|
||||
ptMon = new eoUniformMutation<EOT>(boundsParam.value(), 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>(*ptBounds, epsilonParam.value());
|
||||
ptMon = new eoDetUniformMutation<EOT>(boundsParam.value(), epsilonParam.value());
|
||||
_state.storeFunctor(ptMon);
|
||||
ptCombinedMonOp->add(*ptMon, detMutRateParam.value());
|
||||
|
||||
// mutate all component using Gaussian mutation
|
||||
ptMon = new eoNormalMutation<EOT>(*ptBounds, sigmaParam.value());
|
||||
ptMon = new eoNormalMutation<EOT>(boundsParam.value(), sigmaParam.value());
|
||||
_state.storeFunctor(ptMon);
|
||||
ptCombinedMonOp->add(*ptMon, normalMutRateParam.value());
|
||||
_state.storeFunctor(ptCombinedMonOp);
|
||||
|
|
|
|||
Reference in a new issue