Removed some obsolete files, changed min and max in compatibility, commented the parser out of eoESFullMut and added some default initialization (please check this Marc). Why eoParser has changed is beyond me, but I am too late to uncommit. I will update a real parser very soon now.
This commit is contained in:
parent
b111bf01aa
commit
4a6202ff13
9 changed files with 24 additions and 495 deletions
|
|
@ -31,11 +31,6 @@
|
|||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#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 <class T> T min(const T& a, const T& b)
|
||||
template <class T> const T& min(const T& a, const T& b)
|
||||
{
|
||||
if(a < b)
|
||||
return a;
|
||||
|
|
@ -62,7 +57,7 @@ namespace std
|
|||
return b;
|
||||
}
|
||||
|
||||
template <class T> T max(const T& a, const T& b)
|
||||
template <class T> const T& max(const T& a, const T& b)
|
||||
{
|
||||
if(a > b)
|
||||
return a;
|
||||
|
|
|
|||
|
|
@ -1,302 +0,0 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// eoBreeder.h
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef eoBreeder_h
|
||||
#define eoBreeder_h
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <vector> // vector
|
||||
#include <iterator>
|
||||
#include <eoUniform.h> // eoUniform
|
||||
#include <eoOp.h> // eoOp, eoMonOp, eoBinOp
|
||||
#include <eoPop.h> // eoPop
|
||||
#include <eoPopOps.h> // eoTransform
|
||||
#include <eoOpSelector.h> // eoOpSelector
|
||||
#include <list>
|
||||
#include <eoRnd.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/*****************************************************************************
|
||||
* eoBreeder: transforms a population using genetic operators. *
|
||||
* For every operator there is a rated to be applyed. *
|
||||
*****************************************************************************/
|
||||
|
||||
template<class EOT, class OutIt>
|
||||
class eoGeneralOp: public eoOp<EOT>
|
||||
{
|
||||
public:
|
||||
|
||||
eoGeneralOp()
|
||||
:eoOp<EOT>( Nary ) {};
|
||||
virtual ~eoGeneralOp () {};
|
||||
|
||||
virtual void operator()( vector<const EOT*> _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 EOT, class OutIt>
|
||||
class eoWrappedMonOp : public eoGeneralOp<EOT, OutIt>
|
||||
{
|
||||
public :
|
||||
eoWrappedMonOp(const eoMonOp<EOT>& _op) : eoGeneralOp<EOT, OutIt>(), op(_op) {}
|
||||
virtual ~eoWrappedMonOp() {}
|
||||
|
||||
void operator()( vector<const EOT*> _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<EOT>& op;
|
||||
};
|
||||
|
||||
template <class EOT, class OutIt>
|
||||
class eoWrappedBinOp : public eoGeneralOp<EOT, OutIt>
|
||||
{
|
||||
public :
|
||||
eoWrappedBinOp(const eoBinOp<EOT>& _op) : eoGeneralOp<EOT, OutIt>(), op(_op) {}
|
||||
virtual ~eoWrappedBinOp() {}
|
||||
|
||||
void operator()( vector<const EOT*> _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<EOT>& op;
|
||||
};
|
||||
|
||||
template <class EOT, class OutIt>
|
||||
class eoCombinedOp : public eoGeneralOp<EOT, OutIt>
|
||||
{
|
||||
public :
|
||||
|
||||
eoCombinedOp() : eoGeneralOp<EOT, OutIt>(), arity(0) {}
|
||||
virtual ~eoCombinedOp() {}
|
||||
|
||||
int nInputs(void) const { return arity; }
|
||||
int nOutputs(void) const { return 1; }
|
||||
|
||||
void addOp(eoGeneralOp<EOT, OutIt>* _op)
|
||||
{
|
||||
ops.push_back(_op);
|
||||
arity = arity < _op->nInputs()? _op->nInputs() : arity;
|
||||
}
|
||||
|
||||
|
||||
void clear(void)
|
||||
{
|
||||
ops.resize(0);
|
||||
}
|
||||
|
||||
|
||||
void operator()( vector<const EOT*> _in, OutIt _out) const
|
||||
{
|
||||
for (int i = 0; i < ops.size(); ++i)
|
||||
{
|
||||
(*ops[i])(_in, _out);
|
||||
_in[0] = &*_out;
|
||||
}
|
||||
}
|
||||
|
||||
private :
|
||||
vector<eoGeneralOp<EOT, OutIt>* > ops;
|
||||
int arity;
|
||||
};
|
||||
|
||||
template<class EOT, class OutIt>
|
||||
class eoAltOpSelector: public eoOpSelector<EOT>, public vector<eoGeneralOp<EOT, OutIt>*>
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ID addOp( eoOp<EOT>& _op, float _arg )
|
||||
{
|
||||
eoGeneralOp<EOT, OutIt>* op = dynamic_cast<eoGeneralOp<EOT, OutIt>*>(&_op);
|
||||
|
||||
|
||||
if (op == 0)
|
||||
{
|
||||
switch(_op.readArity())
|
||||
{
|
||||
case unary :
|
||||
oplist.push_back(auto_ptr<eoGeneralOp<EOT, OutIt> >(new eoWrappedMonOp<EOT, OutIt>(static_cast<eoMonOp<EOT>&>(_op))));
|
||||
|
||||
op = oplist.back().get();
|
||||
break;
|
||||
case binary :
|
||||
oplist.push_back(auto_ptr<eoGeneralOp<EOT, OutIt> >(new eoWrappedBinOp<EOT, OutIt>(static_cast<eoBinOp<EOT>&>(_op))));
|
||||
op = oplist.back().get();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
iterator result = find(begin(), end(), (eoGeneralOp<EOT, OutIt>*) 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<EOT>& 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<EOT>* Op()
|
||||
{
|
||||
return &selectOp();
|
||||
}
|
||||
|
||||
|
||||
virtual eoGeneralOp<EOT, OutIt>& selectOp() = 0;
|
||||
|
||||
|
||||
virtual string className() const { return "eoAltOpSelector"; };
|
||||
|
||||
void printOn(ostream& _os) const {}
|
||||
|
||||
|
||||
protected :
|
||||
|
||||
vector<float> rates;
|
||||
list<auto_ptr<eoGeneralOp<EOT, OutIt> > > oplist;
|
||||
};
|
||||
|
||||
template <class EOT, class OutIt>
|
||||
class eoProportionalOpSelector : public eoAltOpSelector<EOT, OutIt>
|
||||
{
|
||||
public :
|
||||
eoProportionalOpSelector() : eoAltOpSelector<EOT, OutIt>() {}
|
||||
|
||||
|
||||
virtual eoGeneralOp<EOT, OutIt>& selectOp()
|
||||
{
|
||||
int what = rng.roulette_wheel(rates);
|
||||
|
||||
return *operator[](what);
|
||||
}
|
||||
};
|
||||
|
||||
template <class EOT, class OutIt>
|
||||
class eoSequentialOpSelector : public eoAltOpSelector<EOT, OutIt>
|
||||
{
|
||||
public :
|
||||
|
||||
eoSequentialOpSelector() : eoAltOpSelector<EOT, OutIt>() {}
|
||||
|
||||
virtual eoGeneralOp<EOT, OutIt>& 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<EOT, OutIt> combined;
|
||||
};
|
||||
|
||||
template <class EOT>
|
||||
class eoRandomIndy // living in a void right now
|
||||
{
|
||||
public :
|
||||
|
||||
eoRandomIndy() {}
|
||||
|
||||
vector<const EOT*> operator()(int _n, eoPop<EOT>::iterator _begin, eoPop<EOT>::iterator _end)
|
||||
{
|
||||
vector<const EOT*> result(_n);
|
||||
|
||||
for (int i = 0; i < result.size(); ++i)
|
||||
{
|
||||
result[i] = &*(_begin + rng.random(_end - _begin));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template<class Chrom> class eoAltBreeder: public eoTransform<Chrom>
|
||||
{
|
||||
public:
|
||||
typedef eoPop<Chrom>::reverse_iterator outIt;
|
||||
/// Default constructor.
|
||||
eoAltBreeder( eoAltOpSelector<Chrom, outIt>& _opSel): opSel( _opSel ) {}
|
||||
|
||||
/// Destructor.
|
||||
virtual ~eoAltBreeder() {}
|
||||
|
||||
/**
|
||||
* Enlarges the population.
|
||||
* @param pop The population to be transformed.
|
||||
*/
|
||||
void operator()(eoPop<Chrom>& pop)
|
||||
{
|
||||
int size = pop.size();
|
||||
|
||||
for (unsigned i = 0; i < size; i++)
|
||||
{
|
||||
eoGeneralOp<Chrom, outIt>& op = opSel.selectOp();
|
||||
|
||||
pop.resize(pop.size() + op.nOutputs());
|
||||
vector<const Chrom*> indies = indySelector(op.nInputs(), pop.begin(), pop.begin() + size);
|
||||
|
||||
op(indies, pop.rbegin());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// The class name.
|
||||
string classname() const { return "eoAltBreeder"; }
|
||||
|
||||
private:
|
||||
eoAltOpSelector<Chrom, outIt >& opSel;
|
||||
eoRandomIndy<Chrom> indySelector;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif eoBreeder_h
|
||||
|
|
@ -79,7 +79,7 @@ class eoESFullChrom : public eoVector<double, fitT> {
|
|||
|
||||
|
||||
/* 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
|
||||
|
|
|
|||
|
|
@ -36,6 +36,10 @@
|
|||
#include <eoESFullChrom.h>
|
||||
#include <eoOp.h>
|
||||
|
||||
#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 fitT>
|
||||
class eoESMutate: public eoMonOp< eoESFullChrom<fitT> > {
|
||||
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<fitT> >( ), TauLcl(_TauLcl), TauGlb(_TauGlb),
|
||||
TauBeta(_TauBeta) {};
|
||||
|
|
|
|||
|
|
@ -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 <iterator>
|
||||
|
||||
#include <eoOp.h>
|
||||
|
||||
/** MultiMonOp combines several monary operators. By itself, it does nothing to the
|
||||
EO it´s handled*/
|
||||
template <class EOT>
|
||||
class eoMultiBinOp: public eoBinOp<EOT> {
|
||||
public:
|
||||
/// Ctor from an already existing op
|
||||
eoMultiBinOp( const eoBinOp<EOT>* _op )
|
||||
: eoBinOp< EOT >( ), vOp(){
|
||||
vOp.push_back( _op );
|
||||
};
|
||||
|
||||
///
|
||||
eoMultiBinOp( )
|
||||
: eoBinOp< EOT >( ), vOp(){};
|
||||
|
||||
/// Ads a new operator
|
||||
void adOp( const eoOp<EOT>* _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<EOT>* >::const_iterator i = vOp.begin();
|
||||
i != vOp.end(); i++ ) {
|
||||
// Admits only unary or binary operator
|
||||
switch ((*i)->readArity()) {
|
||||
case unary:
|
||||
{
|
||||
const eoMonOp<EOT>* monop = static_cast<const eoMonOp<EOT>* >(*i);
|
||||
(*monop)( _eo1 );
|
||||
(*monop)( _eo2 );
|
||||
break;
|
||||
}
|
||||
case binary:
|
||||
{
|
||||
const eoBinOp<EOT>* binop = static_cast<const eoBinOp<EOT>* >(*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<EOT>* > vOp;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -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 <iterator>
|
||||
|
||||
#include <eoOp.h>
|
||||
|
||||
/** MultiMonOp combines several monary operators. By itself, it does nothing to the
|
||||
EO it´s handled*/
|
||||
template <class EOT>
|
||||
class eoMultiMonOp: public eoMonOp<EOT> {
|
||||
public:
|
||||
/// Ctor from an already existing op
|
||||
eoMultiMonOp( const eoMonOp<EOT>* _op )
|
||||
: eoMonOp< EOT >( ), vOp(){
|
||||
vOp.push_back( _op );
|
||||
};
|
||||
|
||||
///
|
||||
eoMultiMonOp( )
|
||||
: eoMonOp< EOT >( ), vOp(){};
|
||||
|
||||
/// Ctor from an already existing op
|
||||
void adOp( const eoMonOp<EOT>* _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 eoMonOp<EOT>* >::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<EOT>* > vOp;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -28,6 +28,10 @@
|
|||
#define _PARSER_H
|
||||
|
||||
#include <string.h> // 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
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
#include <eoParserUtils.h>
|
||||
/// 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;
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@
|
|||
*/
|
||||
|
||||
template <class ScalarType, class Compare = less<ScalarType> >
|
||||
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 <class F, class Cmp>
|
||||
std::ostream& operator<<(std::ostream& os, const eoScalarFitness<F, Cmp>&
|
||||
f)
|
||||
std::ostream& operator<<(std::ostream& os, const eoScalarFitness<F, Cmp>& f)
|
||||
{
|
||||
os << (F) f;
|
||||
return os;
|
||||
|
|
|
|||
Reference in a new issue