From eba2e149503d5fa07e16c79b7a2dcaceb80868e3 Mon Sep 17 00:00:00 2001 From: nojhan Date: Fri, 27 Mar 2020 00:21:52 +0100 Subject: [PATCH] use eoExceptions everywhere --- edo/src/utils/edoFileSnapshot.cpp | 6 +- eo/src/EO.h | 8 +- eo/src/PO.h | 4 +- eo/src/do/make_algo_easea.h | 6 +- eo/src/do/make_algo_scalar.h | 6 +- eo/src/do/make_continue.h | 2 +- eo/src/do/make_general_replacement.h | 4 +- eo/src/eoCtrlCContinue.h | 2 +- eo/src/eoEasyEA.h | 22 ++--- eo/src/eoEasyPSO.h | 18 ++-- eo/src/eoEvalDump.h | 4 +- eo/src/eoExceptions.h | 97 +++++++++++++++++-- eo/src/eoFlOrBinOp.h | 8 +- eo/src/eoFlOrQuadOp.h | 6 +- eo/src/eoG3Replacement.h | 2 +- eo/src/eoInit.h | 3 +- eo/src/eoLinearTopology.h | 2 +- eo/src/eoMGGReplacement.h | 2 +- eo/src/eoMerge.h | 6 +- eo/src/eoNDSorting.h | 4 +- eo/src/eoOneToOneBreeder.h | 2 +- eo/src/eoPop.h | 5 +- eo/src/eoProportionalSelect.h | 2 +- eo/src/eoRandomRealWeightUp.h | 2 +- eo/src/eoRanking.h | 4 +- eo/src/eoReduce.h | 12 +-- eo/src/eoReduceMerge.h | 2 +- eo/src/eoReduceMergeReduce.h | 2 +- eo/src/eoReduceSplit.h | 14 +-- eo/src/eoSIGContinue.h | 2 +- eo/src/eoSelectFactory.h | 2 +- eo/src/eoSelectFromWorth.h | 2 +- eo/src/eoSequentialSelect.h | 2 +- eo/src/eoSharing.h | 3 +- eo/src/eoSimpleEDA.h | 18 ++-- eo/src/eoSocialNeighborhood.h | 2 +- eo/src/eoStochasticUniversalSelect.h | 2 +- eo/src/eoSurviveAndDie.h | 4 +- eo/src/eoSwapMutation.h | 2 +- eo/src/eoSyncEasyPSO.h | 18 ++-- eo/src/es/eoNormalMutation.h | 2 +- eo/src/es/eoRealInitBounded.h | 2 +- eo/src/es/eoRealOp.h | 8 +- eo/src/es/make_algo_scalar_es.cpp | 12 +-- eo/src/es/make_genotype_real.h | 2 +- eo/src/es/make_op.h | 24 ++--- eo/src/es/make_op_es.h | 12 +-- eo/src/es/make_op_real.h | 24 ++--- eo/src/ga/make_PBILupdate.h | 2 +- eo/src/ga/make_op.h | 22 ++--- eo/src/gp/eoParseTreeDepthInit.h | 2 +- eo/src/gp/eoStParseTreeDepthInit.h | 2 +- eo/src/mpi/eoParallelApply.h | 2 +- eo/src/pyeo/PyEO.cpp | 8 +- eo/src/pyeo/PyEO.h | 4 +- eo/src/pyeo/monitors.cpp | 2 +- eo/src/pyeo/statistics.cpp | 2 +- eo/src/pyeo/valueParam.cpp | 6 +- eo/src/utils/eoAssembledFitnessStat.h | 4 +- eo/src/utils/eoFDCStat.h | 2 +- eo/src/utils/eoFileMonitor.cpp | 9 +- eo/src/utils/eoFileMonitor.h | 5 +- eo/src/utils/eoFileSnapshot.h | 10 +- eo/src/utils/eoGnuplot.cpp | 3 +- eo/src/utils/eoGnuplot1DMonitor.cpp | 2 +- eo/src/utils/eoHowMany.h | 6 +- eo/src/utils/eoIntBounds.cpp | 10 +- eo/src/utils/eoIntBounds.h | 37 +++---- eo/src/utils/eoOStreamMonitor.cpp | 4 +- eo/src/utils/eoParam.h | 5 +- eo/src/utils/eoParser.cpp | 4 +- eo/src/utils/eoRealBounds.cpp | 16 +-- eo/src/utils/eoRealBounds.h | 28 +++--- eo/src/utils/eoRealVectorBounds.h | 16 +-- eo/src/utils/eoRndGenerators.h | 3 +- eo/src/utils/eoStat.h | 2 +- eo/src/utils/eoState.cpp | 16 +-- eo/src/utils/eoUniformInit.h | 2 +- eo/src/utils/make_help.cpp | 6 +- eo/src/utils/rnd_generators.h | 5 +- eo/src/utils/selectors.h | 2 +- eo/test/fitness_traits.cpp | 10 +- eo/test/mpi/t-mpi-distrib-exp.cpp | 6 +- eo/test/mpi/t-mpi-multipleRoles.cpp | 2 +- eo/test/mpi/t-mpi-parallelApply.cpp | 2 +- eo/test/t-eoESFull.cpp | 2 +- eo/test/t-eoGenOp.cpp | 2 +- eo/test/t-eoInitPermutation.cpp | 2 +- eo/test/t-eoOrderXover.cpp | 2 +- eo/test/t-eoSelect.cpp | 4 +- eo/test/t-eoSharing.cpp | 2 +- eo/test/t-eoShiftMutation.cpp | 2 +- eo/test/t-eoSwapMutation.cpp | 2 +- eo/test/t-eoTwoOptMutation.cpp | 2 +- eo/tutorial/Lesson5/make_op_OneMax.h | 4 +- eo/tutorial/Templates/EO.tpl | 6 +- eo/tutorial/Templates/MyStructSEA.cpp | 6 +- eo/tutorial/Templates/make_op_MyStruct.h | 4 +- mo/src/continuator/moVectorMonitor.h | 4 +- mo/src/problems/bitString/moBitNeighbor.h | 2 +- mo/src/sampling/moSampling.h | 6 +- moeo/src/CMakeLists.txt | 2 +- moeo/src/algo/moeoEasyEA.h | 22 ++--- .../comparator/moeoOneObjectiveComparator.h | 2 +- moeo/src/core/MOEO.h | 6 +- moeo/src/core/moeoObjectiveVectorTraits.h | 8 +- moeo/src/core/moeoVector.h | 2 +- moeo/src/do/make_continue_moeo.h | 2 +- moeo/src/do/make_ea_moeo.h | 12 +-- .../moeoDominanceDepthFitnessAssignment.h | 2 +- .../explorer/moeoHCMoveLoopExpl.h | 2 +- .../explorer/moeoTSMoveLoopExpl.h | 2 +- moeo/src/utils/moeoBestObjVecStat.h | 2 +- .../flowshop/FlowShopBenchmarkParser.cpp | 3 +- .../examples/flowshop/make_op_FlowShop.h | 4 +- problems/eval/maxSATeval.h | 10 +- problems/eval/nkLandscapesEval.h | 16 +-- problems/eval/nkpLandscapesEval.h | 16 +-- problems/eval/nkqLandscapesEval.h | 18 ++-- problems/eval/qapEval.h | 4 +- problems/eval/ubqpEval.h | 6 +- smp/src/MWAlgo/eoEasyEA.cpp | 24 ++--- smp/src/MWAlgo/eoEasyPSO.cpp | 18 ++-- smp/src/MWAlgo/eoSyncEasyPSO.cpp | 18 ++-- smp/src/MWModel.cpp | 2 +- smp/src/topology/customBooleanTopology.cpp | 8 +- smp/src/topology/customStochasticTopology.cpp | 8 +- 127 files changed, 523 insertions(+), 417 deletions(-) diff --git a/edo/src/utils/edoFileSnapshot.cpp b/edo/src/utils/edoFileSnapshot.cpp index 1860ac0f1..32107b409 100644 --- a/edo/src/utils/edoFileSnapshot.cpp +++ b/edo/src/utils/edoFileSnapshot.cpp @@ -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 ) diff --git a/eo/src/EO.h b/eo/src/EO.h index 19708314f..490dd7d83 100644 --- a/eo/src/EO.h +++ b/eo/src/EO.h @@ -30,6 +30,7 @@ #include // 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) { diff --git a/eo/src/PO.h b/eo/src/PO.h index c4225cf61..477f165c9 100644 --- a/eo/src/PO.h +++ b/eo/src/PO.h @@ -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; } diff --git a/eo/src/do/make_algo_easea.h b/eo/src/do/make_algo_easea.h index 3fadf05ec..bf5b8b188 100644 --- a/eo/src/do/make_algo_easea.h +++ b/eo/src/do/make_algo_easea.h @@ -183,7 +183,7 @@ eoAlgo & 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 & 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(-surviveParents, tSize); @@ -341,7 +341,7 @@ eoAlgo & 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( diff --git a/eo/src/do/make_algo_scalar.h b/eo/src/do/make_algo_scalar.h index 92e16d2f2..7819a4270 100644 --- a/eo/src/do/make_algo_scalar.h +++ b/eo/src/do/make_algo_scalar.h @@ -120,7 +120,7 @@ eoAlgo & 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(nicheSize, *_dist); } else if (ppSelect.first == std::string("StochTour")) @@ -206,7 +206,7 @@ eoAlgo & 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 & 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); diff --git a/eo/src/do/make_continue.h b/eo/src/do/make_continue.h index f09bf8642..9d773fec1 100644 --- a/eo/src/do/make_continue.h +++ b/eo/src/do/make_continue.h @@ -156,7 +156,7 @@ eoContinue & 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); diff --git a/eo/src/do/make_general_replacement.h b/eo/src/do/make_general_replacement.h index 52c54ff6f..717cc668d 100644 --- a/eo/src/do/make_general_replacement.h +++ b/eo/src/do/make_general_replacement.h @@ -97,7 +97,7 @@ eoReduce & 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(p); @@ -110,7 +110,7 @@ eoReduce & 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); diff --git a/eo/src/eoCtrlCContinue.h b/eo/src/eoCtrlCContinue.h index 37b665a10..b184ffcfe 100644 --- a/eo/src/eoCtrlCContinue.h +++ b/eo/src/eoCtrlCContinue.h @@ -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 diff --git a/eo/src/eoEasyEA.h b/eo/src/eoEasyEA.h index d3fd2825a..effe81a14 100644 --- a/eo/src/eoEasyEA.h +++ b/eo/src/eoEasyEA.h @@ -261,8 +261,8 @@ template class eoEasyEA: public eoAlgo do { - try - { + // try + // { unsigned pSize = _pop.size(); offspring.clear(); // new offspring @@ -273,17 +273,17 @@ template class eoEasyEA: public eoAlgo 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 ) ); } diff --git a/eo/src/eoEasyPSO.h b/eo/src/eoEasyPSO.h index f1e00bf2a..87c27cad3 100644 --- a/eo/src/eoEasyPSO.h +++ b/eo/src/eoEasyPSO.h @@ -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); + // } } diff --git a/eo/src/eoEvalDump.h b/eo/src/eoEvalDump.h index 2f26ee327..7a7349360 100644 --- a/eo/src/eoEvalDump.h +++ b/eo/src/eoEvalDump.h @@ -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 diff --git a/eo/src/eoExceptions.h b/eo/src/eoExceptions.h index 476a064d6..b91bd6207 100644 --- a/eo/src/eoExceptions.h +++ b/eo/src/eoExceptions.h @@ -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__ diff --git a/eo/src/eoFlOrBinOp.h b/eo/src/eoFlOrBinOp.h index 343b2c738..a4f18128c 100644 --- a/eo/src/eoFlOrBinOp.h +++ b/eo/src/eoFlOrBinOp.h @@ -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); diff --git a/eo/src/eoFlOrQuadOp.h b/eo/src/eoFlOrQuadOp.h index 1c0c805fd..f887d952a 100644 --- a/eo/src/eoFlOrQuadOp.h +++ b/eo/src/eoFlOrQuadOp.h @@ -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); diff --git a/eo/src/eoG3Replacement.h b/eo/src/eoG3Replacement.h index c7cf20178..e9de717cc 100644 --- a/eo/src/eoG3Replacement.h +++ b/eo/src/eoG3Replacement.h @@ -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); diff --git a/eo/src/eoInit.h b/eo/src/eoInit.h index 9965af919..d9b4a0e30 100644 --- a/eo/src/eoInit.h +++ b/eo/src/eoInit.h @@ -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"); } diff --git a/eo/src/eoLinearTopology.h b/eo/src/eoLinearTopology.h index 027be1871..a9dff1e3c 100644 --- a/eo/src/eoLinearTopology.h +++ b/eo/src/eoLinearTopology.h @@ -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; diff --git a/eo/src/eoMGGReplacement.h b/eo/src/eoMGGReplacement.h index 1e4c40f2d..d33ff6a06 100644 --- a/eo/src/eoMGGReplacement.h +++ b/eo/src/eoMGGReplacement.h @@ -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::iterator it = _offspring.it_best_element(); diff --git a/eo/src/eoMerge.h b/eo/src/eoMerge.h index 5870849cf..1564f3977 100644 --- a/eo/src/eoMerge.h +++ b/eo/src/eoMerge.h @@ -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 result; _pop.nth_element(combienLocal, result); diff --git a/eo/src/eoNDSorting.h b/eo/src/eoNDSorting.h index b8315b458..fee6d1cb8 100644 --- a/eo/src/eoNDSorting.h +++ b/eo/src/eoNDSorting.h @@ -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()); diff --git a/eo/src/eoOneToOneBreeder.h b/eo/src/eoOneToOneBreeder.h index 587dbce19..87470e0f1 100644 --- a/eo/src/eoOneToOneBreeder.h +++ b/eo/src/eoOneToOneBreeder.h @@ -95,7 +95,7 @@ class eoOneToOneBreeder: public eoBreed // 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 diff --git a/eo/src/eoPop.h b/eo/src/eoPop.h index 9213bca5c..ed2c09ef8 100644 --- a/eo/src/eoPop.h +++ b/eo/src/eoPop.h @@ -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, 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, public eoObject, public eoPersistent typename eoPop::const_iterator it = std::max_element(begin(), end()); #endif if( it == end() ) - throw std::runtime_error("eoPop: Empty population, when calling best_element()."); + throw eoPopSizeException(this->size()); return (*it); } diff --git a/eo/src/eoProportionalSelect.h b/eo/src/eoProportionalSelect.h index 35dd3065c..8da608f6f 100644 --- a/eo/src/eoProportionalSelect.h +++ b/eo/src/eoProportionalSelect.h @@ -49,7 +49,7 @@ public: eoProportionalSelect(const eoPop& /*pop*/ = eoPop()) { if (minimizing_fitness()) - throw std::logic_error("eoProportionalSelect: minimizing fitness"); + throw eoException("eoProportionalSelect: minimizing fitness"); } void setup(const eoPop& _pop) diff --git a/eo/src/eoRandomRealWeightUp.h b/eo/src/eoRandomRealWeightUp.h index d135af93f..1adbca105 100644 --- a/eo/src/eoRandomRealWeightUp.h +++ b/eo/src/eoRandomRealWeightUp.h @@ -56,7 +56,7 @@ public: { std::string s; s.append (" min > max in eoRandomRealWeightUp"); - throw std::runtime_error (s); + throw eoException(s); } } diff --git a/eo/src/eoRanking.h b/eo/src/eoRanking.h index 65fbe87a4..63a031071 100644 --- a/eo/src/eoRanking.h +++ b/eo/src/eoRanking.h @@ -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); diff --git a/eo/src/eoReduce.h b/eo/src/eoReduce.h index c1039e47b..81c9b49a1 100644 --- a/eo/src/eoReduce.h +++ b/eo/src/eoReduce.h @@ -57,7 +57,7 @@ template class eoTruncate : public eoReduce 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 eoRandomReduce : public eoReduce 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 scores(presentSize); for (unsigned i=0; i 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::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 void operator()(eoPop& _parents, eoPop& _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); } diff --git a/eo/src/eoReduceMergeReduce.h b/eo/src/eoReduceMergeReduce.h index 0f7f0ad4c..d12a2b692 100644 --- a/eo/src/eoReduceMergeReduce.h +++ b/eo/src/eoReduceMergeReduce.h @@ -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); diff --git a/eo/src/eoReduceSplit.h b/eo/src/eoReduceSplit.h index a8640c039..b31008768 100644 --- a/eo/src/eoReduceSplit.h +++ b/eo/src/eoReduceSplit.h @@ -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(popSize) - static_cast(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( rate ); } else { - throw std::runtime_error( "Incorrect selector type" ); + throw eoException( "Incorrect selector type" ); } } return selectPtr; diff --git a/eo/src/eoSelectFromWorth.h b/eo/src/eoSelectFromWorth.h index c6ba5c1e5..bbd0380a3 100644 --- a/eo/src/eoSelectFromWorth.h +++ b/eo/src/eoSelectFromWorth.h @@ -79,7 +79,7 @@ protected: std::vector 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 diff --git a/eo/src/eoSequentialSelect.h b/eo/src/eoSequentialSelect.h index adf3cf452..53ffdd3b2 100644 --- a/eo/src/eoSequentialSelect.h +++ b/eo/src/eoSequentialSelect.h @@ -134,7 +134,7 @@ template class eoEliteSequentialSelect: public eoSelectOne 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) { diff --git a/eo/src/eoSharing.h b/eo/src/eoSharing.h index fa7583030..824bb20a4 100644 --- a/eo/src/eoSharing.h +++ b/eo/src/eoSharing.h @@ -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 sim(pSize); // to hold the similarities dMatrix distMatrix(pSize); // to hold the distances diff --git a/eo/src/eoSimpleEDA.h b/eo/src/eoSimpleEDA.h index 0704b5722..ac815e1b7 100644 --- a/eo/src/eoSimpleEDA.h +++ b/eo/src/eoSimpleEDA.h @@ -73,21 +73,21 @@ template class eoSimpleEDA: public eoEDA eoPop pop(popSize, _distrib); do { - try - { + // try + // { apply(_distrib, pop); // re-init. of _pop from distrib apply(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 ) ); } diff --git a/eo/src/eoSocialNeighborhood.h b/eo/src/eoSocialNeighborhood.h index 3f46b4a4e..315d105e8 100644 --- a/eo/src/eoSocialNeighborhood.h +++ b/eo/src/eoSocialNeighborhood.h @@ -94,7 +94,7 @@ public: else{ std::string s; s.append (" Invalid indice in eoSocialNeighborhood "); - throw std::runtime_error (s); + throw eoException(s); } } diff --git a/eo/src/eoStochasticUniversalSelect.h b/eo/src/eoStochasticUniversalSelect.h index 956bf62c7..e95f9eb0b 100644 --- a/eo/src/eoStochasticUniversalSelect.h +++ b/eo/src/eoStochasticUniversalSelect.h @@ -47,7 +47,7 @@ public: eoStochasticUniversalSelect(const eoPop& pop = eoPop()) { if (minimizing_fitness()) - throw std::logic_error("eoStochasticUniversalSelect: minimizing fitness"); + throw eoException("eoStochasticUniversalSelect: minimizing fitness"); } void setup(const eoPop& _pop) diff --git a/eo/src/eoSurviveAndDie.h b/eo/src/eoSurviveAndDie.h index 2ca4a3833..3e36ce54e 100644 --- a/eo/src/eoSurviveAndDie.h +++ b/eo/src/eoSurviveAndDie.h @@ -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 diff --git a/eo/src/eoSwapMutation.h b/eo/src/eoSwapMutation.h index 58d3cf604..33d04ac8d 100644 --- a/eo/src/eoSwapMutation.h +++ b/eo/src/eoSwapMutation.h @@ -46,7 +46,7 @@ template class eoSwapMutation: public eoMonOp { // 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. diff --git a/eo/src/eoSyncEasyPSO.h b/eo/src/eoSyncEasyPSO.h index 64cf64724..11640af53 100644 --- a/eo/src/eoSyncEasyPSO.h +++ b/eo/src/eoSyncEasyPSO.h @@ -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); + // } } diff --git a/eo/src/es/eoNormalMutation.h b/eo/src/es/eoNormalMutation.h index 48d09c6d5..266b10103 100644 --- a/eo/src/es/eoNormalMutation.h +++ b/eo/src/es/eoNormalMutation.h @@ -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 */ diff --git a/eo/src/es/eoRealInitBounded.h b/eo/src/es/eoRealInitBounded.h index fa0259ec4..a011484a7 100644 --- a/eo/src/es/eoRealInitBounded.h +++ b/eo/src/es/eoRealInitBounded.h @@ -47,7 +47,7 @@ class eoRealInitBounded : public eoInit eoRealInitBounded(eoRealVectorBounds & _bounds):bounds(_bounds) { if (!bounds.isBounded()) - throw std::runtime_error("Needs bounded bounds to initialize a std::vector"); + throw eoException("Needs bounded bounds to initialize a std::vector"); } /** simply passes the argument to the uniform method of the bounds */ diff --git a/eo/src/es/eoRealOp.h b/eo/src/es/eoRealOp.h index 64b64101d..8c957413d 100644 --- a/eo/src/es/eoRealOp.h +++ b/eo/src/es/eoRealOp.h @@ -111,7 +111,7 @@ template class eoUniformMutation: public eoMonOp { // 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 eoDetUniformMutation: public eoMonOp { // 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 class eoHypercubeCrossover: public eoQuadOp 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 eoHypercubeCrossover: public eoQuadOp 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. diff --git a/eo/src/es/make_algo_scalar_es.cpp b/eo/src/es/make_algo_scalar_es.cpp index e1bd1fb9d..3216a2f01 100644 --- a/eo/src/es/make_algo_scalar_es.cpp +++ b/eo/src/es/make_algo_scalar_es.cpp @@ -51,34 +51,34 @@ // Algo /////// -eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op, eoDistance >* _dist) +eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op, eoDistance >* /*_dist*/) { return do_make_algo_scalar(_parser, _state, _eval, _continue, _op); } -eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op, eoDistance >* _dist) +eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op, eoDistance >* /*_dist*/) { return do_make_algo_scalar(_parser, _state, _eval, _continue, _op); } ////////////// -eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op, eoDistance >* _dist) +eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op, eoDistance >* /*_dist*/) { return do_make_algo_scalar(_parser, _state, _eval, _continue, _op); } -eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op, eoDistance >* _dist) +eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op, eoDistance >* /*_dist*/) { return do_make_algo_scalar(_parser, _state, _eval, _continue, _op); } /////////////// -eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op, eoDistance >* _dist) +eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op, eoDistance >* /*_dist*/) { return do_make_algo_scalar(_parser, _state, _eval, _continue, _op); } -eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op, eoDistance >* _dist) +eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op, eoDistance >* /*_dist*/) { return do_make_algo_scalar(_parser, _state, _eval, _continue, _op); } diff --git a/eo/src/es/make_genotype_real.h b/eo/src/es/make_genotype_real.h index 82b07db8f..7f86e6720 100644 --- a/eo/src/es/make_genotype_real.h +++ b/eo/src/es/make_genotype_real.h @@ -98,7 +98,7 @@ eoEsChromInit & 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(boundsParam.value(), sigma, to_scale); else { diff --git a/eo/src/es/make_op.h b/eo/src/es/make_op.h index 35767b5df..b53022bfe 100644 --- a/eo/src/es/make_op.h +++ b/eo/src/es/make_op.h @@ -107,7 +107,7 @@ eoGenOp & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit proportional choice @@ -138,14 +138,14 @@ eoGenOp & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit 1) ) - throw std::runtime_error("Invalid pCross"); + throw eoParamException("Invalid pCross"); eoValueParam& 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 & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit& arithmeticRateParam = _parser.getORcreateParam(double(2.0), "arithmeticRate", @@ -164,7 +164,7 @@ eoGenOp & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit & 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 & detMutRateParam = _parser.getORcreateParam(1.0, "detMutRate", @@ -217,7 +217,7 @@ eoGenOp & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit & normalMutRateParam = _parser.getORcreateParam(1.0, "normalMutRate", @@ -225,7 +225,7 @@ eoGenOp & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit & sigmaParam = _parser.getORcreateParam(1.0, "sigma", @@ -233,7 +233,7 @@ eoGenOp & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit *ptCombinedMonOp = NULL; diff --git a/eo/src/es/make_op_es.h b/eo/src/es/make_op_es.h index 0b78a724f..d52669489 100644 --- a/eo/src/es/make_op_es.h +++ b/eo/src/es/make_op_es.h @@ -88,7 +88,7 @@ eoGenOp & 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 & 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& 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 & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded< ptObjAtomCross = new eoDoubleIntermediate; else if (crossObjParam.value() == std::string("none")) ptObjAtomCross = new eoBinCloneOp; - 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 & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded< ptStdevAtomCross = new eoDoubleIntermediate; else if (crossStdevParam.value() == std::string("none")) ptStdevAtomCross = new eoBinCloneOp; - 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 & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded< ); ptCross = new eoBinGenOp(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); diff --git a/eo/src/es/make_op_real.h b/eo/src/es/make_op_real.h index 198483a5a..0c202d767 100644 --- a/eo/src/es/make_op_real.h +++ b/eo/src/es/make_op_real.h @@ -89,7 +89,7 @@ eoGenOp & 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 & 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& pMutParam = _parser.getORcreateParam(0.1, "pMut", @@ -111,7 +111,7 @@ eoGenOp & 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 & 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& segmentRateParam @@ -131,7 +131,7 @@ eoGenOp & 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& hypercubeRateParam = _parser.getORcreateParam(double(1.0), "hypercubeRate", @@ -139,7 +139,7 @@ eoGenOp & 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& uxoverRateParam = _parser.getORcreateParam(double(1.0), "uxoverRate", @@ -147,7 +147,7 @@ eoGenOp & 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 & 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 & uniformMutRateParam = _parser.getORcreateParam(1.0, "uniformMutRate", @@ -199,7 +199,7 @@ eoGenOp & 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 & detMutRateParam = _parser.getORcreateParam(1.0, "detMutRate", @@ -207,14 +207,14 @@ eoGenOp & 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 & 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 & sigmaParam = _parser.getORcreateParam(0.3, "sigma", @@ -234,7 +234,7 @@ eoGenOp & 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 *ptCombinedMonOp = NULL; diff --git a/eo/src/ga/make_PBILupdate.h b/eo/src/ga/make_PBILupdate.h index 34a062a96..43a04dd88 100644 --- a/eo/src/ga/make_PBILupdate.h +++ b/eo/src/ga/make_PBILupdate.h @@ -69,7 +69,7 @@ eoDistribUpdater & do_make_PBILupdate(eoParser & _parser, eoState& _state, ptUpdate = new eoPBILAdditive(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); diff --git a/eo/src/ga/make_op.h b/eo/src/ga/make_op.h index b8993f312..afe5a5bc9 100644 --- a/eo/src/ga/make_op.h +++ b/eo/src/ga/make_op.h @@ -78,7 +78,7 @@ eoGenOp & do_make_op(eoParser& _parser, eoState& _state, eoInit& _init eoValueParam& 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 & do_make_op(eoParser& _parser, eoState& _state, eoInit& _init eoValueParam& 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& 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 & do_make_op(eoParser& _parser, eoState& _state, eoInit& _init eoValueParam& 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& 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& 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 & do_make_op(eoParser& _parser, eoState& _state, eoInit& _init eoValueParam & 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 & 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 & 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 & 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 & 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 ? diff --git a/eo/src/gp/eoParseTreeDepthInit.h b/eo/src/gp/eoParseTreeDepthInit.h index 6abe2e4ff..ba1cf1f5a 100644 --- a/eo/src/gp/eoParseTreeDepthInit.h +++ b/eo/src/gp/eoParseTreeDepthInit.h @@ -81,7 +81,7 @@ class eoParseTreeDepthInit : public eoInit< eoParseTree > { 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 diff --git a/eo/src/gp/eoStParseTreeDepthInit.h b/eo/src/gp/eoStParseTreeDepthInit.h index aa7247dd8..54764b1b6 100644 --- a/eo/src/gp/eoStParseTreeDepthInit.h +++ b/eo/src/gp/eoStParseTreeDepthInit.h @@ -87,7 +87,7 @@ class eoStParseTreeDepthInit : public eoInit< eoParseTree > { 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?"); } diff --git a/eo/src/mpi/eoParallelApply.h b/eo/src/mpi/eoParallelApply.h index dfb66e027..c85e5f7a8 100644 --- a/eo/src/mpi/eoParallelApply.h +++ b/eo/src/mpi/eoParallelApply.h @@ -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 ) diff --git a/eo/src/pyeo/PyEO.cpp b/eo/src/pyeo/PyEO.cpp index 8517c9aad..f29f13230 100644 --- a/eo/src/pyeo/PyEO.cpp +++ b/eo/src/pyeo/PyEO.cpp @@ -115,13 +115,13 @@ PyEO& pop_getitem(eoPop& pop, boost::python::object key) { boost::python::extract x(key); if (!x.check()) - throw index_error("Slicing not allowed"); + throw eoException("Slicing not allowed"); int i = x(); if (static_cast(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& pop, boost::python::object key, PyEO& value) { boost::python::extract x(key); if (!x.check()) - throw index_error("Slicing not allowed"); + throw eoException("Slicing not allowed"); int i = x(); if (static_cast(i) >= pop.size()) { - throw index_error("Index out of bounds"); + throw eoException("Index out of bounds"); } pop[i] = value; diff --git a/eo/src/pyeo/PyEO.h b/eo/src/pyeo/PyEO.h index e9452800e..ba5cabd38 100644 --- a/eo/src/pyeo/PyEO.h +++ b/eo/src/pyeo/PyEO.h @@ -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 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(); } diff --git a/eo/src/pyeo/monitors.cpp b/eo/src/pyeo/monitors.cpp index f64881659..814a4c859 100644 --- a/eo/src/pyeo/monitors.cpp +++ b/eo/src/pyeo/monitors.cpp @@ -42,7 +42,7 @@ public: { if (static_cast(i) >= vec.size()) { - throw index_error("Index out of bounds"); + throw eoException("Index out of bounds"); } return vec[i]->getValue(); diff --git a/eo/src/pyeo/statistics.cpp b/eo/src/pyeo/statistics.cpp index e48b6f2fa..df7504b51 100644 --- a/eo/src/pyeo/statistics.cpp +++ b/eo/src/pyeo/statistics.cpp @@ -35,7 +35,7 @@ const PyEO& popview_getitem(const std::vector& pop, int it) { unsigned item = unsigned(it); if (item > pop.size()) - throw index_error("too much"); + throw eoException("too much"); return *pop[item]; } diff --git a/eo/src/pyeo/valueParam.cpp b/eo/src/pyeo/valueParam.cpp index 6e4b06218..3d1a867e2 100644 --- a/eo/src/pyeo/valueParam.cpp +++ b/eo/src/pyeo/valueParam.cpp @@ -109,7 +109,7 @@ void setv< std::vector, numeric::array > { extract 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, tuple > extract 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(); diff --git a/eo/src/utils/eoAssembledFitnessStat.h b/eo/src/utils/eoAssembledFitnessStat.h index 43e922f3f..c9cd7d464 100644 --- a/eo/src/utils/eoAssembledFitnessStat.h +++ b/eo/src/utils/eoAssembledFitnessStat.h @@ -63,7 +63,7 @@ public : virtual void operator()(const eoPop& _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& _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]; } diff --git a/eo/src/utils/eoFDCStat.h b/eo/src/utils/eoFDCStat.h index 69ce60072..75a49674a 100644 --- a/eo/src/utils/eoFDCStat.h +++ b/eo/src/utils/eoFDCStat.h @@ -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 & FDCstat; diff --git a/eo/src/utils/eoFileMonitor.cpp b/eo/src/utils/eoFileMonitor.cpp index e1e58ba21..d504305a8 100644 --- a/eo/src/utils/eoFileMonitor.cpp +++ b/eo/src/utils/eoFileMonitor.cpp @@ -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 ( diff --git a/eo/src/utils/eoFileMonitor.h b/eo/src/utils/eoFileMonitor.h index 0d23dcbf5..9711d7dcf 100644 --- a/eo/src/utils/eoFileMonitor.h +++ b/eo/src/utils/eoFileMonitor.h @@ -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 } diff --git a/eo/src/utils/eoFileSnapshot.h b/eo/src/utils/eoFileSnapshot.h index c474a9293..3c7095894 100644 --- a/eo/src/utils/eoFileSnapshot.h +++ b/eo/src/utils/eoFileSnapshot.h @@ -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 >* >(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 >*>(&_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); } diff --git a/eo/src/utils/eoGnuplot.cpp b/eo/src/utils/eoGnuplot.cpp index 2905e6161..2a7fe5229 100644 --- a/eo/src/utils/eoGnuplot.cpp +++ b/eo/src/utils/eoGnuplot.cpp @@ -29,6 +29,7 @@ #include #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() ); diff --git a/eo/src/utils/eoGnuplot1DMonitor.cpp b/eo/src/utils/eoGnuplot1DMonitor.cpp index ab54b1132..d63d19994 100644 --- a/eo/src/utils/eoGnuplot1DMonitor.cpp +++ b/eo/src/utils/eoGnuplot1DMonitor.cpp @@ -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; diff --git a/eo/src/utils/eoHowMany.h b/eo/src/utils/eoHowMany.h index 56c730f17..780439851 100644 --- a/eo/src/utils/eoHowMany.h +++ b/eo/src/utils/eoHowMany.h @@ -119,7 +119,7 @@ public: { unsigned int combloc = -count; if (_size= _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 diff --git a/eo/src/utils/eoIntBounds.h b/eo/src/utils/eoIntBounds.h index 924d0e022..73b18548e 100644 --- a/eo/src/utils/eoIntBounds.h +++ b/eo/src/utils/eoIntBounds.h @@ -29,6 +29,7 @@ #include // 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"); } /** diff --git a/eo/src/utils/eoOStreamMonitor.cpp b/eo/src/utils/eoOStreamMonitor.cpp index af2bfcf63..b55cebf17 100644 --- a/eo/src/utils/eoOStreamMonitor.cpp +++ b/eo/src/utils/eoOStreamMonitor.cpp @@ -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) { diff --git a/eo/src/utils/eoParam.h b/eo/src/utils/eoParam.h index d2c39efbd..969ea00a8 100644 --- a/eo/src/utils/eoParam.h +++ b/eo/src/utils/eoParam.h @@ -34,6 +34,7 @@ #include #include #include "../eoScalarFitness.h" +#include "../eoExceptions.h" /** @defgroup Parameters Parameters management * @@ -385,14 +386,14 @@ inline void eoValueParam >::setValue(const std: template <> inline std::string eoValueParam >::getValue(void) const { - throw std::runtime_error("I cannot getValue for a std::vector"); + throw eoException("I cannot getValue for a std::vector"); return std::string(""); } template <> inline void eoValueParam >::setValue(const std::string&) { - throw std::runtime_error("I cannot setValue for a std::vector"); + throw eoException("I cannot setValue for a std::vector"); return; } diff --git a/eo/src/utils/eoParser.cpp b/eo/src/utils/eoParser.cpp index 15a66105a..dc615bfa1 100644 --- a/eo/src/utils/eoParser.cpp +++ b/eo/src/utils/eoParser.cpp @@ -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); diff --git a/eo/src/utils/eoRealBounds.cpp b/eo/src/utils/eoRealBounds.cpp index 89dcb3584..bb3ac11a5 100644 --- a/eo/src/utils/eoRealBounds.cpp +++ b/eo/src/utils/eoRealBounds.cpp @@ -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 diff --git a/eo/src/utils/eoRealBounds.h b/eo/src/utils/eoRealBounds.h index 5d28c1741..c76031846 100644 --- a/eo/src/utils/eoRealBounds.h +++ b/eo/src/utils/eoRealBounds.h @@ -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"); } /** diff --git a/eo/src/utils/eoRealVectorBounds.h b/eo/src/utils/eoRealVectorBounds.h index 7fb880f53..d877853c2 100644 --- a/eo/src/utils/eoRealVectorBounds.h +++ b/eo/src/utils/eoRealVectorBounds.h @@ -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"); } }; diff --git a/eo/src/utils/eoRndGenerators.h b/eo/src/utils/eoRndGenerators.h index 454845b17..d70143ff6 100644 --- a/eo/src/utils/eoRndGenerators.h +++ b/eo/src/utils/eoRndGenerators.h @@ -29,6 +29,7 @@ #ifndef eoRndGenerators_h #define eoRndGenerators_h +#include "../eoExceptions.h" #include "eoRNG.h" #include "../eoFunctor.h" #include @@ -80,7 +81,7 @@ template class eoUniformGenerator : public eoRndGenerator 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"); } /** diff --git a/eo/src/utils/eoStat.h b/eo/src/utils/eoStat.h index 5610ecbee..9803f66cd 100644 --- a/eo/src/utils/eoStat.h +++ b/eo/src/utils/eoStat.h @@ -251,7 +251,7 @@ public : virtual void operator()(const std::vector& _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()); } diff --git a/eo/src/utils/eoState.cpp b/eo/src/utils/eoState.cpp index 884549244..0b70f533a 100644 --- a/eo/src/utils/eoState.cpp +++ b/eo/src/utils/eoState.cpp @@ -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); diff --git a/eo/src/utils/eoUniformInit.h b/eo/src/utils/eoUniformInit.h index 8f4cd9d86..d338b2d78 100644 --- a/eo/src/utils/eoUniformInit.h +++ b/eo/src/utils/eoUniformInit.h @@ -82,7 +82,7 @@ template class eoUniformInit : public eoInit 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"); } /** diff --git a/eo/src/utils/make_help.cpp b/eo/src/utils/make_help.cpp index 6fb797eea..26644ea02 100644 --- a/eo/src/utils/make_help.cpp +++ b/eo/src/utils/make_help.cpp @@ -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; } diff --git a/eo/src/utils/rnd_generators.h b/eo/src/utils/rnd_generators.h index d71caf803..60ff04b3f 100644 --- a/eo/src/utils/rnd_generators.h +++ b/eo/src/utils/rnd_generators.h @@ -31,6 +31,7 @@ #ifndef eoRND_GENERATORS_H #define eoRND_GENERATORS_H +#include "../eoExceptions.h" #include "eoRNG.h" #include @@ -56,7 +57,7 @@ template 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(uniform.uniform(range)); } @@ -99,7 +100,7 @@ template 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)); } diff --git a/eo/src/utils/selectors.h b/eo/src/utils/selectors.h index 43992ac3c..8805fb132 100644 --- a/eo/src/utils/selectors.h +++ b/eo/src/utils/selectors.h @@ -89,7 +89,7 @@ double sum_fitness(It begin, It end) { double v = static_cast(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; } diff --git a/eo/test/fitness_traits.cpp b/eo/test/fitness_traits.cpp index 4af0e34bb..2db7ea88f 100644 --- a/eo/test/fitness_traits.cpp +++ b/eo/test/fitness_traits.cpp @@ -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"); } } diff --git a/eo/test/mpi/t-mpi-distrib-exp.cpp b/eo/test/mpi/t-mpi-distrib-exp.cpp index 46a4efa57..d3278fcad 100644 --- a/eo/test/mpi/t-mpi-distrib-exp.cpp +++ b/eo/test/mpi/t-mpi-distrib-exp.cpp @@ -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 ); diff --git a/eo/test/mpi/t-mpi-multipleRoles.cpp b/eo/test/mpi/t-mpi-multipleRoles.cpp index 3a525126b..e0ca7ed68 100644 --- a/eo/test/mpi/t-mpi-multipleRoles.cpp +++ b/eo/test/mpi/t-mpi-multipleRoles.cpp @@ -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 > v; diff --git a/eo/test/mpi/t-mpi-parallelApply.cpp b/eo/test/mpi/t-mpi-parallelApply.cpp index 559505bd1..efe8b2364 100644 --- a/eo/test/mpi/t-mpi-parallelApply.cpp +++ b/eo/test/mpi/t-mpi-parallelApply.cpp @@ -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" diff --git a/eo/test/t-eoESFull.cpp b/eo/test/t-eoESFull.cpp index 7c5e84d99..d2f84adfb 100644 --- a/eo/test/t-eoESFull.cpp +++ b/eo/test/t-eoESFull.cpp @@ -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 diff --git a/eo/test/t-eoGenOp.cpp b/eo/test/t-eoGenOp.cpp index c959a3bb9..7a6f6b7bc 100644 --- a/eo/test/t-eoGenOp.cpp +++ b/eo/test/t-eoGenOp.cpp @@ -174,7 +174,7 @@ void init(eoPop & _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++) { diff --git a/eo/test/t-eoInitPermutation.cpp b/eo/test/t-eoInitPermutation.cpp index e4a683b15..4b64f3576 100644 --- a/eo/test/t-eoInitPermutation.cpp +++ b/eo/test/t-eoInitPermutation.cpp @@ -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; } diff --git a/eo/test/t-eoOrderXover.cpp b/eo/test/t-eoOrderXover.cpp index 32e44dad9..71453c59b 100644 --- a/eo/test/t-eoOrderXover.cpp +++ b/eo/test/t-eoOrderXover.cpp @@ -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; } } diff --git a/eo/test/t-eoSelect.cpp b/eo/test/t-eoSelect.cpp index 23d76c48c..400f6725d 100644 --- a/eo/test/t-eoSelect.cpp +++ b/eo/test/t-eoSelect.cpp @@ -64,7 +64,7 @@ void testSelectMany(eoSelect & _select, std::string _name) { unsigned trouve = isInPop(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 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; diff --git a/eo/test/t-eoSharing.cpp b/eo/test/t-eoSharing.cpp index 86721b098..fee072b75 100644 --- a/eo/test/t-eoSharing.cpp +++ b/eo/test/t-eoSharing.cpp @@ -86,7 +86,7 @@ void testSelectMany(eoSelect & _select, std::string _name) { unsigned trouve = isInPop(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! diff --git a/eo/test/t-eoShiftMutation.cpp b/eo/test/t-eoShiftMutation.cpp index 15c4e6b92..2106233d1 100644 --- a/eo/test/t-eoShiftMutation.cpp +++ b/eo/test/t-eoShiftMutation.cpp @@ -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; } } diff --git a/eo/test/t-eoSwapMutation.cpp b/eo/test/t-eoSwapMutation.cpp index 3099d7075..38601fd2d 100644 --- a/eo/test/t-eoSwapMutation.cpp +++ b/eo/test/t-eoSwapMutation.cpp @@ -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; } } diff --git a/eo/test/t-eoTwoOptMutation.cpp b/eo/test/t-eoTwoOptMutation.cpp index 60ef89a15..7d53b77d4 100644 --- a/eo/test/t-eoTwoOptMutation.cpp +++ b/eo/test/t-eoTwoOptMutation.cpp @@ -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; } } diff --git a/eo/tutorial/Lesson5/make_op_OneMax.h b/eo/tutorial/Lesson5/make_op_OneMax.h index e157720fa..d8c5ed853 100644 --- a/eo/tutorial/Lesson5/make_op_OneMax.h +++ b/eo/tutorial/Lesson5/make_op_OneMax.h @@ -182,12 +182,12 @@ eoGenOp & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit& 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& 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 diff --git a/eo/tutorial/Templates/EO.tpl b/eo/tutorial/Templates/EO.tpl index 959ad56a8..b5cd2a162 100644 --- a/eo/tutorial/Templates/EO.tpl +++ b/eo/tutorial/Templates/EO.tpl @@ -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 op(cross, pCross, mut, pMut); @@ -827,7 +827,7 @@ eoContinue & 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); diff --git a/eo/tutorial/Templates/MyStructSEA.cpp b/eo/tutorial/Templates/MyStructSEA.cpp index 5a05169ea..30dd296f0 100644 --- a/eo/tutorial/Templates/MyStructSEA.cpp +++ b/eo/tutorial/Templates/MyStructSEA.cpp @@ -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 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) diff --git a/eo/tutorial/Templates/make_op_MyStruct.h b/eo/tutorial/Templates/make_op_MyStruct.h index d857e8958..e37dfd6fd 100644 --- a/eo/tutorial/Templates/make_op_MyStruct.h +++ b/eo/tutorial/Templates/make_op_MyStruct.h @@ -182,12 +182,12 @@ eoGenOp & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit& 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& 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 diff --git a/mo/src/continuator/moVectorMonitor.h b/mo/src/continuator/moVectorMonitor.h index 853096448..67535219d 100644 --- a/mo/src/continuator/moVectorMonitor.h +++ b/mo/src/continuator/moVectorMonitor.h @@ -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++) { diff --git a/mo/src/problems/bitString/moBitNeighbor.h b/mo/src/problems/bitString/moBitNeighbor.h index 28cda0093..87f124c44 100644 --- a/mo/src/problems/bitString/moBitNeighbor.h +++ b/mo/src/problems/bitString/moBitNeighbor.h @@ -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); diff --git a/mo/src/sampling/moSampling.h b/mo/src/sampling/moSampling.h index c2db1fa73..90dee4707 100644 --- a/mo/src/sampling/moSampling.h +++ b/mo/src/sampling/moSampling.h @@ -156,8 +156,8 @@ public: os.open(_filename.c_str(), std::ios::app); if (!os) { - std::string str = "moSampling: Could not open " + _filename; - throw std::runtime_error(str); + // std::string str = "moSampling: Could not open " + _filename; + throw eoFileError(_filename); } // set the precision of the output @@ -199,7 +199,7 @@ public: void fileExport(unsigned int _col, std::string _filename, bool _openFile=false) { if (_col >= monitorVec.size()) { std::string str = "moSampling: Could not export into file the vector. The index does not exists (too large)"; - throw std::runtime_error(str); + throw eoException(str); } monitorVec[_col]->precision(precisionOutput); diff --git a/moeo/src/CMakeLists.txt b/moeo/src/CMakeLists.txt index c06351346..e98d91e4e 100644 --- a/moeo/src/CMakeLists.txt +++ b/moeo/src/CMakeLists.txt @@ -1,7 +1,7 @@ ###################################################################################### ### 0) Include directories ###################################################################################### -include_directories(${EO_SRC_DIR}) +include_directories(${EO_SRC_DIR}/src) include_directories(${MO_SRC_DIR}/src) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/moeo/src/algo/moeoEasyEA.h b/moeo/src/algo/moeoEasyEA.h index 8155bfaaa..5169b3c0a 100644 --- a/moeo/src/algo/moeoEasyEA.h +++ b/moeo/src/algo/moeoEasyEA.h @@ -132,8 +132,8 @@ public: bool firstTime = true; do { - try - { + // try + // { unsigned int pSize = _pop.size(); offspring.clear(); // new offspring // fitness and diversity assignment (if you want to or if it is the first generation) @@ -150,19 +150,19 @@ public: replace(_pop, offspring); // after replace, the new pop. is in _pop if (pSize > _pop.size()) { - throw std::runtime_error("Population shrinking!"); + throw eoPopSizeChangeException(_pop.size(), pSize,"Population shrinking!"); } else if (pSize < _pop.size()) { - throw std::runtime_error("Population growing!"); + throw eoPopSizeChangeException(_pop.size(), pSize,"Population growing!"); } - } - catch (std::exception& e) - { - std::string s = e.what(); - s.append( " in moeoEasyEA"); - throw std::runtime_error( s ); - } + // } + // catch (std::exception& e) + // { + // std::string s = e.what(); + // s.append( " in moeoEasyEA"); + // throw std::runtime_error( s ); + // } } while (continuator(_pop)); } diff --git a/moeo/src/comparator/moeoOneObjectiveComparator.h b/moeo/src/comparator/moeoOneObjectiveComparator.h index 32b7ca093..f3543853f 100644 --- a/moeo/src/comparator/moeoOneObjectiveComparator.h +++ b/moeo/src/comparator/moeoOneObjectiveComparator.h @@ -56,7 +56,7 @@ class moeoOneObjectiveComparator : public moeoComparator < MOEOT > { if (obj > MOEOT::ObjectiveVector::nObjectives()) { - throw std::runtime_error("Problem with the index of objective in moeoOneObjectiveComparator"); + throw eoException("Problem with the index of objective in moeoOneObjectiveComparator"); } } diff --git a/moeo/src/core/MOEO.h b/moeo/src/core/MOEO.h index 1a9e1b118..061af300f 100644 --- a/moeo/src/core/MOEO.h +++ b/moeo/src/core/MOEO.h @@ -133,7 +133,7 @@ class MOEO : public EO < MOEOObjectiveVector > { if ( invalidObjectiveVector() ) { - throw std::runtime_error("invalid objective vector in MOEO"); + throw eoInvalidFitnessError("invalid objective vector in MOEO"); } return objectiveVectorValue; } @@ -197,7 +197,7 @@ class MOEO : public EO < MOEOObjectiveVector > { if ( invalidFitness() ) { - throw std::runtime_error("invalid fitness in MOEO"); + throw eoInvalidFitnessError("invalid fitness in MOEO"); } // const_cast< Fitness& >( fitnessValue ).embededDataEx = objectiveVectorValue; @@ -241,7 +241,7 @@ class MOEO : public EO < MOEOObjectiveVector > { if ( invalidDiversity() ) { - throw std::runtime_error("invalid diversity in MOEO"); + throw eoInvalidFitnessError("invalid diversity in MOEO"); } return diversityValue; } diff --git a/moeo/src/core/moeoObjectiveVectorTraits.h b/moeo/src/core/moeoObjectiveVectorTraits.h index bf169371c..517e7bd04 100644 --- a/moeo/src/core/moeoObjectiveVectorTraits.h +++ b/moeo/src/core/moeoObjectiveVectorTraits.h @@ -42,6 +42,8 @@ #include #include +#include + /** * A traits class for moeoObjectiveVector to specify the number of objectives and which ones have to be minimized or maximized. */ @@ -70,7 +72,7 @@ class moeoObjectiveVectorTraits bObj = _bObjectives; // in case the number of objectives and the min/max vector size don't match if (nObj != bObj.size()) - throw std::runtime_error("Number of objectives and min/max size don't match in moeoObjectiveVectorTraits::setup"); + throw eoException("Number of objectives and min/max size don't match in moeoObjectiveVectorTraits::setup"); } @@ -81,7 +83,7 @@ class moeoObjectiveVectorTraits { // in case the number of objectives would not be assigned yet if (! nObj) - throw std::runtime_error("Number of objectives not assigned in moeoObjectiveVectorTraits"); + throw eoException("Number of objectives not assigned in moeoObjectiveVectorTraits"); return nObj; } @@ -94,7 +96,7 @@ class moeoObjectiveVectorTraits { // in case there would be a wrong index if (_i >= bObj.size()) - throw std::runtime_error("Wrong index in moeoObjectiveVectorTraits"); + throw eoException("Wrong index in moeoObjectiveVectorTraits"); return bObj[_i]; } diff --git a/moeo/src/core/moeoVector.h b/moeo/src/core/moeoVector.h index ea4bfc4e0..cf89186df 100644 --- a/moeo/src/core/moeoVector.h +++ b/moeo/src/core/moeoVector.h @@ -89,7 +89,7 @@ class moeoVector : public MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity } else { - throw std::runtime_error("Size not initialized in moeoVector"); + throw eoException("Size not initialized in moeoVector"); } } std::copy(_v.begin(), _v.end(), begin()); diff --git a/moeo/src/do/make_continue_moeo.h b/moeo/src/do/make_continue_moeo.h index 84695d7ee..0267ca77a 100644 --- a/moeo/src/do/make_continue_moeo.h +++ b/moeo/src/do/make_continue_moeo.h @@ -121,7 +121,7 @@ eoContinue & do_make_continue_moeo(eoParser& _parser, eoState& _state, eo #endif // 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); // and return diff --git a/moeo/src/do/make_ea_moeo.h b/moeo/src/do/make_ea_moeo.h index aa5a38ad9..aee4dcd0d 100644 --- a/moeo/src/do/make_ea_moeo.h +++ b/moeo/src/do/make_ea_moeo.h @@ -127,14 +127,14 @@ moeoEA < MOEOT > & do_make_ea_moeo(eoParser & _parser, eoState & _state, eoEvalF else { std::string stmp = std::string("Invalid binary quality indicator: ") + indicatorParam; - throw std::runtime_error(stmp.c_str()); + throw eoException(stmp.c_str()); } fitnessAssignment = new moeoExpBinaryIndicatorBasedFitnessAssignment < MOEOT > (*metric, kappa); } else { std::string stmp = std::string("Invalid fitness assignment strategy: ") + fitnessParam; - throw std::runtime_error(stmp.c_str()); + throw eoException(stmp.c_str()); } _state.storeFunctor(fitnessAssignment); @@ -170,7 +170,7 @@ moeoEA < MOEOT > & do_make_ea_moeo(eoParser & _parser, eoState & _state, eoEvalF else { std::string stmp = std::string("Invalid diversity assignment strategy: ") + diversityParamValue.first; - throw std::runtime_error(stmp.c_str()); + throw eoException(stmp.c_str()); } _state.storeFunctor(diversityAssignment); @@ -194,7 +194,7 @@ moeoEA < MOEOT > & do_make_ea_moeo(eoParser & _parser, eoState & _state, eoEvalF else { std::string stmp = std::string("Invalid comparator strategy: ") + comparatorParam; - throw std::runtime_error(stmp.c_str()); + throw eoException(stmp.c_str()); } _state.storeFunctor(comparator); @@ -250,7 +250,7 @@ moeoEA < MOEOT > & do_make_ea_moeo(eoParser & _parser, eoState & _state, eoEvalF else { std::string stmp = std::string("Invalid selection strategy: ") + ppSelect.first; - throw std::runtime_error(stmp.c_str()); + throw eoException(stmp.c_str()); } _state.storeFunctor(select); @@ -274,7 +274,7 @@ moeoEA < MOEOT > & do_make_ea_moeo(eoParser & _parser, eoState & _state, eoEvalF else { std::string stmp = std::string("Invalid replacement strategy: ") + replacementParam; - throw std::runtime_error(stmp.c_str()); + throw eoException(stmp.c_str()); } _state.storeFunctor(replace); diff --git a/moeo/src/fitness/moeoDominanceDepthFitnessAssignment.h b/moeo/src/fitness/moeoDominanceDepthFitnessAssignment.h index c781b9a92..96f295be4 100644 --- a/moeo/src/fitness/moeoDominanceDepthFitnessAssignment.h +++ b/moeo/src/fitness/moeoDominanceDepthFitnessAssignment.h @@ -103,7 +103,7 @@ public: else { // problem with the number of objectives - throw std::runtime_error("Problem with the number of objectives in moeoDominanceDepthFitnessAssignment"); + throw eoInvalidFitnessError("Problem with the number of objectives in moeoDominanceDepthFitnessAssignment"); } // a higher fitness is better, so the values need to be inverted double max = _pop[0].fitness(); diff --git a/moeo/src/scalarStuffs/explorer/moeoHCMoveLoopExpl.h b/moeo/src/scalarStuffs/explorer/moeoHCMoveLoopExpl.h index 79f1b8003..83dd5f737 100644 --- a/moeo/src/scalarStuffs/explorer/moeoHCMoveLoopExpl.h +++ b/moeo/src/scalarStuffs/explorer/moeoHCMoveLoopExpl.h @@ -89,7 +89,7 @@ class moeoHCMoveLoopExpl:public moMoveLoopExpl < M > if( _old_solution.invalid() ) { - throw std::runtime_error("[moHCMoveLoopExpl.h]: The current solution has not been evaluated."); + throw eoInvalidFitnessError("[moHCMoveLoopExpl.h]: The current solution has not been evaluated."); } /* diff --git a/moeo/src/scalarStuffs/explorer/moeoTSMoveLoopExpl.h b/moeo/src/scalarStuffs/explorer/moeoTSMoveLoopExpl.h index 0f51d2a96..3485184fe 100644 --- a/moeo/src/scalarStuffs/explorer/moeoTSMoveLoopExpl.h +++ b/moeo/src/scalarStuffs/explorer/moeoTSMoveLoopExpl.h @@ -94,7 +94,7 @@ class moeoTSMoveLoopExpl:public moMoveLoopExpl < M > if( _old_solution.invalidFitness() || _old_solution.invalid() ) { - throw std::runtime_error("[moTSMoveLoopExpl.h]: The current solution has not been evaluated."); + throw eoInvalidFitnessError("[moTSMoveLoopExpl.h]: The current solution has not been evaluated."); } //At the begining, the new solution is equivalent to the old one. diff --git a/moeo/src/utils/moeoBestObjVecStat.h b/moeo/src/utils/moeoBestObjVecStat.h index 1d8d7294d..604ca90dd 100644 --- a/moeo/src/utils/moeoBestObjVecStat.h +++ b/moeo/src/utils/moeoBestObjVecStat.h @@ -65,7 +65,7 @@ public: */ const MOEOT & bestindividuals(unsigned int which) { typedef typename moeoObjVecStat::Traits traits; - if(which > traits::nObjectives() ) throw std::logic_error("which is larger than the number of objectives"); + if(which > traits::nObjectives() ) throw eoException("which is larger than the number of objectives"); return *(best_individuals[which]); } diff --git a/moeo/tutorial/examples/flowshop/FlowShopBenchmarkParser.cpp b/moeo/tutorial/examples/flowshop/FlowShopBenchmarkParser.cpp index f2de425a0..68059fc43 100644 --- a/moeo/tutorial/examples/flowshop/FlowShopBenchmarkParser.cpp +++ b/moeo/tutorial/examples/flowshop/FlowShopBenchmarkParser.cpp @@ -36,6 +36,7 @@ //----------------------------------------------------------------------------- #include #include +#include #include "FlowShopBenchmarkParser.h" FlowShopBenchmarkParser::FlowShopBenchmarkParser(const std::string _benchmarkFileName) @@ -96,7 +97,7 @@ void FlowShopBenchmarkParser::init(const std::string _benchmarkFileName) std::ifstream inputFile(_benchmarkFileName.data(), std::ios::in); // opening of the benchmark file if (! inputFile) - throw std::runtime_error("*** ERROR : Unable to open the benchmark file"); + throw eoFileError(_benchmarkFileName); // number of jobs (N) getline(inputFile, buffer, '\n'); N = atoi(buffer.data()); diff --git a/moeo/tutorial/examples/flowshop/make_op_FlowShop.h b/moeo/tutorial/examples/flowshop/make_op_FlowShop.h index 4316f7f65..428fe1d3a 100644 --- a/moeo/tutorial/examples/flowshop/make_op_FlowShop.h +++ b/moeo/tutorial/examples/flowshop/make_op_FlowShop.h @@ -104,12 +104,12 @@ eoGenOp & do_make_op(eoParameterLoader& _parser, eoState& _state) eoValueParam& pCrossParam = _parser.createParam(0.25, "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& pMutParam = _parser.createParam(0.35, "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 crossover - with probability pCross eoProportionalOp * propOp = new eoProportionalOp ; diff --git a/problems/eval/maxSATeval.h b/problems/eval/maxSATeval.h index 87a3c4ca6..985b7d74a 100644 --- a/problems/eval/maxSATeval.h +++ b/problems/eval/maxSATeval.h @@ -111,8 +111,8 @@ public: std::fstream file(_fileName.c_str(), std::ios::in); if (!file) { - std::string str = "MaxSATeval: Could not open file [" + _fileName + "]." ; - throw std::runtime_error(str); + // std::string str = "MaxSATeval: Could not open file [" + _fileName + "]." ; + throw eoFileError(_fileName); } std::string s; @@ -128,12 +128,12 @@ public: // parameters if (s[0] != 'p') { std::string str = "MaxSATeval: could not read the parameters of the instance from file [" + _fileName + "]." ; - throw std::runtime_error(str); + throw eoException(_fileName); } file >> s; if (s != "cnf") { std::string str = "MaxSATeval: " + _fileName + " is not a file in cnf format."; - throw std::runtime_error(str); + throw eoException(_fileName); } file >> nbVar >> nbClauses; @@ -187,7 +187,7 @@ public: if (!file) { std::string str = "MaxSATeval: Could not open " + _fileName; - throw std::runtime_error(str); + throw eoFileError(_fileName); } // write some commentaries diff --git a/problems/eval/nkLandscapesEval.h b/problems/eval/nkLandscapesEval.h index f2e243021..cfdaab60a 100644 --- a/problems/eval/nkLandscapesEval.h +++ b/problems/eval/nkLandscapesEval.h @@ -154,13 +154,13 @@ public: // Read the parameters if (s[0] != 'p') { std::string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] at the begining." ; - throw std::runtime_error(str); + throw eoException(str); } file >> s; if (s != "NK") { std::string str = "nkLandscapesEval.load: -- NK -- expected in [" + _fileName + "] at the begining." ; - throw std::runtime_error(str); + throw eoException(str); } // read parameters N and K @@ -170,7 +170,7 @@ public: // read the links if (s[0] != 'p') { std::string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] after the parameters N and K." ; - throw std::runtime_error(str); + throw eoException(str); } file >> s; @@ -178,13 +178,13 @@ public: loadLinks(file); } else { std::string str = "nkLandscapesEval.load: -- links -- expected in [" + _fileName + "] after the parameters N and K." ; - throw std::runtime_error(str); + throw eoException(str); } // lecture des tables if (s[0] != 'p') { std::string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] after the links." ; - throw std::runtime_error(str); + throw eoException(str); } file >> s; @@ -193,13 +193,13 @@ public: loadTables(file); } else { std::string str = "nkLandscapesEval.load: -- tables -- expected in [" + _fileName + "] after the links." ; - throw std::runtime_error(str); + throw eoException(str); } file.close(); } else { - std::string str = "nkLandscapesEval.load: Could not open file [" + _fileName + "]." ; - throw std::runtime_error(str); + // std::string str = "nkLandscapesEval.load: Could not open file [" + _fileName + "]." ; + throw eoFileError(_fileName); } }; diff --git a/problems/eval/nkpLandscapesEval.h b/problems/eval/nkpLandscapesEval.h index 5f2a5e932..343d25d68 100644 --- a/problems/eval/nkpLandscapesEval.h +++ b/problems/eval/nkpLandscapesEval.h @@ -115,13 +115,13 @@ public: // Read the parameters if (s[0] != 'p') { string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] at the begining." ; - throw runtime_error(str); + throw eoException(str); } file >> s; if (s != "NKp") { string str = "nkpLandscapesEval.load: -- NKp -- expected in [" + _fileName + "] at the begining." ; - throw runtime_error(str); + throw eoException(str); } // read parameters N, K and p @@ -131,7 +131,7 @@ public: // read the links if (s[0] != 'p') { string str = "nkpLandscapesEval.load: -- p -- expected in [" + _fileName + "] after the parameters N, K, and p." ; - throw runtime_error(str); + throw eoException(str); } file >> s; @@ -139,13 +139,13 @@ public: loadLinks(file); } else { string str = "nkpLandscapesEval.load: -- links -- expected in [" + _fileName + "] after the parameters N, K, and q." ; - throw runtime_error(str); + throw eoException(str); } // lecture des tables if (s[0] != 'p') { string str = "nkpLandscapesEval.load: -- p -- expected in [" + _fileName + "] after the links." ; - throw runtime_error(str); + throw eoException(str); } file >> s; @@ -154,13 +154,13 @@ public: loadTables(file); } else { string str = "nkpLandscapesEval.load: -- tables -- expected in [" + _fileName + "] after the links." ; - throw runtime_error(str); + throw eoException(str); } file.close(); } else { - string str = "nkpLandscapesEval.load: Could not open file [" + _fileName + "]." ; - throw runtime_error(str); + // string str = "nkpLandscapesEval.load: Could not open file [" + _fileName + "]." ; + throw eoFileError(_fileName); } }; diff --git a/problems/eval/nkqLandscapesEval.h b/problems/eval/nkqLandscapesEval.h index d40bf3955..368bae969 100644 --- a/problems/eval/nkqLandscapesEval.h +++ b/problems/eval/nkqLandscapesEval.h @@ -114,13 +114,13 @@ public: // Read the parameters if (s[0] != 'p') { string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] at the begining." ; - throw runtime_error(str); + throw eoException(str); } file >> s; if (s != "NKq") { string str = "nkqLandscapesEval.load: -- NKq -- expected in [" + _fileName + "] at the begining." ; - throw runtime_error(str); + throw eoException(str); } // read parameters N, K and q @@ -130,7 +130,7 @@ public: // read the links if (s[0] != 'p') { string str = "nkqLandscapesEval.load: -- p -- expected in [" + _fileName + "] after the parameters N, K, and q." ; - throw runtime_error(str); + throw eoException(str); } file >> s; @@ -138,13 +138,13 @@ public: loadLinks(file); } else { string str = "nkqLandscapesEval.load: -- links -- expected in [" + _fileName + "] after the parameters N, K, and q." ; - throw runtime_error(str); + throw eoException(str); } // lecture des tables if (s[0] != 'p') { string str = "nkqLandscapesEval.load: -- p -- expected in [" + _fileName + "] after the links." ; - throw runtime_error(str); + throw eoException(str); } file >> s; @@ -153,13 +153,13 @@ public: loadTables(file); } else { string str = "nkqLandscapesEval.load: -- tables -- expected in [" + _fileName + "] after the links." ; - throw runtime_error(str); + throw eoException(str); } file.close(); } else { - string str = "nkqLandscapesEval.load: Could not open file [" + _fileName + "]." ; - throw runtime_error(str); + // string str = "nkqLandscapesEval.load: Could not open file [" + _fileName + "]." ; + throw eoFileError(_fileName); } }; @@ -192,7 +192,7 @@ public: } else { string fname(_fileName); string str = "nkqLandscapesEval.save: Could not open file [" + fname + "]." ; - throw runtime_error(str); + throw eoFileError(fname); } }; diff --git a/problems/eval/qapEval.h b/problems/eval/qapEval.h index 40d763c9f..df0d79303 100644 --- a/problems/eval/qapEval.h +++ b/problems/eval/qapEval.h @@ -52,8 +52,8 @@ public: std::fstream file(_fileData.c_str(), std::ios::in); if (!file) { - std::string str = "QAPeval: Could not open file [" + _fileData + "]." ; - throw std::runtime_error(str); + // std::string str = "QAPeval: Could not open file [" + _fileData + "]." ; + throw eoFileError(_fileData); } unsigned i, j; diff --git a/problems/eval/ubqpEval.h b/problems/eval/ubqpEval.h index 6061954b9..094030d59 100644 --- a/problems/eval/ubqpEval.h +++ b/problems/eval/ubqpEval.h @@ -65,8 +65,8 @@ public: std::fstream file(_fileName.c_str(), std::ios::in); if (!file) { - std::string str = "UbqpEval: Could not open file [" + _fileName + "]." ; - throw std::runtime_error(str); + // std::string str = "UbqpEval: Could not open file [" + _fileName + "]." ; + throw eoFileError(_fileName); } unsigned int nbInstances; @@ -119,7 +119,7 @@ public: Q[i - 1][j - 1] = v; else { std::string str = "UbqpEval: some indices are 0 in the instance file (in format 0), please check." ; - throw std::runtime_error(str); + throw eoException(str); } } } else { diff --git a/smp/src/MWAlgo/eoEasyEA.cpp b/smp/src/MWAlgo/eoEasyEA.cpp index bf98c534d..6a2eb485c 100644 --- a/smp/src/MWAlgo/eoEasyEA.cpp +++ b/smp/src/MWAlgo/eoEasyEA.cpp @@ -1,3 +1,5 @@ +#include "eoExceptions.h" + template