use eoExceptions everywhere

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

View file

@ -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})

View file

@ -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));
}

View file

@ -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");
}
}

View file

@ -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;
}

View file

@ -42,6 +42,8 @@
#include <stdexcept>
#include <vector>
#include <eoExceptions.h>
/**
* 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];
}

View file

@ -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());

View file

@ -121,7 +121,7 @@ eoContinue<MOEOT> & 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

View file

@ -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);

View file

@ -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();

View file

@ -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.");
}
/*

View file

@ -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.

View file

@ -65,7 +65,7 @@ public:
*/
const MOEOT & bestindividuals(unsigned int which) {
typedef typename moeoObjVecStat<MOEOT>::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]);
}

View file

@ -36,6 +36,7 @@
//-----------------------------------------------------------------------------
#include <iostream>
#include <stdexcept>
#include <eo>
#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());

View file

@ -104,12 +104,12 @@ eoGenOp<FlowShop> & do_make_op(eoParameterLoader& _parser, eoState& _state)
eoValueParam<double>& 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<double>& 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<FlowShop> * propOp = new eoProportionalOp<FlowShop> ;