moving...

This commit is contained in:
mac 2000-03-22 14:23:20 +00:00
commit 2799347236
7 changed files with 872 additions and 0 deletions

View file

@ -0,0 +1,67 @@
/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
-----------------------------------------------------------------------------
eoExternalEO.h
* Definition of an object that allows an external struct
* to be inserted in EO
(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 eoExternalEO_h
#define eoExternalEO_h
#include "EO.h"
/**
* Definition of an object that allows an external struct
* to be inserted in EO
*/
template <class Fit, class External>
class eoExternalEO : public EO, virtual public External
{
public :
typedef External Type;
eoExternalEO(void) : EO(), Base() {}
eoExternalEO(istream& is) : EO(), Base() { readFrom(is); }
/**
* Read object.\\
* @param _is a istream.
* @throw runtime_exception If a valid object can't be read.
*/
virtual void readFrom(istream& _is)
{
EO::readFrom(is);
throw runtime_excpetion("Reading not defined yet");
}
/**
* Write object. Called printOn since it prints the object _on_ a stream.
* @param _os A ostream.
*/
virtual void printOn(ostream& _os) const
{
EO::printOn(is);
throw runtime_excpetion("Writing not defined yet");
}
};

View file

@ -0,0 +1,41 @@
/* -*- 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 "eoOps.h"
#include "eoRnd.h"
template <class F, class External>
class eoExternalInitFunc
{
public :
};

148
eo/src/other/eoString.h Normal file
View file

@ -0,0 +1,148 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// eoString.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 _eoString_H
#define _eoString_H
// STL libraries
#include <string>
#include <stdexcept>
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 {
public:
/// 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(); };
/** @name Methods from eoObject
readFrom and printOn are directly inherited from eo1d
*/
//@{
/** Inherited from eoObject
@see eoObject
*/
virtual string className() const {return "eoString";};
//@}
};
#endif

View file

@ -0,0 +1,78 @@
// -*- 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