delete the obsolete directory (still versionned in the repository if necessary)
This commit is contained in:
parent
e131c2178e
commit
2670bd857f
79 changed files with 0 additions and 9009 deletions
|
|
@ -1,6 +0,0 @@
|
|||
*.lo
|
||||
*.la
|
||||
.deps
|
||||
.libs
|
||||
Makefile
|
||||
Makefile.in
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
|
||||
######################################################################################
|
||||
### 1) Include the sources
|
||||
######################################################################################
|
||||
|
||||
INCLUDE_DIRECTORIES(${EO_SOURCE_DIR}/src)
|
||||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 2) Define the ga target
|
||||
######################################################################################
|
||||
|
||||
SET(EOOBSOLETE_LIB_OUTPUT_PATH ${EO_BINARY_DIR}/lib)
|
||||
SET(LIBRARY_OUTPUT_PATH ${EOOBSOLETE_LIB_OUTPUT_PATH})
|
||||
|
||||
SET (EOOBSOLETE_SOURCES eoParserUtils.cpp)
|
||||
|
||||
|
||||
ADD_LIBRARY(eoobsolete STATIC ${EOOBSOLETE_SOURCES})
|
||||
######################################################################################
|
||||
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 3) Optionnal
|
||||
######################################################################################
|
||||
|
||||
SET(EOOBSOLETE_VERSION ${GLOBAL_VERSION})
|
||||
SET_TARGET_PROPERTIES(eoobsolete PROPERTIES VERSION "${EOOBSOLETE_VERSION}")
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
|
@ -1,199 +0,0 @@
|
|||
/* -*- 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 std::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
|
||||
std::vector and std::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 std::string, preferably unique
|
||||
*/
|
||||
eo1d( unsigned _size, eoRnd<T>& _rndGen, const std::string& _ID = "");
|
||||
|
||||
/** Ctor from a std::istream. It just passes the stream to EO, subclasses should
|
||||
have to implement this.
|
||||
@param _is the input stream
|
||||
*/
|
||||
eo1d( std::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
|
||||
@std::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
|
||||
@std::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 std::istream.
|
||||
* @throw runtime_std::exception If a valid object can't be read.
|
||||
*/
|
||||
virtual void readFrom(std::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 std::ostream in which things are written*/
|
||||
virtual void printOn( std::ostream& _s ) const{
|
||||
for ( unsigned i = 0; i < length(); i ++ ) {
|
||||
_s << getGene( i ) << " ";
|
||||
}
|
||||
}
|
||||
|
||||
/** Inherited from eoObject
|
||||
@see eoObject
|
||||
*/
|
||||
std::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 std::string, preferably unique
|
||||
*/
|
||||
template< class T, class fitnessT>
|
||||
eo1d<T,fitnessT>::eo1d<T,fitnessT>( unsigned _size, eoRnd<T>& _rndGen,
|
||||
const std::string& _ID )
|
||||
:EO<fitnessT> ( _ID ) {
|
||||
for ( unsigned i = 0; i < _size; i ++ ) {
|
||||
insertGene( i, _rndGen() );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -1,136 +0,0 @@
|
|||
/* -*- 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 std::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
|
||||
@std::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
|
||||
@std::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
|
||||
*/
|
||||
std::string className() const {return "eo1dWDistance";};
|
||||
|
||||
//@}
|
||||
|
||||
private:
|
||||
///Private ctor. Do not use
|
||||
eo1dWDistance() {};
|
||||
|
||||
|
||||
eo1d<T,fitnessT>& innereo1d;
|
||||
};
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -1,242 +0,0 @@
|
|||
// -*- 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 std::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 std::string, preferably unique
|
||||
*/
|
||||
eo2d( const unsigned _rows,
|
||||
const unsigned _columns,
|
||||
eoRnd<T>& _rndGen,
|
||||
const std::string& _ID = "");
|
||||
|
||||
/** Ctor from an std::istream. It just passes the stream to EO, subclasses should
|
||||
have to implement this.
|
||||
@param _is the input stream
|
||||
*/
|
||||
eo2d( std::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
|
||||
@std::exception out_of_range if _r >=numOfRows()
|
||||
@std::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
|
||||
@std::exception out_of_range if _r >=numOfRows()
|
||||
@std::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.
|
||||
@std::exception invalid_argument If _val has not numOfCols() components.
|
||||
@std::exception out_of_range If _r is greater than numOfRows()
|
||||
*/
|
||||
virtual void insertRow( const unsigned _r,
|
||||
const std::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.
|
||||
@std::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.
|
||||
@std::exception invalid_argument if _val has not numOfRows() components.
|
||||
*/
|
||||
virtual void insertCol( const unsigned _c,
|
||||
const std::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.
|
||||
@std::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 std::istream.
|
||||
* @throw runtime_std::exception If a valid object can't be read.
|
||||
*/
|
||||
virtual void readFrom(std::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 std::ostream in which things are written*/
|
||||
virtual void printOn( std::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
|
||||
*/
|
||||
std::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 std::string, preferably unique
|
||||
*/
|
||||
template< class T, class fitnessT>
|
||||
eo2d<T,fitnessT>::eo2d<T,fitnessT>( const unsigned _rows,
|
||||
const unsigned _columns,
|
||||
eoRnd<T>& _rndGen,
|
||||
const std::string& _ID = "")
|
||||
:EO<fitnessT> ( _ID ) {
|
||||
for ( unsigned r = 0; r < _rows; ++r ) {
|
||||
for ( unsigned c = 0; c < _cols; ++c ) {
|
||||
insertGene( r, c, _rndGen() );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -1,334 +0,0 @@
|
|||
// -*- 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
|
||||
std::vectors.
|
||||
|
||||
================ Modif. 1 ================
|
||||
Author........:
|
||||
Date..........:
|
||||
Description...:
|
||||
|
||||
QUEDA: Operador de asignación, lectura desde std::istream, escritura a std::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 std::vector<int>
|
||||
#include <stdexcept>
|
||||
#include <strstream>
|
||||
#include <ostream.h>
|
||||
|
||||
#include <eo2d.h>
|
||||
#include <eoRnd.h>
|
||||
|
||||
/** Adaptor that turns an STL std::vector of vectror into an EO
|
||||
with the same gene type as the type with which
|
||||
the std::vector of std::vector has been instantiated.
|
||||
*/
|
||||
template <class T, class fitnessT>
|
||||
class eo2dVector: public eo2d<T, fitnessT>, public std::vector< std::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>(), std::vector< std::vector<T> >( _rows, std::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 std::istream. The T class should accept reading from a std::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( std::istream& _is);
|
||||
|
||||
|
||||
/// copy ctor
|
||||
eo2dVector( const eo2dVector & _eo )
|
||||
: eo2d<T, fitnessT>( _eo ), std::vector< std::vector<T> >( _eo ){ };
|
||||
|
||||
/// Assignment operator
|
||||
/*
|
||||
const eo2dVector& operator =( const eo2dVector & _eo ) {
|
||||
if ( this != &_eo ){
|
||||
eo2d<T, fitnessT>::operator=( _eo );
|
||||
std::vector< <std::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
|
||||
@std::exception out_of_range if _r >=numOfRows()
|
||||
@std::exception out_of_range if _c >=numOfCols()
|
||||
*/
|
||||
virtual T getGene( const unsigned _r,
|
||||
const unsigned _c ) const {
|
||||
if ( _r >= numOfRows() ) {
|
||||
std::ostrstream msg;
|
||||
msg << "ERROR in eo2dVector::getGene: row out of range. "
|
||||
<< "It should be <" << numOfRows() << '\0' << std::endl;
|
||||
throw out_of_range( msg.str() );
|
||||
}
|
||||
if ( _c >= numOfCols() ) {
|
||||
std::ostrstream msg;
|
||||
msg << "ERROR in eo2dVector::getGene: column out of range. "
|
||||
<< "It should be <" << numOfCols() << '\0' << std::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
|
||||
@std::exception out_of_range if _r >=numOfRows()
|
||||
@std::exception out_of_range if _c >=numOfCols()
|
||||
*/
|
||||
virtual void setGene( const unsigned _r,
|
||||
const unsigned _c,
|
||||
const T& _value ) {
|
||||
if ( _r >= numOfRows() ) {
|
||||
std::ostrstream msg;
|
||||
msg << "ERROR in eo2dVector::setGene: row out of range. "
|
||||
<< "It should be <" << numOfRows() << '\0' << std::endl;
|
||||
throw out_of_range( msg.str() );
|
||||
}
|
||||
if ( _c >= numOfCols() ) {
|
||||
std::ostrstream msg;
|
||||
msg << "ERROR in eo2dVector::setGene: column out of range. "
|
||||
<< "It should be <" << numOfCols() << '\0' << std::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.
|
||||
@std::exception invalid_argument If _val has not numOfCols() components.
|
||||
@std::exception out_of_range If _r is greater than numOfRows()
|
||||
*/
|
||||
virtual void insertRow( const unsigned _r,
|
||||
const std::vector<T>& _val ) {
|
||||
// Test errors.
|
||||
if ( _r > numOfRows() ) {
|
||||
std::ostrstream msg;
|
||||
msg << "ERROR in eo2dVector::insertRow: row out of range. "
|
||||
<< "It should be <=" << numOfRows() << '\0' << std::endl;
|
||||
throw out_of_range( msg.str() );
|
||||
}
|
||||
if ( _val.size() != numOfCols() ) {
|
||||
std::ostrstream msg;
|
||||
msg << "ERROR in eo2dVector::insertRow: "
|
||||
<< "Incorrect number of values to be added. "
|
||||
<< "It should be ==" << numOfCols() << '\0' << std::endl;
|
||||
throw invalid_argument( msg.str() );
|
||||
}
|
||||
|
||||
// Insert the row.
|
||||
std::vector< std::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.
|
||||
@std::exception out_of_range if _r >=numOfRows()
|
||||
*/
|
||||
virtual void deleteRow( const unsigned _r ) {
|
||||
// Test error.
|
||||
if ( _r >= numOfRows() ) {
|
||||
std::ostrstream msg;
|
||||
msg << "ERROR in eo2dVector::deleteRow: "
|
||||
<< "Row out of range. "
|
||||
<< "It should be <" << numOfRows() << '\0' << std::endl;
|
||||
throw out_of_range( msg.str() );
|
||||
}
|
||||
// Delete row.
|
||||
std::vector< std::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.
|
||||
@std::exception invalid_argument if _val has not numOfRows() components.
|
||||
*/
|
||||
virtual void insertCol( const unsigned _c,
|
||||
const std::vector<T>& _val ) {
|
||||
// Test errors.
|
||||
if ( _c > numOfCols() ) {
|
||||
std::ostrstream msg;
|
||||
msg << "ERROR in eo2dVector::insertCol: "
|
||||
<< "Column out of range. "
|
||||
<< "It should be >=" << numOfCols() << '\0' << std::endl;
|
||||
throw out_of_range( msg.str() );
|
||||
}
|
||||
if ( _val.size() != numOfRows() ) {
|
||||
std::ostrstream msg;
|
||||
msg << "ERROR in eo2dVector::insertCol: "
|
||||
<< "Incorrect number of values to be added. "
|
||||
<< "It should be ==" << numOfRows() << '\0' << std::endl;
|
||||
throw invalid_argument( msg.str() );
|
||||
}
|
||||
|
||||
// Insert column.
|
||||
for( unsigned r=0; r<numOfRows(); ++r ) {
|
||||
std::vector<std::vector<T> >::iterator it1 = begin()+r;
|
||||
std::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.
|
||||
@std::exception out_of_range if _c >=numOfCols()
|
||||
*/
|
||||
virtual void deleteCol( const unsigned _c ) {
|
||||
// Test error.
|
||||
if ( _c >= numOfCols() ) {
|
||||
std::ostrstream msg;
|
||||
msg << "ERROR in eo2dVector::deleteCol: "
|
||||
<< "Column out of range. "
|
||||
<< "It should be <" << numOfCols() << '\0' << std::endl;
|
||||
throw out_of_range( msg.str() );
|
||||
}
|
||||
// Delete columns.
|
||||
for( unsigned r=0; r<numOfRows(); ++r ) {
|
||||
std::vector<std::vector<T> >::iterator it1 = begin()+r;
|
||||
std::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
|
||||
*/
|
||||
std::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>(), std::vector< std::vector<T> >( _rows, std::vector<T>( _cols, T() ) ){
|
||||
for ( std::vector< std::vector<T> >::iterator i = begin(); i != end(); ++i ) {
|
||||
for( std::vector<T>::iterator j=(*i).begin(); j!= (*i).end(); ++j ) {
|
||||
*j = _rnd();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//_____________________________________________________________________________
|
||||
/*template <class T, class fitnessT>
|
||||
eoVector<T,fitnessT>::eoVector( std::istream& _is)
|
||||
: eo1d<T, fitnessT>(), std::vector<T>( ){
|
||||
while (_is ) {
|
||||
T tmp;
|
||||
_is >> tmp;
|
||||
push_back( tmp );
|
||||
}
|
||||
|
||||
};
|
||||
*/
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <class T, class fitnessT>
|
||||
std::ostream& operator<<( std::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 << std::endl;
|
||||
}
|
||||
return _os;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
// -*- 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
|
||||
*/
|
||||
std::string className() const {return "eoAtomBitFlip";};
|
||||
//@}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
// -*- 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 std::string className() const {return "eoAtomCreep";};
|
||||
//@}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
/* -*- 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
|
||||
*/
|
||||
std::string className() const {return "eoAtomRandom";};
|
||||
//@}
|
||||
|
||||
private:
|
||||
eoRnd<T>& rnd;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
eoInserter.h
|
||||
Abstract population insertion operator, which is used by the eoGeneralOps
|
||||
to insert the results in the (intermediate) population. This file also
|
||||
contains the definitions of a derived classes that implements a back inserter,
|
||||
probably the only efficient inserter for populations of type std::vector.
|
||||
|
||||
(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 eoBackInserter_h
|
||||
#define eoBackInserter_h
|
||||
|
||||
#include <eoInserter.h>
|
||||
|
||||
/**
|
||||
\ingroup inserters
|
||||
* eoBackInserter: Interface class that enables an operator to insert
|
||||
new individuals at the back of the new population.
|
||||
*/
|
||||
template <class EOT>
|
||||
class eoBackInserter : public eoPopInserter<EOT>
|
||||
{
|
||||
public :
|
||||
|
||||
eoBackInserter(void) : eoPopInserter<EOT>() {}
|
||||
|
||||
eoInserter<EOT>& operator()(const EOT& _eot)
|
||||
{
|
||||
pop().push_back(_eot);
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string className(void) const { return "eoBackInserter"; }
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
/*
|
||||
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> // std::ostream, std::istream
|
||||
#include <functional> // bind2nd
|
||||
#include <string> // std::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_std::vector (std::vector<bool>).
|
||||
*/
|
||||
template <class F> class eoBin: public eoFixedLength<F, bool>
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* (Default) Constructor.
|
||||
* @param size Size of the binary std::string.
|
||||
*/
|
||||
eoBin(unsigned size = 0, bool value = false):
|
||||
eoVector<bool,F>(size, value) {}
|
||||
|
||||
/// My class name.
|
||||
std::string className() const
|
||||
{
|
||||
return "eoBin";
|
||||
}
|
||||
|
||||
/**
|
||||
* To print me on a stream.
|
||||
* @param os The std::ostream.
|
||||
*/
|
||||
void printOn(std::ostream& os) const
|
||||
{
|
||||
copy(begin(), end(), std::ostream_iterator<bool>(os));
|
||||
}
|
||||
|
||||
/**
|
||||
* To read me from a stream.
|
||||
* @param is The std::istream.
|
||||
*/
|
||||
void readFrom(std::istream& is)
|
||||
{
|
||||
std::string bits;
|
||||
is >> bits;
|
||||
if (is)
|
||||
{
|
||||
resize(bits.size());
|
||||
transform(bits.begin(), bits.end(), begin(),
|
||||
bind2nd(equal_to<char>(), '1'));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#endif eoBin_h
|
||||
|
|
@ -1,116 +0,0 @@
|
|||
// -*- 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> // std::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.
|
||||
std::string className() const { return "eoBreeder"; }
|
||||
|
||||
private:
|
||||
eoOpSelector<Chrom>& opSel;
|
||||
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#endif eoBreeder_h
|
||||
|
||||
|
|
@ -1,110 +0,0 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoCopyElite.h
|
||||
// Base class for elitist-merging classes
|
||||
// (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 eoCopyElite_h
|
||||
#define eoCopyElite_h
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// EO includes
|
||||
#include <eoPop.h> // eoPop
|
||||
#include <eoFunctor.h> // eoCopyElite
|
||||
|
||||
/**
|
||||
* eoCopyElite: Base class for elitist replacement algorithms.
|
||||
* Merges the old population (first argument), with the new generation
|
||||
*
|
||||
* Its signature is exactly
|
||||
* that of the selection base eoSelect, but its purpose is to merge the
|
||||
* two populations into one (the second argument).
|
||||
* Note that the algorithms assume that the second argument denotes the
|
||||
* next generation.
|
||||
*/
|
||||
|
||||
template<class Chrom> class eoCopyElite: public eoBinaryFunctor<void, const eoPop<Chrom>&, eoPop<Chrom>&>
|
||||
{};
|
||||
|
||||
/**
|
||||
Straightforward elitism class, specify the number of individuals to copy
|
||||
into new geneneration
|
||||
*/
|
||||
template <class EOT> class eoElitism : public eoCopyElite<EOT>
|
||||
{
|
||||
public :
|
||||
eoElitism(unsigned _howmany) : howmany(_howmany) {}
|
||||
|
||||
void operator()(const eoPop<EOT>& _pop, eoPop<EOT>& offspring)
|
||||
{
|
||||
if (howmany == 0)
|
||||
return;
|
||||
|
||||
if (howmany > _pop.size())
|
||||
throw logical_error("Elite larger than population");
|
||||
|
||||
std::vector<const EOT*> result;
|
||||
_pop.nth_element(howmany, result);
|
||||
|
||||
for (int i = 0; i < result.size(); ++i)
|
||||
{
|
||||
offspring.push_back(*result[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private :
|
||||
unsigned howmany;
|
||||
};
|
||||
|
||||
/**
|
||||
No elite
|
||||
*/
|
||||
template <class EOT> class eoNoElitism : public eoElitism<EOT>
|
||||
{
|
||||
public :
|
||||
eoNoElitism() : eoElitism(0) {}
|
||||
}
|
||||
|
||||
/**
|
||||
Very elitist class, copies entire population into next gen
|
||||
*/
|
||||
template <class EOT> class eoPlus : public eoCopyElite<EOT>
|
||||
{
|
||||
public :
|
||||
void operator()(const eoPop<EOT>& _pop, eoPop<EOT>& offspring)
|
||||
{
|
||||
offspring.reserve(offspring.size() + _pop.size());
|
||||
|
||||
for (int i = 0; i < _pop.size(); ++i)
|
||||
{
|
||||
offspring.push_back(*result[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private :
|
||||
unsigned howmany;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#endif
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoDEA.h
|
||||
// (c) Marc Schoenauer, Maarten Keijzer, 2001
|
||||
/*
|
||||
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: Marc.Schoenauer@polytechnique.fr
|
||||
mkeijzer@dhi.dk
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _eoDEA_h
|
||||
#define _eoDEA_h
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <eoDistribution.h>
|
||||
|
||||
/** eoDEA: Distribution Evolution Algorithm within EO
|
||||
*
|
||||
* The abstract class for algorithms that evolve a probability distribution
|
||||
* on the spaces of populations rather than a population
|
||||
*
|
||||
* It IS NOT an eoAlgo, as it evolves a distribution, not a population
|
||||
*/
|
||||
|
||||
template<class EOT> class eoDEA: public eoUF<eoDistribution<EOT>&, void>
|
||||
{
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoDetTournament.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 eoDetTournament_h
|
||||
#define eoDetTournament_h
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <functional> //
|
||||
#include <numeric> // accumulate
|
||||
|
||||
#include <eoFunctor.h>
|
||||
#include <eoPop.h>
|
||||
#include <utils/selectors.h>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** eoDetTournament: a selection method that selects ONE individual by
|
||||
deterministic tournament
|
||||
-MS- 24/10/99 */
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template <class EOT> class eoDetTournament: public eoSelectOne<EOT>
|
||||
{
|
||||
public:
|
||||
/// (Default) Constructor.
|
||||
eoDetTournament(unsigned _Tsize = 2 ):eoSelectOne<EOT>(), Tsize(_Tsize) {
|
||||
// consistency check
|
||||
if (Tsize < 2) {
|
||||
std::cout << "Warning, Tournament size should be >= 2\nAdjusted\n";
|
||||
Tsize = 2;
|
||||
}
|
||||
}
|
||||
|
||||
/// Perform deterministic tournament
|
||||
virtual const EOT& operator()(const eoPop<EOT>& pop)
|
||||
{
|
||||
return deterministic_tournament(pop, Tsize);
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned Tsize;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#endif eoDetTournament_h
|
||||
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
/* -*- 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
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
eoDetTournamentInserter.h
|
||||
Concrete steady state inserter. It is initialized with a population and
|
||||
inserts individuals in the population based on an inverse deterministic
|
||||
tournament
|
||||
|
||||
(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 eoDetTournamentInserter_h
|
||||
#define eoDetTournamentInserter_h
|
||||
|
||||
|
||||
#include <eoSteadyStateInserter.h>
|
||||
#include <utils/selectors.h>
|
||||
|
||||
/**
|
||||
* eoDetTournamentInserter: Uses an inverse deterministic tournament to figure
|
||||
* out who gets overridden by the new individual. It resets the fitness of the
|
||||
* individual.
|
||||
*/
|
||||
template <class EOT>
|
||||
class eoDetTournamentInserter : public eoSteadyStateInserter<EOT>
|
||||
{
|
||||
public :
|
||||
|
||||
eoDetTournamentInserter(eoEvalFunc<EOT>& _eval, unsigned _t_size):
|
||||
eoSteadyStateInserter<EOT>(_eval),
|
||||
t_size(_t_size)
|
||||
{
|
||||
if (t_size < 2)
|
||||
{ // warning, error?
|
||||
t_size = 2;
|
||||
}
|
||||
}
|
||||
|
||||
eoInserter<EOT>& operator()(const EOT& _eot)
|
||||
{
|
||||
EOT& eo = inverse_deterministic_tournament<EOT>(pop(), t_size);
|
||||
eo = _eot; // overwrite loser of tournament
|
||||
|
||||
eval(eo); // Evaluate after insert
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string className(void) const { return "eoDetTournamentInserter"; }
|
||||
|
||||
private :
|
||||
unsigned t_size;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
/* -*- 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 std::string className() const { return "eoDistance"; }
|
||||
|
||||
};
|
||||
|
||||
#endif EOOBJECT_H
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
// 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 std::string className() const {return "eoDup";};
|
||||
//@}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -1,164 +0,0 @@
|
|||
// -*- 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 std::vector<>
|
||||
#include <stdexcept>
|
||||
#include <strstream>
|
||||
#include <iostream> // for std::ostream
|
||||
|
||||
// EO includes
|
||||
#include <eoVector.h>
|
||||
|
||||
/**@name Chromosomes for evolution strategies
|
||||
Each chromosome in an evolution strategies is composed of a std::vector of floating point
|
||||
values plus a std::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 ) ;
|
||||
}
|
||||
|
||||
///
|
||||
std::ostream & operator << ( std::ostream& _s, const eoESGene& _e ) {
|
||||
_s << _e.val << ", " << _e.sigma << " | ";
|
||||
return _s;
|
||||
}
|
||||
|
||||
/// Dummy >>
|
||||
std::istream & operator >> ( std::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
|
||||
*/
|
||||
std::string className() const {return "eoESChrom";};
|
||||
//@}
|
||||
|
||||
};
|
||||
|
||||
//@}
|
||||
#endif
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue