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

@ -59,7 +59,7 @@ edoFileSnapshot::edoFileSnapshot(std::string dirname,
if ( (res == -1) || (res == 127) )
{
throw std::runtime_error("Problem executing test of dir in eoFileSnapshot");
throw eoSystemError(s, res);
}
// now make sure there is a dir without any genXXX file in it
@ -112,8 +112,8 @@ eoMonitor& edoFileSnapshot::operator()(void)
if (!os)
{
std::string str = "edoFileSnapshot: Could not open " + _currentFileName;
throw std::runtime_error(str);
// std::string str = "edoFileSnapshot: Could not open " + _currentFileName;
throw eoFileError(_currentFileName);
}
if ( _saveFilenames )

View file

@ -30,6 +30,7 @@
#include <stdexcept> // std::runtime_error
#include "eoObject.h" // eoObject
#include "eoPersistent.h" // eoPersistent
#include "eoExceptions.h"
/**
@defgroup Core Core components
@ -73,13 +74,14 @@ public:
/// Return fitness value.
const Fitness& fitness() const {
if (invalid())
throw std::runtime_error("invalid fitness");
throw eoInvalidFitnessError("Cannot retrieve unevaluated fitness");
return repFitness;
}
/// Get fitness as reference, useful when fitness is set in a multi-stage way, e.g., MOFitness gets performance information, is subsequently ranked
Fitness& fitnessReference() {
if (invalid()) throw std::runtime_error("invalid fitness");
if (invalid())
throw eoInvalidFitnessError("Cannot retrieve unevaluated fitness reference");
return repFitness;
}
@ -120,7 +122,7 @@ public:
* The read and print methods should be compatible and have the same format.
* In principle, format is "plain": they just print a number
* @param _is a std::istream.
* @throw runtime_std::exception If a valid object can't be read.
* @throw eoInvalidFitnessError If a valid object can't be read.
*/
virtual void readFrom(std::istream& _is) {

View file

@ -60,7 +60,7 @@ public:
Fitness fitness () const
{
if (invalid ())
throw std::runtime_error ("invalid fitness in PO.h");
throw eoInvalidFitnessError("invalid fitness in PO.h");
return repFitness;
}
@ -80,7 +80,7 @@ public:
Fitness best () const
{
if (invalid ())
throw std::runtime_error ("invalid best fitness in PO.h");
throw eoInvalidFitnessError("invalid best fitness in PO.h");
return bestFitness;
}

View file

@ -183,7 +183,7 @@ eoAlgo<EOT> & do_make_algo_scalar(eoParser& _parser, eoState& _state, eoPopEvalF
else
{
std::string stmp = std::string("Invalid selection: ") + ppSelect.first;
throw std::runtime_error(stmp.c_str());
throw eoException(stmp.c_str());
}
_state.storeFunctor(select);
@ -260,7 +260,7 @@ eoAlgo<EOT> & do_make_algo_scalar(eoParser& _parser, eoState& _state, eoPopEvalF
}
else
{
throw std::runtime_error("Sorry, only deterministic tournament available at the moment");
throw eoException("Sorry, only deterministic tournament available at the moment");
}
}
ptReplace = new eoMGGReplacement<EOT>(-surviveParents, tSize);
@ -341,7 +341,7 @@ eoAlgo<EOT> & do_make_algo_scalar(eoParser& _parser, eoState& _state, eoPopEvalF
}
else // no replacement recognized
{
throw std::runtime_error("Invalid replacement type " + replacementParam.first);
throw eoException("Invalid replacement type " + replacementParam.first);
}
ptReplace = & make_general_replacement<EOT>(

View file

@ -120,7 +120,7 @@ eoAlgo<EOT> & do_make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc
else // parameter passed by user as DetTour(T)
nicheSize = atof(ppSelect.second[0].c_str());
if (_dist == NULL) // no distance
throw std::runtime_error("You didn't specify a distance when calling make_algo_scalar and using sharing");
throw eoException("You didn't specify a distance when calling make_algo_scalar and using sharing");
select = new eoSharingSelect<EOT>(nicheSize, *_dist);
}
else if (ppSelect.first == std::string("StochTour"))
@ -206,7 +206,7 @@ eoAlgo<EOT> & do_make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc
else
{
std::string stmp = std::string("Invalid selection: ") + ppSelect.first;
throw std::runtime_error(stmp.c_str());
throw eoException(stmp.c_str());
}
_state.storeFunctor(select);
@ -282,7 +282,7 @@ eoAlgo<EOT> & do_make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc
else
{
std::string stmp = std::string("Invalid replacement: ") + ppReplace.first;
throw std::runtime_error(stmp.c_str());
throw eoException(stmp.c_str());
}
_state.storeFunctor(replace);

View file

@ -156,7 +156,7 @@ eoContinue<Indi> & do_make_continue(eoParser& _parser, eoState& _state, eoEvalFu
// now check that there is at least one!
if (!continuator)
throw std::runtime_error("You MUST provide a stopping criterion");
throw eoException("You MUST provide a stopping criterion");
// OK, it's there: store in the eoState
_state.storeFunctor(continuator);

View file

@ -97,7 +97,7 @@ eoReduce<EOT> & decode_reduce(eoParamParamType & _ppReduce, eoState & _state)
{
p = atof(_ppReduce.second[0].c_str());
if ( (p<=0.5) || (p>1) )
throw std::runtime_error("Stochastic tournament size should be in [0.5,1]");
throw eoException("Stochastic tournament size should be in [0.5,1]");
}
ptReduce = new eoStochTournamentTruncate<EOT>(p);
@ -110,7 +110,7 @@ eoReduce<EOT> & decode_reduce(eoParamParamType & _ppReduce, eoState & _state)
}
else // no known reduction entered
{
throw std::runtime_error("Unknown reducer: " + _ppReduce.first);
throw eoException("Unknown reducer: " + _ppReduce.first);
}
// all done, stores and return a reference
_state.storeFunctor(ptReduce);

View file

@ -56,7 +56,7 @@ public:
{
// First checks that no other eoCtrlCContinue does exist
if (existCtrlCContinue)
throw std::runtime_error("A signal handler for Ctrl C is already defined!\n");
throw eoParamException("A signal handler for Ctrl C is already defined!\n");
#ifndef _WINDOWS
#ifdef SIGQUIT

View file

@ -261,8 +261,8 @@ template<class EOT> class eoEasyEA: public eoAlgo<EOT>
do
{
try
{
// try
// {
unsigned pSize = _pop.size();
offspring.clear(); // new offspring
@ -273,17 +273,17 @@ template<class EOT> class eoEasyEA: public eoAlgo<EOT>
replace(_pop, offspring); // after replace, the new pop. is in _pop
if (pSize > _pop.size())
throw std::runtime_error("Population shrinking!");
throw eoException("Population shrinking!");
else if (pSize < _pop.size())
throw std::runtime_error("Population growing!");
throw eoException("Population growing!");
}
catch (std::exception& e)
{
std::string s = e.what();
s.append( " in eoEasyEA");
throw std::runtime_error( s );
}
// }
// catch (std::exception& e)
// {
// std::string s = e.what();
// s.append( " in eoEasyEA");
// throw std::runtime_error( s );
// }
}
while ( continuator( _pop ) );
}

View file

@ -129,8 +129,8 @@ public:
/// Apply a few iteration of flight to the population (=swarm).
virtual void operator () (eoPop < POT > &_pop)
{
try
{
// try
// {
// initializes the topology, velocity, best particle(s)
init();
do
@ -154,13 +154,13 @@ public:
}
while (continuator (_pop));
}
catch (std::exception & e)
{
std::string s = e.what ();
s.append (" in eoEasyPSO");
throw std::runtime_error (s);
}
// }
// catch (std::exception & e)
// {
// std::string s = e.what ();
// s.append (" in eoEasyPSO");
// throw std::runtime_error (s);
// }
}

View file

@ -105,8 +105,8 @@ protected:
}
#ifndef NDEBUG
if ( !_of.is_open() ) {
std::string str = "Error, eoEvalDump could not open: " + _filename;
throw std::runtime_error( str );
// std::string str = "Error, eoEvalDump could not open: " + _filename;
throw eoFileError( _filename );
}
#endif
// here, in release mode, we assume that the file could be opened

View file

@ -54,6 +54,69 @@ protected:
const std::string _msg;
};
class eoInvalidFitnessError : public eoException
{
public:
eoInvalidFitnessError(std::string msg = "Invalid fitness") : eoException(msg) {}
~eoInvalidFitnessError() throw() {}
};
class eoPopSizeException : public eoException
{
public:
eoPopSizeException(size_t size, std::string msg = "") :
eoException(),
_size(size),
_msg(msg)
{}
virtual std::string message() const throw()
{
std::ostringstream oss;
oss << "Bad population size: " << _size;
if(_msg != "") {
oss << ", " << _msg;
}
return oss.str();
}
~eoPopSizeException() throw() {}
protected:
const size_t _size;
const std::string _msg;
};
class eoPopSizeChangeException : public eoPopSizeException
{
public:
eoPopSizeChangeException(size_t size_from, size_t size_to, std::string msg="") :
eoPopSizeException(0),
_size_from(size_from),
_size_to(size_to),
_msg(msg)
{}
virtual std::string message() const throw()
{
std::ostringstream oss;
oss << "Population size changed from " << _size_from << " to " << _size_to;
if(_msg != "") {
oss << ", " << _msg;
}
return oss.str();
}
~eoPopSizeChangeException() throw() {}
protected:
const size_t _size_from;
const size_t _size_to;
const std::string _msg;
};
/** Base class for exceptions which need to stop the algorithm to be handled
*
* (like stopping criterion or numerical errors).
@ -110,7 +173,7 @@ public:
virtual std::string message() const throw()
{
std::ostringstream msg;
msg << "STOP because the maximum number of allowed seconds has been reached ("
msg << "The maximum number of allowed seconds has been reached ("
<< _elapsed << ")";
return msg.str();
}
@ -140,7 +203,7 @@ public:
virtual std::string message() const throw()
{
std::ostringstream msg;
msg << " the maximum number of evaluation has been reached ("
msg << "The maximum number of evaluation has been reached ("
<< _threshold << ").";
return msg.str();
}
@ -226,7 +289,7 @@ public:
_cmd(cmd), _has_pipe(false), _err_code(-1), _output("")
{ }
eoSystemError(std::string cmd, int err_code, std::string output) :
eoSystemError(std::string cmd, int err_code, std::string output = "") :
eoException(),
_cmd(cmd), _has_pipe(true), _err_code(err_code), _output(output)
{ }
@ -234,10 +297,12 @@ public:
virtual std::string message() const throw()
{
std::ostringstream ss;
ss << "System call: `" << _cmd << "` error";
ss << "System call: `" << _cmd << "` ended with error";
if(_has_pipe) {
ss << " code #" << _err_code
<< " with the following output:" << std::endl << _output;
ss << " code #" << _err_code;
if(_output != "") {
ss << " with the following output:" << std::endl << _output;
}
}
return ss.str();
}
@ -251,4 +316,24 @@ protected:
const std::string _output;
};
class eoFileError : public eoSystemError
{
public:
eoFileError(std::string filename) :
eoSystemError(""),
_filename(filename)
{ }
virtual std::string message() const throw()
{
std::ostringstream oss;
oss << "Could not open file: " << _filename;
return oss.str();
}
protected:
std::string _filename;
};
#endif // __eoExceptions_h__

View file

@ -66,7 +66,7 @@ public :
if (_eo1.size() != _eo2.size())
{
string s = "Operand size don't match in " + className();
throw runtime_error(s);
throw eoException(s);
}
bool changed = false;
for ( unsigned i = 0; i < _eo1.size(); i++ ) {
@ -109,7 +109,7 @@ public :
if (_eo1.size() != _eo2.size())
{
string s = "Operand size don't match in " + className();
throw runtime_error(s);
throw eoException(s);
}
bool changed = false;
@ -155,7 +155,7 @@ public :
if (_eo1.size() != _eo2.size())
{
string s = "Operand size don't match in " + className();
throw runtime_error(s);
throw eoException(s);
}
bool hasChanged = false;
for (unsigned i=0; i<_eo1.size(); i++)
@ -199,7 +199,7 @@ public :
if (_eo1.size() != _eo2.size())
{
string s = "Operand size don't match in " + className();
throw runtime_error(s);
throw eoException(s);
}
bool hasChanged = false;
unsigned where = eo::rng.random(_eo1.size()-1);

View file

@ -101,7 +101,7 @@ public :
if (_eo1.size() != _eo2.size())
{
string s = "Operand size don't match in " + className();
throw runtime_error(s);
throw eoException(s);
}
bool changed = false;
@ -146,7 +146,7 @@ public :
if (_eo1.size() != _eo2.size())
{
string s = "Operand size don't match in " + className();
throw runtime_error(s);
throw eoException(s);
}
bool hasChanged = false;
for (unsigned i=0; i<_eo1.size(); i++)
@ -191,7 +191,7 @@ public :
if (_eo1.size() != _eo2.size())
{
string s = "Operand size don't match in " + className();
throw runtime_error(s);
throw eoException(s);
}
bool hasChanged = false;
unsigned where = eo::rng.random(_eo1.size()-1);

View file

@ -71,7 +71,7 @@ public:
if (_offspring.size() != toKeep)
{
std::cerr << "Les tailles " << _offspring.size() << " " << toKeep << std::endl;
throw std::runtime_error("eoG3Replacement: wrong number of remaining offspring");
throw eoException("eoG3Replacement: wrong number of remaining offspring");
}
// and put back into _parents
plus(_offspring, _parents);

View file

@ -33,6 +33,7 @@
#include "eoSTLFunctor.h"
#include "utils/eoRndGenerators.h"
#include "utils/rnd_generators.h" // for shuffle method
#include "eoExceptions.h"
/**
@ -134,7 +135,7 @@ typedef typename EOT::AtomType AtomType;
: offset(_minSize), extent(_maxSize - _minSize), init(_init)
{
if (_minSize >= _maxSize)
throw std::logic_error("eoInitVariableLength: minSize larger or equal to maxSize");
throw eoException("eoInitVariableLength: minSize larger or equal to maxSize");
}

View file

@ -67,7 +67,7 @@ public:
if (neighborhoodSize >= _pop.size()){
std::string s;
s.append (" Invalid neighborhood size in eoLinearTopology ");
throw std::runtime_error (s);
throw eoException(s);
}
unsigned howManyNeighborhood=_pop.size()/ neighborhoodSize;

View file

@ -71,7 +71,7 @@ public:
unsigned toKeep = temp.size(); // how many to keep from merged populations
// minimal check
if (toKeep < 2)
throw std::runtime_error("Not enough parents killed in eoMGGReplacement");
throw eoException("Not enough parents killed in eoMGGReplacement");
// select best offspring
typename eoPop<EOT>::iterator it = _offspring.it_best_element();

View file

@ -67,13 +67,13 @@ public :
if (_interpret_as_rate)
{
if ( (_rate<0) || (_rate>1) )
throw std::logic_error("eoElitism: rate shoud be in [0,1]");
throw eoParamException("eoElitism: rate shoud be in [0,1]");
rate = _rate;
}
else
{
if (_rate<0)
throw std::logic_error("Negative number of offspring in eoElitism!");
throw eoParamException("Negative number of offspring in eoElitism!");
combien = (unsigned int)_rate;
if (combien != _rate)
eo::log << eo::warnings << "Warning: Number of guys to merge in eoElitism was rounded" << std::endl;
@ -91,7 +91,7 @@ public :
combienLocal = combien;
if (combienLocal > _pop.size())
throw std::logic_error("Elite larger than population");
throw eoException("Elite larger than population");
std::vector<const EOT*> result;
_pop.nth_element(combienLocal, result);

View file

@ -222,7 +222,7 @@ private :
// Check whether the derived class was nice
if (niche_count.size() != fronts[i].size())
{
throw std::logic_error("eoNDSorting: niche and front should have the same size");
throw eoException("eoNDSorting: niche and front should have the same size");
}
double max_niche = *std::max_element(niche_count.begin(), niche_count.end());
@ -322,7 +322,7 @@ private :
// Check whether the derived class was nice
if (niche_count.size() != current_front.size())
{
throw std::logic_error("eoNDSorting: niche and front should have the same size");
throw eoException("eoNDSorting: niche and front should have the same size");
}
double max_niche = *std::max_element(niche_count.begin(), niche_count.end());

View file

@ -95,7 +95,7 @@ class eoOneToOneBreeder: public eoBreed<EOT>
// check: only one offspring?
unsigned posEnd = popit.tellp();
if (posEnd != pos)
throw std::runtime_error("Operator can only generate a SINGLE offspring in eoOneToOneBreeder");
throw eoException("Operator can only generate a SINGLE offspring in eoOneToOneBreeder");
// do the tournament between parent and offspring
eval(leOffspring); // first need to evaluate the offspring

View file

@ -45,6 +45,7 @@ Authors:
#include "eoPersistent.h"
#include "eoInit.h"
#include "utils/rnd_generators.h" // for shuffle method
#include "eoExceptions.h"
/** A std::vector of EO object, to be used in all algorithms
* (selectors, operators, replacements, ...).
@ -108,7 +109,7 @@ class eoPop: public std::vector<EOT>, public eoObject, public eoPersistent
unsigned oldSize = size();
if (_newPopSize < oldSize)
{
throw std::runtime_error("New size smaller than old size in pop.append");
throw eoPopSizeChangeException(oldSize, _newPopSize);
return;
}
if (_newPopSize == oldSize)
@ -222,7 +223,7 @@ class eoPop: public std::vector<EOT>, public eoObject, public eoPersistent
typename eoPop<EOT>::const_iterator it = std::max_element(begin(), end());
#endif
if( it == end() )
throw std::runtime_error("eoPop<EOT>: Empty population, when calling best_element().");
throw eoPopSizeException(this->size());
return (*it);
}

View file

@ -49,7 +49,7 @@ public:
eoProportionalSelect(const eoPop<EOT>& /*pop*/ = eoPop<EOT>())
{
if (minimizing_fitness<EOT>())
throw std::logic_error("eoProportionalSelect: minimizing fitness");
throw eoException("eoProportionalSelect: minimizing fitness");
}
void setup(const eoPop<EOT>& _pop)

View file

@ -56,7 +56,7 @@ public:
{
std::string s;
s.append (" min > max in eoRandomRealWeightUp");
throw std::runtime_error (s);
throw eoException(s);
}
}

View file

@ -59,7 +59,7 @@ public:
if (_eo == &(*it))
return it-_pop.begin();
}
throw std::runtime_error("Not found in eoLinearRanking");
throw eoException("Not found in eoLinearRanking");
}
/* COmputes the ranked fitness: fitnesses range in [m,M]
@ -74,7 +74,7 @@ public:
unsigned int pSizeMinusOne = pSize-1;
if (pSize <= 1)
throw std::runtime_error("Cannot do ranking with population of size <= 1");
throw eoPopSizeException(pSize,"cannot do ranking with population of size <= 1");
// value() refers to the std::vector of worthes (we're in an eoParamvalue)
value().resize(pSize);

View file

@ -57,7 +57,7 @@ template <class EOT> class eoTruncate : public eoReduce<EOT>
if (_newgen.size() == _newsize)
return;
if (_newgen.size() < _newsize)
throw std::logic_error("eoTruncate: Cannot truncate to a larger size!\n");
throw eoException("eoTruncate: Cannot truncate to a larger size!\n");
_newgen.sort();
_newgen.resize(_newsize);
@ -74,7 +74,7 @@ template <class EOT> class eoRandomReduce : public eoReduce<EOT>
if (_newgen.size() == _newsize)
return;
if (_newgen.size() < _newsize)
throw std::logic_error("eoRandomReduce: Cannot truncate to a larger size!\n");
throw eoException("eoRandomReduce: Cannot truncate to a larger size!\n");
// shuffle the population, then trucate
_newgen.shuffle();
@ -123,7 +123,7 @@ public:
if (presentSize == _newsize)
return;
if (presentSize < _newsize)
throw std::logic_error("eoTruncate: Cannot truncate to a larger size!\n");
throw eoException("eoTruncate: Cannot truncate to a larger size!\n");
std::vector<EPpair> scores(presentSize);
for (unsigned i=0; i<presentSize; i++)
{
@ -186,7 +186,7 @@ class eoLinearTruncate : public eoReduce<EOT>
if (oldSize == _newsize)
return;
if (oldSize < _newsize)
throw std::logic_error("eoLinearTruncate: Cannot truncate to a larger size!\n");
throw eoException("eoLinearTruncate: Cannot truncate to a larger size!\n");
for (unsigned i=0; i<oldSize - _newsize; i++)
{
typename eoPop<EOT>::iterator it = _newgen.it_worse_element();
@ -224,7 +224,7 @@ public:
if (oldSize == _newsize)
return;
if (oldSize < _newsize)
throw std::logic_error("eoDetTournamentTruncate: Cannot truncate to a larger size!\n");
throw eoException("eoDetTournamentTruncate: Cannot truncate to a larger size!\n");
// Now OK to erase some losers
@ -280,7 +280,7 @@ public:
if (oldSize == _newsize)
return;
if (oldSize < _newsize)
throw std::logic_error("eoStochTournamentTruncate: Cannot truncate to a larger size!\n");
throw eoException("eoStochTournamentTruncate: Cannot truncate to a larger size!\n");
// Now OK to erase some losers
for (unsigned i=0; i<oldSize - _newsize; i++)
{

View file

@ -64,7 +64,7 @@ class eoReduceMerge : public eoReplacement<EOT>
void operator()(eoPop<EOT>& _parents, eoPop<EOT>& _offspring)
{
if (_parents.size() < _offspring.size())
throw std::logic_error("eoReduceMerge: More offspring than parents!\n");
throw eoPopSizeChangeException(_parents.size(), _offspring.size(),"more offspring than parents!");
reduce(_parents, _parents.size() - _offspring.size());
merge(_offspring, _parents);
}

View file

@ -90,7 +90,7 @@ public:
// then the offspring
unsigned reducedOffspringSize = howManyReducedOffspring(offSize);
if (!reducedOffspringSize)
throw std::runtime_error("No offspring left after reduction!");
throw eoPopSizeException(reducedOffspringSize,"no offspring left after reduction!");
if (reducedOffspringSize != offSize) // need reduction
reduceOffspring(_offspring, reducedOffspringSize);

View file

@ -66,7 +66,7 @@ public:
return ;
unsigned newsize = popSize - eliminated;
if (newsize < 0)
throw std::logic_error("eoTruncateSplit: Cannot truncate to a larger size!\n");
throw eoException("eoTruncateSplit: Cannot truncate to a larger size!\n");
_newgen.nth_element(newsize);
@ -106,7 +106,7 @@ public:
return ;
long newsize = static_cast<long>(popSize) - static_cast<long>(eliminated);
if (newsize < 0)
throw std::logic_error("eoLinearTruncateSplit: Cannot truncate to a larger size!\n");
throw eoException("eoLinearTruncateSplit: Cannot truncate to a larger size!\n");
_eliminated.reserve(_eliminated.size()+eliminated); //in case not empty?
for (unsigned i=0; i<eliminated; i++)
@ -143,7 +143,7 @@ public:
return ;
unsigned newsize = popSize - eliminated;
if (newsize < 0)
throw std::logic_error("eoRandomSplit: Cannot truncate to a larger size!\n");
throw eoException("eoRandomSplit: Cannot truncate to a larger size!\n");
_newgen.shuffle();
@ -182,7 +182,7 @@ public:
return ;
unsigned newsize = popSize - eliminated;
if (newsize < 0)
throw std::logic_error("eoLinearRandomSplit: Cannot truncate to a larger size!\n");
throw eoException("eoLinearRandomSplit: Cannot truncate to a larger size!\n");
_eliminated.reserve(_eliminated.size()+eliminated); //in case not empty?
for (unsigned i=0; i<eliminated; i++)
@ -234,7 +234,7 @@ public:
return ;
unsigned newsize = popSize - eliminated;
if (newsize < 0)
throw std::logic_error("eoDetTournamentTruncateSplit: Cannot truncate to a larger size!\n");
throw eoException("eoDetTournamentTruncateSplit: Cannot truncate to a larger size!\n");
_eliminated.reserve(_eliminated.size()+eliminated); //in case not empty?
@ -291,7 +291,7 @@ public:
unsigned newSize = oldSize - _eliminated.size();
unsigned eliminated = howMany(popSize);
if (newSize < 0)
throw std::logic_error("eoStochTournamentTruncateSplit: Cannot truncate to a larger size!\n");
throw eoException("eoStochTournamentTruncateSplit: Cannot truncate to a larger size!\n");
end of old version */
@ -301,7 +301,7 @@ end of old version */
return ;
unsigned newsize = popSize - eliminated;
if (newsize < 0)
throw std::logic_error("eoDetTournamentTruncateSplit: Cannot truncate to a larger size!\n");
throw eoException("eoDetTournamentTruncateSplit: Cannot truncate to a larger size!\n");

View file

@ -57,7 +57,7 @@ public:
{
// First checks that no other eoSIGContinue does exist
if (existSIGContinue)
throw std::runtime_error("A signal handler is already defined!\n");
throw eoParamException("A signal handler is already defined!\n");
#ifndef _WINDOWS
#ifdef SIGQUIT

View file

@ -73,7 +73,7 @@ public:
if ( objectTypeStr == "eoRandomSelect" ) {
selectPtr = new eoRandomSelect<EOT>( rate );
} else {
throw std::runtime_error( "Incorrect selector type" );
throw eoException( "Incorrect selector type" );
}
}
return selectPtr;

View file

@ -79,7 +79,7 @@ protected:
std::vector<typename EOT::Fitness> fitness;
void check_sync(unsigned index, const EOT& _eo) {
if (fitness[index] != _eo.fitness()) {
throw std::runtime_error("eoSelectFromWorth: fitnesses are not in sync");
throw eoException("eoSelectFromWorth: fitnesses are not in sync");
}
}
#endif

View file

@ -134,7 +134,7 @@ template <class EOT> class eoEliteSequentialSelect: public eoSelectOne<EOT>
unsigned int ibest = 0;
const EOT * best = eoPters[0];
if (_pop.size() == 1)
throw std::runtime_error("Trying eoEliteSequentialSelect with only one individual!");
throw eoException("Trying eoEliteSequentialSelect with only one individual!");
for (unsigned i=1; i<_pop.size(); i++)
if (*eoPters[i]>*best)
{

View file

@ -26,6 +26,7 @@
#ifndef eoSharing_h
#define eoSharing_h
#include "eoExceptions.h"
#include "eoPerf2Worth.h"
#include "utils/eoDistance.h"
@ -100,7 +101,7 @@ public:
unsigned i, j,
pSize=_pop.size();
if (pSize <= 1)
throw std::runtime_error("Apptempt to do sharing with population of size 1");
throw eoPopSizeException(pSize, "attempt to do sharing with population of size 1");
value().resize(pSize);
std::vector<double> sim(pSize); // to hold the similarities
dMatrix distMatrix(pSize); // to hold the distances

View file

@ -73,21 +73,21 @@ template<class EOT> class eoSimpleEDA: public eoEDA<EOT>
eoPop<EOT> pop(popSize, _distrib);
do
{
try
{
// try
// {
apply<EOT>(_distrib, pop); // re-init. of _pop from distrib
apply<EOT>(eval, pop); // eval of current population
update(_distrib, pop); // updates distrib from _pop
}
catch (std::exception& e)
{
std::string s = e.what();
s.append( " in eoSimpleEDA");
throw std::runtime_error( s );
}
// }
// catch (std::exception& e)
// {
// std::string s = e.what();
// s.append( " in eoSimpleEDA");
// throw std::runtime_error( s );
// }
} while ( continuator( pop ) );
}

View file

@ -94,7 +94,7 @@ public:
else{
std::string s;
s.append (" Invalid indice in eoSocialNeighborhood ");
throw std::runtime_error (s);
throw eoException(s);
}
}

View file

@ -47,7 +47,7 @@ public:
eoStochasticUniversalSelect(const eoPop<EOT>& pop = eoPop<EOT>())
{
if (minimizing_fitness<EOT>())
throw std::logic_error("eoStochasticUniversalSelect: minimizing fitness");
throw eoException("eoStochasticUniversalSelect: minimizing fitness");
}
void setup(const eoPop<EOT>& _pop)

View file

@ -107,7 +107,7 @@ public:
// carefull, we can have a rate of 1 if we want to kill all remaining
unsigned nbDie = std::min(howmanyDie(pSize), pSize-nbSurvive);
if (nbDie > nbRemaining)
throw std::logic_error("eoDeterministicSurviveAndDie: Too many to kill!\n");
throw eoException("eoDeterministicSurviveAndDie: Too many to kill!\n");
if (!nbDie)
{
@ -169,7 +169,7 @@ public:
unsigned survivorSize = luckyOffspring.size() + luckyParents.size();
if (survivorSize > pSize)
throw std::logic_error("eoGeneralReplacement: More survivors than parents!\n");
throw eoPopSizeChangeException(survivorSize, pSize, "more survivors than parents!");
plus(_parents, _offspring); // all that remain in _offspring

View file

@ -46,7 +46,7 @@ template<class Chrom> class eoSwapMutation: public eoMonOp<Chrom>
{
// consistency check
if(howManySwaps < 1)
throw std::runtime_error("Invalid number of swaps in eoSwapMutation");
throw eoException("Invalid number of swaps in eoSwapMutation");
}
/// The class name.

View file

@ -181,8 +181,8 @@ public:
virtual void operator () (eoPop < POT > &_pop)
{
try
{
// try
// {
// initializes the topology, velocity, best particle(s)
init();
@ -206,13 +206,13 @@ public:
}
while (continuator (_pop));
}
catch (std::exception & e)
{
std::string s = e.what ();
s.append (" in eoSyncEasyPSO");
throw std::runtime_error (s);
}
// }
// catch (std::exception & e)
// {
// std::string s = e.what ();
// s.append (" in eoSyncEasyPSO");
// throw std::runtime_error (s);
// }
}

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;

View file

@ -69,7 +69,7 @@ eoDistribUpdater<EOT> & do_make_PBILupdate(eoParser & _parser, eoState& _state,
ptUpdate = new eoPBILAdditive<EOT>(LRBest, nbBest, tolerance, LRWorst, nbWorst);
}
else
throw std::runtime_error("Only PBIL additive update rule available at the moment");
throw eoException("Only PBIL additive update rule available at the moment");
// done: don't forget to store the allocated pointers
_state.storeFunctor(ptUpdate);

View file

@ -78,7 +78,7 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoInit<EOT>& _init
eoValueParam<std::string>& operatorParam = _parser.createParam(std::string("SGA"), "operator", "Description of the operator (SGA only now)", 'o', "Variation Operators");
if (operatorParam.value() != std::string("SGA"))
throw std::runtime_error("Only SGA-like operator available right now\n");
throw eoException("Only SGA-like operator available right now\n");
// now we read Pcross and Pmut,
// the relative weights for all crossovers -> proportional choice
@ -89,12 +89,12 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoInit<EOT>& _init
eoValueParam<double>& pCrossParam = _parser.createParam(0.6, "pCross", "Probability of Crossover", '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.createParam(0.1, "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");
// the crossovers
/////////////////
@ -102,17 +102,17 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoInit<EOT>& _init
eoValueParam<double>& onePointRateParam = _parser.createParam(double(1.0), "onePointRate", "Relative rate for one point crossover", '1', "Variation Operators" );
// minimum check
if ( (onePointRateParam.value() < 0) )
throw std::runtime_error("Invalid onePointRate");
throw eoParamException("Invalid onePointRate");
eoValueParam<double>& twoPointsRateParam = _parser.createParam(double(1.0), "twoPointRate", "Relative rate for two point crossover", '2', "Variation Operators" );
// minimum check
if ( (twoPointsRateParam.value() < 0) )
throw std::runtime_error("Invalid twoPointsRate");
throw eoParamException("Invalid twoPointsRate");
eoValueParam<double>& uRateParam = _parser.createParam(double(2.0), "uRate", "Relative rate for uniform crossover", 'U', "Variation Operators" );
// minimum check
if ( (uRateParam.value() < 0) )
throw std::runtime_error("Invalid uRate");
throw eoParamException("Invalid uRate");
// minimum check
// bool bCross = true; // not used ?
@ -149,29 +149,29 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoInit<EOT>& _init
eoValueParam<double> & pMutPerBitParam = _parser.createParam(0.01, "pMutPerBit", "Probability of flipping 1 bit in bit-flip mutation", 'b', "Variation Operators" );
// minimum check
if ( (pMutPerBitParam.value() < 0) || (pMutPerBitParam.value() > 0.5) )
throw std::runtime_error("Invalid pMutPerBit");
throw eoParamException("Invalid pMutPerBit");
eoValueParam<double> & bitFlipRateParam = _parser.createParam(0.01, "bitFlipRate", "Relative rate for bit-flip mutation", 's', "Variation Operators" );
// minimum check
if ( (bitFlipRateParam.value() < 0) )
throw std::runtime_error("Invalid bitFlipRate");
throw eoParamException("Invalid bitFlipRate");
// oneBitFlip
eoValueParam<double> & oneBitRateParam = _parser.createParam(0.01, "oneBitRate", "Relative rate for deterministic bit-flip mutation", 'd', "Variation Operators" );
// minimum check
if ( (oneBitRateParam.value() < 0) )
throw std::runtime_error("Invalid oneBitRate");
throw eoParamException("Invalid oneBitRate");
// kBitFlip
eoValueParam<unsigned> & kBitParam = _parser.createParam((unsigned)1, "kBit", "Number of bit for deterministic k bit-flip mutation", 0, "Variation Operators" );
// minimum check
if ( ! kBitParam.value() )
throw std::runtime_error("Invalid kBit");
throw eoParamException("Invalid kBit");
eoValueParam<double> & kBitRateParam = _parser.createParam(0.0, "kBitRate", "Relative rate for deterministic k bit-flip mutation", 0, "Variation Operators" );
// minimum check
if ( (kBitRateParam.value() < 0) )
throw std::runtime_error("Invalid kBitRate");
throw eoParamException("Invalid kBitRate");
// minimum check
// bool bMut = true; // not used ?

View file

@ -81,7 +81,7 @@ class eoParseTreeDepthInit : public eoInit< eoParseTree<FType, Node> >
{
if(initializor.empty())
{
throw std::logic_error("eoParseTreeDepthInit: uhm, wouldn't you rather give a non-empty set of Nodes?");
throw eoException("eoParseTreeDepthInit: uhm, wouldn't you rather give a non-empty set of Nodes?");
}
// lets sort the initializor std::vector according to arity (so we can be sure the terminals are in front)
// we use stable_sort so that if element i was in front of element j and they have the same arity i remains in front of j

View file

@ -87,7 +87,7 @@ class eoStParseTreeDepthInit : public eoInit< eoParseTree<FType, Node> >
{
if(_node.empty())
{
throw std::logic_error("eoStParseTreeDepthInit: uhm, wouldn't you rather give a non-empty set of Nodes?");
throw eoException("eoStParseTreeDepthInit: uhm, wouldn't you rather give a non-empty set of Nodes?");
}

View file

@ -102,7 +102,7 @@ namespace eo
{
if ( _packetSize <= 0 )
{
throw std::runtime_error("Packet size should not be negative.");
throw eoException("Packet size should not be negative.");
}
if( table )

View file

@ -115,13 +115,13 @@ PyEO& pop_getitem(eoPop<PyEO>& pop, boost::python::object key)
{
boost::python::extract<int> x(key);
if (!x.check())
throw index_error("Slicing not allowed");
throw eoException("Slicing not allowed");
int i = x();
if (static_cast<unsigned>(i) >= pop.size())
{
throw index_error("Index out of bounds");
throw eoException("Index out of bounds");
}
return pop[i];
}
@ -130,13 +130,13 @@ void pop_setitem(eoPop<PyEO>& pop, boost::python::object key, PyEO& value)
{
boost::python::extract<int> x(key);
if (!x.check())
throw index_error("Slicing not allowed");
throw eoException("Slicing not allowed");
int i = x();
if (static_cast<unsigned>(i) >= pop.size())
{
throw index_error("Index out of bounds");
throw eoException("Index out of bounds");
}
pop[i] = value;

View file

@ -55,7 +55,7 @@ public :
{
if (which >= objective_info.size())
{
throw index_error("Too few elements allocated, resize objectives first");
throw eoException("Too few elements allocated, resize objectives first");
}
objective_info[which] = value;
@ -70,7 +70,7 @@ public :
boost::python::extract<double> x(object::operator[](i));
if (!x.check())
throw std::runtime_error("PyFitness: does not contain doubles");
throw eoException("PyFitness: does not contain doubles");
return x();
}

View file

@ -42,7 +42,7 @@ public:
{
if (static_cast<unsigned>(i) >= vec.size())
{
throw index_error("Index out of bounds");
throw eoException("Index out of bounds");
}
return vec[i]->getValue();

View file

@ -35,7 +35,7 @@ const PyEO& popview_getitem(const std::vector<const PyEO*>& pop, int it)
{
unsigned item = unsigned(it);
if (item > pop.size())
throw index_error("too much");
throw eoException("too much");
return *pop[item];
}

View file

@ -109,7 +109,7 @@ void setv< std::vector<double>, numeric::array >
{
extract<double> x(val[i]);
if (!x.check())
throw std::runtime_error("double expected");
throw eoException("double expected");
v[i] = x();
}
@ -130,9 +130,9 @@ void setv< std::pair<double, double>, tuple >
extract<double> second(val[1]);
if (!first.check())
throw std::runtime_error("doubles expected");
throw eoException("doubles expected");
if (!second.check())
throw std::runtime_error("doubles expected");
throw eoException("doubles expected");
p.value().first = first();
p.value().second = second();

View file

@ -63,7 +63,7 @@ public :
virtual void operator()(const eoPop<EOT>& _pop) {
if( whichFitnessTerm >= _pop[0].fitness().size() )
throw std::logic_error("Fitness term requested out of range");
throw eoException("Fitness term requested out of range");
double result =0.0;
unsigned count = 0;
@ -102,7 +102,7 @@ public:
virtual void operator()(const eoPop<EOT>& _pop) {
if( whichFitnessTerm >= _pop[0].fitness().size() )
throw std::logic_error("Fitness term requested out of range");
throw eoException("Fitness term requested out of range");
value() = _pop.best_element().fitness()[whichFitnessTerm];
}

View file

@ -135,7 +135,7 @@ public:
/** just to be sure the add method is not called further
*/
virtual void add(const eoParam& )
{ throw std::runtime_error("eoFDCFileSnapshot::add(). Trying to add stats to an eoFDCFileSnapshot"); }
{ throw eoException("eoFDCFileSnapshot::add(). Trying to add stats to an eoFDCFileSnapshot"); }
private:
eoFDCStat<EOT> & FDCstat;

View file

@ -10,6 +10,7 @@
#include "eoFileMonitor.h"
#include "compatibility.h"
#include "eoParam.h"
#include "../eoExceptions.h"
using namespace std;
@ -36,8 +37,8 @@ void eoFileMonitor::printHeader()
if (!os)
{
string str = "eoFileMonitor could not open: " + filename;
throw runtime_error(str);
// string str = "eoFileMonitor could not open: " + filename;
throw eoFileError(filename);
}
printHeader(os);
@ -54,8 +55,8 @@ eoMonitor& eoFileMonitor::operator()(void)
if (!os)
{
string str = "eoFileMonitor could not write to: " + filename;
throw runtime_error(str);
// string str = "eoFileMonitor could not write to: " + filename;
throw eoFileError(filename);
}
if (

View file

@ -33,6 +33,7 @@
#include "eoMonitor.h"
#include "../eoObject.h"
#include "../eoExceptions.h"
/** Prints statistics to file
@ -75,8 +76,8 @@ public :
std::ofstream os (filename.c_str ());
if (!os) {
std::string str = "Error, eoFileMonitor could not open: " + filename;
throw std::runtime_error (str);
// std::string str = "Error, eoFileMonitor could not open: " + filename;
throw eoFileError(filename);
}
} // if ! keep
}

View file

@ -67,7 +67,7 @@ public :
int res = system(s.c_str());
// test for (unlikely) errors
if ( (res==-1) || (res==127) )
throw std::runtime_error("Problem executing test of dir in eoFileSnapshot");
throw eoSystemError(s, res);
// now make sure there is a dir without any genXXX file in it
if (res) // no dir present
{
@ -122,8 +122,8 @@ public :
if (!os)
{
std::string str = "eoFileSnapshot: Could not open " + currentFileName;
throw std::runtime_error(str);
// std::string str = "eoFileSnapshot: Could not open " + currentFileName;
throw eoFileError(currentFileName);;
}
return operator()(os);
@ -151,7 +151,7 @@ public :
ptParam = static_cast<const eoValueParam<std::vector<double> >* >(vec[1]);
vv[i] = ptParam->value();
if (vv[i].size() != v.size())
throw std::runtime_error("Dimension error in eoSnapshotMonitor");
throw eoException("Dimension error in eoSnapshotMonitor");
}
for (unsigned k=0; k<v.size(); k++)
{
@ -173,7 +173,7 @@ public :
{
if (!dynamic_cast<const eoValueParam<std::vector<double> >*>(&_param))
{
throw std::logic_error(std::string("eoFileSnapshot: I can only monitor std::vectors of doubles, sorry. The offending parameter name = ") + _param.longName());
throw eoException(std::string("eoFileSnapshot: I can only monitor std::vectors of doubles, sorry. The offending parameter name = ") + _param.longName());
}
eoMonitor::add(_param);
}

View file

@ -29,6 +29,7 @@
#include <stdexcept>
#include "eoGnuplot.h"
#include "../eoExceptions.h"
unsigned eoGnuplot::numWindow=0;
@ -82,7 +83,7 @@ void eoGnuplot::initGnuPlot(std::string _title, std::string _extra)
args[5] = 0;
gpCom = PipeComOpenArgv( GNUPLOT_PROGRAM, args );
if(! gpCom )
throw std::runtime_error("Cannot spawn gnuplot\n");
throw eoSystemError(GNUPLOT_PROGRAM);
else {
PipeComSend( gpCom, "set grid\n" );
PipeComSend( gpCom, _extra.c_str() );

View file

@ -61,7 +61,7 @@ void eoGnuplot1DMonitor::FirstPlot()
{
if (this->vec.size() < 2)
{
throw std::runtime_error("Must have some stats to plot!\n");
throw eoException("Must have some stats to plot!\n");
}
#ifdef HAVE_GNUPLOT
std::ostringstream os;

View file

@ -119,7 +119,7 @@ public:
{
unsigned int combloc = -count;
if (_size<combloc)
throw std::runtime_error("Negative result in eoHowMany");
throw eoException("Negative result in eoHowMany");
return _size-combloc;
}
return unsigned(count);
@ -167,7 +167,7 @@ public:
// minimal check
if ( rate < 0.0 )
throw std::runtime_error("Negative rate read in eoHowMany::readFrom");
throw eoException("Negative rate read in eoHowMany::readFrom");
}
/** The unary - operator: reverses the computation */
@ -188,7 +188,7 @@ public:
{
rate = 1.0+_rate;
if (rate < 0) // was < -1
throw std::logic_error("rate < -1 in eoHowMany!");
throw eoException("rate < -1 in eoHowMany!");
}
}
else

View file

@ -31,17 +31,17 @@ eoIntBounds* eoGeneralIntBounds::getBoundsFromString(std::string _value)
std::string delim(",; ");
std::string beginOrClose("[(])");
if (!remove_leading(_value, delim)) // only delimiters were left
throw std::runtime_error("Syntax error in eoGeneralIntBounds Ctor");
throw eoException("Syntax error in eoGeneralIntBounds Ctor");
// look for opening char
size_t posDeb = _value.find_first_of(beginOrClose); // allow ]a,b]
if (posDeb >= _value.size()) // nothing left to read
throw std::runtime_error("Syntax error in eoGeneralIntBounds Ctor");
throw eoException("Syntax error in eoGeneralIntBounds Ctor");
// ending char: next {}() after posDeb
size_t posFin = _value.find_first_of(beginOrClose,posDeb+1);
if (posFin >= _value.size()) // not found
throw std::runtime_error("Syntax error in eoGeneralIntBounds Ctor");
throw eoException("Syntax error in eoGeneralIntBounds Ctor");
// the bounds
std::string sBounds = _value.substr(posDeb+1, posFin-posDeb-1);
@ -51,7 +51,7 @@ eoIntBounds* eoGeneralIntBounds::getBoundsFromString(std::string _value)
remove_leading(sBounds, delim);
size_t posDelim = sBounds.find_first_of(delim);
if (posDelim >= sBounds.size())
throw std::runtime_error("Syntax error in eoGeneralIntBounds Ctor");
throw eoException("Syntax error in eoGeneralIntBounds Ctor");
bool minBounded=false, maxBounded=false;
long int minBound=0, maxBound=0;
@ -85,7 +85,7 @@ eoIntBounds* eoGeneralIntBounds::getBoundsFromString(std::string _value)
if (minBounded && maxBounded)
{
if (maxBound <= minBound)
throw std::runtime_error("Syntax error in eoGeneralIntBounds Ctor");
throw eoException("Syntax error in eoGeneralIntBounds Ctor");
locBound = new eoIntInterval(minBound, maxBound);
}
else if (!minBounded && !maxBounded) // no bound at all

View file

@ -29,6 +29,7 @@
#include <stdexcept> // std::exceptions!
#include "eoRNG.h"
#include "../eoExceptions.h"
/**
\class eoIntBounds eoIntBounds.h es/eoIntBounds.h
@ -163,29 +164,29 @@ public:
virtual long int minimum() const
{
throw std::logic_error("Trying to get minimum of unbounded eoIntBounds");
throw eoException("Trying to get minimum of unbounded eoIntBounds");
}
virtual long int maximum() const
{
throw std::logic_error("Trying to get maximum of unbounded eoIntBounds");
throw eoException("Trying to get maximum of unbounded eoIntBounds");
}
virtual long int range() const
{
throw std::logic_error("Trying to get range of unbounded eoIntBounds");
throw eoException("Trying to get range of unbounded eoIntBounds");
}
virtual double uniform(eoRng & _rng = eo::rng) const
{
(void)_rng;
throw std::logic_error("Trying to generate uniform values in unbounded eoIntBounds");
throw eoException("Trying to generate uniform values in unbounded eoIntBounds");
}
virtual long int random(eoRng & _rng = eo::rng) const
{
(void)_rng;
throw std::logic_error("Trying to generate uniform values in unbounded eoIntBounds");
throw eoException("Trying to generate uniform values in unbounded eoIntBounds");
}
// methods from eoPersistent
@ -199,7 +200,7 @@ public:
{
(void)_is;
throw std::runtime_error("Should not use eoIntBounds::readFrom");
throw eoException("Should not use eoIntBounds::readFrom");
}
/**
@ -244,7 +245,7 @@ public :
repMinimum(_min), repMaximum(_max), repRange(_max-_min)
{
if (repRange<=0)
throw std::logic_error("Void range in eoIntBounds");
throw eoException("Void range in eoIntBounds");
}
// accessors
@ -328,7 +329,7 @@ public :
{
(void)_is;
throw std::runtime_error("Should not use eoIntInterval::readFrom");
throw eoException("Should not use eoIntInterval::readFrom");
}
/**
@ -374,25 +375,25 @@ public :
virtual long int maximum() const
{
throw std::logic_error("Trying to get maximum of eoIntBelowBound");
throw eoException("Trying to get maximum of eoIntBelowBound");
}
virtual long int range() const
{
throw std::logic_error("Trying to get range of eoIntBelowBound");
throw eoException("Trying to get range of eoIntBelowBound");
}
virtual double uniform(eoRng & _rng = eo::rng) const
{
(void)_rng;
throw std::logic_error("Trying to generate uniform values in eoIntBelowBound");
throw eoException("Trying to generate uniform values in eoIntBelowBound");
}
virtual long int random(eoRng & _rng = eo::rng) const
{
(void)_rng;
throw std::logic_error("Trying to generate uniform values in eoIntBelowBound");
throw eoException("Trying to generate uniform values in eoIntBelowBound");
}
// description
@ -437,7 +438,7 @@ public :
{
(void)_is;
throw std::runtime_error("Should not use eoIntBelowBound::readFrom");
throw eoException("Should not use eoIntBelowBound::readFrom");
}
/**
@ -482,25 +483,25 @@ public :
virtual long int minimum() const
{
throw std::logic_error("Trying to get minimum of eoIntAboveBound");
throw eoException("Trying to get minimum of eoIntAboveBound");
}
virtual long int range() const
{
throw std::logic_error("Trying to get range of eoIntAboveBound");
throw eoException("Trying to get range of eoIntAboveBound");
}
virtual double uniform(eoRng & _rng = eo::rng) const
{
(void)_rng;
throw std::logic_error("Trying to generate uniform values in eoIntAboveBound");
throw eoException("Trying to generate uniform values in eoIntAboveBound");
}
virtual long int random(eoRng & _rng = eo::rng) const
{
(void)_rng;
throw std::logic_error("Trying to generate uniform values in eoIntAboveBound");
throw eoException("Trying to generate uniform values in eoIntAboveBound");
}
// description
@ -545,7 +546,7 @@ public :
{
(void)_is;
throw std::runtime_error("Should not use eoIntAboveBound::readFrom");
throw eoException("Should not use eoIntAboveBound::readFrom");
}
/**

View file

@ -19,8 +19,8 @@
eoMonitor& eoOStreamMonitor::operator()(void)
{
if (!out) {
std::string str = "eoOStreamMonitor: Could not write to the output stream";
throw std::runtime_error(str);
// std::string str = "eoOStreamMonitor: Could not write to the output stream";
throw eoFileError("output stream");
}
if (firsttime) {

View file

@ -34,6 +34,7 @@
#include <string>
#include <vector>
#include "../eoScalarFitness.h"
#include "../eoExceptions.h"
/** @defgroup Parameters Parameters management
*
@ -385,14 +386,14 @@ inline void eoValueParam<std::vector<eoMinimizingFitness> >::setValue(const std:
template <>
inline std::string eoValueParam<std::vector<void*> >::getValue(void) const
{
throw std::runtime_error("I cannot getValue for a std::vector<EOT*>");
throw eoException("I cannot getValue for a std::vector<EOT*>");
return std::string("");
}
template <>
inline void eoValueParam<std::vector<void*> >::setValue(const std::string&)
{
throw std::runtime_error("I cannot setValue for a std::vector<EOT*>");
throw eoException("I cannot setValue for a std::vector<EOT*>");
return;
}

View file

@ -96,8 +96,8 @@ eoParser::eoParser ( unsigned _argc, char **_argv , string _programDescription,
ifs.peek(); // check if it exists
if (!ifs)
{
string msg = string("Could not open response file: ") + pts;
throw runtime_error(msg);
// string msg = string("Could not open response file: ") + pts;
throw eoFileError(pts);
}
// read - will be overwritten by command-line
readFrom(ifs);

View file

@ -101,7 +101,7 @@ void eoRealVectorBounds::readFrom(std::string _value)
size_t posFin = _value.find_first_of(std::string(closeChar));
if (posFin >= _value.size())
throw std::runtime_error("Syntax error when reading bounds");
throw eoException("Syntax error when reading bounds");
// y a-t-il un nbre devant
unsigned count = 1;
@ -110,7 +110,7 @@ void eoRealVectorBounds::readFrom(std::string _value)
std::string sCount = _value.substr(0, posDeb);
count = read_int(sCount);
if (count <= 0)
throw std::runtime_error("Syntax error when reading bounds");
throw eoException("Syntax error when reading bounds");
}
// the bounds
@ -121,7 +121,7 @@ void eoRealVectorBounds::readFrom(std::string _value)
remove_leading(sBounds, delim);
size_t posDelim = sBounds.find_first_of(delim);
if (posDelim >= sBounds.size())
throw std::runtime_error("Syntax error when reading bounds");
throw eoException("Syntax error when reading bounds");
bool minBounded=false, maxBounded=false;
double minBound=0, maxBound=0;
@ -192,17 +192,17 @@ eoRealBounds* eoGeneralRealBounds::getBoundsFromString(std::string _value)
std::string delim(",; ");
std::string beginOrClose("[(])");
if (!remove_leading(_value, delim)) // only delimiters were left
throw std::runtime_error("Syntax error in eoGeneralRealBounds Ctor");
throw eoException("Syntax error in eoGeneralRealBounds Ctor");
// look for opening char
size_t posDeb = _value.find_first_of(beginOrClose); // allow ]a,b]
if (posDeb >= _value.size()) // nothing left to read
throw std::runtime_error("Syntax error in eoGeneralRealBounds Ctor");
throw eoException("Syntax error in eoGeneralRealBounds Ctor");
// ending char: next {}() after posDeb
size_t posFin = _value.find_first_of(beginOrClose,posDeb+1);
if (posFin >= _value.size()) // not found
throw std::runtime_error("Syntax error in eoGeneralRealBounds Ctor");
throw eoException("Syntax error in eoGeneralRealBounds Ctor");
// the bounds
std::string sBounds = _value.substr(posDeb+1, posFin-posDeb-1);
@ -212,7 +212,7 @@ eoRealBounds* eoGeneralRealBounds::getBoundsFromString(std::string _value)
remove_leading(sBounds, delim);
size_t posDelim = sBounds.find_first_of(delim);
if (posDelim >= sBounds.size())
throw std::runtime_error("Syntax error in eoGeneralRealBounds Ctor");
throw eoException("Syntax error in eoGeneralRealBounds Ctor");
bool minBounded=false, maxBounded=false;
double minBound=0, maxBound=0;
@ -246,7 +246,7 @@ eoRealBounds* eoGeneralRealBounds::getBoundsFromString(std::string _value)
if (minBounded && maxBounded)
{
if (maxBound <= minBound)
throw std::runtime_error("Syntax error in eoGeneralRealBounds Ctor");
throw eoException("Syntax error in eoGeneralRealBounds Ctor");
locBound = new eoRealInterval(minBound, maxBound);
}
else if (!minBounded && !maxBounded) // no bound at all

View file

@ -161,22 +161,22 @@ public:
virtual double minimum() const
{
throw std::logic_error("Trying to get minimum of unbounded eoRealBounds");
throw eoException("Trying to get minimum of unbounded eoRealBounds");
}
virtual double maximum() const
{
throw std::logic_error("Trying to get maximum of unbounded eoRealBounds");
throw eoException("Trying to get maximum of unbounded eoRealBounds");
}
virtual double range() const
{
throw std::logic_error("Trying to get range of unbounded eoRealBounds");
throw eoException("Trying to get range of unbounded eoRealBounds");
}
virtual double uniform(eoRng & _rng = eo::rng) const
{
(void)_rng;
throw std::logic_error("Trying to generate uniform values in unbounded eoRealBounds");
throw eoException("Trying to generate uniform values in unbounded eoRealBounds");
}
// methods from eoPersistent
@ -190,7 +190,7 @@ public:
{
(void)_is;
throw std::runtime_error("Should not use eoRealBounds::readFrom");
throw eoException("Should not use eoRealBounds::readFrom");
}
/**
@ -315,7 +315,7 @@ public :
{
(void)_is;
throw std::runtime_error("Should not use eoRealInterval::readFrom");
throw eoException("Should not use eoRealInterval::readFrom");
}
/**
@ -360,11 +360,11 @@ public :
virtual double maximum() const
{
throw std::logic_error("Trying to get maximum of eoRealBelowBound");
throw eoException("Trying to get maximum of eoRealBelowBound");
}
virtual double range() const
{
throw std::logic_error("Trying to get range of eoRealBelowBound");
throw eoException("Trying to get range of eoRealBelowBound");
}
// random generators
@ -372,7 +372,7 @@ public :
{
(void)_rng;
throw std::logic_error("Trying to generate uniform values in eoRealBelowBound");
throw eoException("Trying to generate uniform values in eoRealBelowBound");
}
// description
@ -417,7 +417,7 @@ public :
{
(void)_is;
throw std::runtime_error("Should not use eoRealBelowBound::readFrom");
throw eoException("Should not use eoRealBelowBound::readFrom");
}
/**
@ -459,11 +459,11 @@ public :
virtual double minimum() const
{
throw std::logic_error("Trying to get minimum of eoRealAboveBound");
throw eoException("Trying to get minimum of eoRealAboveBound");
}
virtual double range() const
{
throw std::logic_error("Trying to get range of eoRealAboveBound");
throw eoException("Trying to get range of eoRealAboveBound");
}
// random generators
@ -471,7 +471,7 @@ public :
{
(void)_rng;
throw std::logic_error("Trying to generate uniform values in eoRealAboveBound");
throw eoException("Trying to generate uniform values in eoRealAboveBound");
}
// description
@ -516,7 +516,7 @@ public :
{
(void)_is;
throw std::runtime_error("Should not use eoRealAboveBound::readFrom");
throw eoException("Should not use eoRealAboveBound::readFrom");
}
/**

View file

@ -250,7 +250,7 @@ public:
eoRealBaseVectorBounds(), factor(1, _dim), ownedBounds(0)
{
if (_max-_min<=0)
throw std::logic_error("Void range in eoRealVectorBounds");
throw eoException("Void range in eoRealVectorBounds");
eoRealBounds *ptBounds = new eoRealInterval(_min, _max);
// handle memory once
ownedBounds.push_back(ptBounds);
@ -265,7 +265,7 @@ public:
factor(_min.size(), 1), ownedBounds(0)
{
if (_max.size() != _min.size())
throw std::logic_error("Dimensions don't match in eoRealVectorBounds");
throw eoException("Dimensions don't match in eoRealVectorBounds");
// the bounds
eoRealBounds *ptBounds;
for (unsigned i=0; i<_min.size(); i++)
@ -386,20 +386,20 @@ public:
// accessors
virtual double minimum(unsigned)
{
throw std::logic_error("Trying to get minimum of eoRealVectorNoBounds");
throw eoException("Trying to get minimum of eoRealVectorNoBounds");
}
virtual double maximum(unsigned)
{
throw std::logic_error("Trying to get maximum of eoRealVectorNoBounds");
throw eoException("Trying to get maximum of eoRealVectorNoBounds");
}
virtual double range(unsigned)
{
throw std::logic_error("Trying to get range of eoRealVectorNoBounds");
throw eoException("Trying to get range of eoRealVectorNoBounds");
}
virtual double averageRange()
{
throw std::logic_error("Trying to get average range of eoRealVectorNoBounds");
throw eoException("Trying to get average range of eoRealVectorNoBounds");
}
// random generators
@ -407,7 +407,7 @@ public:
{
(void)_rng;
throw std::logic_error("No uniform distribution on eoRealVectorNoBounds");
throw eoException("No uniform distribution on eoRealVectorNoBounds");
}
// fills a std::vector with uniformly chosen variables in bounds
@ -415,7 +415,7 @@ public:
{
(void)_rng;
throw std::logic_error("No uniform distribution on eoRealVectorNoBounds");
throw eoException("No uniform distribution on eoRealVectorNoBounds");
}
};

View file

@ -29,6 +29,7 @@
#ifndef eoRndGenerators_h
#define eoRndGenerators_h
#include "../eoExceptions.h"
#include "eoRNG.h"
#include "../eoFunctor.h"
#include <stdexcept>
@ -80,7 +81,7 @@ template <class T = double> class eoUniformGenerator : public eoRndGenerator<T>
minim(_min), range(_max-_min), uniform(_rng)
{
if (_min>_max)
throw std::logic_error("Min is greater than Max in uniform_generator");
throw eoException("Min is greater than Max in uniform_generator");
}
/**

View file

@ -251,7 +251,7 @@ public :
virtual void operator()(const std::vector<const EOT*>& _pop)
{
if (whichElement > _pop.size())
throw std::logic_error("fitness requested of element outside of pop");
throw eoException("fitness requested of element outside of pop");
doit(_pop, Fitness());
}

View file

@ -69,7 +69,7 @@ void eoState::registerObject(eoPersistent& registrant)
}
else
{
throw logic_error("Interval error: object already present in the state");
throw eoException("Interval error: object already present in the state");
}
}
@ -79,8 +79,8 @@ void eoState::load(const string& _filename)
if (!is)
{
string str = "Could not open file " + _filename;
throw runtime_error(str);
// string str = "Could not open file " + _filename;
throw eoFileError(_filename);
}
load(is);
@ -96,8 +96,8 @@ void eoState::load(std::istream& is)
if (is.fail())
{
string str = "Error while reading stream";
throw runtime_error(str);
// string str = "Error while reading stream";
throw eoFileError("stream");
}
while(! is.eof())
@ -127,7 +127,7 @@ void eoState::load(std::istream& is)
while (getline(is, str))
{
if (is.eof())
throw runtime_error("No section in load file");
throw eoException("No section in load file");
if (is_section(str, name))
break;
@ -154,8 +154,8 @@ void eoState::save(const string& filename) const
if (!os)
{
string msg = "Could not open file: " + filename + " for writing!";
throw runtime_error(msg);
// string msg = "Could not open file: " + filename + " for writing!";
throw eoFileError(filename);
}
save(os);

View file

@ -82,7 +82,7 @@ template <class T = double> class eoUniformInit : public eoInit<T>
minim(_min), range(_max-_min), uniform(_rng)
{
if (_min>_max)
throw std::logic_error("Min is greater than Max in uniform_generator");
throw eoParamException("Min is greater than Max in uniform_generator");
}
/**

View file

@ -85,8 +85,8 @@ bool testDirRes(std::string _dirName, bool _erase=true)
// test for (unlikely) errors
if ( (res==-1) || (res==127) )
{
s = "Problem executing test of dir " + _dirName;
throw runtime_error(s);
// s = "Problem executing test of dir " + _dirName;
throw eoSystemError(s,res);
}
// now make sure there is a dir without any file in it - or quit
if (res) // no dir present
@ -108,7 +108,7 @@ bool testDirRes(std::string _dirName, bool _erase=true)
// WARNING: bug if dir exists and is empty; this says it is not!
// shoudl use scandir instead - no time now :-((( MS Aug. 01
s = "Dir " + _dirName + " is not empty";
throw runtime_error(s);
throw eoException(s);
return true;
}

View file

@ -31,6 +31,7 @@
#ifndef eoRND_GENERATORS_H
#define eoRND_GENERATORS_H
#include "../eoExceptions.h"
#include "eoRNG.h"
#include <stdexcept>
@ -56,7 +57,7 @@ template <class T = double> class uniform_generator
minim(_min), range(_max-_min), uniform(_rng)
{
if (_min>_max)
throw std::logic_error("Min is greater than Max in uniform_generator");
throw eoParamException("Min is greater than Max in uniform_generator");
}
T operator()(void) { return minim+static_cast<T>(uniform.uniform(range)); }
@ -99,7 +100,7 @@ template <class T = uint32_t> class random_generator
minim(_min), range(_max-_min), random(_rng)
{
if (_min>_max)
throw std::logic_error("Min is greater than Max in random_generator");
throw eoParamException("Min is greater than Max in random_generator");
}
T operator()(void) { return (T) (minim + random.random(range)); }

View file

@ -89,7 +89,7 @@ double sum_fitness(It begin, It end)
{
double v = static_cast<double>(begin->fitness());
if (v < 0.0)
throw std::logic_error("sum_fitness: negative fitness value encountered");
throw eoInvalidFitnessError("sum_fitness: negative fitness value encountered");
sum += v;
}

View file

@ -133,7 +133,7 @@ public :
performance_type performance(void) const
{
if(!valid_performance) throw runtime_error("no performance");
if(!valid_performance) throw eoException("no performance");
return Traits::get_performance(rep_fitness);
}
@ -145,8 +145,8 @@ public :
worth_type worth(void) const
{
if(!valid_worth) throw runtime_error("no worth");
if(!Traits::needs_mapping) throw runtime_error("no mapping");
if(!valid_worth) throw eoException("no worth");
if(!Traits::needs_mapping) throw eoException("no mapping");
return Traits::get_worth(rep_fitness);
}
@ -236,14 +236,14 @@ public :
{
if (!fitness_traits::needs_mapping)
{
throw runtime_error("eoPop: no scaling needed, yet a scaling function is defined");
throw eoException("eoPop: no scaling needed, yet a scaling function is defined");
}
(*p2w)(*this);
}
else if (fitness_traits::needs_mapping)
{
throw runtime_error("eoPop: no scaling function attached to the population, while one was certainly called for");
throw eoException("eoPop: no scaling function attached to the population, while one was certainly called for");
}
}

View file

@ -374,7 +374,7 @@ class Experiment : public eoserial::Persistent
} else if( distribName == "exponential" ) {
_distribution = & exponentialDistribution;
} else {
throw std::runtime_error("When unpacking experience, no distribution found.");
throw eoException("When unpacking experience, no distribution found.");
}
eoserial::unpackObject( *obj, "distribution", *_distribution );
@ -503,7 +503,7 @@ int main( int argc, char** argv )
{
if( isChosenDistrib )
{
throw std::runtime_error("Only one distribution can be chosen during a launch!");
throw eoException("Only one distribution can be chosen during a launch!");
} else
{
isChosenDistrib = true;
@ -517,7 +517,7 @@ int main( int argc, char** argv )
if( !isChosenDistrib )
{
throw std::runtime_error("No distribution chosen. One distribution should be chosen.");
throw eoException("No distribution chosen. One distribution should be chosen.");
}
Experiment e( pdistrib, size, packet_size, worker_print_waiting_time, seed, fileName );

View file

@ -130,7 +130,7 @@ int main(int argc, char** argv)
// eo::log << eo::setlevel( eo::debug );
Node::init( argc, argv );
if( Node::comm().size() != 7 ) {
throw std::runtime_error("World size should be 7.");
throw eoException("World size should be 7.");
}
SerializableVector< SerializableBase<int> > v;

View file

@ -105,7 +105,7 @@ int main(int argc, char** argv)
const int ALL = Node::comm().size();
if( ALL < 3 ) {
throw std::runtime_error("Needs at least 3 processes to be launched!");
throw eoException("Needs at least 3 processes to be launched!");
}
// Tests are auto described thanks to member "description"

View file

@ -120,7 +120,7 @@ void runAlgorithm(EOT, eoParser& _parser, eoState& _state, eoRealVectorBounds& _
if (lambda_rate.value() < 1.0f)
{
throw logic_error("lambda_rate must be larger than 1 in a comma strategy");
throw eoParamException("lambda_rate must be larger than 1 in a comma strategy");
}
// Initialization

View file

@ -174,7 +174,7 @@ void init(eoPop<Dummy> & _pop, unsigned _pSize)
}
else
{
throw std::runtime_error("init pop with 0 size");
throw eoPopSizeException(_pSize,"init pop with 0 size");
}
for (unsigned i=0; i<_pSize; i++)
{

View file

@ -32,7 +32,7 @@ bool check_permutation(const Chrom & _chrom)
std::cout << " Error: Wrong permutation !" << std::endl;
std::string s;
s.append( " Wrong permutation in t-eoInitPermutation");
throw std::runtime_error( s );
throw eoException( s );
}
return true;
}

View file

@ -23,7 +23,7 @@ bool check_permutation(const Chrom& _chrom){
std::cout << " Error: Wrong permutation !" << std::endl;
std::string s;
s.append( " Wrong permutation in t-eoShiftMutation");
throw std::runtime_error( s );
throw eoException( s );
return false;
}
}

View file

@ -64,7 +64,7 @@ void testSelectMany(eoSelect<EOT> & _select, std::string _name)
{
unsigned trouve = isInPop<Dummy>(offspring[i], parents);
if (trouve == parents.size()) // pas trouve
throw std::runtime_error("Pas trouve ds parents");
throw eoException("Pas trouve ds parents");
nb[trouve]++;
}
// dump to file so you can plot using gnuplot - dir name is hardcoded!
@ -149,7 +149,7 @@ eoValueParam<unsigned> tournamentSizeParam = parser.createParam(unsigned(2), "to
parentsOrg[pSize-1].fitness(10*pSize);
}
else
throw std::runtime_error("Invalid fitness Type"+fitnessType);
throw eoInvalidFitnessError("Invalid fitness Type"+fitnessType);
std::cout << "Initial parents (odd)\n" << parentsOrg << std::endl;

View file

@ -86,7 +86,7 @@ void testSelectMany(eoSelect<EOT> & _select, std::string _name)
{
unsigned trouve = isInPop<Dummy>(offspring[i], parents);
if (trouve == parents.size()) // pas trouve
throw std::runtime_error("Pas trouve ds parents");
throw eoException("Pas trouve ds parents");
nb[trouve]++;
}
// dump to file so you can plot using gnuplot - dir name is hardcoded!

View file

@ -32,7 +32,7 @@ bool check_permutation(const Chrom& _chrom){
std::cout << " Error: Wrong permutation !" << std::endl;
std::string s;
s.append( " Wrong permutation in t-eoShiftMutation");
throw std::runtime_error( s );
throw eoException( s );
return false;
}
}

View file

@ -33,7 +33,7 @@ bool check_permutation(const Chrom& _chrom){
std::cout << " Error: Wrong permutation !" << std::endl;
std::string s;
s.append( " Wrong permutation in t-eoShiftMutation");
throw std::runtime_error( s );
throw eoException( s );
return false;
}
}

View file

@ -33,7 +33,7 @@ bool check_permutation(const Chrom& _chrom){
std::cout << " Error: Wrong permutation !" << std::endl;
std::string s;
s.append( " Wrong permutation in t-eoShiftMutation");
throw std::runtime_error( s );
throw eoException( s );
return false;
}
}

View file

@ -182,12 +182,12 @@ eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit<EO
eoValueParam<double>& pCrossParam = _parser.createParam(0.6, "pCross", "Probability of Crossover", 'C', "Variation Operators" );
// minimum check
if ( (pCrossParam.value() < 0) || (pCrossParam.value() > 1) )
throw runtime_error("Invalid pCross");
throw eoParamException("Invalid pCross");
eoValueParam<double>& pMutParam = _parser.createParam(0.1, "pMut", "Probability of Mutation", 'M', "Variation Operators" );
// minimum check
if ( (pMutParam.value() < 0) || (pMutParam.value() > 1) )
throw runtime_error("Invalid pMut");
throw eoParamException("Invalid pMut");
// the crossover - with probability pCross

View file

@ -215,12 +215,12 @@ try {
double pCross = parser.createParam(0.6, "pCross", "Probability of Crossover", 'C', "Variation Operators" ).value();
// minimum check
if ( (pCross < 0) || (pCross > 1) )
throw runtime_error("Invalid pCross");
throw eoParamException("Invalid pCross");
double pMut = parser.createParam(0.1, "pMut", "Probability of Mutation", 'M', "Variation Operators" ).value();
// minimum check
if ( (pMut < 0) || (pMut > 1) )
throw runtime_error("Invalid pMut");
throw eoParamException("Invalid pMut");
// now create the generalOp
eoSGAGenOp<Indi> op(cross, pCross, mut, pMut);
@ -827,7 +827,7 @@ eoContinue<Indi> & do_make_continue(eoParser& _parser, eoState& _state, eoEvalFu
// now check that there is at least one!
if (!continuator)
throw runtime_error("You MUST provide a stopping criterion");
throw eoException("You MUST provide a stopping criterion");
// OK, it's there: store in the eoState
_state.storeFunctor(continuator);

View file

@ -206,12 +206,12 @@ try
double pCross = parser.createParam(0.6, "pCross", "Probability of Crossover", 'C', "Variation Operators" ).value();
// minimum check
if ( (pCross < 0) || (pCross > 1) )
throw runtime_error("Invalid pCross");
throw eoParamException("Invalid pCross");
double pMut = parser.createParam(0.1, "pMut", "Probability of Mutation", 'M', "Variation Operators" ).value();
// minimum check
if ( (pMut < 0) || (pMut > 1) )
throw runtime_error("Invalid pMut");
throw eoParamException("Invalid pMut");
// now create the generalOp
eoSGAGenOp<Indi> op(cross, pCross, mut, pMut);
@ -278,7 +278,7 @@ try
// first check the directory (and creates it if not exists already):
if (fileMyStructStat || plotMyStructStat)
if (! testDirRes(dirName, true) )
throw runtime_error("Problem with resDir");
throw eoParamException("Problem with resDir");
// should we write it to a file ?
if (fileMyStructStat)

View file

@ -182,12 +182,12 @@ eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit<EO
eoValueParam<double>& pCrossParam = _parser.createParam(0.6, "pCross", "Probability of Crossover", 'C', "Variation Operators" );
// minimum check
if ( (pCrossParam.value() < 0) || (pCrossParam.value() > 1) )
throw runtime_error("Invalid pCross");
throw eoParamException("Invalid pCross");
eoValueParam<double>& pMutParam = _parser.createParam(0.1, "pMut", "Probability of Mutation", 'M', "Variation Operators" );
// minimum check
if ( (pMutParam.value() < 0) || (pMutParam.value() > 1) )
throw runtime_error("Invalid pMut");
throw eoParamException("Invalid pMut");
// the crossover - with probability pCross

View file

@ -263,8 +263,8 @@ public:
if (!os) {
std::string str = "moVectorMonitor: Could not open " + _filename;
throw std::runtime_error(str);
// std::string str = "moVectorMonitor: Could not open " + _filename;
throw eoFileError(_filename);;
}
for (unsigned int i = 0; i < size(); i++) {

View file

@ -89,7 +89,7 @@ public:
int pos = _is.tellg();
_is >> fitness_str;
if (fitness_str == "INVALID") {
throw std::runtime_error("invalid fitness");
throw eoInvalidFitnessError("invalid fitness");
} else {
Fitness repFit;
_is.seekg(pos);

Some files were not shown because too many files have changed in this diff Show more