diff --git a/eo/src/eoCombinedContinue.h b/eo/src/eoCombinedContinue.h index 4dac4d69..5226e28d 100644 --- a/eo/src/eoCombinedContinue.h +++ b/eo/src/eoCombinedContinue.h @@ -19,6 +19,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Contact: todos@geneura.ugr.es, http://geneura.ugr.es +Authors : + todos@geneura.ugr.es + Marc Schoenauer + Ramón Casero Cañas + Johann Dréo */ //----------------------------------------------------------------------------- @@ -40,7 +45,7 @@ @ingroup Combination */ template< class EOT> -class eoCombinedContinue: public eoContinue { +class eoCombinedContinue: public eoContinue, public std::vector* > { public: /// Define Fitness @@ -48,45 +53,45 @@ public: /// Ctor, make sure that at least on continuator is present eoCombinedContinue( eoContinue& _cont) - : eoContinue () + : eoContinue(), std::vector* >(1, &_cont) { - continuators.push_back(&_cont); } /// Ctor - for historical reasons ... should disspear some day eoCombinedContinue( eoContinue& _cont1, eoContinue& _cont2) - : eoContinue () + : eoContinue(), std::vector* >() { - continuators.push_back(&_cont1); - continuators.push_back(&_cont2); +#pragma message "The double continuators constructor of eocombinedContinue is deprecated and will be removed in the next release." + + this->push_back(&_cont1); + this->push_back(&_cont2); } void add(eoContinue & _cont) { - continuators.push_back(&_cont); + this->push_back(&_cont); } - ///////////// RAMON'S CODE /////////////// void removeLast(void) { - continuators.pop_back(); +#pragma message "The removeLast method of eocombinedContinue is deprecated and will be removed in the next release, use pop_back instead." + this->pop_back(); } - ///////////// RAMON'S CODE (end) /////////////// /** Returns false when one of the embedded continuators say so (logical and) */ virtual bool operator() ( const eoPop& _pop ) { - for (unsigned i = 0; i < continuators.size(); ++i) - if ( !(*continuators[i])(_pop) ) return false; + for (unsigned i = 0; i < this->size(); ++i) + if ( ! (*this->at(i))(_pop) ) return false; return true; } virtual std::string className(void) const { return "eoCombinedContinue"; } -private: - std::vector*> continuators; +//private: +// std::vector*> continuators; }; #endif diff --git a/eo/src/eoDualFitness.h b/eo/src/eoDualFitness.h index 3b7fda0d..674fe075 100644 --- a/eo/src/eoDualFitness.h +++ b/eo/src/eoDualFitness.h @@ -103,6 +103,17 @@ public: _is_feasible(dual.second) {} + // FIXME is it a good idea to include implicit conversion here? + /** Conversion operator: it permits to use a fitness instance as its scalar + * type, if needed. For example, this is possible: + * eoDualFitness > fit; + * double val = 1.0; + * fit = val; + * val = fit; + */ + operator BaseType(void) const { return _value; } + + inline bool is_feasible() const { return _is_feasible; diff --git a/eo/src/eoExceptions.h b/eo/src/eoExceptions.h index 3b888436..4d56ddb9 100644 --- a/eo/src/eoExceptions.h +++ b/eo/src/eoExceptions.h @@ -55,7 +55,6 @@ private: }; - /*! An error that signals that a maximum number of evaluations has been reached. @@ -80,4 +79,54 @@ private: }; +/*! + * An error that signals a missing parameter + * + * Thrown by eoParser::getParam + * + * @ingroup Parameters + */ +class eoMissingParamException : public std::exception +{ +public: + eoMissingParamException(std::string name) : _name(name){} + + virtual const char* what() const throw() + { + std::ostringstream ss; + ss << "The command parameter " << _name << " has not been declared"; + return ss.str().c_str(); + } + + ~eoMissingParamException() throw() {} + +private: + std::string _name; +}; + +/*! + * An error that signals a bad parameter type + * + * Thrown by eoParser::valueOf + * + * @ingroup Parameters + */ +class eoWrongParamTypeException : public std::exception +{ +public: + eoWrongParamTypeException(std::string name) : _name(name){} + + virtual const char* what() const throw() + { + std::ostringstream ss; + ss << "You asked for the parameter " << _name << " but it has not been declared under this type"; + return ss.str().c_str(); + } + + ~eoWrongParamTypeException() throw() {} + +private: + std::string _name; +}; + #endif // __eoExceptions_h__ diff --git a/eo/src/eoProportionalCombinedOp.h b/eo/src/eoProportionalCombinedOp.h index 123c634b..4fea77e5 100644 --- a/eo/src/eoProportionalCombinedOp.h +++ b/eo/src/eoProportionalCombinedOp.h @@ -188,6 +188,7 @@ public: virtual void add(eoQuadOp & _op, const double _rate, bool _verbose) { +#pragma message "The use of the verbose parameter in eoPropCombinedQuadOp::add is deprecated and will be removed in the next release." eo::log << eo::warnings << "WARNING: the use of the verbose parameter in eoPropCombinedQuadOp::add is deprecated and will be removed in the next release." << std::endl; add(_op,_rate); } diff --git a/eo/src/utils/eoOStreamMonitor.h b/eo/src/utils/eoOStreamMonitor.h index b09a11b5..cb4c476a 100644 --- a/eo/src/utils/eoOStreamMonitor.h +++ b/eo/src/utils/eoOStreamMonitor.h @@ -49,6 +49,7 @@ public : { (void)_verbose; eo::log << eo::warnings << "WARNING: the use of the verbose parameter in eoOStreamMonitor constructor is deprecated and will be removed in the next release" << std::endl; +#pragma message "WARNING: the use of the verbose parameter in eoOStreamMonitor constructor is deprecated and will be removed in the next release" } eoOStreamMonitor( std::ostream & _out, std::string _delim = "\t", unsigned int _width=20, char _fill=' ' ) : diff --git a/eo/src/utils/eoParser.cpp b/eo/src/utils/eoParser.cpp index fc1068b3..cc306bf7 100644 --- a/eo/src/utils/eoParser.cpp +++ b/eo/src/utils/eoParser.cpp @@ -18,9 +18,12 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Contact: todos@geneura.ugr.es, http://geneura.ugr.es - Marc.Schoenauer@inria.fr - mkeijzer@dhi.dk +Contact: http://eodev.sourceforge.net +Authors: + todos@geneura.ugr.es, http://geneura.ugr.es + Marc.Schoenauer@polytechnique.fr + mkeijzer@dhi.dk + Johann Dréo */ //----------------------------------------------------------------------------- @@ -38,6 +41,7 @@ #include #include + using namespace std; std::ostream& printSectionHeader(std::ostream& os, std::string section) @@ -129,6 +133,15 @@ eoParam * eoParser::getParamWithLongName(const std::string& _name) const return 0; } +eoParam * eoParser::getParam(const std::string& _name) const +{ + eoParam * p = getParamWithLongName( _name ); + if( p == NULL ) { + throw eoMissingParamException(_name ); + } else { + return p; + } +} void eoParser::processParam(eoParam& param, std::string section) { diff --git a/eo/src/utils/eoParser.h b/eo/src/utils/eoParser.h index e65f7566..be680ab0 100644 --- a/eo/src/utils/eoParser.h +++ b/eo/src/utils/eoParser.h @@ -1,4 +1,4 @@ -/* (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2000 +/* (c) Marc Schoenauer, Maarten Keijzer, GeNeura Team, Thales group This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free @@ -14,9 +14,11 @@ with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Contact: http://eodev.sourceforge.net - todos@geneura.ugr.es, http://geneura.ugr.es - Marc.Schoenauer@polytechnique.fr - mkeijzer@dhi.dk +Authors: + todos@geneura.ugr.es, http://geneura.ugr.es + Marc.Schoenauer@polytechnique.fr + mkeijzer@dhi.dk + Johann Dréo */ @@ -30,6 +32,7 @@ Contact: http://eodev.sourceforge.net #include "eoParam.h" #include "eoObject.h" #include "eoPersistent.h" +#include "eoExceptions.h" /** Parameter saving and loading @@ -176,15 +179,46 @@ public: eoParam * getParamWithLongName(const std::string& _name) const; + /** + * Get a handle on a param from its long name + * If not found, raise an eoMissingParamException + */ + eoParam * getParam(const std::string& _name) const; + + + /** + * Get the value of a param from its long name + * If not found, raise an eoMissingParamException + * + * Remember to specify the expected return type with a templated call: + * unsigned int popSize = eoparser.value("popSize"); + * + * If the template type is not the good one, an eoWrongParamTypeException is raised. + */ + template + ValueType valueOf(const std::string& _name) const + { + eoParam* param = getParam(_name); + + // Note: eoParam is the polymorphic base class of eoValueParam, thus we can do a dynamix cast + eoValueParam* vparam = dynamic_cast< eoValueParam* >(param); + + if( vparam == NULL ) { + // if the dynamic cast has failed, chances are that ValueType + // is not the same than the one used at declaration. + throw eoWrongParamTypeException( _name ); + } else { + return vparam->value(); + } + } + + /** Get or create parameter It seems finally that the easiest use of the above method is through the following, whose interface is similar to that of the widely-used createParam. - - For some (probably very stupid) reason, I failed to put it in the - .cpp. Any hint??? */ template eoValueParam& getORcreateParam(ValueType _defaultValue,