Extreme cleanup, see src/obsolete for details

This commit is contained in:
mac 2000-08-10 14:18:34 +00:00
commit 6d8e3a6504
141 changed files with 3937 additions and 1815 deletions

View file

@ -40,8 +40,6 @@ class eoExternalEO : public EO<Fit>, virtual public External
{
public :
typedef External Type;
eoExternalEO(void) : EO<Fit>(), External() {}
/**

View file

@ -1,43 +0,0 @@
/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
-----------------------------------------------------------------------------
eoExternalOpFunc.h
Defines eoExternalInitOpFunc, eoExternalMonOpFunc, eoExternalBinOpFunc, eoExternalQuadOpFunc
that are used to wrap a function pointer to externally defined initialization
and 'genetic' operators
(c) Maarten Keijzer (mkeijzer@mad.scientist.com) and GeNeura Team, 1999, 2000
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 eoExternalOpFunc_h
#define eoExternalOpFunc_h
#include <eoExternalEO.h>
#include <eoOp.h>
#include <utils/eoRNG.h>
template <class F, class External>
class eoExternalInitFunc
{
public :
};
#endif

View file

@ -30,7 +30,7 @@
#include <other/eoExternalEO.h>
#include <eoOp.h>
#include <eoRnd.h>
#include <eoInit.h>
#include <eoEvalFunc.h>
/**
@ -41,18 +41,20 @@
Where External is the user defined struct or class
*/
template <class F, class External>
class eoExternalInit : public eoRnd<eoExternalEO<F, External> >
template <class F, class External, class ExternalEO = eoExternalEO<F, External> >
class eoExternalInit : public eoInit<ExternalEO>
{
public :
typedef eoExternalEO<F, External> ExternalEO;
eoExternalInit(External (*_init)(void)) : init(_init) {}
ExternalEO operator()(void) { return (*init)(); }
void operator()(ExternalEO& _eo)
{
_eo = (*init)();
_eo.invalidate();
}
private :
@ -67,18 +69,17 @@ private :
Where External is the user defined struct or class and Fit the fitness type
*/
template <class F, class External>
class eoExternalEvalFunc : public eoEvalFunc<eoExternalEO<F, External> >
template <class F, class External, class ExternalEO = eoExternalEO<F, External> >
class eoExternalEvalFunc : public eoEvalFunc<ExternalEO>
{
public :
typedef eoExternalEO<F, External> ExternalEO;
eoExternalEvalFunc(F (*_eval)(const External&)) : eval(_eval) {}
void operator()(ExternalEO& eo) const
void operator()(ExternalEO& eo)
{
eo.fitness( (*eval)(eo) );
if (eo.invalid())
eo.fitness( (*eval)(eo) );
}
private :
@ -90,88 +91,86 @@ class eoExternalEvalFunc : public eoEvalFunc<eoExternalEO<F, External> >
Mutation of external struct, ctor expects a function of the following
signature:
void func(External&);
bool func(External&);
Where External is the user defined struct or class
Where External is the user defined struct or class.
The function should return true when it changed something, false otherwise
*/
template <class F, class External>
class eoExternalMonOp : public eoMonOp<eoExternalEO<F, External> >
template <class F, class External, class ExternalEO = eoExternalEO<F, External> >
class eoExternalMonOp : public eoMonOp<ExternalEO>
{
public :
typedef eoExternalEO<F, External> ExternalEO;
eoExternalMonOp(bool (*_mutate)(External&)) : mutate(_mutate) {}
eoExternalMonOp(void (*_mutate)(External&)) : mutate(_mutate) {}
void operator()(ExternalEO& eo) const
void operator()(ExternalEO& eo)
{
(*mutate)(eo);
eo.invalidate();
if ((*mutate)(eo))
eo.invalidate();
}
private :
void (*mutate)(External&);
bool (*mutate)(External&);
};
/**
Crossover of external struct, ctor expects a function of the following
signature:
void func(External&, const External&);
bool func(External&, const External&);
Where External is the user defined struct or class
The function should return true when it changed something, false otherwise
*/
template <class F, class External>
class eoExternalBinOp : public eoBinOp<eoExternalEO<F, External> >
template <class F, class External, class ExternalEO = eoExternalEO<F, External> >
class eoExternalBinOp : public eoBinOp<ExternalEO>
{
public :
typedef eoExternalEO<F, External> ExternalEO;
eoExternalBinOp(bool (*_binop)(External&, const External&)) : binop(_binop) {}
eoExternalBinOp(void (*_binop)(External&, const External&)) : binop(_binop) {}
void operator()(ExternalEO& eo1, const ExternalEO& eo2) const
void operator()(ExternalEO& eo1, const ExternalEO& eo2)
{
(*binop)(eo1, eo2);
eo1.invalidate();
if ((*binop)(eo1, eo2))
eo1.invalidate();
}
private :
void (*binop)(External&, const External&);
bool (*binop)(External&, const External&);
};
/**
Crossover of external struct, ctor expects a function of the following
signature:
void func(External&, External&);
bool func(External&, External&);
Where External is the user defined struct or class
The function should return true when it changed something, false otherwise
*/
template <class F, class External>
class eoExternalQuadraticOp : public eoQuadraticOp<eoExternalEO<F, External> >
template <class F, class External, class ExternalEO = eoExternalEO<F, External> >
class eoExternalQuadraticOp : public eoQuadraticOp<ExternalEO>
{
public :
typedef eoExternalEO<F, External> ExternalEO;
eoExternalQuadraticOp(bool (*_quadop)(External&, External&)) : quadop(_quadop) {}
eoExternalQuadraticOp(void (*_quadop)(External&, External&)) : quadop(_quadop) {}
void operator()(ExternalEO& eo1, ExternalEO& eo2) const
void operator()(ExternalEO& eo1, ExternalEO& eo2)
{
(*quadop)(eo1, eo2);
eo1.invalidate();
eo2.invalidate();
if ((*quadop)(eo1, eo2))
{
eo1.invalidate();
eo2.invalidate();
}
}
private :
void (*quadop)(External&, External&);
bool (*quadop)(External&, External&);
};
#endif

View file

@ -31,105 +31,23 @@
using namespace std;
// EO headers
#include <eo1d.h>
//-----------------------------------------------------------------------------
// eoString
//-----------------------------------------------------------------------------
/** Adaptor that turns an STL string into an EO */
template <class fitnessT >
class eoString: public eo1d<char, fitnessT>, public string {
class eoString: public EO<fitnessT>, public string
{
public:
typedef char Type;
/// Canonical part of the objects: several ctors, copy ctor, dtor and assignment operator
//@{
/// ctor
eoString( const string& _str ="" )
: eo1d<char, fitnessT>(), string( _str ) {};
/** Ctor using a random number generator
@param _size Lineal length of the object
@param _rnd a random number generator, which returns a random value each time it´s called
*/
eoString( unsigned _size, eoRnd<char>& _rnd )
: eo1d<char, fitnessT>(), string(){
for ( unsigned i = 0; i < _size; i ++ ) {
*this += _rnd();
}
};
/** Ctor from a stream
@param _s input stream
*/
eoString( istream & _s )
: eo1d<char, fitnessT>(){
_s >> *this;
};
/// copy ctor
eoString( const eoString<fitnessT>& _eoStr )
:eo1d<char, fitnessT>( static_cast<const eo1d<char, fitnessT> & > ( _eoStr ) ),
string( _eoStr ){};
/// Assignment operator
const eoString& operator =( const eoString& _eoStr ) {
if ( this != & _eoStr ) {
eo1d<char, fitnessT>::operator = ( _eoStr );
string::operator = ( _eoStr );
}
return *this;
}
/// dtor
virtual ~eoString() {};
//@}
/** methods that implement the eo1d <em>protocol</em>
@exception out_of_range if _i is larger than EO´s size
*/
virtual char getGene( unsigned _i ) const {
if ( _i >= length() )
throw out_of_range( "out_of_range when reading gene");
return (*this)[_i];
};
/** methods that implement the eo1d <em>protocol</em>
@exception out_of_range if _i is larger than EO´s size
*/
virtual void setGene( unsigned _i, const char& _value ) {
if ( _i >= size() )
throw out_of_range( "out_of_range when writing a gene");
(*this)[_i] = _value;
};
/** Inserts a value after _i, displacing anything to the right
@exception out_of_range if _i is larger than EO´s size
*/
virtual void insertGene( unsigned _i, char _val ) {
if (_i <= this->size() ) {
string::iterator i = this->begin()+_i;
this->insert( i, _val );
} else
throw out_of_range( "out_of_range when inserting gene");
};
/** Eliminates the gene at position _i
@exception out_of_range if _i is larger than EO´s size
*/
virtual void deleteGene( unsigned _i ) {
if (_i < this->size() ) {
string::iterator i = this->begin()+_i;
this->erase( i );
} else
throw out_of_range( "out_of_range when deleting gene");
};
/// methods that implement the EO <em>protocol</em>
virtual unsigned length() const { return this->size(); };
: string( _str ) {};
/** @name Methods from eoObject
readFrom and printOn are directly inherited from eo1d

View file

@ -1,78 +0,0 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// eoStringMutation.h
// (c) GeNeura Team, 1999
/*
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 _EOSTRINGMUTATION_H
#define _EOSRTINGMUTATION_H
#include <math.h>
// EO includes
#include <eoOp.h>
#include <eoUniform.h>
#include <eoMutation.h>
/** Mutation of an eoString.
The eoString's genes are changed by adding or substracting 1 to
*/
template <class EOT>
class eoStringMutation: public eoMutation<EOT> {
public:
///
eoStringMutation(const double _rate=0.0) : eoMutation< EOT >(_rate) {};
///
virtual ~eoStringMutation() {};
/** @name Methods from eoObject
*/
//@{
/** Inherited from eoObject
@see eoObject
*/
string className() const {return "eoStringMutation";};
//@}
private:
#ifdef _MSC_VER
typedef EOT::Type Type;
#else
typedef typename EOT::Type Type;
#endif
/// applies operator to one gene in the EO. It increments or decrements the value of that gene by one.
virtual void applyAt( EOT& _eo, unsigned _i ) const {
eoUniform<double> uniform( 0, 1 );
if( rate < uniform() ) {
_eo.gene(_i) += ( uniform()>=0.5 )? (1) : (-1) ;
}
}
};
//-----------------------------------------------------------------------------
#endif