Use getORcreateParam instead of createParam when getting values from
the eoParser. Update setORcreateParam.
This commit is contained in:
parent
f948ccda3a
commit
438e8ef6d6
9 changed files with 290 additions and 194 deletions
|
|
@ -94,7 +94,10 @@ eoContinue<Indi> & do_make_continue(eoParser& _parser, eoState& _state, eoEvalFu
|
|||
}
|
||||
|
||||
// Same thing with Eval - but here default value is 0
|
||||
eoValueParam<unsigned long>& maxEvalParam = _parser.createParam((unsigned long)0, "maxEval", "Maximum number of evaluations (0 = none)",'E',"Stopping criterion");
|
||||
eoValueParam<unsigned long>& maxEvalParam
|
||||
= _parser.getORcreateParam((unsigned long)0, "maxEval",
|
||||
"Maximum number of evaluations (0 = none)",
|
||||
'E', "Stopping criterion");
|
||||
|
||||
if (maxEvalParam.value()) // positive: -> define and store
|
||||
{
|
||||
|
|
|
|||
|
|
@ -59,7 +59,9 @@ class eoEsMutationInit
|
|||
{
|
||||
if (TauLclParam == 0)
|
||||
{
|
||||
TauLclParam = &parser.createParam(1.0, TauLclName(), "Local Tau (before normalization)", TauLclShort(), section());
|
||||
TauLclParam = &parser.getORcreateParam(1.0, TauLclName(),
|
||||
"Local Tau (before normalization)",
|
||||
TauLclShort(), section());
|
||||
}
|
||||
|
||||
return TauLclParam->value();
|
||||
|
|
@ -69,7 +71,9 @@ class eoEsMutationInit
|
|||
{
|
||||
if (TauGlbParam == 0)
|
||||
{
|
||||
TauGlbParam = &parser.createParam(1.0, TauGlbName(), "Global Tau (before normalization)", TauGlbShort(), section());
|
||||
TauGlbParam = &parser.getORcreateParam(1.0, TauGlbName(),
|
||||
"Global Tau (before normalization)",
|
||||
TauGlbShort(), section());
|
||||
}
|
||||
|
||||
return TauGlbParam->value();
|
||||
|
|
@ -79,7 +83,8 @@ class eoEsMutationInit
|
|||
{
|
||||
if (TauBetaParam == 0)
|
||||
{
|
||||
TauBetaParam = &parser.createParam(0.0873, TauBetaName(), "Beta", TauBetaShort(), section());
|
||||
TauBetaParam = &parser.getORcreateParam(0.0873, TauBetaName(),
|
||||
"Beta", TauBetaShort(), section());
|
||||
}
|
||||
|
||||
return TauBetaParam->value();
|
||||
|
|
@ -93,11 +98,11 @@ class eoEsMutationInit
|
|||
virtual std::string TauLclName(void) const { return "TauLoc"; }
|
||||
virtual char TauLclShort(void) const { return 'l'; }
|
||||
|
||||
virtual std::string TauGlbName(void) const { return "TauGlob"; }
|
||||
virtual char TauGlbShort(void) const { return 'g'; }
|
||||
virtual std::string TauGlbName(void) const { return "TauGlob"; }
|
||||
virtual char TauGlbShort(void) const { return 'g'; }
|
||||
|
||||
virtual std::string TauBetaName(void) const { return "Beta"; }
|
||||
virtual char TauBetaShort(void) const { return 'b'; }
|
||||
virtual std::string TauBetaName(void) const { return "Beta"; }
|
||||
virtual char TauBetaShort(void) const { return 'b'; }
|
||||
|
||||
private :
|
||||
|
||||
|
|
|
|||
|
|
@ -55,13 +55,19 @@
|
|||
// the templatized code
|
||||
#include <es/make_genotype_real.h>
|
||||
|
||||
/// The following function merely call the templatized do_* functions
|
||||
/// The following functions merely call the templatized do_* functions
|
||||
eoRealInitBounded<eoReal<double> > & make_genotype(eoParser& _parser,
|
||||
eoState& _state,
|
||||
eoReal<double> _eo)
|
||||
{
|
||||
return do_make_genotype(_parser, _state, _eo);
|
||||
}
|
||||
|
||||
eoRealInitBounded<eoReal<double> > & make_genotype(eoParser& _parser, eoState& _state, eoReal<double> _eo)
|
||||
|
||||
|
||||
eoRealInitBounded<eoReal<eoMinimizingFitness> > & make_genotype(eoParser& _parser,
|
||||
eoState& _state,
|
||||
eoReal<eoMinimizingFitness> _eo)
|
||||
{
|
||||
return do_make_genotype(_parser, _state, _eo);
|
||||
}
|
||||
eoRealInitBounded<eoReal<eoMinimizingFitness> > & make_genotype(eoParser& _parser, eoState& _state, eoReal<eoMinimizingFitness> _eo)
|
||||
{
|
||||
return do_make_genotype(_parser, _state, _eo);
|
||||
return do_make_genotype(_parser, _state, _eo);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,12 +63,14 @@
|
|||
* _init(myEO);
|
||||
* and myEO is then an ACTUAL object
|
||||
*/
|
||||
|
||||
template <class EOT>
|
||||
eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit<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', "Genetic Operators");
|
||||
eoValueParam<eoParamParamType>& boundsParam
|
||||
= _parser.getORcreateParam(eoParamParamType("(0,1)"), "objectBounds",
|
||||
"Bounds for variables (unbounded if absent)",
|
||||
'B', "Genetic Operators");
|
||||
|
||||
// get initisalizer size == std::vector size
|
||||
// eoRealInitBounded<EOT> * realInit = (eoRealInitBounded<EOT>*)(&_init);
|
||||
|
|
@ -113,7 +115,10 @@ eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit<EO
|
|||
// 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<std::string>& operatorParam = _parser.createParam(std::string("SGA"), "operator", "Description of the operator (SGA only now)", 'o', "Genetic Operators");
|
||||
eoValueParam<std::string>& operatorParam
|
||||
= _parser.getORcreateParam(std::string("SGA"), "operator",
|
||||
"Description of the operator (SGA only now)",
|
||||
'o', "Genetic Operators");
|
||||
|
||||
if (operatorParam.value() != std::string("SGA"))
|
||||
throw std::runtime_error("Sorry, only SGA-like operator available right now\n");
|
||||
|
|
@ -124,12 +129,16 @@ 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" );
|
||||
eoValueParam<double>& pCrossParam
|
||||
= _parser.getORcreateParam(0.6, "pCross", "Probability of Crossover",
|
||||
'C', "Genetic Operators" );
|
||||
// minimum check
|
||||
if ( (pCrossParam.value() < 0) || (pCrossParam.value() > 1) )
|
||||
throw std::runtime_error("Invalid pCross");
|
||||
|
||||
eoValueParam<double>& pMutParam = _parser.createParam(0.1, "pMut", "Probability of Mutation", 'M', "Genetic Operators" );
|
||||
eoValueParam<double>& pMutParam
|
||||
= _parser.getORcreateParam(0.1, "pMut", "Probability of Mutation",
|
||||
'M', "Genetic Operators" );
|
||||
// minimum check
|
||||
if ( (pMutParam.value() < 0) || (pMutParam.value() > 1) )
|
||||
throw std::runtime_error("Invalid pMut");
|
||||
|
|
@ -137,12 +146,18 @@ eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit<EO
|
|||
// the crossovers
|
||||
/////////////////
|
||||
// the parameters
|
||||
eoValueParam<double>& segmentRateParam = _parser.createParam(double(1.0), "segmentRate", "Relative rate for segment crossover", 's', "Genetic Operators" );
|
||||
eoValueParam<double>& segmentRateParam
|
||||
= _parser.getORcreateParam(double(1.0), "segmentRate",
|
||||
"Relative rate for segment crossover",
|
||||
's', "Genetic Operators" );
|
||||
// minimum check
|
||||
if ( (segmentRateParam.value() < 0) )
|
||||
throw std::runtime_error("Invalid segmentRate");
|
||||
|
||||
eoValueParam<double>& arithmeticRateParam = _parser.createParam(double(2.0), "arithmeticRate", "Relative rate for arithmetic crossover", 'A', "Genetic Operators" );
|
||||
eoValueParam<double>& arithmeticRateParam
|
||||
= _parser.getORcreateParam(double(2.0), "arithmeticRate",
|
||||
"Relative rate for arithmetic crossover",
|
||||
'A', "Genetic Operators" );
|
||||
// minimum check
|
||||
if ( (arithmeticRateParam.value() < 0) )
|
||||
throw std::runtime_error("Invalid arithmeticRate");
|
||||
|
|
@ -178,27 +193,40 @@ eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit<EO
|
|||
// the mutations
|
||||
/////////////////
|
||||
// the parameters
|
||||
eoValueParam<double> & epsilonParam = _parser.createParam(0.01, "epsilon", "Half-size of interval for Uniform Mutation", 'e', "Genetic Operators" );
|
||||
eoValueParam<double> & epsilonParam
|
||||
= _parser.getORcreateParam(0.01, "epsilon", "Half-size of interval for Uniform Mutation",
|
||||
'e', "Genetic Operators" );
|
||||
// minimum check
|
||||
if ( (epsilonParam.value() < 0) )
|
||||
throw std::runtime_error("Invalid epsilon");
|
||||
|
||||
eoValueParam<double> & uniformMutRateParam = _parser.createParam(1.0, "uniformMutRate", "Relative rate for uniform mutation", 'u', "Genetic Operators" );
|
||||
eoValueParam<double> & uniformMutRateParam
|
||||
= _parser.getORcreateParam(1.0, "uniformMutRate",
|
||||
"Relative rate for uniform mutation", 'u', "Genetic Operators" );
|
||||
// minimum check
|
||||
if ( (uniformMutRateParam.value() < 0) )
|
||||
throw std::runtime_error("Invalid uniformMutRate");
|
||||
|
||||
eoValueParam<double> & detMutRateParam = _parser.createParam(1.0, "detMutRate", "Relative rate for deterministic uniform mutation", 'd', "Genetic Operators" );
|
||||
eoValueParam<double> & detMutRateParam
|
||||
= _parser.getORcreateParam(1.0, "detMutRate",
|
||||
"Relative rate for deterministic uniform mutation",
|
||||
'd', "Genetic Operators" );
|
||||
// minimum check
|
||||
if ( (detMutRateParam.value() < 0) )
|
||||
throw std::runtime_error("Invalid detMutRate");
|
||||
|
||||
eoValueParam<double> & normalMutRateParam = _parser.createParam(1.0, "normalMutRate", "Relative rate for Gaussian mutation", 'd', "Genetic Operators" );
|
||||
eoValueParam<double> & normalMutRateParam
|
||||
= _parser.getORcreateParam(1.0, "normalMutRate",
|
||||
"Relative rate for Gaussian mutation",
|
||||
'd', "Genetic Operators" );
|
||||
// minimum check
|
||||
if ( (normalMutRateParam.value() < 0) )
|
||||
throw std::runtime_error("Invalid normalMutRate");
|
||||
// and the sigma
|
||||
eoValueParam<double> & sigmaParam = _parser.createParam(1.0, "sigma", "Sigma (fixed) for Gaussian mutation", 'S', "Genetic Operators" );
|
||||
eoValueParam<double> & sigmaParam
|
||||
= _parser.getORcreateParam(1.0, "sigma",
|
||||
"Sigma (fixed) for Gaussian mutation",
|
||||
'S', "Genetic Operators" );
|
||||
// minimum check
|
||||
if ( (sigmaParam.value() < 0) )
|
||||
throw std::runtime_error("Invalid sigma");
|
||||
|
|
|
|||
|
|
@ -74,10 +74,15 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
|
|||
unsigned vecSize = _init.size();
|
||||
|
||||
// First, decide whether the objective variables are bounded
|
||||
eoValueParam<eoRealVectorBounds>& boundsParam = _parser.createParam(eoRealVectorBounds(vecSize,eoDummyRealNoBounds), "objectBounds", "Bounds for variables", 'B', "Variation Operators");
|
||||
eoValueParam<eoRealVectorBounds>& boundsParam
|
||||
= _parser.getORcreateParam(eoRealVectorBounds(vecSize,eoDummyRealNoBounds),
|
||||
"objectBounds", "Bounds for variables", 'B', "Variation Operators");
|
||||
|
||||
// now we read Pcross and Pmut,
|
||||
eoValueParam<std::string>& operatorParam = _parser.createParam(std::string("SGA"), "operator", "Description of the operator (SGA only now)", 'o', "Variation Operators");
|
||||
eoValueParam<std::string>& operatorParam
|
||||
= _parser.getORcreateParam(std::string("SGA"), "operator",
|
||||
"Description of the operator (SGA only now)",
|
||||
'o', "Variation Operators");
|
||||
|
||||
if (operatorParam.value() != std::string("SGA"))
|
||||
throw std::runtime_error("Sorry, only SGA-like operator available right now\n");
|
||||
|
|
@ -86,12 +91,16 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
|
|||
// and create the eoGenOp that is exactly
|
||||
// crossover with pcross + mutation with pmut
|
||||
|
||||
eoValueParam<double>& pCrossParam = _parser.createParam(1.0, "pCross", "Probability of Crossover", 'C', "Variation Operators" );
|
||||
eoValueParam<double>& pCrossParam
|
||||
= _parser.getORcreateParam(1.0, "pCross", "Probability of Crossover",
|
||||
'C', "Variation Operators" );
|
||||
// minimum check
|
||||
if ( (pCrossParam.value() < 0) || (pCrossParam.value() > 1) )
|
||||
throw std::runtime_error("Invalid pCross");
|
||||
|
||||
eoValueParam<double>& pMutParam = _parser.createParam(1.0, "pMut", "Probability of Mutation", 'M', "Variation Operators" );
|
||||
eoValueParam<double>& pMutParam
|
||||
= _parser.getORcreateParam(1.0, "pMut", "Probability of Mutation",
|
||||
'M', "Variation Operators" );
|
||||
// minimum check
|
||||
if ( (pMutParam.value() < 0) || (pMutParam.value() > 1) )
|
||||
throw std::runtime_error("Invalid pMut");
|
||||
|
|
@ -100,10 +109,19 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
|
|||
// crossover
|
||||
/////////////
|
||||
// ES crossover
|
||||
eoValueParam<std::string>& crossTypeParam = _parser.createParam(std::string("global"), "crossType", "Type of ES recombination (global or standard)", 'C', "Variation Operators");
|
||||
eoValueParam<std::string>& crossTypeParam
|
||||
= _parser.getORcreateParam(std::string("global"), "crossType",
|
||||
"Type of ES recombination (global or standard)",
|
||||
'C', "Variation Operators");
|
||||
|
||||
eoValueParam<std::string>& crossObjParam = _parser.createParam(std::string("discrete"), "crossObj", "Recombination of object variables (discrete, intermediate or none)", 'O', "Variation Operators");
|
||||
eoValueParam<std::string>& crossStdevParam = _parser.createParam(std::string("intermediate"), "crossStdev", "Recombination of mutation strategy parameters (intermediate, discrete or none)", 'S', "Variation Operators");
|
||||
eoValueParam<std::string>& crossObjParam
|
||||
= _parser.getORcreateParam(std::string("discrete"), "crossObj",
|
||||
"Recombination of object variables (discrete, intermediate or none)",
|
||||
'O', "Variation Operators");
|
||||
eoValueParam<std::string>& crossStdevParam
|
||||
= _parser.getORcreateParam(std::string("intermediate"), "crossStdev",
|
||||
"Recombination of mutation strategy parameters (intermediate, discrete or none)",
|
||||
'S', "Variation Operators");
|
||||
|
||||
// The pointers: first the atom Xover
|
||||
eoBinOp<double> *ptObjAtomCross = NULL;
|
||||
|
|
|
|||
|
|
@ -71,13 +71,18 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
|
|||
unsigned vecSize = _init.size();
|
||||
|
||||
// First, decide whether the objective variables are bounded
|
||||
eoValueParam<eoRealVectorBounds>& boundsParam = _parser.createParam(eoRealVectorBounds(vecSize,eoDummyRealNoBounds), "objectBounds", "Bounds for variables", 'B', "Variation Operators");
|
||||
eoValueParam<eoRealVectorBounds>& boundsParam
|
||||
= _parser.getORcreateParam(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
|
||||
// BTW we must leave that simple version available somehow, as it is the one
|
||||
// that 90% people use!
|
||||
eoValueParam<std::string>& operatorParam = _parser.createParam(std::string("SGA"), "operator", "Description of the operator (SGA only now)", 'o', "Variation Operators");
|
||||
eoValueParam<std::string>& operatorParam
|
||||
= _parser.getORcreateParam(std::string("SGA"), "operator",
|
||||
"Description of the operator (SGA only now)",
|
||||
'o', "Variation Operators");
|
||||
|
||||
if (operatorParam.value() != std::string("SGA"))
|
||||
throw std::runtime_error("Sorry, only SGA-like operator available right now\n");
|
||||
|
|
@ -88,12 +93,18 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
|
|||
// 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', "Variation Operators" );
|
||||
eoValueParam<double>& pCrossParam
|
||||
= _parser.getORcreateParam(0.6, "pCross",
|
||||
"Probability of Crossover",
|
||||
'C', "Variation Operators" );
|
||||
// minimum check
|
||||
if ( (pCrossParam.value() < 0) || (pCrossParam.value() > 1) )
|
||||
throw std::runtime_error("Invalid pCross");
|
||||
|
||||
eoValueParam<double>& pMutParam = _parser.createParam(0.1, "pMut", "Probability of Mutation", 'M', "Variation Operators" );
|
||||
eoValueParam<double>& pMutParam
|
||||
= _parser.getORcreateParam(0.1, "pMut",
|
||||
"Probability of Mutation",
|
||||
'M', "Variation Operators" );
|
||||
// minimum check
|
||||
if ( (pMutParam.value() < 0) || (pMutParam.value() > 1) )
|
||||
throw std::runtime_error("Invalid pMut");
|
||||
|
|
@ -101,23 +112,35 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
|
|||
// the crossovers
|
||||
/////////////////
|
||||
// the parameters
|
||||
eoValueParam<double>& alphaParam = _parser.createParam(double(0.0), "alpha", "Bound for factor of linear recombinations", 'a', "Variation Operators" );
|
||||
eoValueParam<double>& alphaParam
|
||||
= _parser.getORcreateParam(double(0.0), "alpha",
|
||||
"Bound for factor of linear recombinations",
|
||||
'a', "Variation Operators" );
|
||||
// minimum check
|
||||
if ( (alphaParam.value() < 0) )
|
||||
throw std::runtime_error("Invalid BLX coefficient alpha");
|
||||
|
||||
|
||||
eoValueParam<double>& segmentRateParam = _parser.createParam(double(1.0), "segmentRate", "Relative rate for segment crossover", 's', "Variation Operators" );
|
||||
eoValueParam<double>& segmentRateParam
|
||||
= _parser.getORcreateParam(double(1.0), "segmentRate",
|
||||
"Relative rate for segment crossover",
|
||||
's', "Variation Operators" );
|
||||
// minimum check
|
||||
if ( (segmentRateParam.value() < 0) )
|
||||
throw std::runtime_error("Invalid segmentRate");
|
||||
|
||||
eoValueParam<double>& hypercubeRateParam = _parser.createParam(double(1.0), "hypercubeRate", "Relative rate for hypercube crossover", 'A', "Variation Operators" );
|
||||
eoValueParam<double>& hypercubeRateParam
|
||||
= _parser.getORcreateParam(double(1.0), "hypercubeRate",
|
||||
"Relative rate for hypercube crossover",
|
||||
'A', "Variation Operators" );
|
||||
// minimum check
|
||||
if ( (hypercubeRateParam.value() < 0) )
|
||||
throw std::runtime_error("Invalid hypercubeRate");
|
||||
|
||||
eoValueParam<double>& uxoverRateParam = _parser.createParam(double(1.0), "uxoverRate", "Relative rate for uniform crossover", 'A', "Variation Operators" );
|
||||
eoValueParam<double>& uxoverRateParam
|
||||
= _parser.getORcreateParam(double(1.0), "uxoverRate",
|
||||
"Relative rate for uniform crossover",
|
||||
'A', "Variation Operators" );
|
||||
// minimum check
|
||||
if ( (uxoverRateParam.value() < 0) )
|
||||
throw std::runtime_error("Invalid uxoverRate");
|
||||
|
|
@ -158,29 +181,46 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
|
|||
// the mutations
|
||||
/////////////////
|
||||
// the parameters
|
||||
eoValueParam<double> & epsilonParam = _parser.createParam(0.01, "epsilon", "Half-size of interval for Uniform Mutation", 'e', "Variation Operators" );
|
||||
eoValueParam<double> & epsilonParam
|
||||
= _parser.getORcreateParam(0.01, "epsilon",
|
||||
"Half-size of interval for Uniform Mutation",
|
||||
'e', "Variation Operators" );
|
||||
// minimum check
|
||||
if ( (epsilonParam.value() < 0) )
|
||||
throw std::runtime_error("Invalid epsilon");
|
||||
|
||||
eoValueParam<double> & uniformMutRateParam = _parser.createParam(1.0, "uniformMutRate", "Relative rate for uniform mutation", 'u', "Variation Operators" );
|
||||
eoValueParam<double> & uniformMutRateParam
|
||||
= _parser.getORcreateParam(1.0, "uniformMutRate",
|
||||
"Relative rate for uniform mutation",
|
||||
'u', "Variation Operators" );
|
||||
// minimum check
|
||||
if ( (uniformMutRateParam.value() < 0) )
|
||||
throw std::runtime_error("Invalid uniformMutRate");
|
||||
|
||||
eoValueParam<double> & detMutRateParam = _parser.createParam(1.0, "detMutRate", "Relative rate for deterministic uniform mutation", 'd', "Variation Operators" );
|
||||
eoValueParam<double> & detMutRateParam
|
||||
= _parser.getORcreateParam(1.0, "detMutRate",
|
||||
"Relative rate for deterministic uniform mutation",
|
||||
'd', "Variation Operators" );
|
||||
// minimum check
|
||||
if ( (detMutRateParam.value() < 0) )
|
||||
throw std::runtime_error("Invalid detMutRate");
|
||||
|
||||
eoValueParam<double> & normalMutRateParam = _parser.createParam(1.0, "normalMutRate", "Relative rate for Gaussian mutation", 'd', "Variation Operators" );
|
||||
eoValueParam<double> & normalMutRateParam
|
||||
= _parser.getORcreateParam(1.0, "normalMutRate",
|
||||
"Relative rate for Gaussian mutation", 'd', "Variation Operators" );
|
||||
// minimum check
|
||||
if ( (normalMutRateParam.value() < 0) )
|
||||
throw std::runtime_error("Invalid normalMutRate");
|
||||
|
||||
eoValueParam<double> & sigmaParam = _parser.createParam(0.3, "sigma", "Sigma (fixed) for Gaussian mutation", 's', "Variation Operators" );
|
||||
eoValueParam<double> & sigmaParam
|
||||
= _parser.getORcreateParam(0.3, "sigma",
|
||||
"Sigma (fixed) for Gaussian mutation",
|
||||
's', "Variation Operators" );
|
||||
|
||||
eoValueParam<double> & pNormalParam = _parser.createParam(1.0, "pNormal", "Proba. to change each variable for Gaussian mutation", 's', "Variation Operators" );
|
||||
eoValueParam<double> & pNormalParam
|
||||
= _parser.getORcreateParam(1.0, "pNormal",
|
||||
"Proba. to change each variable for Gaussian mutation",
|
||||
's', "Variation Operators" );
|
||||
|
||||
// minimum check
|
||||
bool bMut = true;
|
||||
|
|
|
|||
|
|
@ -123,11 +123,10 @@ void eoParser::processParam(eoParam& param, std::string section)
|
|||
{
|
||||
// this param enters the parser: add the prefix to the long name
|
||||
if (prefix != "")
|
||||
{
|
||||
{
|
||||
param.setLongName(prefix+param.longName());
|
||||
section = prefix + section; // and to section
|
||||
}
|
||||
|
||||
}
|
||||
doRegisterParam(param); // plainly register it
|
||||
params.insert(make_pair(section, ¶m));
|
||||
}
|
||||
|
|
@ -139,9 +138,7 @@ void eoParser::doRegisterParam(eoParam& param) const
|
|||
string msg = "Required parameter: " + param.longName() + " missing";
|
||||
messages.push_back(msg);
|
||||
}
|
||||
|
||||
pair<bool, string> value = getValue(param);
|
||||
|
||||
if (value.first)
|
||||
{
|
||||
param.setValue(value.second);
|
||||
|
|
@ -162,9 +159,7 @@ pair<bool, string> eoParser::getValue(eoParam& _param) const
|
|||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
map<string, string>::const_iterator it = longNameMap.find(_param.longName());
|
||||
|
||||
if (it != longNameMap.end())
|
||||
{
|
||||
result.second = it->second;
|
||||
|
|
@ -172,7 +167,6 @@ pair<bool, string> eoParser::getValue(eoParam& _param) const
|
|||
return result;
|
||||
}
|
||||
// else (TODO: check environment, just long names)
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -188,72 +182,72 @@ void eoParser::updateParameters() const
|
|||
|
||||
void eoParser::readFrom(istream& is)
|
||||
{
|
||||
string str;
|
||||
// we must avoid processing \section{xxx} if xxx is NOT "Parser"
|
||||
bool processing = true;
|
||||
while (is >> str)
|
||||
string str;
|
||||
// we must avoid processing \section{xxx} if xxx is NOT "Parser"
|
||||
bool processing = true;
|
||||
while (is >> str)
|
||||
{
|
||||
if (str.find(string("\\section{"))==0) // found section begin
|
||||
processing = (str.find(string("Parser"))<str.size());
|
||||
if (str.find(string("\\section{"))==0) // found section begin
|
||||
processing = (str.find(string("Parser"))<str.size());
|
||||
|
||||
if (processing) // right \section (or no \section at all)
|
||||
if (processing) // right \section (or no \section at all)
|
||||
{
|
||||
if (str[0] == '#')
|
||||
if (str[0] == '#')
|
||||
{ // skip the rest of the line
|
||||
string tempStr;
|
||||
getline(is, tempStr);
|
||||
string tempStr;
|
||||
getline(is, tempStr);
|
||||
}
|
||||
if (str[0] == '-')
|
||||
if (str[0] == '-')
|
||||
{
|
||||
if (str.size() < 2)
|
||||
if (str.size() < 2)
|
||||
{
|
||||
eoWarning("Missing parameter");
|
||||
needHelp.value() = true;
|
||||
return;
|
||||
eoWarning("Missing parameter");
|
||||
needHelp.value() = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (str[1] == '-') // two consecutive dashes
|
||||
if (str[1] == '-') // two consecutive dashes
|
||||
{
|
||||
string::iterator equalLocation = find(str.begin() + 2, str.end(), '=');
|
||||
string value;
|
||||
string::iterator equalLocation = find(str.begin() + 2, str.end(), '=');
|
||||
string value;
|
||||
|
||||
if (equalLocation == str.end())
|
||||
if (equalLocation == str.end())
|
||||
{ // TODO: it should be the next string
|
||||
value = "";
|
||||
value = "";
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
value = string(equalLocation + 1, str.end());
|
||||
value = string(equalLocation + 1, str.end());
|
||||
}
|
||||
|
||||
string name(str.begin() + 2, equalLocation);
|
||||
longNameMap[name] = value;
|
||||
string name(str.begin() + 2, equalLocation);
|
||||
longNameMap[name] = value;
|
||||
|
||||
}
|
||||
else // it should be a char
|
||||
else // it should be a char
|
||||
{
|
||||
string value = "1"; // flags do not need a special
|
||||
string value = "1"; // flags do not need a special
|
||||
|
||||
if (str.size() >= 2)
|
||||
if (str.size() >= 2)
|
||||
{
|
||||
if (str[2] == '=')
|
||||
if (str[2] == '=')
|
||||
{
|
||||
if (str.size() >= 3)
|
||||
value = string(str.begin() + 3, str.end());
|
||||
if (str.size() >= 3)
|
||||
value = string(str.begin() + 3, str.end());
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
value = string(str.begin() + 2, str.end());
|
||||
value = string(str.begin() + 2, str.end());
|
||||
}
|
||||
}
|
||||
|
||||
shortNameMap[str[1]] = value;
|
||||
shortNameMap[str[1]] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateParameters();
|
||||
updateParameters();
|
||||
}
|
||||
|
||||
void eoParser::printOn(ostream& os) const
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
CVS Info: $Date: 2005-08-29 07:50:50 $ $Version$ $Author: kuepper $
|
||||
CVS Info: $Date: 2005-09-12 17:53:24 $ $Version$ $Author: kuepper $
|
||||
*/
|
||||
#ifndef eoParser_h
|
||||
#define eoParser_h
|
||||
|
|
@ -73,29 +73,27 @@ public :
|
|||
* @param _required If it is a necessary parameter or not
|
||||
*/
|
||||
template <class ValueType>
|
||||
eoValueParam<ValueType>& createParam
|
||||
(ValueType _defaultValue,
|
||||
std::string _longName,
|
||||
std::string _description,
|
||||
char _shortHand = 0,
|
||||
std::string _section = "",
|
||||
bool _required = false)
|
||||
{
|
||||
eoValueParam<ValueType>* p = new eoValueParam<ValueType>(_defaultValue,
|
||||
_longName,
|
||||
_description,
|
||||
_shortHand,
|
||||
_required);
|
||||
ownedParams.push_back(p);
|
||||
processParam(*p, _section);
|
||||
return *p;
|
||||
}
|
||||
eoValueParam<ValueType>& createParam(ValueType _defaultValue,
|
||||
std::string _longName,
|
||||
std::string _description,
|
||||
char _shortHand = 0,
|
||||
std::string _section = "",
|
||||
bool _required = false)
|
||||
{
|
||||
eoValueParam<ValueType>* p = new eoValueParam<ValueType>(_defaultValue,
|
||||
_longName,
|
||||
_description,
|
||||
_shortHand,
|
||||
_required);
|
||||
ownedParams.push_back(p);
|
||||
processParam(*p, _section);
|
||||
return *p;
|
||||
}
|
||||
|
||||
|
||||
private :
|
||||
|
||||
std::vector<eoParam*> ownedParams;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -198,7 +196,10 @@ public:
|
|||
|
||||
|
||||
|
||||
/** Make sure parameter has specific value
|
||||
/** Set parameter value or create parameter
|
||||
|
||||
This makes sure that the specified parameter has the given value.
|
||||
If the parameter does not exist yet, it is created.
|
||||
|
||||
This requires that operator<< is defined for ValueType.
|
||||
*/
|
||||
|
|
@ -207,18 +208,19 @@ public:
|
|||
std::string _description, char _shortHand = 0,
|
||||
std::string _section = "", bool _required = false)
|
||||
{
|
||||
eoParam *param = getParamWithLongName(_longName);
|
||||
if(0 == param) {
|
||||
createParam(_defaultValue, _longName, _description,
|
||||
_shortHand, _section, _required);
|
||||
} else {
|
||||
eoValueParam<ValueType>& param = createParam(_defaultValue, _longName, _description,
|
||||
_shortHand, _section, _required);
|
||||
#ifdef HAVE_SSTREAM
|
||||
std::ostringstream os;
|
||||
std::ostringstream os;
|
||||
#else
|
||||
std::ostrstream os;
|
||||
std::ostrstream os;
|
||||
#endif
|
||||
os << _defaultValue;
|
||||
dynamic_cast<eoValueParam<int> *>(param)->setValue(os.str());
|
||||
os << _defaultValue;
|
||||
if(isItThere(param)) {
|
||||
param.setValue(os.str());
|
||||
} else {
|
||||
longNameMap[_longName] = os.str();
|
||||
shortNameMap[_shortHand] = os.str();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue