use eoExceptions everywhere

This commit is contained in:
Johann Dreo 2020-03-27 00:21:52 +01:00
commit eba2e14950
127 changed files with 524 additions and 418 deletions

View file

@ -207,7 +207,7 @@ public:
{
// minimal check
if (updateFactor>=1)
throw std::runtime_error("Update factor must be < 1 in eoOneFifthMutation");
throw eoParamException("Update factor must be < 1 in eoOneFifthMutation");
}
/** The class name */

View file

@ -47,7 +47,7 @@ class eoRealInitBounded : public eoInit<EOT>
eoRealInitBounded(eoRealVectorBounds & _bounds):bounds(_bounds)
{
if (!bounds.isBounded())
throw std::runtime_error("Needs bounded bounds to initialize a std::vector<double>");
throw eoException("Needs bounded bounds to initialize a std::vector<double>");
}
/** simply passes the argument to the uniform method of the bounds */

View file

@ -111,7 +111,7 @@ template<class EOT> class eoUniformMutation: public eoMonOp<EOT>
{
// sanity check ?
if (_eo.size() != bounds.size())
throw std::runtime_error("Invalid size of indi in eoUniformMutation");
throw eoException("Invalid size of indi in eoUniformMutation");
for (unsigned lieu=0; lieu<_eo.size(); lieu++)
if (rng.flip(p_change[lieu]))
@ -213,7 +213,7 @@ template<class EOT> class eoDetUniformMutation: public eoMonOp<EOT>
{
// sanity check ?
if (_eo.size() != bounds.size())
throw std::runtime_error("Invalid size of indi in eoDetUniformMutation");
throw eoException("Invalid size of indi in eoDetUniformMutation");
for (unsigned i=0; i<no; i++)
{
unsigned lieu = rng.random(_eo.size());
@ -357,7 +357,7 @@ template<class EOT> class eoHypercubeCrossover: public eoQuadOp<EOT>
bounds(eoDummyVectorNoBounds), alpha(_alpha), range(1+2*_alpha)
{
if (_alpha < 0)
throw std::runtime_error("BLX coefficient should be positive");
throw eoParamException("BLX coefficient should be positive");
}
/**
@ -373,7 +373,7 @@ template<class EOT> class eoHypercubeCrossover: public eoQuadOp<EOT>
bounds(_bounds), alpha(_alpha), range(1+2*_alpha)
{
if (_alpha < 0)
throw std::runtime_error("BLX coefficient should be positive");
throw eoParamException("BLX coefficient should be positive");
}
/// The class name.

View file

@ -51,34 +51,34 @@
// Algo
///////
eoAlgo<eoEsSimple<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsSimple<double> >& _eval, eoContinue<eoEsSimple<double> >& _continue, eoGenOp<eoEsSimple<double> >& _op, eoDistance<eoEsSimple<double> >* _dist)
eoAlgo<eoEsSimple<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsSimple<double> >& _eval, eoContinue<eoEsSimple<double> >& _continue, eoGenOp<eoEsSimple<double> >& _op, eoDistance<eoEsSimple<double> >* /*_dist*/)
{
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
}
eoAlgo<eoEsSimple<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsSimple<eoMinimizingFitness> >& _eval, eoContinue<eoEsSimple<eoMinimizingFitness> >& _continue, eoGenOp<eoEsSimple<eoMinimizingFitness> >& _op, eoDistance<eoEsSimple<eoMinimizingFitness> >* _dist)
eoAlgo<eoEsSimple<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsSimple<eoMinimizingFitness> >& _eval, eoContinue<eoEsSimple<eoMinimizingFitness> >& _continue, eoGenOp<eoEsSimple<eoMinimizingFitness> >& _op, eoDistance<eoEsSimple<eoMinimizingFitness> >* /*_dist*/)
{
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
}
//////////////
eoAlgo<eoEsStdev<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsStdev<double> >& _eval, eoContinue<eoEsStdev<double> >& _continue, eoGenOp<eoEsStdev<double> >& _op, eoDistance<eoEsStdev<double> >* _dist)
eoAlgo<eoEsStdev<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsStdev<double> >& _eval, eoContinue<eoEsStdev<double> >& _continue, eoGenOp<eoEsStdev<double> >& _op, eoDistance<eoEsStdev<double> >* /*_dist*/)
{
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
}
eoAlgo<eoEsStdev<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsStdev<eoMinimizingFitness> >& _eval, eoContinue<eoEsStdev<eoMinimizingFitness> >& _continue, eoGenOp<eoEsStdev<eoMinimizingFitness> >& _op, eoDistance<eoEsStdev<eoMinimizingFitness> >* _dist)
eoAlgo<eoEsStdev<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsStdev<eoMinimizingFitness> >& _eval, eoContinue<eoEsStdev<eoMinimizingFitness> >& _continue, eoGenOp<eoEsStdev<eoMinimizingFitness> >& _op, eoDistance<eoEsStdev<eoMinimizingFitness> >* /*_dist*/)
{
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
}
///////////////
eoAlgo<eoEsFull<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsFull<double> >& _eval, eoContinue<eoEsFull<double> >& _continue, eoGenOp<eoEsFull<double> >& _op, eoDistance<eoEsFull<double> >* _dist)
eoAlgo<eoEsFull<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsFull<double> >& _eval, eoContinue<eoEsFull<double> >& _continue, eoGenOp<eoEsFull<double> >& _op, eoDistance<eoEsFull<double> >* /*_dist*/)
{
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
}
eoAlgo<eoEsFull<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsFull<eoMinimizingFitness> >& _eval, eoContinue<eoEsFull<eoMinimizingFitness> >& _continue, eoGenOp<eoEsFull<eoMinimizingFitness> >& _op, eoDistance<eoEsFull<eoMinimizingFitness> >* _dist)
eoAlgo<eoEsFull<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsFull<eoMinimizingFitness> >& _eval, eoContinue<eoEsFull<eoMinimizingFitness> >& _continue, eoGenOp<eoEsFull<eoMinimizingFitness> >& _op, eoDistance<eoEsFull<eoMinimizingFitness> >* /*_dist*/)
{
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
}

View file

@ -98,7 +98,7 @@ eoEsChromInit<EOT> & do_make_genotype(eoParser& _parser, eoState& _state, EOT)
is >> sigma;
// minimum check
if(sigma < 0)
throw std::runtime_error("Negative sigma in make_genotype");
throw eoException("Negative sigma in make_genotype");
if(to_scale)
init = new eoEsChromInit<EOT>(boundsParam.value(), sigma, to_scale);
else {

View file

@ -107,7 +107,7 @@ eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit<EO
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 std::runtime_error("Sorry, only unique bounds for all variables implemented at the moment. Come back later");
throw eoException("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
}
@ -125,7 +125,7 @@ eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit<EO
'o', "Genetic Operators");
if (operatorParam.value() != std::string("SGA"))
throw std::runtime_error("Sorry, only SGA-like operator available right now\n");
throw eoException("Sorry, only SGA-like operator available right now\n");
// now we read Pcross and Pmut,
// the relative weights for all crossovers -> proportional choice
@ -138,14 +138,14 @@ eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit<EO
'C', "Genetic Operators" );
// minimum check
if ( (pCrossParam.value() < 0) || (pCrossParam.value() > 1) )
throw std::runtime_error("Invalid pCross");
throw eoParamException("Invalid pCross");
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");
throw eoParamException("Invalid pMut");
// the crossovers
/////////////////
@ -156,7 +156,7 @@ eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit<EO
's', "Genetic Operators" );
// minimum check
if ( (segmentRateParam.value() < 0) )
throw std::runtime_error("Invalid segmentRate");
throw eoParamException("Invalid segmentRate");
eoValueParam<double>& arithmeticRateParam
= _parser.getORcreateParam(double(2.0), "arithmeticRate",
@ -164,7 +164,7 @@ eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit<EO
'A', "Genetic Operators" );
// minimum check
if ( (arithmeticRateParam.value() < 0) )
throw std::runtime_error("Invalid arithmeticRate");
throw eoParamException("Invalid arithmeticRate");
// minimum check
bool bCross = true;
@ -202,14 +202,14 @@ eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit<EO
'e', "Genetic Operators" );
// minimum check
if ( (epsilonParam.value() < 0) )
throw std::runtime_error("Invalid epsilon");
throw eoParamException("Invalid epsilon");
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");
throw eoParamException("Invalid uniformMutRate");
eoValueParam<double> & detMutRateParam
= _parser.getORcreateParam(1.0, "detMutRate",
@ -217,7 +217,7 @@ eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit<EO
'd', "Genetic Operators" );
// minimum check
if ( (detMutRateParam.value() < 0) )
throw std::runtime_error("Invalid detMutRate");
throw eoParamException("Invalid detMutRate");
eoValueParam<double> & normalMutRateParam
= _parser.getORcreateParam(1.0, "normalMutRate",
@ -225,7 +225,7 @@ eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit<EO
'd', "Genetic Operators" );
// minimum check
if ( (normalMutRateParam.value() < 0) )
throw std::runtime_error("Invalid normalMutRate");
throw eoParamException("Invalid normalMutRate");
// and the sigma
eoValueParam<double> & sigmaParam
= _parser.getORcreateParam(1.0, "sigma",
@ -233,7 +233,7 @@ eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit<EO
'S', "Genetic Operators" );
// minimum check
if ( (sigmaParam.value() < 0) )
throw std::runtime_error("Invalid sigma");
throw eoParamException("Invalid sigma");
// minimum check
bool bMut = true;
@ -243,7 +243,7 @@ eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit<EO
bMut = false;
}
if (!bCross && !bMut)
throw std::runtime_error("No operator called in SGA operator definition!!!");
throw eoException("No operator called in SGA operator definition!!!");
// Create the CombinedMonOp
eoPropCombinedMonOp<EOT> *ptCombinedMonOp = NULL;

View file

@ -88,7 +88,7 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
'o', "Variation Operators");
if (operatorParam.value() != std::string("SGA"))
throw std::runtime_error("Sorry, only SGA-like operator available right now\n");
throw eoException("Sorry, only SGA-like operator available right now\n");
// now we read Pcross and Pmut,
// and create the eoGenOp that is exactly
@ -99,14 +99,14 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
'C', "Variation Operators" );
// minimum check
if ( (pCrossParam.value() < 0) || (pCrossParam.value() > 1) )
throw std::runtime_error("Invalid pCross");
throw eoParamException("Invalid pCross");
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");
throw eoParamException("Invalid pMut");
// crossover
@ -140,7 +140,7 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
ptObjAtomCross = new eoDoubleIntermediate;
else if (crossObjParam.value() == std::string("none"))
ptObjAtomCross = new eoBinCloneOp<double>;
else throw std::runtime_error("Invalid Object variable crossover type");
else throw eoException("Invalid Object variable crossover type");
if (crossStdevParam.value() == std::string("discrete"))
ptStdevAtomCross = new eoDoubleExchange;
@ -148,7 +148,7 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
ptStdevAtomCross = new eoDoubleIntermediate;
else if (crossStdevParam.value() == std::string("none"))
ptStdevAtomCross = new eoBinCloneOp<double>;
else throw std::runtime_error("Invalid mutation strategy parameter crossover type");
else throw eoException("Invalid mutation strategy parameter crossover type");
// and build the indi Xover
if (crossTypeParam.value() == std::string("global"))
@ -160,7 +160,7 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
);
ptCross = new eoBinGenOp<EOT>(crossTmp);
}
else throw std::runtime_error("Invalide Object variable crossover type");
else throw eoException("Invalide Object variable crossover type");
// now that everything is OK, DON'T FORGET TO STORE MEMORY
_state.storeFunctor(ptObjAtomCross);

