Extreme cleanup, see src/obsolete for details
This commit is contained in:
parent
7f04d616e6
commit
6d8e3a6504
47 changed files with 3937 additions and 1815 deletions
199
eo/src/obsolete/eo1d.h
Normal file
199
eo/src/obsolete/eo1d.h
Normal file
|
|
@ -0,0 +1,199 @@
|
|||
/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
eo1d.h
|
||||
Serial EO.
|
||||
|
||||
(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 _EO1D_H
|
||||
#define _EO1D_H
|
||||
|
||||
#include <iostream> // for ostream
|
||||
|
||||
// EO Includes
|
||||
#include <EO.h>
|
||||
#include <eoRnd.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/** @name eo1d class
|
||||
* Randomly accesible evolvable object with one dimension, with variable
|
||||
* length. Use this if you want to evolve "linear" things, like bitstrings,
|
||||
* or floating-point arrays. If you don't, subclass directly from EO
|
||||
* @see EO
|
||||
* @author GeNeura
|
||||
* @version 0.2
|
||||
*/
|
||||
|
||||
//@{
|
||||
/**
|
||||
@deprecated {eo1d} eo1d
|
||||
\deprecated
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
eo1d: Base class for "chromosomes" with a single dimension
|
||||
#T# is the type it will be instantiated with; this type must have, at
|
||||
least, a copy ctor, assignment operators,
|
||||
|
||||
\deprecated
|
||||
As eo1d provides a so-called 'fat' interface, it might be wiser to
|
||||
use eoFixedLength or eoVariableLength instead, that derive from
|
||||
vector and list respectively and (important) redirect the less than
|
||||
comparison operator to EO rather than the STL variants.
|
||||
|
||||
@see eoFixedLength eoVariableLength
|
||||
*/
|
||||
template<class T, class fitnessT = float>
|
||||
class eo1d: public EO< fitnessT > {
|
||||
public:
|
||||
|
||||
/// Declaration to make it accessible from subclasses
|
||||
typedef T Type;
|
||||
|
||||
/** Can be used as default ctor; should be called from derived
|
||||
classes. Fitness should be at birth
|
||||
*/
|
||||
eo1d()
|
||||
:EO<fitnessT> ( ) {};
|
||||
|
||||
/** Ctor using a random number generator and with an specified size
|
||||
@param _rndGen Random number generator
|
||||
@param _size lineal dimension of the eo1d
|
||||
@param _ID An ID string, preferably unique
|
||||
*/
|
||||
eo1d( unsigned _size, eoRnd<T>& _rndGen, const string& _ID = "");
|
||||
|
||||
/** Ctor from a istream. It just passes the stream to EO, subclasses should
|
||||
have to implement this.
|
||||
@param _is the input stream
|
||||
*/
|
||||
eo1d( istream& _is): EO<fitnessT>(){ readFrom(is); }
|
||||
|
||||
/// Copy ctor
|
||||
eo1d( const eo1d& _eo )
|
||||
:EO<fitnessT> ( _eo ) {};
|
||||
|
||||
/// Assignment operator
|
||||
const eo1d& operator= ( const eo1d& _eo ) {
|
||||
EO<fitnessT>::operator = ( _eo );
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Needed virtual dtor
|
||||
virtual ~eo1d(){};
|
||||
|
||||
/** Reads and returns a copy of the gene in position _i
|
||||
This implies that T must have a copy ctor .
|
||||
@param _i index of the gene, which is the minimal unit. Must be
|
||||
an unsigned less than #length()#
|
||||
@return what's inside the gene, with the correct type
|
||||
@exception out_of_range if _i > size()
|
||||
*/
|
||||
virtual T getGene( unsigned _i ) const = 0;
|
||||
|
||||
/** Overwrites the gene placed in position _i with a
|
||||
* new value. This means that the assignment operator
|
||||
* for T must be defined .
|
||||
@param _i index
|
||||
@return what's inside the gene, with the correct type
|
||||
@exception out_of_range if _i > size()
|
||||
*/
|
||||
virtual void setGene( unsigned _i, const T& _value ) = 0;
|
||||
|
||||
/** Inserts a gene, moving the rest to the right. If
|
||||
* _i = length(), it should insert it at the end.
|
||||
* Obviously, changes length
|
||||
@param _i index
|
||||
@param _val new value
|
||||
*/
|
||||
virtual void insertGene( unsigned _i, T _val ) = 0;
|
||||
|
||||
/** Eliminates the gene at position _i; all the other genes will
|
||||
be shifted left
|
||||
@param _i index of the gene that is going to be modified.
|
||||
*/
|
||||
virtual void deleteGene( unsigned _i ) = 0;
|
||||
|
||||
/// Returns the number of genes in the eo1d
|
||||
virtual unsigned length() const = 0;
|
||||
|
||||
/// @name Methods from eoObject
|
||||
//@{
|
||||
/**
|
||||
* Read object. Theoretically, the length is known in advance. All objects
|
||||
* Should call base class
|
||||
* @param _s A istream.
|
||||
* @throw runtime_exception If a valid object can't be read.
|
||||
*/
|
||||
virtual void readFrom(istream& _s) {
|
||||
|
||||
for ( unsigned i = 0; i < length(); i ++ ) {
|
||||
T tmp;
|
||||
_s >> tmp;
|
||||
setGene( i, tmp );
|
||||
}
|
||||
// there is no way of distinguishing fitness from the object, so
|
||||
// it's skipped
|
||||
}
|
||||
|
||||
/** Print itself: inherited from eoObject implementation.
|
||||
Instance from base classes are processed in
|
||||
base classes, so you don´t have to worry about, for instance, fitness.
|
||||
@param _s the ostream in which things are written*/
|
||||
virtual void printOn( ostream& _s ) const{
|
||||
for ( unsigned i = 0; i < length(); i ++ ) {
|
||||
_s << getGene( i ) << " ";
|
||||
}
|
||||
}
|
||||
|
||||
/** Inherited from eoObject
|
||||
@see eoObject
|
||||
*/
|
||||
string className() const {return "eo1d";};
|
||||
|
||||
//@}
|
||||
|
||||
};
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
// --------------- Implementations --------------------------
|
||||
|
||||
/* Ctor using a random number generator and with an specified size
|
||||
@param _rndGen Random number generator
|
||||
@param _size lineal dimension of the eo1d
|
||||
@param _ID An ID string, preferably unique
|
||||
*/
|
||||
template< class T, class fitnessT>
|
||||
eo1d<T,fitnessT>::eo1d<T,fitnessT>( unsigned _size, eoRnd<T>& _rndGen,
|
||||
const string& _ID )
|
||||
:EO<fitnessT> ( _ID ) {
|
||||
for ( unsigned i = 0; i < _size; i ++ ) {
|
||||
insertGene( i, _rndGen() );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
136
eo/src/obsolete/eo1dWDistance.h
Normal file
136
eo/src/obsolete/eo1dWDistance.h
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
eo1dWDistance.h
|
||||
Serial EO with distances. Acts as a wrapper for normal eo1ds
|
||||
|
||||
(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 _EO1DWDISTANCE_H
|
||||
#define _EO1DWDISTANCE_H
|
||||
|
||||
#include <iostream> // for ostream
|
||||
|
||||
// EO Includes
|
||||
#include <eo1d.h>
|
||||
#include <eoDistance.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/** eo1dWDistance: wraps around eo1ds and adds the possibility of computing distances
|
||||
around them.
|
||||
*/
|
||||
template<class T, class fitnessT = float>
|
||||
class eo1dWDistance:
|
||||
public eo1d< T,fitnessT >,
|
||||
public eoDistance<eo1d<T,fitnessT> > {
|
||||
public:
|
||||
|
||||
/** Can be used as default ctor; should be called from derived
|
||||
classes. Fitness should be at birth
|
||||
*/
|
||||
eo1dWDistance( eo1d<T,fitnessT>& _eo)
|
||||
:eo1d<T,fitnessT> (), eoDistance< eo1d<T,fitnessT> >(), innereo1d( _eo ) {};
|
||||
|
||||
/// Needed virtual dtor
|
||||
virtual ~eo1dWDistance(){};
|
||||
|
||||
/** Reads and returns a copy of the gene in position _i
|
||||
This implies that T must have a copy ctor .
|
||||
@param _i index of the gene, which is the minimal unit. Must be
|
||||
an unsigned less than #length()#
|
||||
@return what's inside the gene, with the correct type
|
||||
@exception out_of_range if _i > size()
|
||||
*/
|
||||
virtual T getGene( unsigned _i ) const {
|
||||
return innereo1d.getGene( _i );
|
||||
};
|
||||
|
||||
/** Overwrites the gene placed in position _i with a
|
||||
* new value. This means that the assignment operator
|
||||
* for T must be defined .
|
||||
@param _i index
|
||||
@return what's inside the gene, with the correct type
|
||||
@exception out_of_range if _i > size()
|
||||
*/
|
||||
virtual void setGene( unsigned _i, const T& _value ) {
|
||||
innereo1d.setGene( _i, _value);
|
||||
};
|
||||
|
||||
/** Inserts a gene, moving the rest to the right. If
|
||||
* _i = length(), it should insert it at the end.
|
||||
* Obviously, changes length
|
||||
@param _i index
|
||||
@param _val new value
|
||||
*/
|
||||
virtual void insertGene( unsigned _i, T _val ) {
|
||||
innereo1d.insertGene( _i, _val);
|
||||
}
|
||||
|
||||
/** Eliminates the gene at position _i; all the other genes will
|
||||
be shifted left
|
||||
@param _i index of the gene that is going to be modified.
|
||||
*/
|
||||
virtual void deleteGene( unsigned _i ) {
|
||||
innereo1d.deleteGene( _i );
|
||||
}
|
||||
|
||||
/// Returns the number of genes in the eo1d
|
||||
virtual unsigned length() const {
|
||||
return innereo1d.length();
|
||||
}
|
||||
|
||||
/// Returns the distance from this EO to the other
|
||||
virtual double distance( const eo1d<T,fitnessT>& _eo ) const {
|
||||
double tmp = 0;
|
||||
// Which one is shorter
|
||||
unsigned len = (innereo1d.length() < _eo.length()) ? _eo.length():innereo1d.length();
|
||||
|
||||
// Compute over the whole length. If it does not exists, it counts as 0
|
||||
for ( unsigned i = 0; i < len; i ++ ) {
|
||||
T val1, val2;
|
||||
val1 = ( i > innereo1d.length())?0:innereo1d.getGene(i);
|
||||
val2 = ( i > _eo.length() )?0:_eo.getGene(i);
|
||||
double diff = val1 - val2;
|
||||
tmp += diff*diff;
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/** Inherited from eoObject
|
||||
@see eoObject
|
||||
*/
|
||||
string className() const {return "eo1dWDistance";};
|
||||
|
||||
//@}
|
||||
|
||||
private:
|
||||
///Private ctor. Do not use
|
||||
eo1dWDistance() {};
|
||||
|
||||
|
||||
eo1d<T,fitnessT>& innereo1d;
|
||||
};
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
#endif
|
||||
242
eo/src/obsolete/eo2d.h
Normal file
242
eo/src/obsolete/eo2d.h
Normal file
|
|
@ -0,0 +1,242 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
File............: eo2d.h
|
||||
Author..........: Geneura Team (this file: Victor Rivas, vrivas@ujaen.es)
|
||||
Date............: 21-Sep-1999, at Fac. of Sciences, Univ. of Granada (Spain)
|
||||
Description.....: Implementation of a 2-dimensional chromosome.
|
||||
|
||||
================ Modif. 1 ================
|
||||
Author........:
|
||||
Date..........:
|
||||
Description...:
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
// eo2d.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 _EO2D_H
|
||||
#define _EO2D_H
|
||||
|
||||
#include <iostream> // for ostream
|
||||
#include <vector>
|
||||
|
||||
// EO Includes
|
||||
#include <EO.h>
|
||||
#include <eoRnd.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/** @name eo2d class
|
||||
* Randomly accesible evolvable object with two dimension, with
|
||||
variable length each of them.
|
||||
* Use this if you want to evolve "two-dimensional" things, like bit arrays, or
|
||||
floating-point arrays. If you don't, subclass directly from EO
|
||||
* @see EO
|
||||
* @author GeNeura
|
||||
* @version 0.2
|
||||
*/
|
||||
|
||||
//@{
|
||||
|
||||
/** eo2d: Base class for "chromosomes" with a double dimension
|
||||
#T# is the type it will be instantiated with; this type must have, at
|
||||
least, a copy ctor, assignment operators,
|
||||
*/
|
||||
template<class T, class fitnessT = float>
|
||||
class eo2d: public EO< fitnessT > {
|
||||
public:
|
||||
|
||||
/// Declaration to make it accessible from subclasses
|
||||
typedef T Type;
|
||||
|
||||
/** Can be used as default ctor; should be called from derived
|
||||
classes. Fitness should be at birth
|
||||
*/
|
||||
eo2d()
|
||||
:EO<fitnessT> ( ) {};
|
||||
|
||||
/** Ctor using a random number generator and with an specified size
|
||||
@param _rows Initial number of rows
|
||||
@param _columns Initial number of columns
|
||||
@param _rndGen Random "T-type" generator
|
||||
@param _ID An ID string, preferably unique
|
||||
*/
|
||||
eo2d( const unsigned _rows,
|
||||
const unsigned _columns,
|
||||
eoRnd<T>& _rndGen,
|
||||
const string& _ID = "");
|
||||
|
||||
/** Ctor from an istream. It just passes the stream to EO, subclasses should
|
||||
have to implement this.
|
||||
@param _is the input stream
|
||||
*/
|
||||
eo2d( istream& _is): EO<fitnessT>( _is ){};
|
||||
|
||||
/// Copy ctor
|
||||
eo2d( const eo2d& _eo )
|
||||
:EO<fitnessT> ( _eo ) {};
|
||||
|
||||
/// Assignment operator
|
||||
const eo2d& operator= ( const eo2d& _eo ) {
|
||||
EO<fitnessT>::operator = ( _eo );
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Needed virtual dtor
|
||||
virtual ~eo2d(){};
|
||||
|
||||
/** Reads and returns a copy of the gene in position _r,_c.\
|
||||
This implies that T must have a copy ctor .
|
||||
@param _r Index for rows. Must be an unsigned less than #numOfRows()#
|
||||
@param _c Index for columns. Must be an unsigned less than #numOfCols()#
|
||||
@return what's inside the gene, with the correct type
|
||||
@exception out_of_range if _r >=numOfRows()
|
||||
@exception out_of_range if _c >=numOfCols()
|
||||
*/
|
||||
virtual T getGene( const unsigned _r,
|
||||
const unsigned _j ) const = 0;
|
||||
|
||||
/** Overwrites the gene placed in position _r,_c with a
|
||||
* new value. This means that the assignment operator
|
||||
* for T must be defined .
|
||||
@param _r Index for rows. Must be an unsigned less than #numOfRows()#
|
||||
@param _c Index for columns. Must be an unsigned less than #numOfCols()#
|
||||
@return what's inside the gene, with the correct type
|
||||
@exception out_of_range if _r >=numOfRows()
|
||||
@exception out_of_range if _c >=numOfCols()
|
||||
*/
|
||||
virtual void setGene( const unsigned _r,
|
||||
const unsigned _c,
|
||||
const T& _value ) = 0;
|
||||
|
||||
/** Inserts a row, moving the rest to the bottom.
|
||||
* If _r = numOfRows(), it insert it at the end.
|
||||
* Obviously, changes number of rows.
|
||||
@param _r Position where the new row will be inserted.
|
||||
@param _val Vector containing the new values to be inserted.
|
||||
@exception invalid_argument If _val has not numOfCols() components.
|
||||
@exception out_of_range If _r is greater than numOfRows()
|
||||
*/
|
||||
virtual void insertRow( const unsigned _r,
|
||||
const vector<T>& _val ) = 0;
|
||||
|
||||
/** Eliminates the row at position _r; all the other genes will
|
||||
be shifted up.
|
||||
@param _r Number of he row to be deleted.
|
||||
@exception out_of_range if _r >=numOfRows()
|
||||
*/
|
||||
virtual void deleteRow( const unsigned _r ) = 0;
|
||||
|
||||
/** Inserts a column, moving the rest to the right.
|
||||
* If _c = numOfCols(), it insert it at the end.
|
||||
* Obviously, changes number of cols.
|
||||
@param _r Position where the new column will be inserted.
|
||||
@param _val Vector containing the new values to be inserted.
|
||||
@exception invalid_argument if _val has not numOfRows() components.
|
||||
*/
|
||||
virtual void insertCol( const unsigned _c,
|
||||
const vector<T>& _val ) = 0;
|
||||
|
||||
/** Eliminates the column at position _c; all the other columns will
|
||||
be shifted left.
|
||||
@param _c Number of he column to be deleted.
|
||||
@exception out_of_range if _c >=numOfCols()
|
||||
*/
|
||||
virtual void deleteCol( const unsigned _c ) = 0;
|
||||
|
||||
/// Returns the number of rows in the eo2d
|
||||
virtual unsigned numOfRows() const = 0;
|
||||
|
||||
/// Returns the number of columns in the eo2d
|
||||
virtual unsigned numOfCols() const = 0;
|
||||
|
||||
/// @name Methods from eoObject
|
||||
//@{
|
||||
/**
|
||||
* Read object. Theoretically, the length is known in advance. All objects
|
||||
* Should call base class
|
||||
* @param _s A istream.
|
||||
* @throw runtime_exception If a valid object can't be read.
|
||||
*/
|
||||
virtual void readFrom(istream& _s) {
|
||||
|
||||
for ( unsigned r = 0; r < numOfRows(); ++r ) {
|
||||
for ( unsigned c = 0; c < numOfCols(); ++c ) {
|
||||
T tmp;
|
||||
_s >> tmp;
|
||||
setGene( r, c, tmp );
|
||||
}
|
||||
}
|
||||
// there is no way of distinguishing fitness from the object, so
|
||||
// it's skipped
|
||||
}
|
||||
|
||||
/** Print itself: inherited from eoObject implementation.
|
||||
Instance from base classes are processed in
|
||||
base classes, so you don´t have to worry about, for instance, fitness.
|
||||
@param _s the ostream in which things are written*/
|
||||
virtual void printOn( ostream& _s ) const{
|
||||
for ( unsigned r = 0; r < numOfRows(); ++r ) {
|
||||
for ( unsigned c = 0; c < numOfCols(); ++c ) {
|
||||
_s << getGene( r,c ) << " ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Inherited from eoObject
|
||||
@see eoObject
|
||||
*/
|
||||
string className() const {return "eo2d";};
|
||||
|
||||
//@}
|
||||
|
||||
};
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
// --------------- Implementations --------------------------
|
||||
|
||||
/** Ctor using a random number generator and with an specified size
|
||||
@param _rows Initial number of rows
|
||||
@param _columns Initial number of columns
|
||||
@param _rndGen Random "T-type" generator
|
||||
@param _ID An ID string, preferably unique
|
||||
*/
|
||||
template< class T, class fitnessT>
|
||||
eo2d<T,fitnessT>::eo2d<T,fitnessT>( const unsigned _rows,
|
||||
const unsigned _columns,
|
||||
eoRnd<T>& _rndGen,
|
||||
const string& _ID = "")
|
||||
:EO<fitnessT> ( _ID ) {
|
||||
for ( unsigned r = 0; r < _rows; ++r ) {
|
||||
for ( unsigned c = 0; c < _cols; ++c ) {
|
||||
insertGene( r, c, _rndGen() );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
334
eo/src/obsolete/eo2dVector.h
Normal file
334
eo/src/obsolete/eo2dVector.h
Normal file
|
|
@ -0,0 +1,334 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
File............: eo2dVector.h
|
||||
Author..........: Geneura Team (this file: Victor Rivas, vrivas@ujaen.es)
|
||||
Date............: 29-Sep-1999, at Fac. of Sciences, Univ. of Granada (Spain)
|
||||
Description.....: Implementation of a 2-dimensional chromosome usign STL
|
||||
vectors.
|
||||
|
||||
================ Modif. 1 ================
|
||||
Author........:
|
||||
Date..........:
|
||||
Description...:
|
||||
|
||||
QUEDA: Operador de asignación, lectura desde istream, escritura a ostream
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
// eo2dVector.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 _eo2dVector_H
|
||||
#define _eo2dVector_H
|
||||
|
||||
// STL libraries
|
||||
#include <vector> // For vector<int>
|
||||
#include <stdexcept>
|
||||
#include <strstream>
|
||||
#include <iostream.h>
|
||||
|
||||
#include <eo2d.h>
|
||||
#include <eoRnd.h>
|
||||
|
||||
/** Adaptor that turns an STL vector of vectror into an EO
|
||||
with the same gene type as the type with which
|
||||
the vector of vector has been instantiated.
|
||||
*/
|
||||
template <class T, class fitnessT>
|
||||
class eo2dVector: public eo2d<T, fitnessT>, public vector< vector<T> > {
|
||||
public:
|
||||
typedef T Type ;
|
||||
|
||||
/** @name Canonical part of the objects: several ctors, copy ctor, \
|
||||
* dtor and assignment operator.
|
||||
*/
|
||||
//@{
|
||||
|
||||
/** Ctor.
|
||||
@param _rows Number of rows.
|
||||
@param _cols Number of columns.
|
||||
@param _val Common initial value
|
||||
*/
|
||||
eo2dVector( const unsigned _rows = 0,
|
||||
const unsigned _cols = 0,
|
||||
T _val = T() )
|
||||
: eo2d<T, fitnessT>(), vector< vector<T> >( _rows, vector<T>( _cols, _val ) ){};
|
||||
|
||||
/** Ctor using a random number generator.
|
||||
@param _rows Number of rows.
|
||||
@param _cols Number of columns.
|
||||
@param _rnd A random "T-type" generator, which returns a random value each time it´s called.
|
||||
*/
|
||||
eo2dVector( const unsigned _rows,
|
||||
const unsigned _cols,
|
||||
eoRnd<T>& _rnd );
|
||||
|
||||
/** Ctor from a istream. The T class should accept reading from a istream. It doesn't read fitness,
|
||||
which is supposed to be dynamic and dependent on environment.
|
||||
@param _is the input stream; should have all values in a single line, separated by whitespace
|
||||
*/
|
||||
//eo2dVector( istream& _is);
|
||||
|
||||
|
||||
/// copy ctor
|
||||
eo2dVector( const eo2dVector & _eo )
|
||||
: eo2d<T, fitnessT>( _eo ), vector< vector<T> >( _eo ){ };
|
||||
|
||||
/// Assignment operator
|
||||
/*
|
||||
const eo2dVector& operator =( const eo2dVector & _eo ) {
|
||||
if ( this != &_eo ){
|
||||
eo2d<T, fitnessT>::operator=( _eo );
|
||||
vector< <vector<T> >::operator=( _eo );
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
*/
|
||||
/// dtor
|
||||
virtual ~eo2dVector() {};
|
||||
|
||||
//@}
|
||||
/** Reads and returns a copy of the gene in position _r,_c.\
|
||||
This implies that T must have a copy ctor .
|
||||
@param _r Index for rows. Must be an unsigned less than #numOfRows()#
|
||||
@param _c Index for columns. Must be an unsigned less than #numOfCols()#
|
||||
@return what's inside the gene, with the correct type
|
||||
@exception out_of_range if _r >=numOfRows()
|
||||
@exception out_of_range if _c >=numOfCols()
|
||||
*/
|
||||
virtual T getGene( const unsigned _r,
|
||||
const unsigned _c ) const {
|
||||
if ( _r >= numOfRows() ) {
|
||||
ostrstream msg;
|
||||
msg << "ERROR in eo2dVector::getGene: row out of range. "
|
||||
<< "It should be <" << numOfRows() << '\0' << endl;
|
||||
throw out_of_range( msg.str() );
|
||||
}
|
||||
if ( _c >= numOfCols() ) {
|
||||
ostrstream msg;
|
||||
msg << "ERROR in eo2dVector::getGene: column out of range. "
|
||||
<< "It should be <" << numOfCols() << '\0' << endl;
|
||||
throw out_of_range( msg.str() );
|
||||
}
|
||||
return (*this)[_r][_c];
|
||||
};
|
||||
/** Overwrites the gene placed in position _r,_c with a
|
||||
* new value. This means that the assignment operator
|
||||
* for T must be defined .
|
||||
@param _r Index for rows. Must be an unsigned less than #numOfRows()#
|
||||
@param _c Index for columns. Must be an unsigned less than #numOfCols()#
|
||||
@return what's inside the gene, with the correct type
|
||||
@exception out_of_range if _r >=numOfRows()
|
||||
@exception out_of_range if _c >=numOfCols()
|
||||
*/
|
||||
virtual void setGene( const unsigned _r,
|
||||
const unsigned _c,
|
||||
const T& _value ) {
|
||||
if ( _r >= numOfRows() ) {
|
||||
ostrstream msg;
|
||||
msg << "ERROR in eo2dVector::setGene: row out of range. "
|
||||
<< "It should be <" << numOfRows() << '\0' << endl;
|
||||
throw out_of_range( msg.str() );
|
||||
}
|
||||
if ( _c >= numOfCols() ) {
|
||||
ostrstream msg;
|
||||
msg << "ERROR in eo2dVector::setGene: column out of range. "
|
||||
<< "It should be <" << numOfCols() << '\0' << endl;
|
||||
throw out_of_range( msg.str() );
|
||||
}
|
||||
(*this)[_r][_c]=_value;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** Inserts a row, moving the rest to the bottom.
|
||||
* If _r = numOfRows(), it insert it at the end.
|
||||
* Obviously, changes number of rows.
|
||||
@param _r Position where the new row will be inserted.
|
||||
@param _val Vector containing the new values to be inserted.
|
||||
@exception invalid_argument If _val has not numOfCols() components.
|
||||
@exception out_of_range If _r is greater than numOfRows()
|
||||
*/
|
||||
virtual void insertRow( const unsigned _r,
|
||||
const vector<T>& _val ) {
|
||||
// Test errors.
|
||||
if ( _r > numOfRows() ) {
|
||||
ostrstream msg;
|
||||
msg << "ERROR in eo2dVector::insertRow: row out of range. "
|
||||
<< "It should be <=" << numOfRows() << '\0' << endl;
|
||||
throw out_of_range( msg.str() );
|
||||
}
|
||||
if ( _val.size() != numOfCols() ) {
|
||||
ostrstream msg;
|
||||
msg << "ERROR in eo2dVector::insertRow: "
|
||||
<< "Incorrect number of values to be added. "
|
||||
<< "It should be ==" << numOfCols() << '\0' << endl;
|
||||
throw invalid_argument( msg.str() );
|
||||
}
|
||||
|
||||
// Insert the row.
|
||||
vector< vector<T> >::iterator ite = begin()+_r;
|
||||
insert( ite, _val );
|
||||
};
|
||||
|
||||
/** Eliminates the row at position _r; all the other genes will
|
||||
be shifted up.
|
||||
@param _r Number of he row to be deleted.
|
||||
@exception out_of_range if _r >=numOfRows()
|
||||
*/
|
||||
virtual void deleteRow( const unsigned _r ) {
|
||||
// Test error.
|
||||
if ( _r >= numOfRows() ) {
|
||||
ostrstream msg;
|
||||
msg << "ERROR in eo2dVector::deleteRow: "
|
||||
<< "Row out of range. "
|
||||
<< "It should be <" << numOfRows() << '\0' << endl;
|
||||
throw out_of_range( msg.str() );
|
||||
}
|
||||
// Delete row.
|
||||
vector< vector<T> >::iterator ite = this->begin()+_r;
|
||||
this->erase( ite );
|
||||
};
|
||||
|
||||
/** Inserts a column, moving the rest to the right.
|
||||
* If _c = numOfCols(), it insert it at the end.
|
||||
* Obviously, changes number of cols.
|
||||
@param _r Position where the new column will be inserted.
|
||||
@param _val Vector containing the new values to be inserted.
|
||||
@exception invalid_argument if _val has not numOfRows() components.
|
||||
*/
|
||||
virtual void insertCol( const unsigned _c,
|
||||
const vector<T>& _val ) {
|
||||
// Test errors.
|
||||
if ( _c > numOfCols() ) {
|
||||
ostrstream msg;
|
||||
msg << "ERROR in eo2dVector::insertCol: "
|
||||
<< "Column out of range. "
|
||||
<< "It should be >=" << numOfCols() << '\0' << endl;
|
||||
throw out_of_range( msg.str() );
|
||||
}
|
||||
if ( _val.size() != numOfRows() ) {
|
||||
ostrstream msg;
|
||||
msg << "ERROR in eo2dVector::insertCol: "
|
||||
<< "Incorrect number of values to be added. "
|
||||
<< "It should be ==" << numOfRows() << '\0' << endl;
|
||||
throw invalid_argument( msg.str() );
|
||||
}
|
||||
|
||||
// Insert column.
|
||||
for( unsigned r=0; r<numOfRows(); ++r ) {
|
||||
vector<vector<T> >::iterator it1 = begin()+r;
|
||||
vector<T>::iterator it2 = (*it1).begin()+_c;
|
||||
(*it1).insert( it2, _val[r] );
|
||||
};
|
||||
}
|
||||
|
||||
/** Eliminates the column at position _c; all the other columns will
|
||||
be shifted left.
|
||||
@param _c Number of he column to be deleted.
|
||||
@exception out_of_range if _c >=numOfCols()
|
||||
*/
|
||||
virtual void deleteCol( const unsigned _c ) {
|
||||
// Test error.
|
||||
if ( _c >= numOfCols() ) {
|
||||
ostrstream msg;
|
||||
msg << "ERROR in eo2dVector::deleteCol: "
|
||||
<< "Column out of range. "
|
||||
<< "It should be <" << numOfCols() << '\0' << endl;
|
||||
throw out_of_range( msg.str() );
|
||||
}
|
||||
// Delete columns.
|
||||
for( unsigned r=0; r<numOfRows(); ++r ) {
|
||||
vector<vector<T> >::iterator it1 = begin()+r;
|
||||
vector<T>::iterator it2 = (*it1).begin()+_c;
|
||||
(*it1).erase( it2 );
|
||||
}
|
||||
};
|
||||
|
||||
/// Returns the number of rows in the eo2d
|
||||
virtual unsigned numOfRows() const {
|
||||
return size();
|
||||
};
|
||||
|
||||
/// Returns the number of columns in the eo2d
|
||||
virtual unsigned numOfCols() const {
|
||||
return begin()->size();
|
||||
};
|
||||
|
||||
|
||||
/** @name Methods from eoObject
|
||||
readFrom and printOn are directly inherited from eo1d
|
||||
*/
|
||||
//@{
|
||||
/** Inherited from eoObject
|
||||
@see eoObject
|
||||
*/
|
||||
string className() const {return "eo2dVector";};
|
||||
//@}
|
||||
|
||||
};
|
||||
|
||||
|
||||
//____________________________ Some method implementation ____________________
|
||||
|
||||
// Ctors_______________________________________________________________________
|
||||
//_____________________________________________________________________________
|
||||
template <class T, class fitnessT>
|
||||
eo2dVector<T,fitnessT>::eo2dVector( const unsigned _rows,
|
||||
const unsigned _cols,
|
||||
eoRnd<T>& _rnd )
|
||||
: eo2d<T, fitnessT>(), vector< vector<T> >( _rows, vector<T>( _cols, T() ) ){
|
||||
for ( vector< vector<T> >::iterator i = begin(); i != end(); ++i ) {
|
||||
for( vector<T>::iterator j=(*i).begin(); j!= (*i).end(); ++j ) {
|
||||
*j = _rnd();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//_____________________________________________________________________________
|
||||
/*template <class T, class fitnessT>
|
||||
eoVector<T,fitnessT>::eoVector( istream& _is)
|
||||
: eo1d<T, fitnessT>(), vector<T>( ){
|
||||
while (_is ) {
|
||||
T tmp;
|
||||
_is >> tmp;
|
||||
push_back( tmp );
|
||||
}
|
||||
|
||||
};
|
||||
*/
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <class T, class fitnessT>
|
||||
ostream& operator<<( ostream& _os, const eo2dVector<T,fitnessT>& _eo) {
|
||||
for( unsigned i=0; i<_eo.numOfRows(); ++i ) {
|
||||
for( unsigned j=0; j<_eo.numOfCols(); ++j ) {
|
||||
_os << _eo.getGene( i,j ) << " ";
|
||||
}
|
||||
_os << endl;
|
||||
}
|
||||
return _os;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
58
eo/src/obsolete/eoAtomBitFlip.h
Normal file
58
eo/src/obsolete/eoAtomBitFlip.h
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoAtomBitFlip.h
|
||||
// Increments or decrements by one a single element
|
||||
// (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 _EOATOMBITFLIP_H
|
||||
#define _EOATOMBITFLIP_H
|
||||
|
||||
/** Flips a single bit
|
||||
*/
|
||||
template <class T>
|
||||
class eoAtomBitFlip: public eoAtomMutator<bool> {
|
||||
public:
|
||||
|
||||
///
|
||||
eoAtomBitFlip() {};
|
||||
|
||||
///
|
||||
virtual ~eoAtomBitFlip() {};
|
||||
|
||||
///
|
||||
virtual void operator()( T& _val ) const {
|
||||
_val = !val;
|
||||
}
|
||||
|
||||
/** @name Methods from eoObject
|
||||
*/
|
||||
//@{
|
||||
/** Inherited from eoObject
|
||||
@see eoObject
|
||||
*/
|
||||
string className() const {return "eoAtomBitFlip";};
|
||||
//@}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
66
eo/src/obsolete/eoAtomCreep.h
Normal file
66
eo/src/obsolete/eoAtomCreep.h
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoAtomCreep.h
|
||||
// Increments or decrements by one a single element
|
||||
// (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 _EOATOMCREEP_H
|
||||
#define _EOATOMCREEP_H
|
||||
|
||||
#include <utils/eoRNG.h>
|
||||
#include <eoAtomMutator.h>
|
||||
|
||||
/** With uniform probability, decrements or increments by one the value.
|
||||
The value type must admit post increment and decrement.
|
||||
*/
|
||||
template <class T>
|
||||
class eoAtomCreep: public eoAtomMutator<T> {
|
||||
public:
|
||||
|
||||
///
|
||||
eoAtomCreep() {};
|
||||
|
||||
///
|
||||
virtual ~eoAtomCreep() {};
|
||||
|
||||
///
|
||||
virtual void operator()( T& _val ) const {
|
||||
if ( rng.flip( 0.5 ) ) {
|
||||
_val++;
|
||||
} else {
|
||||
_val--;
|
||||
}
|
||||
}
|
||||
|
||||
/** @name Methods from eoObject
|
||||
*/
|
||||
//@{
|
||||
/** Inherited from eoObject
|
||||
@see eoObject
|
||||
*/
|
||||
virtual string className() const {return "eoAtomCreep";};
|
||||
//@}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
95
eo/src/obsolete/eoAtomMutation.h
Normal file
95
eo/src/obsolete/eoAtomMutation.h
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoAtomMutation.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 _EOATOMMUTATION_H
|
||||
#define _EOATOMMUTATION_H
|
||||
|
||||
// STL includes
|
||||
#include <iterator>
|
||||
|
||||
// EO includes
|
||||
#include <eoOp.h>
|
||||
#include <utils/eoRNG.h>
|
||||
#include <eoAtomMutator.h>
|
||||
|
||||
/** Atomic mutation of an EO. Acts on containers, and applies a mutation
|
||||
operator to each element of the container with some probability. EOT must
|
||||
be a container of any type
|
||||
*/
|
||||
template <class EOT>
|
||||
class eoAtomMutation: public eoMonOp<EOT> {
|
||||
public:
|
||||
|
||||
#ifdef _MSC_VER
|
||||
typedef EOT::Type Type;
|
||||
#else
|
||||
typedef typename EOT::Type Type;
|
||||
#endif
|
||||
|
||||
///
|
||||
eoAtomMutation(const eoAtomMutator<Type>& _atomMut, const double _rate=0.0)
|
||||
: eoMonOp< EOT >(), rate(_rate), atomMutator( _atomMut ) {};
|
||||
|
||||
///
|
||||
virtual ~eoAtomMutation() {};
|
||||
|
||||
///
|
||||
virtual void operator()( EOT& _eo ) const {
|
||||
typename EOT::iterator i;
|
||||
for ( i = _eo.begin(); i != _eo.end(); i ++ )
|
||||
if ( rng.flip( rate ) ) {
|
||||
atomMutator( *i );
|
||||
}
|
||||
}
|
||||
|
||||
/** To print me on a stream.
|
||||
@param os The ostream.
|
||||
*/
|
||||
void printOn(ostream& os) const {
|
||||
os << rate ;
|
||||
}
|
||||
|
||||
/** To read me from a stream.
|
||||
@param is The istream */
|
||||
void readFrom(istream& is) {
|
||||
is >> rate ;
|
||||
}
|
||||
|
||||
/** @name Methods from eoObject
|
||||
*/
|
||||
//@{
|
||||
/** Inherited from eoObject
|
||||
@see eoObject
|
||||
*/
|
||||
string className() const {return "eoMutation";};
|
||||
//@}
|
||||
|
||||
private:
|
||||
|
||||
double rate;
|
||||
const eoAtomMutator<Type>& atomMutator;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
40
eo/src/obsolete/eoAtomMutator.h
Normal file
40
eo/src/obsolete/eoAtomMutator.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoAtomMutator.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 _EOATOMMUTATOR_H
|
||||
#define _EOATOMMUTATOR_H
|
||||
|
||||
#include <eoFunctor.h>
|
||||
|
||||
/** Abstract base class for functors that modify a single element in an EO
|
||||
that is composed of several atomic components. An atom would, for instance, flip
|
||||
a bit, or change a real number, or things like that. The header is completely
|
||||
empty and thus just provides a name rather than functionality.
|
||||
*/
|
||||
|
||||
template <class T>
|
||||
class eoAtomMutator: public eoUnaryFunctor<void, T&> {};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
64
eo/src/obsolete/eoAtomRandom.h
Normal file
64
eo/src/obsolete/eoAtomRandom.h
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
eoAtomRandom.h
|
||||
Increments or decrements by one a single element
|
||||
(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 _EOATOMRANDOM_H
|
||||
#define _EOATOMRANDOM_H
|
||||
|
||||
#include <eoRnd.h>
|
||||
|
||||
/** Modifies using a random number generator, that is entered in the ctor.
|
||||
The RNG must return positive or negative numbers, whatever.
|
||||
*/
|
||||
template <class T>
|
||||
class eoAtomRandom: public eoAtomMutator<T> {
|
||||
public:
|
||||
|
||||
///
|
||||
eoAtomRandom( eoRnd<T>& _rng): rnd( _rng ) {};
|
||||
|
||||
///
|
||||
virtual ~eoAtomRandom() {};
|
||||
|
||||
/// Adds the value generated by the RNG to the former value
|
||||
virtual void operator()( T& _val ) const {
|
||||
_val += rnd();
|
||||
}
|
||||
|
||||
/** @name Methods from eoObject
|
||||
*/
|
||||
//@{
|
||||
/** Inherited from eoObject
|
||||
@see eoObject
|
||||
*/
|
||||
string className() const {return "eoAtomRandom";};
|
||||
//@}
|
||||
|
||||
private:
|
||||
eoRnd<T>& rnd;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
89
eo/src/obsolete/eoBin.h
Normal file
89
eo/src/obsolete/eoBin.h
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
eoBin.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 eoBin_h
|
||||
#define eoBin_h
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <iostream> // ostream, istream
|
||||
#include <functional> // bind2nd
|
||||
#include <string> // string
|
||||
|
||||
#include <eoFixedLength.h>
|
||||
|
||||
/**
|
||||
\defgroup bitstring
|
||||
|
||||
Various functions for a bitstring representation
|
||||
*/
|
||||
|
||||
/** eoBin: implementation of binary chromosome.
|
||||
\class eoBin eoBin.h ga/eoBin.h
|
||||
\ingroup bitstring
|
||||
* based on STL's bit_vector (vector<bool>).
|
||||
*/
|
||||
template <class F> class eoBin: public eoFixedLength<F, bool>
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* (Default) Constructor.
|
||||
* @param size Size of the binary string.
|
||||
*/
|
||||
eoBin(unsigned size = 0, bool value = false):
|
||||
eoVector<bool,F>(size, value) {}
|
||||
|
||||
/// My class name.
|
||||
string className() const
|
||||
{
|
||||
return "eoBin";
|
||||
}
|
||||
|
||||
/**
|
||||
* To print me on a stream.
|
||||
* @param os The ostream.
|
||||
*/
|
||||
void printOn(ostream& os) const
|
||||
{
|
||||
copy(begin(), end(), ostream_iterator<bool>(os));
|
||||
}
|
||||
|
||||
/**
|
||||
* To read me from a stream.
|
||||
* @param is The istream.
|
||||
*/
|
||||
void readFrom(istream& is)
|
||||
{
|
||||
string bits;
|
||||
is >> bits;
|
||||
if (is)
|
||||
{
|
||||
resize(bits.size());
|
||||
transform(bits.begin(), bits.end(), begin(),
|
||||
bind2nd(equal_to<char>(), '1'));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#endif eoBin_h
|
||||
116
eo/src/obsolete/eoBreeder.h
Normal file
116
eo/src/obsolete/eoBreeder.h
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoBreeder.h
|
||||
// Takes two populations and mixes them
|
||||
// (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 eoBreeder_h
|
||||
#define eoBreeder_h
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <vector> // vector
|
||||
#include <utils/eoRNG.h>
|
||||
#include <eoOp.h> // eoOp, eoMonOp, eoBinOp
|
||||
#include <eoPop.h> // eoPop
|
||||
#include <eoOpSelector.h> // eoOpSelector
|
||||
|
||||
#include <eoFunctor.h>
|
||||
|
||||
#include <eoRandomIndiSelector.h>
|
||||
#include <eoBackInserter.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/*****************************************************************************
|
||||
* eoBreeder: transforms a population using genetic operators. *
|
||||
* For every operator there is a rated to be applyed. *
|
||||
*****************************************************************************/
|
||||
|
||||
template<class Chrom> class eoBreeder: public eoTransform<EOT>
|
||||
//eoUnaryFunctor<void, eoPop<Chrom>&>
|
||||
{
|
||||
public:
|
||||
/// Default constructor.
|
||||
eoBreeder( eoOpSelector<Chrom>& _opSel): opSel( _opSel ) {}
|
||||
|
||||
/// Destructor.
|
||||
virtual ~eoBreeder() {}
|
||||
|
||||
/**
|
||||
* Transforms a population.
|
||||
* @param pop The population to be transformed.
|
||||
*/
|
||||
void operator()(eoPop<Chrom>& pop)
|
||||
{
|
||||
size_t orgsize = pop.size();
|
||||
|
||||
for (unsigned i = 0; i < pop.size(); i++)
|
||||
{
|
||||
eoOp<Chrom>* op = opSel.Op();
|
||||
switch (op->getType())
|
||||
{
|
||||
case eoOp<Chrom>::unary:
|
||||
{
|
||||
eoMonOp<Chrom>* monop = static_cast<eoMonOp<Chrom>* >(op);
|
||||
(*monop)( pop[i] );
|
||||
break;
|
||||
}
|
||||
case eoOp<Chrom>::binary:
|
||||
{
|
||||
eoBinOp<Chrom>* binop = static_cast<eoBinOp<Chrom>* >(op);
|
||||
(*binop)(pop[i], pop[ rng.random(pop.size()) ] );
|
||||
break;
|
||||
}
|
||||
case eoOp<Chrom>::quadratic:
|
||||
{
|
||||
eoQuadraticOp<Chrom>* Qop = static_cast<eoQuadraticOp<Chrom>* >(op);
|
||||
|
||||
(*Qop)(pop[i], pop[ rng.random(pop.size()) ] );
|
||||
break;
|
||||
}
|
||||
case eoOp<Chrom>::general :
|
||||
{
|
||||
eoGeneralOp<Chrom>* Gop = static_cast<eoGeneralOp<Chrom>* >(op);
|
||||
|
||||
eoRandomIndiSelector<Chrom> selector;
|
||||
eoBackInserter<Chrom> inserter;
|
||||
|
||||
(*Gop)(selector.bind(pop, orgsize).bias(i), inserter.bind(pop));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/// The class name.
|
||||
string className() const { return "eoBreeder"; }
|
||||
|
||||
private:
|
||||
eoOpSelector<Chrom>& opSel;
|
||||
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#endif eoBreeder_h
|
||||
|
||||
58
eo/src/obsolete/eoDetTournamentIndiSelector.h
Normal file
58
eo/src/obsolete/eoDetTournamentIndiSelector.h
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
eoDetTournamentIndiSelector.h
|
||||
|
||||
(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 eoDetTournamentIndiSelector_h
|
||||
#define eoDetTournamentIndiSelector_h
|
||||
|
||||
#include "eoIndiSelector.h"
|
||||
#include "utils/selectors.h"
|
||||
|
||||
|
||||
/**
|
||||
\ingroup selectors
|
||||
* eoDetTournamentIndiSelector: selects children through a deterministic_tournament
|
||||
*/
|
||||
template <class EOT>
|
||||
class eoDetTournamentIndiSelector : public eoPopIndiSelector<EOT>
|
||||
{
|
||||
public :
|
||||
|
||||
eoDetTournamentIndiSelector(int _tournamentSize)
|
||||
: eoPopIndiSelector<EOT>(),
|
||||
tournamentSize(_tournamentSize)
|
||||
{}
|
||||
|
||||
virtual ~eoDetTournamentIndiSelector(void) {}
|
||||
|
||||
const EOT& do_select(void)
|
||||
{
|
||||
return *deterministic_tournament(begin(), end(), tournamentSize);
|
||||
}
|
||||
|
||||
private :
|
||||
|
||||
int tournamentSize;
|
||||
};
|
||||
|
||||
#endif
|
||||
63
eo/src/obsolete/eoDistance.h
Normal file
63
eo/src/obsolete/eoDistance.h
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
eoObject.h
|
||||
This is the base class for most objects in EO. It basically defines an interf
|
||||
face for giving names to classes.
|
||||
|
||||
(c) GeNeura Team, 1998, 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 EODISTANCE_H
|
||||
#define EODISTANCE_H
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
using namespace std;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoDistance
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Defines an interface for measuring distances between evolving objects */
|
||||
template <class EOT>
|
||||
class eoDistance {
|
||||
public:
|
||||
|
||||
/// Default Constructor.
|
||||
eoDistance() {}
|
||||
|
||||
/// Copy constructor.
|
||||
eoDistance( const eoDistance& ) {}
|
||||
|
||||
/// Virtual dtor. They are needed in virtual class hierarchies.
|
||||
virtual ~eoDistance() {}
|
||||
|
||||
|
||||
/** Return the distance from the object with this interface to other
|
||||
object of the same type.
|
||||
*/
|
||||
virtual double distance( const EOT& ) const = 0;
|
||||
|
||||
/// Returns classname
|
||||
virtual string className() const { return "eoDistance"; }
|
||||
|
||||
};
|
||||
|
||||
#endif EOOBJECT_H
|
||||
70
eo/src/obsolete/eoDup.h
Normal file
70
eo/src/obsolete/eoDup.h
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
// eoDup.h
|
||||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoKill.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 _EODUP_h
|
||||
#define _EODUP_h
|
||||
|
||||
#include <utils/eoRNG.h>
|
||||
|
||||
#include <eoOp.h>
|
||||
|
||||
/// Dup or duplicate: duplicates a gene in a chromosome
|
||||
template <class FitT, class Atomic>
|
||||
class eoDup: public eoMonOp<eoVariableLength<FitT, Atomic> > {
|
||||
public:
|
||||
///
|
||||
eoDup( )
|
||||
: eoMonOp< EOT >( ){};
|
||||
|
||||
/// needed virtual dtor
|
||||
virtual ~eoDup() {};
|
||||
|
||||
///
|
||||
virtual void operator()(eoVariableLength<FitT, Atomic>& _eo ) const
|
||||
{
|
||||
unsigned pos = rng.random(_eo.size());
|
||||
eoVariableLength<FitT, Atomic>::iterator it = begin();
|
||||
|
||||
while (pos--) {++it;}
|
||||
|
||||
_eo.insert(it, 1, *it);
|
||||
|
||||
_eo.invalidate();
|
||||
}
|
||||
|
||||
|
||||
/** @name Methods from eoObject
|
||||
readFrom and printOn are directly inherited from eoOp
|
||||
*/
|
||||
//@{
|
||||
/** Inherited from eoObject
|
||||
@see eoObject
|
||||
*/
|
||||
virtual string className() const {return "eoDup";};
|
||||
//@}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
164
eo/src/obsolete/eoES.h
Normal file
164
eo/src/obsolete/eoES.h
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoESChrom.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 _eoESCHROM_H
|
||||
#define _eoESCHROM_H
|
||||
|
||||
// STL libraries
|
||||
#include <vector> // For vector<>
|
||||
#include <stdexcept>
|
||||
#include <strstream>
|
||||
#include <iostream> // for ostream
|
||||
|
||||
// EO includes
|
||||
#include <eoVector.h>
|
||||
|
||||
/**@name Chromosomes for evolution strategies
|
||||
Each chromosome in an evolution strategies is composed of a vector of floating point
|
||||
values plus a vector of sigmas, that are added to them during mutation
|
||||
*/
|
||||
//@{
|
||||
|
||||
/**
|
||||
\class eoESValue
|
||||
|
||||
*/
|
||||
template <class T>
|
||||
struct eoESValue
|
||||
{
|
||||
T value;
|
||||
|
||||
/**
|
||||
The gene has a mutate member because this particular gaussian mutation
|
||||
is paradigmatic for an evolution strategy.
|
||||
*/
|
||||
void mutate(double sigma, T minimum = T(), T maximum = T())
|
||||
{
|
||||
value += rng.normal(0.0, sigma);
|
||||
|
||||
if (minimum > value)
|
||||
value = minimum;
|
||||
if (value > maximum)
|
||||
value = maximum;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
\class eoESGene eoESGene.h es/eoESGene.h
|
||||
Each gene in an Evolution Strategies is composed of a value plus an standard
|
||||
deviation, sigma, used for mutation*/
|
||||
template <class T>
|
||||
struct eoESGene : public eoESValue<T>
|
||||
{
|
||||
double sigma;
|
||||
|
||||
eoESGene( double _val = 0, double _sigma = 1.0 ): eoESValue( _val ), sigma( _sigma ) {};
|
||||
|
||||
/**
|
||||
The gene has a mutate member because the sigma member implies
|
||||
that the updating routine should use a normal distribution
|
||||
*/
|
||||
void mutate(T minimum, T maximum)
|
||||
{
|
||||
mutate(sigma, minimum, maximum);
|
||||
}
|
||||
};
|
||||
|
||||
/// Tricky operator to avoid errors in some VC++ systems, namely VC 5.0 SP3
|
||||
bool operator < ( eoESGene _e1, eoESGene _e2 ) {
|
||||
return _e1.val < _e2.val;
|
||||
}
|
||||
|
||||
/// Tricky operator to avoid errors in some VC++ systems
|
||||
bool operator == ( eoESGene _e1, eoESGene _e2 ) {
|
||||
return ( _e1.val == _e2.val ) && ( _e1.sigma == _e2.sigma ) ;
|
||||
}
|
||||
|
||||
///
|
||||
ostream & operator << ( ostream& _s, const eoESGene& _e ) {
|
||||
_s << _e.val << ", " << _e.sigma << " | ";
|
||||
return _s;
|
||||
}
|
||||
|
||||
/// Dummy >>
|
||||
istream & operator >> ( istream& _s, const eoESGene& _e ) {
|
||||
_s >> _e.val;
|
||||
_s >> _e.sigma;
|
||||
return _s;
|
||||
}
|
||||
|
||||
|
||||
/** Basic chromosome for evolution strategies (ES), as defined by Rechenberg and
|
||||
Schwefel. Each chromosomes is composed of "genes"; each one of then is an eoESGene
|
||||
@see eoESGene
|
||||
*/
|
||||
template <typename fitT = float >
|
||||
class eoESChrom: public eoVector<eoESGene, fitT> {
|
||||
public:
|
||||
/// Basic ctor
|
||||
eoESChrom( ):eoVector<eoESGene, fitT>() {};
|
||||
|
||||
/** Ctor using a couple of random number generators
|
||||
@param _size Lineal length of the object
|
||||
@param _rnd a random number generator, which returns a random value each time it´s called.
|
||||
@param _rndS another one, for the sigma
|
||||
*/
|
||||
eoESChrom( unsigned _size, eoRnd<double>& _rnd, eoRnd<double>& _rndS )
|
||||
: eoVector<eoESGene, fitT>( _size ){
|
||||
for ( iterator i = begin(); i != end(); i ++ ) {
|
||||
i->val = _rnd();
|
||||
i->sigma = _rndS();
|
||||
}
|
||||
};
|
||||
|
||||
/// Copy ctor
|
||||
eoESChrom( const eoESChrom& _eoes): eoVector<eoESGene, fitT>( _eoes ) {};
|
||||
|
||||
/// Assignment operator
|
||||
const eoESChrom& operator =( const eoESChrom & _eoes ) {
|
||||
if ( this != &_eoes ){
|
||||
eoVector<eoESGene, fitT>::operator=( _eoes );
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
///
|
||||
~eoESChrom() {};
|
||||
|
||||
/** @name Methods from eoObject
|
||||
readFrom and printOn are directly inherited from eo1d
|
||||
*/
|
||||
//@{
|
||||
/** Inherited from eoObject
|
||||
@see eoObject
|
||||
*/
|
||||
string className() const {return "eoESChrom";};
|
||||
//@}
|
||||
|
||||
};
|
||||
|
||||
//@}
|
||||
#endif
|
||||
|
||||
164
eo/src/obsolete/eoESChrom.h
Normal file
164
eo/src/obsolete/eoESChrom.h
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoESChrom.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 _eoESCHROM_H
|
||||
#define _eoESCHROM_H
|
||||
|
||||
// STL libraries
|
||||
#include <vector> // For vector<>
|
||||
#include <stdexcept>
|
||||
#include <strstream>
|
||||
#include <iostream> // for ostream
|
||||
|
||||
// EO includes
|
||||
#include <eoVector.h>
|
||||
|
||||
/**@name Chromosomes for evolution strategies
|
||||
Each chromosome in an evolution strategies is composed of a vector of floating point
|
||||
values plus a vector of sigmas, that are added to them during mutation
|
||||
*/
|
||||
//@{
|
||||
|
||||
/**
|
||||
\class eoESValue
|
||||
|
||||
*/
|
||||
template <class T>
|
||||
struct eoESValue
|
||||
{
|
||||
T value;
|
||||
|
||||
/**
|
||||
The gene has a mutate member because this particular gaussian mutation
|
||||
is paradigmatic for an evolution strategy.
|
||||
*/
|
||||
void mutate(double sigma, T minimum, T maximum)
|
||||
{
|
||||
value += rng.normal(0.0, sigma);
|
||||
|
||||
if (minimum > value)
|
||||
value = minimum;
|
||||
if (value > maximum)
|
||||
value = maximum;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
\class eoESGene eoESGene.h es/eoESGene.h
|
||||
Each gene in an Evolution Strategies is composed of a value plus an standard
|
||||
deviation, sigma, used for mutation*/
|
||||
template <class T>
|
||||
struct eoESGene : public eoESValue<T>
|
||||
{
|
||||
double sigma;
|
||||
|
||||
eoESGene( double _val = 0, double _sigma = 1.0 ): eoESValue( _val ), sigma( _sigma ) {};
|
||||
|
||||
/**
|
||||
The gene has a mutate member because the sigma member implies
|
||||
that the updating routine should use a normal distribution
|
||||
*/
|
||||
void mutate(T minimum, T maximum)
|
||||
{
|
||||
mutate(sigma, minimum, maximum);
|
||||
}
|
||||
};
|
||||
|
||||
/// Tricky operator to avoid errors in some VC++ systems, namely VC 5.0 SP3
|
||||
bool operator < ( eoESGene _e1, eoESGene _e2 ) {
|
||||
return _e1.val < _e2.val;
|
||||
}
|
||||
|
||||
/// Tricky operator to avoid errors in some VC++ systems
|
||||
bool operator == ( eoESGene _e1, eoESGene _e2 ) {
|
||||
return ( _e1.val == _e2.val ) && ( _e1.sigma == _e2.sigma ) ;
|
||||
}
|
||||
|
||||
///
|
||||
ostream & operator << ( ostream& _s, const eoESGene& _e ) {
|
||||
_s << _e.val << ", " << _e.sigma << " | ";
|
||||
return _s;
|
||||
}
|
||||
|
||||
/// Dummy >>
|
||||
istream & operator >> ( istream& _s, const eoESGene& _e ) {
|
||||
_s >> _e.val;
|
||||
_s >> _e.sigma;
|
||||
return _s;
|
||||
}
|
||||
|
||||
|
||||
/** Basic chromosome for evolution strategies (ES), as defined by Rechenberg and
|
||||
Schwefel. Each chromosomes is composed of "genes"; each one of then is an eoESGene
|
||||
@see eoESGene
|
||||
*/
|
||||
template <typename fitT = float >
|
||||
class eoESChrom: public eoVector<eoESGene, fitT> {
|
||||
public:
|
||||
/// Basic ctor
|
||||
eoESChrom( ):eoVector<eoESGene, fitT>() {};
|
||||
|
||||
/** Ctor using a couple of random number generators
|
||||
@param _size Lineal length of the object
|
||||
@param _rnd a random number generator, which returns a random value each time it´s called.
|
||||
@param _rndS another one, for the sigma
|
||||
*/
|
||||
eoESChrom( unsigned _size, eoRnd<double>& _rnd, eoRnd<double>& _rndS )
|
||||
: eoVector<eoESGene, fitT>( _size ){
|
||||
for ( iterator i = begin(); i != end(); i ++ ) {
|
||||
i->val = _rnd();
|
||||
i->sigma = _rndS();
|
||||
}
|
||||
};
|
||||
|
||||
/// Copy ctor
|
||||
eoESChrom( const eoESChrom& _eoes): eoVector<eoESGene, fitT>( _eoes ) {};
|
||||
|
||||
/// Assignment operator
|
||||
const eoESChrom& operator =( const eoESChrom & _eoes ) {
|
||||
if ( this != &_eoes ){
|
||||
eoVector<eoESGene, fitT>::operator=( _eoes );
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
///
|
||||
~eoESChrom() {};
|
||||
|
||||
/** @name Methods from eoObject
|
||||
readFrom and printOn are directly inherited from eo1d
|
||||
*/
|
||||
//@{
|
||||
/** Inherited from eoObject
|
||||
@see eoObject
|
||||
*/
|
||||
string className() const {return "eoESChrom";};
|
||||
//@}
|
||||
|
||||
};
|
||||
|
||||
//@}
|
||||
#endif
|
||||
|
||||
267
eo/src/obsolete/eoESFullChrom.h
Normal file
267
eo/src/obsolete/eoESFullChrom.h
Normal file
|
|
@ -0,0 +1,267 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoESInd.h
|
||||
// (c) GeNeura Team, 1998 - EEAAX 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
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _EOESFULLCHROM_H
|
||||
#define _EOESFULLCHROM_H
|
||||
|
||||
// STL libraries
|
||||
#include <vector> // For vector<>
|
||||
#include <stdexcept>
|
||||
#include <strstream>
|
||||
#include <iostream> // for ostream
|
||||
|
||||
// EO includes
|
||||
#include <eoVector.h>
|
||||
#include <utils/eoRNG.h>
|
||||
/**@name Chromosomes for evolution strategies
|
||||
Each chromosome in an evolution strategies is composed of a vector of floating point
|
||||
values plus a vector of sigmas, that are added to them during mutation and a vector of correlations
|
||||
*/
|
||||
//@{
|
||||
|
||||
|
||||
/**@name individuals for evolution strategies -MS- 22/10/99
|
||||
Each individual in an evolution strategy is composed of
|
||||
a vector of floating point values
|
||||
a vector of std deviations
|
||||
a vector of rotation angles (for correlated mutations)
|
||||
|
||||
These individuals CANNOT BE IMPLEMENTED as vectors of anything
|
||||
at least in the case of correlated mutations
|
||||
*/
|
||||
//@{
|
||||
|
||||
template <typename fitT = float >
|
||||
class eoESFullChrom : public eoVector<double, fitT> {
|
||||
public:
|
||||
/// constructor
|
||||
eoESFullChrom( unsigned _num_genes = 1,
|
||||
unsigned _num_sigma = 1, unsigned _num_correl = 0,
|
||||
bool _verbose = false,
|
||||
double _ObjMin = 0, double _ObjMax = 1,
|
||||
double _StdDevInit = 0.3 ):
|
||||
eoVector<double, fitT>(_num_genes),
|
||||
// ObjVar( _num_genes ), now an eoVector<double>
|
||||
StdDev( _num_sigma ),
|
||||
CorCff( _num_correl ),
|
||||
verbose( _verbose ),
|
||||
ObjMin( _ObjMin ),
|
||||
ObjMax(_ObjMax ),
|
||||
StdDevInit( _StdDevInit )
|
||||
{ // check consistency
|
||||
}
|
||||
|
||||
|
||||
/* And now the useful constructor: from a parser (should be in the
|
||||
factory, if such a thing exists one day for eoESFullChrom
|
||||
*/
|
||||
eoESFullChrom(eoParser & parser) : StdDev(0), CorCff(0) {
|
||||
parser.AddTitle("Description of ES individuals");
|
||||
int num_genes, num_sigma;
|
||||
bool correlated_mutations;
|
||||
try {
|
||||
num_genes = parser.getInt("-Io", "--NbObjVar", "2",
|
||||
"Number of Object Variables" );
|
||||
num_sigma = parser.getInt("-Is", "--NbSigma", "1",
|
||||
"Number of Standard Deviations" );
|
||||
correlated_mutations = parser.getBool("-Ic", "--Correlated",
|
||||
"Correlated mutation?" );
|
||||
ObjMin = parser.getFloat("-Im", "--min", "0",
|
||||
"Minimum value for object variables" );
|
||||
ObjMax = parser.getFloat("-IM", "--max", "1",
|
||||
"Maximum value for object variables" );
|
||||
StdDevInit = parser.getFloat("-II", "--SigmaInit", "0.3",
|
||||
"Initial value for std. dev. (scaled by range)" );
|
||||
verbose = parser.getBool("-Iv", "--verbose",
|
||||
"Verbose listing of ES individuals (mutation parameters");
|
||||
}
|
||||
catch (exception & e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
parser.printHelp();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// consistency tests
|
||||
if (! num_sigma) { // no std dev??? EXCEPTION
|
||||
throw invalid_argument( "No standard deviation: choose another representation please" );
|
||||
}
|
||||
if (num_sigma > num_genes) {
|
||||
cout << "WARNING, Number of Standard Deviations > Number of Object Variables\nAdjusted!\n";
|
||||
num_sigma = num_genes;
|
||||
// modify the Param value - so .status is OK
|
||||
ostrstream sloc;
|
||||
sloc << num_genes;
|
||||
parser.setParamValue("--NbSigma", sloc.str());
|
||||
}
|
||||
// adjust the sizes!!!
|
||||
resize(num_genes);
|
||||
if (num_sigma)
|
||||
StdDev.resize(num_sigma);
|
||||
if (correlated_mutations) {
|
||||
if (num_sigma < num_genes) {
|
||||
cout << "WARNING less Std Dev. than number of variables + Correlated mutations\n";
|
||||
cout << "Though possible, this is a strange setting" << endl;
|
||||
}
|
||||
// nb of rotation angles: N*(N-1)/2 (in general!)
|
||||
CorCff.resize ( (2*num_genes - num_sigma)*(num_sigma - 1) / 2 );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/// Operator =
|
||||
const eoESFullChrom& operator = ( const eoESFullChrom& _eo ) {
|
||||
if ( this != &_eo ) {
|
||||
// Change EO part
|
||||
eoVector<double, fitT>::operator = (_eo);
|
||||
|
||||
// Change this part
|
||||
// ObjVar = _eo.ObjVar;
|
||||
StdDev = _eo.StdDev;
|
||||
CorCff = _eo.CorCff;
|
||||
verbose = _eo.verbose;
|
||||
ObjMin = _eo.ObjMin;
|
||||
ObjMax = _eo.ObjMax;
|
||||
StdDevInit = _eo.StdDevInit;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// destructor
|
||||
virtual ~eoESFullChrom() {}
|
||||
|
||||
///
|
||||
double getStdDev( unsigned _i ) const {
|
||||
if ( _i >= length() )
|
||||
throw out_of_range( "out_of_range when reading StdDev");
|
||||
return StdDev[ _i ];
|
||||
}
|
||||
|
||||
///
|
||||
void setStdDev( unsigned _i, double _val ) {
|
||||
if ( _i < length() ) {
|
||||
StdDev[_i] = _val;
|
||||
} else
|
||||
throw out_of_range( "out_of_range when writing StdDev");
|
||||
}
|
||||
|
||||
///
|
||||
double getCorCff( unsigned _i ) const {
|
||||
if ( _i >= length() )
|
||||
throw out_of_range( "out_of_range when reading CorCff");
|
||||
return CorCff[ _i ];
|
||||
}
|
||||
|
||||
///
|
||||
void setCorCff( unsigned _i, double _val ) {
|
||||
if ( _i < length() ) {
|
||||
CorCff[_i] = _val;
|
||||
} else
|
||||
throw out_of_range( "out_of_range when writing CorCff");
|
||||
}
|
||||
|
||||
///
|
||||
void insertGene( unsigned _i, double _val ) {
|
||||
throw FixedLengthChromosome();
|
||||
};
|
||||
|
||||
///
|
||||
void deleteGene( unsigned _i ) {
|
||||
throw FixedLengthChromosome();
|
||||
};
|
||||
|
||||
///
|
||||
unsigned length() const { return size();}/* formerly ObjVar.size() */
|
||||
unsigned StdDevLength() const { return StdDev.size();}
|
||||
unsigned CorCffLength() const { return CorCff.size();}
|
||||
|
||||
|
||||
/** Print itself: inherited from eoObject implementation.
|
||||
Instance from base classes are processed in
|
||||
base classes, so you don´t have to worry about, for instance, fitness.
|
||||
@param _s the ostream in which things are written*/
|
||||
virtual void printOn( ostream& _s ) const{
|
||||
copy( begin(), end(), ostream_iterator<double>( _s, " ") );
|
||||
// The formatting instructinos shoudl be left to the caller
|
||||
// _s << "\n";
|
||||
if (verbose) {
|
||||
_s << "\n\tStd Dev. " ;
|
||||
copy( StdDev.begin(), StdDev.end(), ostream_iterator<double>( _s, " ") );
|
||||
if (CorCff.size()) {
|
||||
_s << "\n\t";
|
||||
copy( CorCff.begin(), CorCff.end(), ostream_iterator<double>( _s, " ") );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/** This exception should be thrown when trying to insert or delete a gene
|
||||
in a fixed length chromosome
|
||||
*/
|
||||
class FixedLengthChromosome : public exception {
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
FixedLengthChromosome()
|
||||
: exception() { };
|
||||
|
||||
~FixedLengthChromosome() {};
|
||||
};
|
||||
|
||||
// accessors
|
||||
double getObjMin() const {return ObjMin;}
|
||||
double getObjMax() const {return ObjMax;}
|
||||
double getStdDevInit () const {return StdDevInit;}
|
||||
|
||||
/** Inherited from eoObject
|
||||
@see eoObject
|
||||
*/
|
||||
virtual string className() const {return "eoESFullChrom";};
|
||||
|
||||
private:
|
||||
// vector<double> ObjVar; /* object variable vector */
|
||||
// or shoudl the class be subclass of EOVector<double> ???
|
||||
|
||||
vector<double> StdDev; /* standard deviation vector */
|
||||
vector<double> CorCff; /* correlation coefficient vector */
|
||||
|
||||
bool verbose; /* Print std deviations or not */
|
||||
|
||||
/** the range is used for mutation AND random initialization,
|
||||
* while the StdDevInit is used only for random initialization
|
||||
* this in a little inconsistent!
|
||||
*/
|
||||
double ObjMin, ObjMax; /* Range for Object variables */
|
||||
double StdDevInit; /* Initial value of Standard Deviations */
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
261
eo/src/obsolete/eoESFullMut.h
Normal file
261
eo/src/obsolete/eoESFullMut.h
Normal file
|
|
@ -0,0 +1,261 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoESMute.h : ES mutation
|
||||
// (c) Maarten Keijzer 2000 & GeNeura Team, 1998 for the EO part
|
||||
// Th. Baeck 1994 and EEAAX 1999 for the ES part
|
||||
/*
|
||||
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
|
||||
marc.schoenauer@polytechnique.fr
|
||||
http://eeaax.cmap.polytchnique.fr/
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#ifndef _EOESMUT_H
|
||||
#define _EOESMUT_H
|
||||
|
||||
#include <utils/eoParser.h>
|
||||
#include <utils/eoRNG.h>
|
||||
#include <cmath> // for exp
|
||||
|
||||
#include <es/eoESFullChrom.h>
|
||||
#include <es/eoESInit.h>
|
||||
#include <eoOp.h>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.1415926535897932384626433832795
|
||||
#endif
|
||||
|
||||
/** ES-style mutation in the large: Obviously, valid only for eoES*
|
||||
|
||||
It is currently valid for three types of ES chromosomes:
|
||||
|
||||
eoEsSimple: only 1 std deviation
|
||||
eoEsStdev: as many standard deviations as object variables
|
||||
eoEsFull: The whole guacemole: correlations, stdevs and object variables
|
||||
|
||||
Each of these three variant has it's own operator() in eoEsMutate
|
||||
*/
|
||||
|
||||
template <class EOT>
|
||||
class eoESMutate: public eoMonOp< EOT > {
|
||||
public:
|
||||
|
||||
typedef EOT::Fitness FitT;
|
||||
|
||||
/** Initialization
|
||||
parameters:
|
||||
|
||||
@param _init proxy class for initializating the three parameters eoEsMutate needs
|
||||
@param _bounds the bounds for the objective variables
|
||||
*/
|
||||
eoESMutate(eoESMutationInit& _init, eoESObjectiveBounds& _bounds) : bounds(_bounds)
|
||||
{
|
||||
unsigned size = bounds.chromSize();
|
||||
|
||||
if (eoEsInfo<EOT>::single_stdev)
|
||||
{
|
||||
TauLcl = _init.TauLcl();
|
||||
TauLcl /= sqrt((double) size);
|
||||
}
|
||||
else
|
||||
{
|
||||
TauLcl = _init.TauLcl();
|
||||
TauGlb = _init.TauGlb();
|
||||
|
||||
// renormalization
|
||||
TauLcl /= sqrt( 2.0 * sqrt( (double)size ) );
|
||||
TauGlb /= sqrt( 2.0 * ( (double) size ) );
|
||||
|
||||
if (eoEsInfo<EOT>::has_correlation)
|
||||
{ // Correlated Mutations
|
||||
TauBeta = _init.TauBeta();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// needed virtual dtor
|
||||
virtual ~eoESMutate() {};
|
||||
|
||||
/** Inherited from eoObject
|
||||
@see eoObject
|
||||
*/
|
||||
virtual string className() const {return "eoESMutate";};
|
||||
|
||||
/**
|
||||
Mutate eoEsSimple
|
||||
*/
|
||||
virtual void operator()( eoEsSimple<FitT>& _eo) const
|
||||
{
|
||||
_eo.stdev *= exp(TauLcl * rng.normal());
|
||||
|
||||
if (_eo.stdev < eoEsInfo<EOT>::stdev_eps)
|
||||
_eo.stdev = eoEsInfo<EOT>::stdev_eps;
|
||||
|
||||
// now apply to all
|
||||
|
||||
for (unsigned i = 0; i < _eo.size(); ++i)
|
||||
{
|
||||
_eo[i] += _eo.stdev * rng.normal();
|
||||
}
|
||||
|
||||
keepInBounds(_eo);
|
||||
}
|
||||
|
||||
/// mutations - standard and correlated
|
||||
// =========
|
||||
/*
|
||||
* Standard mutation of object variables and standard
|
||||
* deviations in ESs.
|
||||
* If there are fewer different standard deviations available
|
||||
* than the dimension of the objective function requires, the
|
||||
* last standard deviation is responsible for ALL remaining
|
||||
* object variables.
|
||||
* Schwefel 1977: Numerische Optimierung von Computer-Modellen
|
||||
* mittels der Evolutionsstrategie, pp. 165 ff.
|
||||
*/
|
||||
|
||||
virtual void operator()( eoESStdev<FitT>& _eo ) const
|
||||
{
|
||||
double global = exp(TauGlb * rng.normal());
|
||||
for (unsigned i = 0; i < _eo.size(); i++)
|
||||
{
|
||||
double stdev = _eo.stdevs[i];
|
||||
stdev *= global * exp(TauLcl * rng.normal());
|
||||
|
||||
if (stdev < eoEsInfo<EOT>::stdev_eps)
|
||||
stdev = eoEsInfo<EOT>::stdev_eps;
|
||||
|
||||
_eo.stdevs[i] = stdev;
|
||||
_eo[i] += stdev * rng.normal();
|
||||
}
|
||||
|
||||
keepInBounds(_eo);
|
||||
}
|
||||
|
||||
/*
|
||||
* Correlated mutations in ESs, according to the following
|
||||
* sources:
|
||||
* H.-P. Schwefel: Internal Report of KFA Juelich, KFA-STE-IB-3/80
|
||||
* p. 43, 1980
|
||||
* G. Rudolph: Globale Optimierung mit parallelen Evolutions-
|
||||
* strategien, Diploma Thesis, University of Dortmund, 1990
|
||||
*/
|
||||
|
||||
// Code from Thomas Baeck
|
||||
|
||||
virtual void operator()( eoEsFull<fitT> & _eo ) const
|
||||
{
|
||||
|
||||
/*
|
||||
* First: mutate standard deviations (as above).
|
||||
*/
|
||||
|
||||
double global = exp(TauGlb * rng.normal());
|
||||
for (unsigned i = 0; i < _eo.size(); i++)
|
||||
{
|
||||
double stdev = _eo.stdevs[i];
|
||||
stdev *= global * exp(TauLcl * rng.normal());
|
||||
|
||||
if (stdev < eoEsInfo<EOT>::stdev_eps)
|
||||
stdev = eoEsInfo<EOT>::stdev_eps;
|
||||
|
||||
_eo.stdevs[i] = stdev;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Mutate rotation angles.
|
||||
*/
|
||||
|
||||
for (i = 0; i < _eo.correlations.size(); i++)
|
||||
{
|
||||
_eo.correlations[i] += TauBeta * rng.normal();
|
||||
if ( fabs(_eo.correlations[i]) > M_PI )
|
||||
{
|
||||
_eo.correlations[i] -= M_PI * (int) (_eo.correlations[i]/M_PI) ;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform correlated mutations.
|
||||
*/
|
||||
unsigned i,k;
|
||||
|
||||
vector<double> VarStp(_eo.size());
|
||||
for (i = 0; i < _eo.size(); i++)
|
||||
VarStp[i] = _eo.stdevs[i] * rng.normal();
|
||||
|
||||
unsigned nq = _eo.correlations.size() - 1;
|
||||
|
||||
for (k = 0; k < _eo.size()-1; k++)
|
||||
{
|
||||
n1 = _eo.size() - k - 1;
|
||||
n2 = _eo.size() - 1;
|
||||
|
||||
for (i = 0; i < k; i++)
|
||||
{
|
||||
d1 = VarStp[n1];
|
||||
d2 = VarStp[n2];
|
||||
S = sin( _eo.correlations[nq] );
|
||||
C = cos( _eo.correlations[nq] );
|
||||
VarStp[n2] = d1 * S + d2 * C;
|
||||
VarStp[n1] = d1 * C - d2 * S;
|
||||
n2--;
|
||||
nq--;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < _eo.size(); i++)
|
||||
_eo[i] += VarStp[i];
|
||||
|
||||
keepInBounds(_eo);
|
||||
}
|
||||
|
||||
void keepInBounds(EOT& _eo) const
|
||||
{
|
||||
for (unsigned i = 0; i < _eo.size(); ++i)
|
||||
{
|
||||
if (_eo[i] < bounds.minimum(i))
|
||||
_eo[i] = bounds.minimum(i);
|
||||
else if (_eo[i] > bounds.maximum(i))
|
||||
_eo[i] = bounds.maximum(i);
|
||||
}
|
||||
}
|
||||
|
||||
private :
|
||||
// the data
|
||||
//=========
|
||||
double TauLcl; /* Local factor for mutation of std deviations */
|
||||
double TauGlb; /* Global factor for mutation of std deviations */
|
||||
double TauBeta; /* Factor for mutation of correlation parameters */
|
||||
|
||||
eoESObjectiveBounds& bounds;
|
||||
};
|
||||
|
||||
/*
|
||||
* Correlated mutations in ESs, according to the following
|
||||
* sources:
|
||||
* H.-P. Schwefel: Internal Report of KFA Juelich, KFA-STE-IB-3/80
|
||||
* p. 43, 1980
|
||||
* G. Rudolph: Globale Optimierung mit parallelen Evolutions-
|
||||
* strategien, Diploma Thesis, University of Dortmund, 1990
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
62
eo/src/obsolete/eoEvalFuncPtrCnt.h
Normal file
62
eo/src/obsolete/eoEvalFuncPtrCnt.h
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
eoEvalFuncPtrCnt.h
|
||||
Same as eoEvalFuncPtr, but counts the number of evaluations
|
||||
|
||||
(c) GeNeura Team, 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 EOEVALFUNCPTRCNT_H
|
||||
#define EOEVALFUNCPTRCNT_H
|
||||
|
||||
#include <eoEvalFuncPtr.h>
|
||||
|
||||
/** EOEvalFuncCntPtr: This class
|
||||
* takes an existing function pointer and converts it into a evaluation
|
||||
* function class. That way, old style C or C++ functions can be adapted to EO
|
||||
* function classes.
|
||||
*/
|
||||
template< class EOT >
|
||||
struct eoEvalFuncPtrCnt: public eoEvalFuncPtr<EOT> {
|
||||
|
||||
/** Applies the function to the chromosome and sets the fitness of the
|
||||
Chrom. Thus, the evaluation function need not be worried about that.
|
||||
@param _eval pointer to the evaluation function, takes a EOT as an
|
||||
argument and returns the fitness
|
||||
@return the evaluated fitness for that object.
|
||||
*/
|
||||
eoEvalFuncPtrCnt( EOFitT (* _eval)( const EOT& ) )
|
||||
: eoEvalFuncPtr<EOT>( _eval ), numOfEvaluations( 0 ) {};
|
||||
|
||||
/// Effectively applies the evaluation function to an EO
|
||||
virtual void operator() ( EOT & _eo ) const {
|
||||
eoEvalFuncPtr<EOT>::operator()( _eo );
|
||||
numOfEvaluations++;
|
||||
};
|
||||
|
||||
///
|
||||
unsigned getNumOfEvaluations() const { return numOfEvaluations; };
|
||||
|
||||
private:
|
||||
mutable unsigned numOfEvaluations;
|
||||
};
|
||||
|
||||
#endif
|
||||
59
eo/src/obsolete/eoFitTerm.h
Normal file
59
eo/src/obsolete/eoFitTerm.h
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoGenTerm.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 _EOFITTERM_H
|
||||
#define _EOFITTERM_H
|
||||
|
||||
#include <eoContinue.h>
|
||||
|
||||
|
||||
/**
|
||||
Fitness continuation:
|
||||
|
||||
Continues until the maximum fitness level is reached.
|
||||
*/
|
||||
template< class EOT>
|
||||
class eoFitContinue: public eoContinue<EOT> {
|
||||
public:
|
||||
|
||||
/// Define Fitness
|
||||
typedef typename EOT::Fitness FitnessType;
|
||||
|
||||
/// Ctor
|
||||
eoFitContinue( const FitnessType _maximum)
|
||||
: eoContinuator<EOT> (), maximum( _maximum ) {};
|
||||
|
||||
/** Returns false when a fitness criterium is
|
||||
* reached, assumes sorted population */
|
||||
virtual bool operator() ( const eoPop<EOT>& _vEO )
|
||||
{
|
||||
return (bestFitness < maximum);
|
||||
}
|
||||
|
||||
private:
|
||||
FitnessType maximum;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show more
Reference in a new issue