diff --git a/eo/src/compatibility.h b/eo/src/compatibility.h index 1297fc9e..75479c14 100644 --- a/eo/src/compatibility.h +++ b/eo/src/compatibility.h @@ -31,11 +31,6 @@ #include #include -#ifdef _1__GNUC__ -// Specifics for GNUC -#define NO_GOOD_ISTREAM_ITERATORS -#endif - #ifdef _MSC_VER /* Maarten: added this code here because Mirkosoft has the @@ -54,7 +49,7 @@ here. Sure hope it works // add min and max to std... namespace std { - template T min(const T& a, const T& b) + template const T& min(const T& a, const T& b) { if(a < b) return a; @@ -62,7 +57,7 @@ namespace std return b; } - template T max(const T& a, const T& b) + template const T& max(const T& a, const T& b) { if(a > b) return a; diff --git a/eo/src/eoAltBreeder.h b/eo/src/eoAltBreeder.h deleted file mode 100644 index 1a8241bd..00000000 --- a/eo/src/eoAltBreeder.h +++ /dev/null @@ -1,302 +0,0 @@ -//----------------------------------------------------------------------------- -// eoBreeder.h -//----------------------------------------------------------------------------- - -#ifndef eoBreeder_h -#define eoBreeder_h - -//----------------------------------------------------------------------------- - -#include // vector -#include -#include // eoUniform -#include // eoOp, eoMonOp, eoBinOp -#include // eoPop -#include // eoTransform -#include // eoOpSelector -#include -#include - -using namespace std; - -/***************************************************************************** - * eoBreeder: transforms a population using genetic operators. * - * For every operator there is a rated to be applyed. * - *****************************************************************************/ - -template -class eoGeneralOp: public eoOp -{ -public: - - eoGeneralOp() - :eoOp( Nary ) {}; - virtual ~eoGeneralOp () {}; - - virtual void operator()( vector _in, OutIt _out) const = 0; - virtual int nInputs(void) const = 0; - virtual int nOutputs(void) const = 0; // no support for 2 -> 2 xover - - virtual string className() const {return "eoGeneralOp";}; -}; - -template -class eoWrappedMonOp : public eoGeneralOp -{ -public : - eoWrappedMonOp(const eoMonOp& _op) : eoGeneralOp(), op(_op) {} - virtual ~eoWrappedMonOp() {} - - void operator()( vector _in, OutIt _out) const - { - *_out = *_in[0]; - op(*_out ); - } - - int nInputs(void) const { return 1; } - int nOutputs(void) const { return 1; } - - virtual string className() const {return "eoWrappedOp";}; - - -private : - const eoMonOp& op; -}; - -template -class eoWrappedBinOp : public eoGeneralOp -{ -public : - eoWrappedBinOp(const eoBinOp& _op) : eoGeneralOp(), op(_op) {} - virtual ~eoWrappedBinOp() {} - - void operator()( vector _in, OutIt _out) const - { - *_out = *_in[0]; - *(_out + 1) = *_in[1]; - op(*_out, *(_out + 1)); - } - - int nInputs(void) const { return 2; } - int nOutputs(void) const { return 2; } // Yup, due to the bad design, can't choose between outputting 1 or 2 - - virtual string className() const {return "eoWrappedOp";}; - - -private : - const eoBinOp& op; -}; - -template -class eoCombinedOp : public eoGeneralOp -{ -public : - - eoCombinedOp() : eoGeneralOp(), arity(0) {} - virtual ~eoCombinedOp() {} - - int nInputs(void) const { return arity; } - int nOutputs(void) const { return 1; } - - void addOp(eoGeneralOp* _op) - { - ops.push_back(_op); - arity = arity < _op->nInputs()? _op->nInputs() : arity; - } - - - void clear(void) - { - ops.resize(0); - } - - - void operator()( vector _in, OutIt _out) const - { - for (int i = 0; i < ops.size(); ++i) - { - (*ops[i])(_in, _out); - _in[0] = &*_out; - } - } - -private : - vector* > ops; - int arity; -}; - -template -class eoAltOpSelector: public eoOpSelector, public vector*> -{ -public: - - virtual ID addOp( eoOp& _op, float _arg ) - { - eoGeneralOp* op = dynamic_cast*>(&_op); - - - if (op == 0) - { - switch(_op.readArity()) - { - case unary : - oplist.push_back(auto_ptr >(new eoWrappedMonOp(static_cast&>(_op)))); - - op = oplist.back().get(); - break; - case binary : - oplist.push_back(auto_ptr >(new eoWrappedBinOp(static_cast&>(_op)))); - op = oplist.back().get(); - break; - } - } - - iterator result = find(begin(), end(), (eoGeneralOp*) 0); // search for nullpointer - - if (result == end()) - { - push_back(op); - rates.push_back(_arg); - return size(); - } - // else - - *result = op; - ID id = result - begin(); - rates[id] = _arg; - return id; - } - - virtual const eoOp& getOp( ID _id ) - { - return *operator[](_id); - } - - virtual void deleteOp( ID _id ) - { - operator[](_id) = 0; // TODO, check oplist and clear it there too. - rates[_id] = 0.0; - } - - virtual eoOp* Op() - { - return &selectOp(); - } - - - virtual eoGeneralOp& selectOp() = 0; - - - virtual string className() const { return "eoAltOpSelector"; }; - - void printOn(ostream& _os) const {} - - -protected : - - vector rates; - list > > oplist; -}; - -template -class eoProportionalOpSelector : public eoAltOpSelector -{ - public : - eoProportionalOpSelector() : eoAltOpSelector() {} - - - virtual eoGeneralOp& selectOp() - { - int what = rng.roulette_wheel(rates); - - return *operator[](what); - } -}; - -template -class eoSequentialOpSelector : public eoAltOpSelector -{ - public : - - eoSequentialOpSelector() : eoAltOpSelector() {} - - virtual eoGeneralOp& selectOp() - { - for (int i = 0; i < size(); ++i) - { - if (operator[](i) == 0) - continue; - - if (rng.flip(rates[i])) - combined.addOp(operator[](i)); - } - - return combined; - } - - private : - - eoCombinedOp combined; -}; - -template -class eoRandomIndy // living in a void right now -{ - public : - - eoRandomIndy() {} - - vector operator()(int _n, eoPop::iterator _begin, eoPop::iterator _end) - { - vector result(_n); - - for (int i = 0; i < result.size(); ++i) - { - result[i] = &*(_begin + rng.random(_end - _begin)); - } - - return result; - } -}; - -template class eoAltBreeder: public eoTransform -{ - public: - typedef eoPop::reverse_iterator outIt; - /// Default constructor. - eoAltBreeder( eoAltOpSelector& _opSel): opSel( _opSel ) {} - - /// Destructor. - virtual ~eoAltBreeder() {} - - /** - * Enlarges the population. - * @param pop The population to be transformed. - */ - void operator()(eoPop& pop) - { - int size = pop.size(); - - for (unsigned i = 0; i < size; i++) - { - eoGeneralOp& op = opSel.selectOp(); - - pop.resize(pop.size() + op.nOutputs()); - vector indies = indySelector(op.nInputs(), pop.begin(), pop.begin() + size); - - op(indies, pop.rbegin()); - - } - } - - /// The class name. - string classname() const { return "eoAltBreeder"; } - - private: - eoAltOpSelector& opSel; - eoRandomIndy indySelector; -}; - - - -#endif eoBreeder_h diff --git a/eo/src/eoESFullChrom.h b/eo/src/eoESFullChrom.h index 29c56656..85bd4f22 100644 --- a/eo/src/eoESFullChrom.h +++ b/eo/src/eoESFullChrom.h @@ -79,7 +79,7 @@ class eoESFullChrom : public eoVector { /* another constructor, for compatibility reasons */ - eoESFullChrom(istream& _s) {cout << "Not Yet implemented\n";exit(1);}; + eoESFullChrom(istream& _s) { cout << "Not Yet implemented\n";exit(1);}; /* And now the useful constructor: from a parser (should be in the factory, if such a thing exists one day for eoESFullChrom diff --git a/eo/src/eoESFullMut.h b/eo/src/eoESFullMut.h index d30232af..37b6c472 100644 --- a/eo/src/eoESFullMut.h +++ b/eo/src/eoESFullMut.h @@ -36,6 +36,10 @@ #include #include +#ifndef M_PI +#define M_PI 3.1415926535897932384626433832795 +#endif + const double ES_SIGEPS = 1.0e-40; /* ES lower bound for sigma values */ // should not be a parameter ... @@ -44,7 +48,13 @@ const double ES_SIGEPS = 1.0e-40; /* ES lower bound for sigma values */ template class eoESMutate: public eoMonOp< eoESFullChrom > { public: - /// + eoESMutate(double n) + { + TauLcl = 1/sqrt(2*sqrt(n)); + TauGlb= 1 / sqrt(2 * n); + TauBeta = 0.0873; + }/// + eoESMutate( double _TauLcl, double _TauGlb, double _TauBeta ) : eoMonOp< eoESFullChrom >( ), TauLcl(_TauLcl), TauGlb(_TauGlb), TauBeta(_TauBeta) {}; diff --git a/eo/src/eoMultiBinOp.h b/eo/src/eoMultiBinOp.h deleted file mode 100644 index 06237d84..00000000 --- a/eo/src/eoMultiBinOp.h +++ /dev/null @@ -1,100 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoMultiBinOp.h -// Class that combines several binary or unary operators -// (c) GeNeura Team, 1998 -/* - 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 Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - 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 - */ -//----------------------------------------------------------------------------- - -#ifndef _EOMULTIBINOP_h -#define _EOMULTIBINOP_h - -#include - -#include - -/** MultiMonOp combines several monary operators. By itself, it does nothing to the -EO itīs handled*/ -template -class eoMultiBinOp: public eoBinOp { -public: - /// Ctor from an already existing op - eoMultiBinOp( const eoBinOp* _op ) - : eoBinOp< EOT >( ), vOp(){ - vOp.push_back( _op ); - }; - - /// - eoMultiBinOp( ) - : eoBinOp< EOT >( ), vOp(){}; - - /// Ads a new operator - void adOp( const eoOp* _op ){ - vOp.push_back( _op ); - }; - - /// needed virtual dtor - virtual ~eoMultiBinOp() {}; - - /// - /// Applies all operators to the EO - virtual void operator()( EOT& _eo1, EOT& _eo2 ) const { - if ( vOp.begin() != vOp.end() ) { // which would mean it's empty - for ( vector< const eoOp* >::const_iterator i = vOp.begin(); - i != vOp.end(); i++ ) { - // Admits only unary or binary operator - switch ((*i)->readArity()) { - case unary: - { - const eoMonOp* monop = static_cast* >(*i); - (*monop)( _eo1 ); - (*monop)( _eo2 ); - break; - } - case binary: - { - const eoBinOp* binop = static_cast* >(*i); - (*binop)( _eo1, _eo2 ); - break; - } - } - } - } - } - - - /** @name Methods from eoObject - readFrom and printOn are directly inherited from eoOp - */ - //@{ - /** Inherited from eoObject - @see eoObject - */ - string className() const {return "eoMultiBinOp";}; - //@} - -private: - - /// uses pointers to base class since operators can be unary or binary - vector< const eoOp* > vOp; -}; - -#endif - diff --git a/eo/src/eoMultiMonOp.h b/eo/src/eoMultiMonOp.h deleted file mode 100644 index 09167206..00000000 --- a/eo/src/eoMultiMonOp.h +++ /dev/null @@ -1,80 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoMultiMonOp.h -// (c) GeNeura Team, 1998 -/* - 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 Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - 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 - */ -//----------------------------------------------------------------------------- - -#ifndef _EOMULTIMONOP_h -#define _EOMULTIMONOP_h - -#include - -#include - -/** MultiMonOp combines several monary operators. By itself, it does nothing to the -EO itīs handled*/ -template -class eoMultiMonOp: public eoMonOp { -public: - /// Ctor from an already existing op - eoMultiMonOp( const eoMonOp* _op ) - : eoMonOp< EOT >( ), vOp(){ - vOp.push_back( _op ); - }; - - /// - eoMultiMonOp( ) - : eoMonOp< EOT >( ), vOp(){}; - - /// Ctor from an already existing op - void adOp( const eoMonOp* _op ){ - vOp.push_back( _op ); - }; - - /// needed virtual dtor - virtual ~eoMultiMonOp() {}; - - /// - /// Applies all operators to the EO - virtual void operator()( EOT& _eo ) const { - if ( vOp.begin() != vOp.end() ) { - for ( vector* >::const_iterator i = vOp.begin(); - i != vOp.end(); i++ ) { - (*i)->operator () ( _eo ); - } - } - } - - - /** @name Methods from eoObject - readFrom and printOn are directly inherited from eoOp - */ - //@{ - /** Inherited from eoObject - @see eoObject - */ - string className() const {return "eoMonOp";}; - //@} -private: - vector< const eoMonOp* > vOp; -}; - -#endif diff --git a/eo/src/eoParser.h b/eo/src/eoParser.h index 3e5601a9..01369913 100644 --- a/eo/src/eoParser.h +++ b/eo/src/eoParser.h @@ -28,6 +28,10 @@ #define _PARSER_H #include // for strcasecmp ... maybe there's a c++ way of doing it? + // Yep there is, but needs either a simple functor for the equal function + // or a hand-rolled string template class (this isn't that horrible as + // it sounds, it just means a new string_traits class with two changed + // function definitions. (Maarten) #ifdef _MSC_VER #define strcasecmp(a,b) _strnicmp(a,b,strlen(a)) #endif diff --git a/eo/src/eoParserUtils.cpp b/eo/src/eoParserUtils.cpp index b4db0b8d..084af77c 100644 --- a/eo/src/eoParserUtils.cpp +++ b/eo/src/eoParserUtils.cpp @@ -4,6 +4,8 @@ #include /// Reproducible random seed +// For the Mersenne-Twister used in EO, the entire rng needs to be saved + //---------------------------------- void InitRandom( Parser & parser) { //---------------------------------- @@ -25,6 +27,7 @@ void InitRandom( Parser & parser) { s << _seed; parser.setParamValue("--seed", s.str()); // so it will be printed out in the status file, and canbe later re-used to re-run EXACTLY the same run } +#error This does not work: load and save the entire state of the rng object. rng.reseed(_seed); return; diff --git a/eo/src/eoScalarFitness.h b/eo/src/eoScalarFitness.h index 277888bd..63409191 100644 --- a/eo/src/eoScalarFitness.h +++ b/eo/src/eoScalarFitness.h @@ -39,7 +39,7 @@ */ template > -class eoScalarFitness +class eoScalarFitness { public : @@ -56,15 +56,14 @@ class eoScalarFitness // Comparison, using less by default bool operator<(const eoScalarFitness& other) const - { return Compare()(this->value, other.value); } + { return Compare()(value, other.value); } private : ScalarType value; }; template -std::ostream& operator<<(std::ostream& os, const eoScalarFitness& -f) +std::ostream& operator<<(std::ostream& os, const eoScalarFitness& f) { os << (F) f; return os;