View file

@ -89,7 +89,7 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
'o', "Variation Operators");
if (operatorParam.value() != std::string("SGA"))
throw std::runtime_error("Sorry, only SGA-like operator available right now\n");
throw eoException("Sorry, only SGA-like operator available right now\n");
// now we read Pcross and Pmut,
// the relative weights for all crossovers -> proportional choice
@ -103,7 +103,7 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
'C', "Variation Operators" );
// minimum check
if ( (pCrossParam.value() < 0) || (pCrossParam.value() > 1) )
throw std::runtime_error("Invalid pCross");
throw eoParamException("Invalid pCross");
eoValueParam<double>& pMutParam
= _parser.getORcreateParam(0.1, "pMut",
@ -111,7 +111,7 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
'M', "Variation Operators" );
// minimum check
if ( (pMutParam.value() < 0) || (pMutParam.value() > 1) )
throw std::runtime_error("Invalid pMut");
throw eoParamException("Invalid pMut");
// the crossovers
/////////////////
@ -122,7 +122,7 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
'a', "Variation Operators" );
// minimum check
if ( (alphaParam.value() < 0) )
throw std::runtime_error("Invalid BLX coefficient alpha");
throw eoParamException("Invalid BLX coefficient alpha");
eoValueParam<double>& segmentRateParam
@ -131,7 +131,7 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
's', "Variation Operators" );
// minimum check
if ( (segmentRateParam.value() < 0) )
throw std::runtime_error("Invalid segmentRate");
throw eoParamException("Invalid segmentRate");
eoValueParam<double>& hypercubeRateParam
= _parser.getORcreateParam(double(1.0), "hypercubeRate",
@ -139,7 +139,7 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
'A', "Variation Operators" );
// minimum check
if ( (hypercubeRateParam.value() < 0) )
throw std::runtime_error("Invalid hypercubeRate");
throw eoParamException("Invalid hypercubeRate");
eoValueParam<double>& uxoverRateParam
= _parser.getORcreateParam(double(1.0), "uxoverRate",
@ -147,7 +147,7 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
'A', "Variation Operators" );
// minimum check
if ( (uxoverRateParam.value() < 0) )
throw std::runtime_error("Invalid uxoverRate");
throw eoParamException("Invalid uxoverRate");
// minimum check
bool bCross = true;
@ -191,7 +191,7 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
'e', "Variation Operators" );
// minimum check
if ( (epsilonParam.value() < 0) )
throw std::runtime_error("Invalid epsilon");
throw eoParamException("Invalid epsilon");
eoValueParam<double> & uniformMutRateParam
= _parser.getORcreateParam(1.0, "uniformMutRate",
@ -199,7 +199,7 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
'u', "Variation Operators" );
// minimum check
if ( (uniformMutRateParam.value() < 0) )
throw std::runtime_error("Invalid uniformMutRate");
throw eoParamException("Invalid uniformMutRate");
eoValueParam<double> & detMutRateParam
= _parser.getORcreateParam(1.0, "detMutRate",
@ -207,14 +207,14 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
'd', "Variation Operators" );
// minimum check
if ( (detMutRateParam.value() < 0) )
throw std::runtime_error("Invalid detMutRate");
throw eoParamException("Invalid detMutRate");
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");
throw eoParamException("Invalid normalMutRate");
eoValueParam<double> & sigmaParam
= _parser.getORcreateParam(0.3, "sigma",
@ -234,7 +234,7 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
bMut = false;
}
if (!bCross && !bMut)
throw std::runtime_error("No operator called in SGA operator definition!!!");
throw eoException("No operator called in SGA operator definition!!!");
// Create the CombinedMonOp
eoPropCombinedMonOp<EOT> *ptCombinedMonOp = NULL;