From 2670bd857fe5876d480b461ef95f068ea58ced79 Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Mon, 1 Nov 2010 18:19:37 +0100 Subject: [PATCH] delete the obsolete directory (still versionned in the repository if necessary) --- eo/src/obsolete/.cvsignore | 6 - eo/src/obsolete/CMakeLists.txt | 35 - eo/src/obsolete/eo1d.h | 199 ----- eo/src/obsolete/eo1dWDistance.h | 136 --- eo/src/obsolete/eo2d.h | 242 ----- eo/src/obsolete/eo2dVector.h | 334 ------- eo/src/obsolete/eoAtomBitFlip.h | 58 -- eo/src/obsolete/eoAtomCreep.h | 66 -- eo/src/obsolete/eoAtomRandom.h | 64 -- eo/src/obsolete/eoBackInserter.h | 56 -- eo/src/obsolete/eoBin.h | 89 -- eo/src/obsolete/eoBreeder.h | 116 --- eo/src/obsolete/eoCopyElite.h | 110 --- eo/src/obsolete/eoDEA.h | 46 - eo/src/obsolete/eoDetTournament.h | 69 -- eo/src/obsolete/eoDetTournamentIndiSelector.h | 58 -- eo/src/obsolete/eoDetTournamentInserter.h | 70 -- eo/src/obsolete/eoDistance.h | 63 -- eo/src/obsolete/eoDup.h | 70 -- eo/src/obsolete/eoES.h | 164 ---- eo/src/obsolete/eoESChrom.h | 164 ---- eo/src/obsolete/eoESFullChrom.h | 267 ------ eo/src/obsolete/eoESFullMut.h | 261 ------ eo/src/obsolete/eoEsObjectiveBounds.h | 81 -- eo/src/obsolete/eoEvalFuncPtrCnt.h | 62 -- eo/src/obsolete/eoEvolutionStrategy.h | 101 --- eo/src/obsolete/eoFitTerm.h | 59 -- eo/src/obsolete/eoFitness.h | 57 -- eo/src/obsolete/eoGOpBreeder.h | 62 -- eo/src/obsolete/eoGOpSelector.h | 181 ---- eo/src/obsolete/eoGenTerm.h | 68 -- eo/src/obsolete/eoGeneration.h | 85 -- eo/src/obsolete/eoGenericBinOp.h | 75 -- eo/src/obsolete/eoGenericMonOp.h | 75 -- eo/src/obsolete/eoGenericQuadOp.h | 83 -- eo/src/obsolete/eoID.h | 110 --- eo/src/obsolete/eoInclusion.h | 64 -- eo/src/obsolete/eoIndiSelector.h | 160 ---- eo/src/obsolete/eoInplaceTransform.h | 193 ---- eo/src/obsolete/eoInserter.h | 93 -- eo/src/obsolete/eoInsertion.h | 96 -- eo/src/obsolete/eoKill.h | 62 -- eo/src/obsolete/eoLottery.h | 105 --- eo/src/obsolete/eoMutation.h | 90 -- eo/src/obsolete/eoNegExp.h | 67 -- eo/src/obsolete/eoNonUniform.h | 87 -- eo/src/obsolete/eoNormal.h | 89 -- eo/src/obsolete/eoOpFactory.h | 87 -- eo/src/obsolete/eoOpSelector.h | 94 -- eo/src/obsolete/eoParser.h | 838 ------------------ eo/src/obsolete/eoParserUtils.cpp | 35 - eo/src/obsolete/eoParserUtils.h | 24 - eo/src/obsolete/eoPopOps.h | 142 --- eo/src/obsolete/eoProblem.h | 45 - eo/src/obsolete/eoProportional.h | 71 -- eo/src/obsolete/eoProportionalGOpSel.h | 51 -- eo/src/obsolete/eoProportionalOpSel.h | 158 ---- eo/src/obsolete/eoRandomBreed.h | 200 ----- eo/src/obsolete/eoRandomIndiSelector.h | 53 -- eo/src/obsolete/eoRandomSelect.h | 130 --- eo/src/obsolete/eoRank.h | 140 --- eo/src/obsolete/eoScheme.h | 360 -------- eo/src/obsolete/eoSelectRandom.h | 52 -- eo/src/obsolete/eoSequentialGOpSel.h | 55 -- eo/src/obsolete/eoSimpleDEA.h | 105 --- eo/src/obsolete/eoSteadyStateEA.h | 84 -- eo/src/obsolete/eoSteadyStateInserter.h | 53 -- eo/src/obsolete/eoSteadyStateTransform.h | 88 -- eo/src/obsolete/eoStochTournament.h | 69 -- eo/src/obsolete/eoStochTournamentInserter.h | 75 -- eo/src/obsolete/eoStringMutation.h | 77 -- eo/src/obsolete/eoTerm.h | 56 -- eo/src/obsolete/eoTournament.h | 157 ---- eo/src/obsolete/eoTranspose.h | 94 -- eo/src/obsolete/eoUniformXOver.h | 176 ---- eo/src/obsolete/eoVector.h | 170 ---- eo/src/obsolete/eoWrappedOps.h | 200 ----- eo/src/obsolete/eoXOver2.h | 107 --- eo/src/obsolete/evolution_strategies | 15 - 79 files changed, 9009 deletions(-) delete mode 100644 eo/src/obsolete/.cvsignore delete mode 100644 eo/src/obsolete/CMakeLists.txt delete mode 100644 eo/src/obsolete/eo1d.h delete mode 100644 eo/src/obsolete/eo1dWDistance.h delete mode 100644 eo/src/obsolete/eo2d.h delete mode 100644 eo/src/obsolete/eo2dVector.h delete mode 100644 eo/src/obsolete/eoAtomBitFlip.h delete mode 100644 eo/src/obsolete/eoAtomCreep.h delete mode 100644 eo/src/obsolete/eoAtomRandom.h delete mode 100644 eo/src/obsolete/eoBackInserter.h delete mode 100644 eo/src/obsolete/eoBin.h delete mode 100644 eo/src/obsolete/eoBreeder.h delete mode 100644 eo/src/obsolete/eoCopyElite.h delete mode 100644 eo/src/obsolete/eoDEA.h delete mode 100644 eo/src/obsolete/eoDetTournament.h delete mode 100644 eo/src/obsolete/eoDetTournamentIndiSelector.h delete mode 100644 eo/src/obsolete/eoDetTournamentInserter.h delete mode 100644 eo/src/obsolete/eoDistance.h delete mode 100644 eo/src/obsolete/eoDup.h delete mode 100644 eo/src/obsolete/eoES.h delete mode 100644 eo/src/obsolete/eoESChrom.h delete mode 100644 eo/src/obsolete/eoESFullChrom.h delete mode 100644 eo/src/obsolete/eoESFullMut.h delete mode 100644 eo/src/obsolete/eoEsObjectiveBounds.h delete mode 100644 eo/src/obsolete/eoEvalFuncPtrCnt.h delete mode 100644 eo/src/obsolete/eoEvolutionStrategy.h delete mode 100644 eo/src/obsolete/eoFitTerm.h delete mode 100644 eo/src/obsolete/eoFitness.h delete mode 100644 eo/src/obsolete/eoGOpBreeder.h delete mode 100644 eo/src/obsolete/eoGOpSelector.h delete mode 100644 eo/src/obsolete/eoGenTerm.h delete mode 100644 eo/src/obsolete/eoGeneration.h delete mode 100644 eo/src/obsolete/eoGenericBinOp.h delete mode 100644 eo/src/obsolete/eoGenericMonOp.h delete mode 100644 eo/src/obsolete/eoGenericQuadOp.h delete mode 100644 eo/src/obsolete/eoID.h delete mode 100644 eo/src/obsolete/eoInclusion.h delete mode 100644 eo/src/obsolete/eoIndiSelector.h delete mode 100644 eo/src/obsolete/eoInplaceTransform.h delete mode 100644 eo/src/obsolete/eoInserter.h delete mode 100644 eo/src/obsolete/eoInsertion.h delete mode 100644 eo/src/obsolete/eoKill.h delete mode 100644 eo/src/obsolete/eoLottery.h delete mode 100644 eo/src/obsolete/eoMutation.h delete mode 100644 eo/src/obsolete/eoNegExp.h delete mode 100644 eo/src/obsolete/eoNonUniform.h delete mode 100644 eo/src/obsolete/eoNormal.h delete mode 100644 eo/src/obsolete/eoOpFactory.h delete mode 100644 eo/src/obsolete/eoOpSelector.h delete mode 100644 eo/src/obsolete/eoParser.h delete mode 100644 eo/src/obsolete/eoParserUtils.cpp delete mode 100644 eo/src/obsolete/eoParserUtils.h delete mode 100644 eo/src/obsolete/eoPopOps.h delete mode 100644 eo/src/obsolete/eoProblem.h delete mode 100644 eo/src/obsolete/eoProportional.h delete mode 100644 eo/src/obsolete/eoProportionalGOpSel.h delete mode 100644 eo/src/obsolete/eoProportionalOpSel.h delete mode 100644 eo/src/obsolete/eoRandomBreed.h delete mode 100644 eo/src/obsolete/eoRandomIndiSelector.h delete mode 100644 eo/src/obsolete/eoRandomSelect.h delete mode 100644 eo/src/obsolete/eoRank.h delete mode 100644 eo/src/obsolete/eoScheme.h delete mode 100644 eo/src/obsolete/eoSelectRandom.h delete mode 100644 eo/src/obsolete/eoSequentialGOpSel.h delete mode 100644 eo/src/obsolete/eoSimpleDEA.h delete mode 100644 eo/src/obsolete/eoSteadyStateEA.h delete mode 100644 eo/src/obsolete/eoSteadyStateInserter.h delete mode 100644 eo/src/obsolete/eoSteadyStateTransform.h delete mode 100644 eo/src/obsolete/eoStochTournament.h delete mode 100644 eo/src/obsolete/eoStochTournamentInserter.h delete mode 100644 eo/src/obsolete/eoStringMutation.h delete mode 100644 eo/src/obsolete/eoTerm.h delete mode 100644 eo/src/obsolete/eoTournament.h delete mode 100644 eo/src/obsolete/eoTranspose.h delete mode 100644 eo/src/obsolete/eoUniformXOver.h delete mode 100644 eo/src/obsolete/eoVector.h delete mode 100644 eo/src/obsolete/eoWrappedOps.h delete mode 100644 eo/src/obsolete/eoXOver2.h delete mode 100644 eo/src/obsolete/evolution_strategies diff --git a/eo/src/obsolete/.cvsignore b/eo/src/obsolete/.cvsignore deleted file mode 100644 index 69fb0bd8..00000000 --- a/eo/src/obsolete/.cvsignore +++ /dev/null @@ -1,6 +0,0 @@ -*.lo -*.la -.deps -.libs -Makefile -Makefile.in diff --git a/eo/src/obsolete/CMakeLists.txt b/eo/src/obsolete/CMakeLists.txt deleted file mode 100644 index 3fe15630..00000000 --- a/eo/src/obsolete/CMakeLists.txt +++ /dev/null @@ -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}") - -###################################################################################### - diff --git a/eo/src/obsolete/eo1d.h b/eo/src/obsolete/eo1d.h deleted file mode 100644 index 73e83ea0..00000000 --- a/eo/src/obsolete/eo1d.h +++ /dev/null @@ -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 // for std::ostream - -// EO Includes -#include -#include - -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 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 ( ) {}; - - /** 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& _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(){ readFrom(is); } - - /// Copy ctor - eo1d( const eo1d& _eo ) - :EO ( _eo ) {}; - - /// Assignment operator - const eo1d& operator= ( const eo1d& _eo ) { - EO::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::eo1d( unsigned _size, eoRnd& _rndGen, - const std::string& _ID ) - :EO ( _ID ) { - for ( unsigned i = 0; i < _size; i ++ ) { - insertGene( i, _rndGen() ); - } -}; - - -#endif diff --git a/eo/src/obsolete/eo1dWDistance.h b/eo/src/obsolete/eo1dWDistance.h deleted file mode 100644 index 2019e95c..00000000 --- a/eo/src/obsolete/eo1dWDistance.h +++ /dev/null @@ -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 // for std::ostream - -// EO Includes -#include -#include - -using namespace std; - -/** eo1dWDistance: wraps around eo1ds and adds the possibility of computing distances -around them. -*/ -template -class eo1dWDistance: - public eo1d< T,fitnessT >, - public eoDistance > { -public: - - /** Can be used as default ctor; should be called from derived - classes. Fitness should be at birth - */ - eo1dWDistance( eo1d& _eo) - :eo1d (), eoDistance< eo1d >(), 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& _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& innereo1d; -}; - -//@} - - -#endif diff --git a/eo/src/obsolete/eo2d.h b/eo/src/obsolete/eo2d.h deleted file mode 100644 index c8d08219..00000000 --- a/eo/src/obsolete/eo2d.h +++ /dev/null @@ -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 // for std::ostream -#include - -// EO Includes -#include -#include - -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 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 ( ) {}; - - /** 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& _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( _is ){}; - - /// Copy ctor - eo2d( const eo2d& _eo ) - :EO ( _eo ) {}; - - /// Assignment operator - const eo2d& operator= ( const eo2d& _eo ) { - EO::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& _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& _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::eo2d( const unsigned _rows, - const unsigned _columns, - eoRnd& _rndGen, - const std::string& _ID = "") - :EO ( _ID ) { - for ( unsigned r = 0; r < _rows; ++r ) { - for ( unsigned c = 0; c < _cols; ++c ) { - insertGene( r, c, _rndGen() ); - } - } -}; - - -#endif diff --git a/eo/src/obsolete/eo2dVector.h b/eo/src/obsolete/eo2dVector.h deleted file mode 100644 index ec583368..00000000 --- a/eo/src/obsolete/eo2dVector.h +++ /dev/null @@ -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 // For std::vector -#include -#include -#include - -#include -#include - -/** 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 eo2dVector: public eo2d, public std::vector< std::vector > { -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(), std::vector< std::vector >( _rows, std::vector( _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& _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( _eo ), std::vector< std::vector >( _eo ){ }; - - /// Assignment operator - /* - const eo2dVector& operator =( const eo2dVector & _eo ) { - if ( this != &_eo ){ - eo2d::operator=( _eo ); - std::vector< >::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& _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 >::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 >::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& _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 >::iterator it1 = begin()+r; - std::vector::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 >::iterator it1 = begin()+r; - std::vector::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 -eo2dVector::eo2dVector( const unsigned _rows, - const unsigned _cols, - eoRnd& _rnd ) - : eo2d(), std::vector< std::vector >( _rows, std::vector( _cols, T() ) ){ - for ( std::vector< std::vector >::iterator i = begin(); i != end(); ++i ) { - for( std::vector::iterator j=(*i).begin(); j!= (*i).end(); ++j ) { - *j = _rnd(); - } - } -}; - -//_____________________________________________________________________________ -/*template -eoVector::eoVector( std::istream& _is) - : eo1d(), std::vector( ){ - while (_is ) { - T tmp; - _is >> tmp; - push_back( tmp ); - } - -}; -*/ - -//_____________________________________________________________________________ -template -std::ostream& operator<<( std::ostream& _os, const eo2dVector& _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 - diff --git a/eo/src/obsolete/eoAtomBitFlip.h b/eo/src/obsolete/eoAtomBitFlip.h deleted file mode 100644 index be1a1be5..00000000 --- a/eo/src/obsolete/eoAtomBitFlip.h +++ /dev/null @@ -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 eoAtomBitFlip: public eoAtomMutator { -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 - diff --git a/eo/src/obsolete/eoAtomCreep.h b/eo/src/obsolete/eoAtomCreep.h deleted file mode 100644 index 8c293208..00000000 --- a/eo/src/obsolete/eoAtomCreep.h +++ /dev/null @@ -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 -#include - -/** With uniform probability, decrements or increments by one the value. - The value type must admit post increment and decrement. -*/ -template -class eoAtomCreep: public eoAtomMutator { -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 - diff --git a/eo/src/obsolete/eoAtomRandom.h b/eo/src/obsolete/eoAtomRandom.h deleted file mode 100644 index 1cc846ee..00000000 --- a/eo/src/obsolete/eoAtomRandom.h +++ /dev/null @@ -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 - -/** Modifies using a random number generator, that is entered in the ctor. - The RNG must return positive or negative numbers, whatever. -*/ -template -class eoAtomRandom: public eoAtomMutator { -public: - - /// - eoAtomRandom( eoRnd& _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& rnd; - -}; - - -#endif diff --git a/eo/src/obsolete/eoBackInserter.h b/eo/src/obsolete/eoBackInserter.h deleted file mode 100644 index 24bdad38..00000000 --- a/eo/src/obsolete/eoBackInserter.h +++ /dev/null @@ -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 - -/** -\ingroup inserters - * eoBackInserter: Interface class that enables an operator to insert - new individuals at the back of the new population. -*/ -template -class eoBackInserter : public eoPopInserter -{ - public : - - eoBackInserter(void) : eoPopInserter() {} - - eoInserter& operator()(const EOT& _eot) - { - pop().push_back(_eot); - return *this; - } - - std::string className(void) const { return "eoBackInserter"; } - -}; - -#endif diff --git a/eo/src/obsolete/eoBin.h b/eo/src/obsolete/eoBin.h deleted file mode 100644 index 86dc8e7a..00000000 --- a/eo/src/obsolete/eoBin.h +++ /dev/null @@ -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 // std::ostream, std::istream -#include // bind2nd -#include // std::string - -#include - -/** -\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). -*/ -template class eoBin: public eoFixedLength -{ - public: - - /** - * (Default) Constructor. - * @param size Size of the binary std::string. - */ - eoBin(unsigned size = 0, bool value = false): - eoVector(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(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(), '1')); - } - } -}; - -//----------------------------------------------------------------------------- - -#endif eoBin_h diff --git a/eo/src/obsolete/eoBreeder.h b/eo/src/obsolete/eoBreeder.h deleted file mode 100644 index 7d8dd9bc..00000000 --- a/eo/src/obsolete/eoBreeder.h +++ /dev/null @@ -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 // std::vector -#include -#include // eoOp, eoMonOp, eoBinOp -#include // eoPop -#include // eoOpSelector - -#include - -#include -#include - -using namespace std; - -/***************************************************************************** - * eoBreeder: transforms a population using genetic operators. * - * For every operator there is a rated to be applyed. * - *****************************************************************************/ - -template class eoBreeder: public eoTransform -//eoUnaryFunctor&> -{ - public: - /// Default constructor. - eoBreeder( eoOpSelector& _opSel): opSel( _opSel ) {} - - /// Destructor. - virtual ~eoBreeder() {} - - /** - * Transforms a population. - * @param pop The population to be transformed. - */ - void operator()(eoPop& pop) - { - size_t orgsize = pop.size(); - - for (unsigned i = 0; i < pop.size(); i++) - { - eoOp* op = opSel.Op(); - switch (op->getType()) - { - case eoOp::unary: - { - eoMonOp* monop = static_cast* >(op); - (*monop)( pop[i] ); - break; - } - case eoOp::binary: - { - eoBinOp* binop = static_cast* >(op); - (*binop)(pop[i], pop[ rng.random(pop.size()) ] ); - break; - } - case eoOp::quadratic: - { - eoQuadraticOp* Qop = static_cast* >(op); - - (*Qop)(pop[i], pop[ rng.random(pop.size()) ] ); - break; - } - case eoOp::general : - { - eoGeneralOp* Gop = static_cast* >(op); - - eoRandomIndiSelector selector; - eoBackInserter inserter; - - (*Gop)(selector.bind(pop, orgsize).bias(i), inserter.bind(pop)); - break; - } - } - } - }; - - /// The class name. - std::string className() const { return "eoBreeder"; } - - private: - eoOpSelector& opSel; - -}; - -//----------------------------------------------------------------------------- - -#endif eoBreeder_h - diff --git a/eo/src/obsolete/eoCopyElite.h b/eo/src/obsolete/eoCopyElite.h deleted file mode 100644 index 19dafcff..00000000 --- a/eo/src/obsolete/eoCopyElite.h +++ /dev/null @@ -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 -#include // 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 eoCopyElite: public eoBinaryFunctor&, eoPop&> -{}; - -/** -Straightforward elitism class, specify the number of individuals to copy -into new geneneration -*/ -template class eoElitism : public eoCopyElite -{ - public : - eoElitism(unsigned _howmany) : howmany(_howmany) {} - - void operator()(const eoPop& _pop, eoPop& offspring) - { - if (howmany == 0) - return; - - if (howmany > _pop.size()) - throw logical_error("Elite larger than population"); - - std::vector 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 eoNoElitism : public eoElitism -{ - public : - eoNoElitism() : eoElitism(0) {} -} - -/** -Very elitist class, copies entire population into next gen -*/ -template class eoPlus : public eoCopyElite -{ - public : - void operator()(const eoPop& _pop, eoPop& offspring) - { - offspring.reserve(offspring.size() + _pop.size()); - - for (int i = 0; i < _pop.size(); ++i) - { - offspring.push_back(*result[i]); - } - } - - private : - unsigned howmany; -}; - -//----------------------------------------------------------------------------- - -#endif diff --git a/eo/src/obsolete/eoDEA.h b/eo/src/obsolete/eoDEA.h deleted file mode 100644 index bb717ae1..00000000 --- a/eo/src/obsolete/eoDEA.h +++ /dev/null @@ -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 - -/** 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 eoDEA: public eoUF&, void> -{ -}; - -#endif - diff --git a/eo/src/obsolete/eoDetTournament.h b/eo/src/obsolete/eoDetTournament.h deleted file mode 100644 index 2bd15b9d..00000000 --- a/eo/src/obsolete/eoDetTournament.h +++ /dev/null @@ -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 // -#include // accumulate - -#include -#include -#include - -//----------------------------------------------------------------------------- -/** eoDetTournament: a selection method that selects ONE individual by - deterministic tournament - -MS- 24/10/99 */ -//----------------------------------------------------------------------------- - -template class eoDetTournament: public eoSelectOne -{ - public: - /// (Default) Constructor. - eoDetTournament(unsigned _Tsize = 2 ):eoSelectOne(), 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& pop) - { - return deterministic_tournament(pop, Tsize); - } - - private: - unsigned Tsize; -}; - -//----------------------------------------------------------------------------- - -#endif eoDetTournament_h - diff --git a/eo/src/obsolete/eoDetTournamentIndiSelector.h b/eo/src/obsolete/eoDetTournamentIndiSelector.h deleted file mode 100644 index 75d36c21..00000000 --- a/eo/src/obsolete/eoDetTournamentIndiSelector.h +++ /dev/null @@ -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 eoDetTournamentIndiSelector : public eoPopIndiSelector -{ - public : - - eoDetTournamentIndiSelector(int _tournamentSize) - : eoPopIndiSelector(), - tournamentSize(_tournamentSize) - {} - - virtual ~eoDetTournamentIndiSelector(void) {} - - const EOT& do_select(void) - { - return *deterministic_tournament(begin(), end(), tournamentSize); - } - - private : - - int tournamentSize; -}; - -#endif diff --git a/eo/src/obsolete/eoDetTournamentInserter.h b/eo/src/obsolete/eoDetTournamentInserter.h deleted file mode 100644 index 9077aece..00000000 --- a/eo/src/obsolete/eoDetTournamentInserter.h +++ /dev/null @@ -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 -#include - -/** - * 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 eoDetTournamentInserter : public eoSteadyStateInserter -{ -public : - - eoDetTournamentInserter(eoEvalFunc& _eval, unsigned _t_size): - eoSteadyStateInserter(_eval), - t_size(_t_size) - { - if (t_size < 2) - { // warning, error? - t_size = 2; - } - } - - eoInserter& operator()(const EOT& _eot) - { - EOT& eo = inverse_deterministic_tournament(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 diff --git a/eo/src/obsolete/eoDistance.h b/eo/src/obsolete/eoDistance.h deleted file mode 100644 index 5f3c333e..00000000 --- a/eo/src/obsolete/eoDistance.h +++ /dev/null @@ -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 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 diff --git a/eo/src/obsolete/eoDup.h b/eo/src/obsolete/eoDup.h deleted file mode 100644 index 67e4a863..00000000 --- a/eo/src/obsolete/eoDup.h +++ /dev/null @@ -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 - -#include - -/// Dup or duplicate: duplicates a gene in a chromosome -template -class eoDup: public eoMonOp > { -public: - /// - eoDup( ) - : eoMonOp< EOT >( ){}; - - /// needed virtual dtor - virtual ~eoDup() {}; - - /// - virtual void operator()(eoVariableLength& _eo ) const - { - unsigned pos = rng.random(_eo.size()); - eoVariableLength::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 - diff --git a/eo/src/obsolete/eoES.h b/eo/src/obsolete/eoES.h deleted file mode 100644 index 9f4051f8..00000000 --- a/eo/src/obsolete/eoES.h +++ /dev/null @@ -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 // For std::vector<> -#include -#include -#include // for std::ostream - -// EO includes -#include - -/**@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 -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 -struct eoESGene : public eoESValue -{ - 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 -class eoESChrom: public eoVector { -public: - /// Basic ctor - eoESChrom( ):eoVector() {}; - - /** 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& _rnd, eoRnd& _rndS ) - : eoVector( _size ){ - for ( iterator i = begin(); i != end(); i ++ ) { - i->val = _rnd(); - i->sigma = _rndS(); - } - }; - - /// Copy ctor - eoESChrom( const eoESChrom& _eoes): eoVector( _eoes ) {}; - - /// Assignment operator - const eoESChrom& operator =( const eoESChrom & _eoes ) { - if ( this != &_eoes ){ - eoVector::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 - diff --git a/eo/src/obsolete/eoESChrom.h b/eo/src/obsolete/eoESChrom.h deleted file mode 100644 index 1ad0bcf4..00000000 --- a/eo/src/obsolete/eoESChrom.h +++ /dev/null @@ -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 // For std::vector<> -#include -#include -#include // for std::ostream - -// EO includes -#include - -/**@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 -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 -struct eoESGene : public eoESValue -{ - 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 -class eoESChrom: public eoVector { -public: - /// Basic ctor - eoESChrom( ):eoVector() {}; - - /** 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& _rnd, eoRnd& _rndS ) - : eoVector( _size ){ - for ( iterator i = begin(); i != end(); i ++ ) { - i->val = _rnd(); - i->sigma = _rndS(); - } - }; - - /// Copy ctor - eoESChrom( const eoESChrom& _eoes): eoVector( _eoes ) {}; - - /// Assignment operator - const eoESChrom& operator =( const eoESChrom & _eoes ) { - if ( this != &_eoes ){ - eoVector::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 - diff --git a/eo/src/obsolete/eoESFullChrom.h b/eo/src/obsolete/eoESFullChrom.h deleted file mode 100644 index e00914b5..00000000 --- a/eo/src/obsolete/eoESFullChrom.h +++ /dev/null @@ -1,267 +0,0 @@ -// -*- 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 // For std::vector<> -#include -#include -#include // for std::ostream - -// EO includes -#include -#include -/**@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 and a std::vector of correlations -*/ -//@{ - - -/**@name individuals for evolution strategies -MS- 22/10/99 -Each individual in an evolution strategy is composed of - a std::vector of floating point values - a std::vector of std deviations - a std::vector of rotation angles (for correlated mutations) - -These individuals CANNOT BE IMPLEMENTED as std::vectors of anything - at least in the case of correlated mutations -*/ -//@{ - -template -class eoESFullChrom : public eoVector { - 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(_num_genes), - // ObjVar( _num_genes ), now an eoVector - 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 std::listing of ES individuals (mutation parameters"); - } - catch (std::exception & e) - { - std::cout << e.what() << std::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) { - std::cout << "WARNING, Number of Standard Deviations > Number of Object Variables\nAdjusted!\n"; - num_sigma = num_genes; - // modify the Param value - so .status is OK - std::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) { - std::cout << "WARNING less Std Dev. than number of variables + Correlated mutations\n"; - std::cout << "Though possible, this is a strange setting" << std::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::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 std::ostream in which things are written*/ - virtual void printOn( std::ostream& _s ) const{ - copy( begin(), end(), std::ostream_iterator( _s, " ") ); - // The formatting instructinos shoudl be left to the caller - // _s << "\n"; - if (verbose) { - _s << "\n\tStd Dev. " ; - copy( StdDev.begin(), StdDev.end(), std::ostream_iterator( _s, " ") ); - if (CorCff.size()) { - _s << "\n\t"; - copy( CorCff.begin(), CorCff.end(), std::ostream_iterator( _s, " ") ); - } - } - }; - - /** This std::exception should be thrown when trying to insert or delete a gene - in a fixed length chromosome - */ - class FixedLengthChromosome : public std::exception { - - public: - /** - * Constructor - */ - FixedLengthChromosome() - : std::exception() { }; - - ~FixedLengthChromosome() {}; - }; - - // accessors - double getObjMin() const {return ObjMin;} - double getObjMax() const {return ObjMax;} - double getStdDevInit () const {return StdDevInit;} - - /** Inherited from eoObject - @see eoObject - */ - virtual std::string className() const {return "eoESFullChrom";}; - -private: - // std::vector ObjVar; /* object variable std::vector */ -// or shoudl the class be subclass of EOVector ??? - - std::vector StdDev; /* standard deviation std::vector */ - std::vector CorCff; /* correlation coefficient std::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 - - diff --git a/eo/src/obsolete/eoESFullMut.h b/eo/src/obsolete/eoESFullMut.h deleted file mode 100644 index 9d967c7a..00000000 --- a/eo/src/obsolete/eoESFullMut.h +++ /dev/null @@ -1,261 +0,0 @@ -// -*- 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 -#include -#include // for exp - -#include -#include -#include - -#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 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::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::has_correlation) - { // Correlated Mutations - TauBeta = _init.TauBeta(); - } - } - } - - /// needed virtual dtor - virtual ~eoESMutate() {}; - - /** Inherited from eoObject - @see eoObject - */ - virtual std::string className() const {return "eoESMutate";}; - - /** - Mutate eoEsSimple - */ - virtual void operator()( eoEsSimple& _eo) const - { - _eo.stdev *= exp(TauLcl * rng.normal()); - - if (_eo.stdev < eoEsInfo::stdev_eps) - _eo.stdev = eoEsInfo::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& _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::stdev_eps) - stdev = eoEsInfo::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 & _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::stdev_eps) - stdev = eoEsInfo::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; - - std::vector 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 - diff --git a/eo/src/obsolete/eoEsObjectiveBounds.h b/eo/src/obsolete/eoEsObjectiveBounds.h deleted file mode 100644 index 4a25aa30..00000000 --- a/eo/src/obsolete/eoEsObjectiveBounds.h +++ /dev/null @@ -1,81 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoEsObjectiveBounds.h -// (c) Maarten Keijzer 2000, 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 - mak@dhi.dk - */ -//----------------------------------------------------------------------------- - -#ifndef _eoEsObjectiveBounds_h -#define _eoEsObjectiveBounds_h - -/** -\defgroup EvolutionStrategies - - Various classes for the initialization and mutation of real valued std::vectors. - - Supports simple mutations and various more adaptable mutations, including - correlated mutations. - -*/ - - -/** -\class eoEsObjectiveBounds eoEsObjectiveBounds.h es/eoEsObjectiveBounds.h -\ingroup EvolutionStrategies - - Defines the minima and maxima of the object variables. Needed by eoEsChromInit - and eoEsMutate - - @see eoEsChromInit eoEsMutate -*/ -class eoEsObjectiveBounds -{ - public : - - /** - Objective bounds for a global minimum and maximum - */ - eoEsObjectiveBounds(int _nGenes, double _min, double _max) : repMinimum(_nGenes), repMaximum(_nGenes) - { - std::fill(repMinimum.begin(), repMinimum.end(), _min); - std::fill(repMaximum.begin(), repMaximum.end(), _max); - } - - /** - Objective bounds for a per gene minimum and maximum - */ - eoEsObjectiveBounds(const std::vector& _min, const std::vector& _max) - : repMinimum(_min), repMaximum(_max) {} - - typedef double doubleype; - - double minimum(size_t i) { return repMinimum[i]; } - double maximum(size_t i) { return repMaximum[i]; } - - unsigned chromSize(void) const { return repMinimum.size(); } - - private : - std::vector repMinimum; - std::vector repMaximum; -}; - -#endif diff --git a/eo/src/obsolete/eoEvalFuncPtrCnt.h b/eo/src/obsolete/eoEvalFuncPtrCnt.h deleted file mode 100644 index ffa99859..00000000 --- a/eo/src/obsolete/eoEvalFuncPtrCnt.h +++ /dev/null @@ -1,62 +0,0 @@ -/** -*- 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 - -/** 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 { - - /** 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( _eval ), numOfEvaluations( 0 ) {}; - - /// Effectively applies the evaluation function to an EO - virtual void operator() ( EOT & _eo ) const { - eoEvalFuncPtr::operator()( _eo ); - numOfEvaluations++; - }; - - /// - unsigned getNumOfEvaluations() const { return numOfEvaluations; }; - -private: - mutable unsigned numOfEvaluations; -}; - -#endif diff --git a/eo/src/obsolete/eoEvolutionStrategy.h b/eo/src/obsolete/eoEvolutionStrategy.h deleted file mode 100644 index b863ae8a..00000000 --- a/eo/src/obsolete/eoEvolutionStrategy.h +++ /dev/null @@ -1,101 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoEvolutionStrategy.h -// (c) Maarten Keijzer 2000, 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 _eoEvolutionStrategy_h -#define _eoEvolutionStrategy_h - -//----------------------------------------------------------------------------- - -#include -#include -/** eoEvolutionStrategy: -*/ - -template -class eoEvolutionStrategy: public eoAlgo -{ - public: - struct plus_strategy{}; - struct comma_strategy{}; - - eoEvolutionStrategy( - eoContinue& _continuator, - eoEvalFunc& _eval, - eoGOpSelector& _opSel, - float _lambdaRate, - comma_strategy) - : selectPerc(randomSelect, _lambdaRate), - transform(_opSel), - easyEA(_continuator, _eval, selectPerc, transform, noElitism, truncate) - {} - - eoEvolutionStrategy( - eoContinue& _continuator, - eoEvalFunc& _eval, - eoGOpSelector& _opSel, - float _lambdaRate, - plus_strategy) - : selectPerc(randomSelect, _lambdaRate), - transform(_opSel), - easyEA(_continuator, _eval, selectPerc, transform, plus, truncate) - {} - - - /// Apply a few generation of evolution to the population. - virtual void operator()(eoPop& _pop) - { - easyEA(_pop); - } - - private: - - eoPlus plus; - eoNoElitism noElitism; - eoTruncate truncate; - eoRandomSelect randomSelect; - eoSelectPerc selectPerc; - eoInplaceTransform2 transform; - - /// easyEA is contained rather than a base because of member initialization order! - eoEasyEA easyEA; -}; - -template -eoEvolutionStrategy make_es(eoContinue& _continuator, - eoEvalFunc& _eval, - eoGOpSelector& _opSel, - float _lambdaRate, - bool _comma) - -{ - if (_comma) - return eoEvolutionStrategy(_continuator, _eval, _opSel, _lambdaRate, eoEvolutionStrategy::comma_strategy()); - //else - return eoEvolutionStrategy(_continuator, _eval, _opSel, _lambdaRate, eoEvolutionStrategy::plus_strategy()); -} - -//----------------------------------------------------------------------------- - -#endif eoSelectTransformReduce_h - diff --git a/eo/src/obsolete/eoFitTerm.h b/eo/src/obsolete/eoFitTerm.h deleted file mode 100644 index 4dded609..00000000 --- a/eo/src/obsolete/eoFitTerm.h +++ /dev/null @@ -1,59 +0,0 @@ -// -*- 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 - - -/** -Fitness continuation: - - Continues until the maximum fitness level is reached. -*/ -template< class EOT> -class eoFitContinue: public eoContinue { -public: - - /// Define Fitness - typedef typename EOT::Fitness FitnessType; - - /// Ctor - eoFitContinue( const FitnessType _maximum) - : eoContinuator (), maximum( _maximum ) {}; - - /** Returns false when a fitness criterium is - * reached, assumes sorted population */ - virtual bool operator() ( const eoPop& _vEO ) - { - return (bestFitness < maximum); - } - -private: - FitnessType maximum; -}; - -#endif - diff --git a/eo/src/obsolete/eoFitness.h b/eo/src/obsolete/eoFitness.h deleted file mode 100644 index c1e03fc3..00000000 --- a/eo/src/obsolete/eoFitness.h +++ /dev/null @@ -1,57 +0,0 @@ -// eoFitness.h -//----------------------------------------------------------------------------- -// eoFitness.cpp -// (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 EOFITNESS_H -#define EOFITNESS_H - -//----------------------------------------------------------------------------- -/** -\deprecated This class will dissapear in time, use eoScalarFitness instead -*/ -class eoFitness: public eoPersistent -{ - public: - virtual operator float() const = 0; - - virtual bool operator<(const eoFitness& other) const = 0; - - virtual bool operator>(const eoFitness& other) const - { - return !(*this < other || *this == other); - } - - virtual bool operator==(const eoFitness& other) const - { - return !(other < *this || *this < other); - } - - virtual bool operator!=(const eoFitness& other) const - { - return other < *this || *this < other; - } -}; - -//----------------------------------------------------------------------------- - -#endif EOFITNESS_H - diff --git a/eo/src/obsolete/eoGOpBreeder.h b/eo/src/obsolete/eoGOpBreeder.h deleted file mode 100644 index 0b8c76f6..00000000 --- a/eo/src/obsolete/eoGOpBreeder.h +++ /dev/null @@ -1,62 +0,0 @@ -//----------------------------------------------------------------------------- -// eoBreeder.h -//----------------------------------------------------------------------------- - -#ifndef eoGopBreeder_h -#define eoGopBreeder_h - -//----------------------------------------------------------------------------- - -/***************************************************************************** - * eoBreeder: transforms a population using genetic operators. * - * For every operator there is a rated to be applyed. * - *****************************************************************************/ - -#include -#include -#include -#include -#include - -/** - Base class for breeders using generalized operators, I'm not sure if we - will maintain the generalized operators in their current form, so - it might change. -*/ -template -class eoGOpBreeder: public eoUF&, void> -{ - public: - /// Default constructor. - eoGOpBreeder( eoGOpSelector& _opSel, - eoSelectOneIndiSelector& _selector) - : opSel( _opSel ), selector(_selector) - {} - - /** - * Enlarges the population. - * @param pop The population to be transformed. - */ - void operator()(eoPop& _pop) - { - unsigned size = _pop.size(); - - for (unsigned i = 0; i < size; i++) - { // and the one liner - opSel.selectOp()(selector.bind(_pop,size).bias(i), inserter.bind(_pop)); - } - } - - /// The class name. - std::string className() const { return "eoGOpBreeder"; } - - private: - eoGOpSelector& opSel; - eoSelectOneIndiSelector& selector; - - // the inserter can be local as there's no point in changing it from the outside - eoBackInserter inserter; -}; - -#endif eoBreeder_h - diff --git a/eo/src/obsolete/eoGOpSelector.h b/eo/src/obsolete/eoGOpSelector.h deleted file mode 100644 index 279d709b..00000000 --- a/eo/src/obsolete/eoGOpSelector.h +++ /dev/null @@ -1,181 +0,0 @@ -/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - - ----------------------------------------------------------------------------- - eoGOpSelector.h - Base class for generalized (n-inputs, n-outputs) operator selectors. - Includes code and variables that contain operators and rates. - Also included eoProportionalGOpSelector and eoSequentialGOpSelector, that offer - a few concrete implementations. - - (c) Maarten Keijzer, 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 eoGOpSelector_h -#define eoGOpSelector_h - -//----------------------------------------------------------------------------- - -#include -#include "eoOpSelector.h" -#include "eoWrappedOps.h" // for eoCombinedOp -#include - -using namespace std; - -/** Base class for alternative selectors, which use the generalized operator - interface. eoGOpBreeders expects this class */ -template -class eoGOpSelector: public eoOpSelector, public std::vector*> -{ -public: - - typedef eoOpSelector::ID ID; - - /// Dtor - virtual ~eoGOpSelector() { - for ( std::list< eoGeneralOp* >::iterator i= ownOpList.begin(); - i != ownOpList.end(); i++ ) { - delete *i; - } - } - - /* - Add any kind of operator to the operator mix, - @param _op operator, one of eoMonOp, eoBinOp, eoQuadraticOp or eoGeneralOp - @param _rate the rate at which it should be applied, it should be a probability - - */ - virtual ID addOp( eoOp& _op, float _rate ); - // implementation can be found below - - /** Retrieve the operator using its integer handle - @param _id The id number. Should be a valid id, or an std::exception - will be thrown - @return a reference of the operator corresponding to that id. - */ - virtual eoOp& getOp( ID _id ) - { - return *operator[](_id); - } - - /// - virtual void deleteOp( ID _id ); - // implemented below - - /// - virtual eoOp* Op() - { - return &selectOp(); - } - - /// Select an operator from the operators present here - virtual eoGeneralOp& selectOp() = 0; - - /// - virtual std::string className() const { return "eoGOpSelector"; }; - - /// - void printOn(std::ostream& _os) const {} - // _os << className().c_str() << std::endl; - // for ( unsigned i=0; i!= rates.size(); i++ ) { - // _os << *(operator[](i)) << "\t" << rates[i] << std::endl; - // } - //} - - - const std::vector& getRates(void) const { return rates; } - -private : - std::vector rates; - std::list< eoGeneralOp* > ownOpList; -}; - -/* Implementation of longish functions defined above */ - -template -inline eoOpSelector::ID eoGOpSelector::addOp( eoOp& _op, - float _arg ) -{ - eoGeneralOp* op; - - if (_op.getType() == eoOp::general) - { - op = static_cast*>(&_op); - } - else - { - // if it's not a general op, it's a "old" op; create a wrapped op from it - // and keep it on a std::list to delete them afterwards - // will use auto_ptr when they're readily available - - switch(_op.getType()) - { - case eoOp::unary : - op= new eoWrappedMonOp(static_cast&>(_op)); - break; - case eoOp::binary : - op = new eoWrappedBinOp(static_cast&>(_op)); - break; - case eoOp::quadratic : - op = new eoWrappedQuadraticOp(static_cast&>(_op)); - break; - case eoOp::general : break; // cannot happen, but gcc issued a warning - } - ownOpList.push_back( op ); - } - - // Now 'op' is a general operator, either because '_op' was one or - // because we wrapped it in an appropriate wrapper in the code above. - - typename eoGOpSelector::iterator result = find(begin(), end(), (eoGeneralOp*) 0); // search for nullpointer - - if (result == end()) - { - push_back(op); - rates.push_back(_arg); - return size(); - } - // else - - *result = op; - ID id = result - begin(); - rates[id] = _arg; - return id; -} - -template -inline void eoGOpSelector::deleteOp( ID _id ) -{ - eoGeneralOp* op = operator[](_id); - - operator[](_id) = 0; - rates[_id] = 0.0; - - // check opstd::list and clear it there too. - - std::list< eoGeneralOp* >::iterator it = find(ownOpList.begin(), ownOpList.end(), op); - - if(it != ownOpList.end()) - { - ownOpList.erase(it); - } -} - -#endif eoGOpSelector_h - diff --git a/eo/src/obsolete/eoGenTerm.h b/eo/src/obsolete/eoGenTerm.h deleted file mode 100644 index 615ab90b..00000000 --- a/eo/src/obsolete/eoGenTerm.h +++ /dev/null @@ -1,68 +0,0 @@ -// -*- 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 _EOGENTERM_H -#define _EOGENTERM_H - -#include - -/** Generational continuator: continues until a number of generations is reached -*/ -template< class EOT> -class eoGenContinue: public eoContinue { -public: - - /// Ctors/dtors - eoGenContinue( unsigned _totalGens) - : repTotalGenerations( _totalGens ), - thisGeneration(0){}; - - /** Returns false when a certain number of generations is - * reached */ - virtual bool operator() ( const eoPop& _vEO ) { - thisGeneration++; - // std::cout << " [" << thisGeneration << "] "; - return (thisGeneration < repTotalGenerations) ; // for the postincrement - } - - /** Sets the number of generations to reach - and sets the current generation to 0 (the begin)*/ - virtual void totalGenerations( unsigned _tg ) { - repTotalGenerations = _tg; - // thisGeneration = 0; - }; - - /** Returns the number of generations to reach*/ - virtual unsigned totalGenerations( ) { - return repTotalGenerations; - }; - - std::string className(void) const { return "eoGenTerm"; } - -private: - unsigned repTotalGenerations, thisGeneration; -}; - -#endif - diff --git a/eo/src/obsolete/eoGeneration.h b/eo/src/obsolete/eoGeneration.h deleted file mode 100644 index 282de928..00000000 --- a/eo/src/obsolete/eoGeneration.h +++ /dev/null @@ -1,85 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoOp.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 eoGeneration_h -#define eoGeneration_h - -//----------------------------------------------------------------------------- -#include // eoPop -#include -#include // eoSelect, eoTranform, eoMerge - -//----------------------------------------------------------------------------- - -/** eoGeneration - * Single step of a evolutionary algorithm. Applies selection, then genetic - * operators, replaces using a replacement policy, and finally evaluates the - * new ones */ -template class eoGeneration: public eoAlgo -{ - public: - /// Constructor. - eoGeneration(eoSelect& _select, - eoBreeder& _breeder, - eoBinPopOp& _replace, - eoEvalFunc& _evaluator): - select(_select), transform(_transform), - replace(_replace), evaluator( _evaluator) {}; - - /// Copy Constructor. - eoGeneration(eoGeneration& _gen): - select(_gen.select), transform(_gen.transform), - replace(_gen.replace), evaluator( _gen.evaluator ) {}; - - - /// Apply one generation of evolution to the population. - virtual void operator()(eoPop& pop) { - eoPop breeders; - try { - select(pop, breeders); - transform(breeders); - eoPop::iterator i; - // Can't use foreach here since foreach takes the - // parameter by reference - for ( i = breeders.begin(); i != breeders.end(); i++) - evaluator(*i); - replace(breeders, pop); - } catch ( std::exception& e ) { - throw std::runtime_error( e.what() ); - } - } - - /// Class name. - std::string className() const { return "eoGeneration"; } - - private: - eoBinPopOp& select; - eoMonPopOp& transform; - eoBinPopOp& replace; - eoEvalFunc& evaluator; -}; - -//----------------------------------------------------------------------------- - -#endif eoGeneration_h diff --git a/eo/src/obsolete/eoGenericBinOp.h b/eo/src/obsolete/eoGenericBinOp.h deleted file mode 100644 index 7c06546a..00000000 --- a/eo/src/obsolete/eoGenericBinOp.h +++ /dev/null @@ -1,75 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoGenericBinOp.h -// (c) GeNeura Team, 2000 - EEAAX 1999 - Maarten Keijzer 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 - Marc.Schoenauer@polytechnique.fr - mak@dhi.dk - */ -//----------------------------------------------------------------------------- - -#ifndef _eoGenericBinOp_h -#define _eoGenericBinOp_h - -#include - -/** Contains base classes for generic binary operators for eoFixedLength - and eoVariableLength (They also derive from the eoOp) as well as - the corresponding converters to actual Ops. -*/ - -/** eoGenericBinOp is the generic binary operator: -it takes two arguments, modifies the first one, and returns a boolean -indicating if the argument has actually been modified -*/ - -template -class eoGenericBinOp: public eoOp, public eoBF -{ -public: - /// Ctor - eoGenericBinOp() - : eoOp( eoOp::binary ) {}; - virtual std::string className() const {return "eoGenericBinOp";}; -}; - -/** Converter from eoGenericBinOp to eoBinOp - the only thinig to do is to transform the boolean into invalidation -*/ - -template -class eoGeneric2TrueBinOp: public eoBinOp -{ -public: - /// Ctor - eoGeneric2TrueBinOp(eoGenericBinOp & _binOp) - : binOp( _binOp ) {}; - virtual std::string className() const {return "eoGeneric2TrueBinOp";} - - virtual void operator()(EOT & _eo1, const EOT & _eo2) - { - if (binOp(_eo1, _eo2)) - _eo1.invalidate(); - } - - private: - eoGenericBinOp & binOp; -}; - -#endif diff --git a/eo/src/obsolete/eoGenericMonOp.h b/eo/src/obsolete/eoGenericMonOp.h deleted file mode 100644 index f090d1fa..00000000 --- a/eo/src/obsolete/eoGenericMonOp.h +++ /dev/null @@ -1,75 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoGenericMonOp.h -// (c) GeNeura Team, 2000 - EEAAX 1999 - Maarten Keijzer 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 - Marc.Schoenauer@polytechnique.fr - mak@dhi.dk - */ -//----------------------------------------------------------------------------- - -#ifndef _eoGenericMonOp_h -#define _eoGenericMonOp_h - -#include - -/** Contains base classes for generic operators for eoFixedLength - and eoVariableLength (They also derive from the eoOp) as well as - the corresponding converters to actual Ops. -*/ - -/** eoGenericMonOp is the generic unary operator: -it takes one argument, and returns a boolean indicating if the argument -has been modified -*/ - -template -class eoGenericMonOp: public eoOp, public eoUF -{ -public: - /// Ctor - eoGenericMonOp() - : eoOp( eoOp::unary ) {}; - virtual std::string className() const {return "eoGenericMonOp";}; -}; - -/** COnverter from eoGenericMonOp to eoMonOp - the only thinig to do is to transform the boolean into invalidation -*/ - -template -class eoGeneric2TrueMonOp: public eoMonOp -{ -public: - /// Ctor - eoGeneric2TrueMonOp(eoGenericMonOp & _monOp) - : monOp( _monOp ) {}; - virtual std::string className() const {return "eoGeneric2trueMonOp";} - - virtual void operator()(EOT & _eo) - { - if (monOp(_eo)) - _eo.invalidate(); - } - - private: - eoGenericMonOp & monOp; -}; - -#endif diff --git a/eo/src/obsolete/eoGenericQuadOp.h b/eo/src/obsolete/eoGenericQuadOp.h deleted file mode 100644 index 35455cfb..00000000 --- a/eo/src/obsolete/eoGenericQuadOp.h +++ /dev/null @@ -1,83 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoGenericQuadOp.h -// (c) GeNeura Team, 2000 - EEAAX 1999 - Maarten Keijzer 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 - Marc.Schoenauer@polytechnique.fr - mak@dhi.dk - */ -//----------------------------------------------------------------------------- - -#ifndef _eoGenericQuadOp_h -#define _eoGenericQuadOp_h - -#include - -/** Contains base classes for generic quadratic operators for eoFixedLength - and eoVariableLength (They also derive from the eoOp) as well as - the corresponding converters to actual Ops. -*/ - -/** eoGenericQuadOp is the generic quadratic operator: -it takes two arguments, modifies the first one, and returns a boolean -indicating if the arguments have actually been modified - -WARNING: even if only 1 argument is modified, it should return true, - and both fitnesses will be invalidated. It is assumed that - quadratic operators do some exchange of genetic material, so - if one is modified, the other is, too! -*/ - -template -class eoGenericQuadOp: public eoOp, public eoBF -{ -public: - /// Ctor - eoGenericQuadOp() - : eoOp( eoOp::quadratic ) {}; - virtual std::string className() const {return "eoGenericQuadOp";}; -}; - -/** Converter from eoGenericQuadOp to eoQuadOp - the only thinig to do is to transform the boolean into invalidation -*/ - -template -class eoGeneric2TrueQuadOp: public eoQuadOp -{ -public: - /// Ctor - eoGeneric2TrueQuadOp(eoGenericQuadOp & _quadOp) - : quadOp( _quadOp ) {}; - virtual std::string className() const {return "eoGeneric2TrueQuadOp";} - - virtual void operator()(EOT & _eo1, EOT & _eo2) - { - if (quadOp(_eo1, _eo2)) - { - _eo1.invalidate(); - _eo2.invalidate(); - } - } - - private: - eoGenericQuadOp & quadOp; -}; - -#endif diff --git a/eo/src/obsolete/eoID.h b/eo/src/obsolete/eoID.h deleted file mode 100644 index 5763b11b..00000000 --- a/eo/src/obsolete/eoID.h +++ /dev/null @@ -1,110 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoID.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 EOID_H -#define EOID_H - -//----------------------------------------------------------------------------- - -#include // std::istream, std::ostream -#include // for std::string - -using namespace std; - -//----------------------------------------------------------------------------- -// eoID -//----------------------------------------------------------------------------- - -/** eoID is a template class that adds an ID to an object.\\ -Requisites for template instantiation are that the object must admit a default ctor -and a copy ctor. The Object must be an eoObject, thus, it must have its methods: className, -printOn, readFrom, that is why we donīt subclass eoObject to avoid multiple inheritance.\\ -IDs can be used to count objects of a a kind, or track them, or whatever. -@see eoObject -*/ -template -class eoID: public Object -{ - public: - /// Main ctor from an already built Object. - eoID( const Object& _o): Object( _o ), thisID(globalID++) {}; - - /// Copy constructor. - eoID( const eoID& _id): Object( _id ), thisID(globalID++ ) {}; - - /// Virtual dtor. They are needed in virtual class hierarchies - virtual ~eoID() {}; - - - ///returns the age of the object - unsigned long ID() const {return thisID;} - - /** @name Methods from eoObject - readFrom and printOn are directly inherited from eo1d - */ - //@{ - /** Return the class id. This should be redefined in each class; but - it's got code as an example of implementation. Only "leaf" classes - can be non-virtual. - */ - virtual std::string className() const { return std::string("[eoID]")+Object::className(); }; - - /** - * Read object. - * @param _is A std::istream. - * @throw runtime_std::exception If a valid object can't be read. - */ - virtual void readFrom(std::istream& _is) { - Object::readFrom( _is ); - _is >> thisID; - } - - - /** - * Write object. It's called printOn since it prints the object _on_ a stream. - * @param _os A std::ostream. - */ - virtual void printOn(std::ostream& _os) const{ - Object::printOn( _os ); - _os << thisID; - } -//@} - - private: - - /** Default Constructor. \\ - Itīs private so that it is not used anywhere; the right way of using this object - is to create an Object and passing it to an aged by means of the copy ctor; that way - itīs turned into an Aged object*/ - eoID(): Object(), thisID( globalID++ ) {}; - - unsigned long thisID; - static unsigned long globalID; -}; - -template< class Object> -unsigned long eoID< Object >::globalID = 0; - -#endif EOID_H - diff --git a/eo/src/obsolete/eoInclusion.h b/eo/src/obsolete/eoInclusion.h deleted file mode 100644 index 5e752a15..00000000 --- a/eo/src/obsolete/eoInclusion.h +++ /dev/null @@ -1,64 +0,0 @@ -//----------------------------------------------------------------------------- -// eoInclusion.h -//----------------------------------------------------------------------------- - -#ifndef eoInclusion_h -#define eoInclusion_h - -//----------------------------------------------------------------------------- - -#include - -// EO includes -#include -#include - -/***************************************************************************** - * eoInclusion: A replacement algorithm. * - * Creates a new population by selecting the best individuals from the * - * breeders and original populations * - *****************************************************************************/ - -template class eoInclusion: public eoMerge -{ - public: - /// (Default) Constructor. - eoInclusion(const float& _rate = 1.0): eoMerge( _rate ) {} - - /// Ctor from std::istream - eoInclusion( std::istream& _is): eoBinPopOp( _is ) {}; - - /// Dtor - virtual ~eoInclusion() {}; - - /** - * Creates a new population based on breeders and original populations. - * @param breeders The population of breeders. - * @param pop The original population. - */ - void operator()(eoPop& breeders, eoPop& pop) - { - unsigned target = min(static_cast(pop.size() * rate()), - pop.size() + breeders.size()); - - copy(breeders.begin(), breeders.end(), - back_insert_iterator >(pop)); - partial_sort(pop.begin(), pop.begin() + target, pop.end(), - greater()); - pop.erase(pop.begin() + target, pop.end()); - } - - /** @name Methods from eoObject */ - //@{ - /** readFrom and printOn inherited from eoMerge */ - - /** Inherited from eoObject. Returns the class name. - @see eoObject - */ - virtual std::string className() const {return "eoInclusion";}; - //@} -}; - -//----------------------------------------------------------------------------- - -#endif eoInclusion_h diff --git a/eo/src/obsolete/eoIndiSelector.h b/eo/src/obsolete/eoIndiSelector.h deleted file mode 100644 index ea4fc34c..00000000 --- a/eo/src/obsolete/eoIndiSelector.h +++ /dev/null @@ -1,160 +0,0 @@ -/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - - ----------------------------------------------------------------------------- - eoIndiSelector.h - Abstract selection operator, which is used by the eoGeneralOps - to obtain individuals from a source population. It also gives a - direct descended eoPopIndiSelector that can be used to - initialize objects with an eoPop. For most uses use eoPopIndividualSelector - rather than eoIndividualSelector to derive from. - - (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 eoIndiSelector_h -#define eoIndiSelector_h - -#include - -/** - * eoIndividualSelector: This class defines the interface. This - * interface is used by the eoGeneralOp to get new individuals - * from a pop, a subpop or a remote pop - * for convenience when implementing an nary operator a size() and operator[] - * need to be implemented. -*/ - -template -class eoIndiSelector : public eoF -{ -public : - - eoIndiSelector() {} - - virtual ~eoIndiSelector(void) {} - - /** - return the number of individuals that can be selected by an nary operator (through operator[] below) - */ - virtual size_t size(void) const = 0; - - /** - return the specified individual, the size_t argument should be between 0 and eoIndiSelector::size() - */ - virtual const EOT& operator[](size_t i) const = 0; -}; - - -#include - -/** - * eoSelectOneAdaptor: Adaptor class for dispensing individuals. - - It produces the eoIndiSelector interface and an eoSelectOne implementation - This class can then be used for general operators - - various useful things can be done with this class: - you can specify how many of the population can ever be dispensed to the - operators, but you can also specify a preference to the first guy being - dispensed. This is useful if you want to perform the operator on a specific - individual. - - @see eoSelectOne, eoIndiSelector -*/ -template -class eoSelectOneIndiSelector : public eoIndiSelector -{ - public : - eoSelectOneIndiSelector(eoSelectOne& _select) : pop(0), last(0), firstChoice(-1), secondChoice(-1), select(_select) {} - - struct eoUnitializedException{}; - - /** Initialization function, binds the population to the selector, can also - be used to specify an optional end - */ - eoSelectOneIndiSelector& bind(const eoPop& _pop, int _end = -1) - { - pop = &_pop; - last = _end; - - if (last < 0 || last > (int) pop->size()) - { - last = pop->size(); - } - - select.setup(*pop); - - return *this; - } - - /** Bias function to bias the selection function to select specific individuals - first before applying a selection algorithm defined in derived classes - */ - eoSelectOneIndiSelector& bias(int _first, int _second = -1) - { - firstChoice = _first; - secondChoice = _second; - return *this; - } - - - size_t size(void) const { valid(); return last; } - const EOT& operator[](size_t _i) const { valid(); return pop->operator[](_i); } - - eoPop::const_iterator begin(void) const { valid(); return pop->begin(); } - eoPop::const_iterator end(void) const { valid(); return pop->end(); } - - /// operator() does the work. Note that it is not virtual. It calls do_select that needs to be implemented by the derived classes - const EOT& operator()(void) - { - valid(); - if (firstChoice < 0 || firstChoice >= last) - { - // see if we have a second choice - if (secondChoice < 0 || secondChoice >= last) - { - return select(*pop); // let the embedded selector figure out what to do - } - - const EOT& result = pop->operator[](secondChoice); - secondChoice = -1; - return result; - } - - const EOT& result = pop->operator[](firstChoice); - firstChoice = -1; - return result; - } - - private : - - void valid(void) const - { - if (pop == 0) - throw eoUnitializedException(); - } - - const eoPop* pop; // need a pointer as this the pop argument can be re-instated - int last; - int firstChoice; - int secondChoice; - eoSelectOne& select; -}; - -#endif diff --git a/eo/src/obsolete/eoInplaceTransform.h b/eo/src/obsolete/eoInplaceTransform.h deleted file mode 100644 index a2785506..00000000 --- a/eo/src/obsolete/eoInplaceTransform.h +++ /dev/null @@ -1,193 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoInplaceTransform.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 eoInplaceTransform_h -#define eoInplaceTransform_h - -//----------------------------------------------------------------------------- - -#include // std::vector -#include -#include // eoOp, eoMonOp, eoBinOp -#include // eoPop -#include // eoOpSelector -#include -#include -#include - -/***************************************************************************** - * eoInplaceTransform1: transforms a population using genetic operators. * - * It does it in an SGA like manner - *****************************************************************************/ -template class eoInplaceTransform1 : public eoTransform -{ - public: - - /// Default constructor. - eoInplaceTransform1( eoOpSelector& _opSel): opSel( _opSel ), select(defaultSelect) {} - eoInplaceTransform1( eoOpSelector& _opSel, eoSelectOne& _select) - : opSel(_opSel), select(_select) {} - /** - * Transforms a population. - * @param pop The population to be transformed. - */ - void operator()(eoPop& pop) - { - // copy the guys in a newpop - // because otherwise eoSelectRandom might select freshly created individuals - eoPop newpop; - newpop.reserve(pop.size()); - - // Set up general op helper classes - eoSelectOneIndiSelector inplace(select); - eoBackInserter inserter; - - // set up selection routine - select.setup(pop); - - for (unsigned i = 0; i < pop.size(); i++) - { - eoOp* op = opSel.Op(); - - switch (op->getType()) - { - case eoOp::unary: - { - eoMonOp* monop = static_cast* >(op); - newpop.push_back(pop[i]); - (*monop)( newpop.back() ); - break; - } - case eoOp::binary: - { - eoBinOp* binop = static_cast* >(op); - newpop.push_back(pop[i]); - (*binop)(newpop[i], select(pop)); - break; - } - case eoOp::quadratic: - { - - eoQuadraticOp* Qop = static_cast* >(op); - - newpop.push_back(pop[i]); - Chrom& indy1 = newpop.back(); - - if (++i == pop.size()) - newpop.push_back(select(pop)); - else - newpop.push_back(pop[i]); - - (*Qop)(indy1, newpop.back() ); - break; - } - case eoOp::general : - { - eoGeneralOp* Gop = static_cast* >(op); - - inplace.bind(pop); - inplace.bias(i,i + 1); - - inserter.bind(newpop); - unsigned orgsize = newpop.size(); - (*Gop)(inplace, inserter); - unsigned diff = newpop.size() - orgsize; - i = i + (diff-1); - break; - } - } - pop.swap(newpop); // overwrite existing pop - } - }; - - private: - eoOpSelector& opSel; - eoRandomSelect defaultSelect; - eoSelectOne& select; - -}; - -#include - -/***************************************************************************** - * eoInplaceTransform2: transforms a population using general genetic operators. * - * It does it in an SGA like manner - *****************************************************************************/ -template class eoInplaceTransform2 : public eoTransform -{ - public: - - /// Default constructor. - eoInplaceTransform2( eoGOpSelector& _opSel): opSel( _opSel ), select(defaultSelect) {} - eoInplaceTransform2( eoGOpSelector& _opSel, eoSelectOne& _select) - : opSel(_opSel), select(_select) {} - /** - * Transforms a population. - * @param pop The population to be transformed. - */ - void operator()(eoPop& pop) - { - // copy the guys in a newpop - // because otherwise eoSelectRandom might select freshly created individuals - eoPop newpop; - newpop.reserve(pop.size()); - - // Set up general op helper classes - eoSelectOneIndiSelector inplace(select); - eoBackInserter inserter; - - // set up selection routine - select.setup(pop); - - for (unsigned i = 0; i < pop.size(); i++) - { - eoGeneralOp& Gop = opSel.selectOp(); - - inplace.bind(pop); - inplace.bias(i,i + 1); - - inserter.bind(newpop); - unsigned orgsize = newpop.size(); - Gop(inplace, inserter); - - // see how many have been inserted and add that to i (minus one ofcourse) - unsigned diff = newpop.size() - orgsize; - i = i + (diff-1); - } - - pop.swap(newpop); // overwrite existing pop - } - - private: - eoGOpSelector& opSel; - eoRandomSelect defaultSelect; - eoSelectOne& select; - -}; - - -//----------------------------------------------------------------------------- - -#endif eoBreeder_h - diff --git a/eo/src/obsolete/eoInserter.h b/eo/src/obsolete/eoInserter.h deleted file mode 100644 index f498cd61..00000000 --- a/eo/src/obsolete/eoInserter.h +++ /dev/null @@ -1,93 +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. It also contains - a direct descended eoPopInserter that defines a convenient inbetween class - for working with eoPop. The user will most likely derive from eoPopInserter - rather than eoInserter. - - (c) Maarten Keijzer (mak@dhi.dk) 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 eoInserter_h -#define eoInserter_h - -#include -#include - - /** - * eoInserter: Interface class that enables an operator to insert - new individuals into the (intermediate) population for example. -*/ -template -class eoInserter : public eoUF&> -{ - public : - virtual ~eoInserter() {} - - struct eoInserterException{}; -}; - -/** - * eoPopInserter: In-between class that defines an initialization - * of the eoIndividualInserter. -*/ -template -class eoPopInserter : public eoInserter -{ - public : - - eoPopInserter(void) : eoInserter(), thePop(0) {} - - /// Binds the population to this class. This is an initialization routine used by breeders - eoInserter& bind(eoPop& _pop) - { - thePop = &_pop; - return *this; - } - - protected : - - eoPop& pop(void) const { valid(); return *thePop; } - - private : - - void valid(void) const - { - if (thePop == 0) - throw eoInserterException(); - } - - // Need a pointer as the inserter should be able to bind to different populations. - // This is caused by the 'one template parameter only' convention in EO. - - eoPop* thePop; - - // If eoGOpBreeder could be templatized over the inserter and the selector, - // the pop could be a ref as this class could be created every time it is applied - // and subsequently would get the population through the constructor - -}; - - - -#endif - diff --git a/eo/src/obsolete/eoInsertion.h b/eo/src/obsolete/eoInsertion.h deleted file mode 100644 index 26774f67..00000000 --- a/eo/src/obsolete/eoInsertion.h +++ /dev/null @@ -1,96 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoInsertion.h -// Inserts new members into the population -// (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 eoInsertion_h -#define eoInsertion_h - -//----------------------------------------------------------------------------- - -#include - -// EO includes -#include // eoPop -#include // eoMerge - -/****************************************************************************** - * eoInsertion: A replacement algorithm. - * Creates a new population with all the breeders and the best individuals - * from the original population. - *****************************************************************************/ - -template class eoInsertion: public eoBinaryFunctor&, const eoPop&> -{ - public: - /// (Default) Constructor. - eoInsertion(const float& _rate = 1.0): eoMerge( _rate ) {} - - /// Ctor from std::istream - eoInsertion( std::istream& _is): eoBinPopOp( _is ) {}; - - /// Dtor - virtual ~eoInsertion() {}; - - /** - * Creates a new population based on breeders and original populations. - * @param breeders The population of breeders. Should be sorted to work correctly - * @param pop The original population. - */ - void operator()( eoPop& _breeders, const eoPop& _pop) - { - unsigned target = static_cast((_pop.size() * rate())); - - _pop.swap(_breeders); - - if (target < _pop.size()) - { - partial_sort(_pop.begin(), _pop.begin() + target, _pop.end(), - greater()); - _pop.erase(_pop.begin() + target, _pop.end()); - } - else - { - target = min(target - _pop.size(), _breeders.size()); - partial_sort(_breeders.begin(), _breeders.begin() + target, - _breeders.end(), greater()); - copy(_breeders.begin(), _breeders.begin() + target, - back_insert_iterator >(_pop)); - } - }; - - /** @name Methods from eoObject */ - //@{ - /** readFrom and printOn inherited from eoMerge */ - - /** Inherited from eoObject. Returns the class name. - @see eoObject - */ - virtual std::string className() const {return "eoInsertion";}; - //@} - -}; - -//----------------------------------------------------------------------------- - -#endif eoInsertion_h diff --git a/eo/src/obsolete/eoKill.h b/eo/src/obsolete/eoKill.h deleted file mode 100644 index e7ec85a5..00000000 --- a/eo/src/obsolete/eoKill.h +++ /dev/null @@ -1,62 +0,0 @@ -// -*- 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 _EOKILL_h -#define _EOKILL_h - -#include - -#include - -/// Kill eliminates a gen in a chromosome -template -class eoKill: public eoMonOp { -public: - /// - eoKill( ) - : eoMonOp< EOT >(){}; - - /// needed virtual dtor - virtual ~eoKill() {}; - - /// - virtual void operator()( EOT& _eo ) const - { - unsigned pos = rng.random(_eo.length()); - _eo.deleteGene( pos ); - } - - /** @name Methods from eoObject - readFrom and printOn are directly inherited from eoOp - */ - //@{ - /** Inherited from eoObject - @see eoObject - */ - virtual std::string className() const {return "eoKill";}; - //@} -}; - -#endif - diff --git a/eo/src/obsolete/eoLottery.h b/eo/src/obsolete/eoLottery.h deleted file mode 100644 index 39ca8723..00000000 --- a/eo/src/obsolete/eoLottery.h +++ /dev/null @@ -1,105 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoLottery.h -// Implements the lottery procedure for selection -// (c) GeNeura Team, 1998 - Marc Schoenauer, 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 eoLottery_h -#define eoLottery_h - -//----------------------------------------------------------------------------- - -#include // std::logic_error -#include // sum_fitness -#include - -// #include // -// #include // accumulate -// #include // eoPop eoSelect MINFLOAT - - -//----------------------------------------------------------------------------- -/** eoLottery: a selection method. Puts into the output a group of individuals - selected using lottery; individuals with higher probability will have more - chances of being selected. - Requires EOT::Fitness to be float castable -*/ -//----------------------------------------------------------------------------- - -template class eoLottery: public eoBinaryFunctor&, eoPop& > -{ - public: - /// (Default) Constructor. - eoLottery(const float& _rate = 1.0): eoBinPopOp(), rate_(_rate) - { - if (minimizing_fitness()) - { - throw std::logic_error("eoLottery: minimizing fitness"); - } - } - - /** actually selects individuals from pop and pushes them back them into breeders - * until breeders has the right size: rate*pop.size() - * BUT what happens if breeders is already too big? - * Too big for what? - */ - void operator()(const eoPop& pop, eoPop& breeders) - { - size_t target = static_cast(rate_ * pop.size()); - - /* Gustavo: uncomment this if it must be here - // test of consistency - if (breeders.size() >= target) { - throw("Problem in eoLottery: already too many offspring"); - } - - double total; - - try - { - total = sum_fitness (pop); - } - catch (eoNegativeFitnessException&) - { // say where it occured... - throw eoNegativeFitnessException(*this); - } - */ - - double total = sum_fitness (pop); - - // selection of chromosomes - while (breeders.size() < target) - { - breeders.push_back(roulette_wheel(pop, total)); - } - } - - double rate(void) const { return rate_; } - - private: - double rate_; // selection rate -}; - -//----------------------------------------------------------------------------- - -#endif eoLottery_h - diff --git a/eo/src/obsolete/eoMutation.h b/eo/src/obsolete/eoMutation.h deleted file mode 100644 index f3225fff..00000000 --- a/eo/src/obsolete/eoMutation.h +++ /dev/null @@ -1,90 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoMutation.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 _EOMUTATION_H -#define _EOMUTATION_H - -#include -// EO includes -#include - -/** Generic Mutation of an EO. - This is a virtual class, just to establish the interface for the ctor. - Mutation is usually type-specific -*/ - -template -class eoMutation: public eoMonOp { -public: - - /// - eoMutation(const double _rate=0.0) : eoMonOp< EOT >(), rate(_rate) {}; - - /// - virtual ~eoMutation() {}; - - /// - virtual void operator()( EOT& _eo ) const { - typename EOT::iterator i; - for ( i = _eo.begin(); i != _eo.end(); i ++ ) - applyAt( _eo, *i ); - } - - /// To print me on a stream. - /// @param os The std::ostream. - void printOn(std::ostream& os) const { - os << rate ; - } - - /// To read me from a stream. - /// @param is The std::istream. - void readFrom(std::istream& is) { - is >> rate ; - } - - /** @name Methods from eoObject - */ - //@{ - /** Inherited from eoObject - @see eoObject - */ - std::string className() const {return "eoMutation";}; - //@} - -protected: - double rate; - -private: -#ifdef _MSC_VER - typedef EOT::Type Type; -#else - typedef typename EOT::Type Type; -#endif - - /// applies operator to one gene in the EO. It is empty, so each descent class must define it. - virtual void applyAt( EOT& _eo, unsigned _i ) const = 0 ; -}; - - -#endif - diff --git a/eo/src/obsolete/eoNegExp.h b/eo/src/obsolete/eoNegExp.h deleted file mode 100644 index 3d6be5e2..00000000 --- a/eo/src/obsolete/eoNegExp.h +++ /dev/null @@ -1,67 +0,0 @@ -/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - ------------------------------------------------------------------------------ - eoNegExp.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 _EONEGEXP_H -#define _EONEGEXP_H - -//----------------------------------------------------------------------------- - -#include - -#include // for base class -#include // for base class - -//----------------------------------------------------------------------------- -// Class eoNegExp -//----------------------------------------------------------------------------- - -/// Generates random numbers using a negative exponential distribution -template -class eoNegExp: public eoRnd -{ - public: - /** - * Default constructor. - * @param _mean Distribution mean - */ - eoNegExp(T _mean): eoRnd(), mean(_mean) {}; - - /** - * Copy constructor. - * @param _rnd the copyee - */ - eoNegExp( const eoNegExp& _rnd): eoRnd( _rnd), mean(_rnd.mean) {}; - - /// Returns an uniform dandom number over the interval [min, max). - virtual T operator()() { - return T( -mean*log((double)rng.rand() / rng.rand_max())); } - - private: - T mean; -}; - -//----------------------------------------------------------------------------- - -#endif - diff --git a/eo/src/obsolete/eoNonUniform.h b/eo/src/obsolete/eoNonUniform.h deleted file mode 100644 index b5065d21..00000000 --- a/eo/src/obsolete/eoNonUniform.h +++ /dev/null @@ -1,87 +0,0 @@ -//----------------------------------------------------------------------------- -// eoNonUniform.h -//----------------------------------------------------------------------------- - -#ifndef EONONUNIFORM_H -#define EONONUNIFORM_H - -//----------------------------------------------------------------------------- - -#include // pow - -//----------------------------------------------------------------------------- -// eoNonUniform -//----------------------------------------------------------------------------- - -class eoNonUniform -{ -public: - eoNonUniform(const unsigned _num_step): - step_value(0), num_step_value(_num_step) {} - - void reset() { step_value = 0; } - - const unsigned& step() const { return step_value; } - const unsigned& num_step() const { return num_step_value; } - - operator int() const { return step_value < num_step_value; } - - void operator++() { ++step_value; } - void operator++(int) { ++step_value; } - -private: - unsigned step_value, num_step_value; -}; - -//----------------------------------------------------------------------------- -// eoLinear -//----------------------------------------------------------------------------- - -class eoLinear -{ -public: - eoLinear(const double _first, - const double _last, - const eoNonUniform& _non_uniform): - first(_first), - diff((_last - _first) / (_non_uniform.num_step() - 1)), - non_uniform(_non_uniform) {} - - double operator()() const - { - return first + diff * non_uniform.step(); - } - -private: - double first, diff; - const eoNonUniform& non_uniform; -}; - -//----------------------------------------------------------------------------- -// eoNegExp2 -//----------------------------------------------------------------------------- - -class eoNegExp2 -{ - public: - eoNegExp2(const double _r, - const double _b, - const eoNonUniform& _non_uniform): - r(_r), b(_b), - non_uniform(_non_uniform) {} - - double operator()() const - { - return 1.0 - pow(r, pow(1.0 - (double)non_uniform.step() / - non_uniform.num_step(), b)); - } - - private: - double r, b; - const eoNonUniform& non_uniform; -}; - -//----------------------------------------------------------------------------- - -#endif NON_UNIFORM_HH - diff --git a/eo/src/obsolete/eoNormal.h b/eo/src/obsolete/eoNormal.h deleted file mode 100644 index 09a75d7f..00000000 --- a/eo/src/obsolete/eoNormal.h +++ /dev/null @@ -1,89 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoNormal.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 _EONORMAL_H -#define _EONORMAL_H - -//----------------------------------------------------------------------------- - -#include -#include // for base class -#include // for random number generator - -//----------------------------------------------------------------------------- -// Class eoNormal -//----------------------------------------------------------------------------- - -/// Generates random number using a normal distribution -template -class eoNormal: public eoRnd -{ - public: - /** - * Default constructor. - * @param _mean Dsitribution mean - * @param _sd Standard Deviation - */ - eoNormal(T _mean, T _sd) - : eoRnd(), mean(_mean), sd(_sd), phase(false) {} - - /** - * Copy constructor. - * @param _rnd the other one - */ - eoNormal( const eoNormal& _rnd ) - : eoRnd( _rnd), mean(_rnd.mean), sd(_rnd.sd), phase(false) {} - - /** Returns an uniform random number over the interval [min, max). - @return an uniform random number over the interval [min, max). - */ - virtual T operator()() { - if (phase) { // Already have one stored up. - phase = false; - return T ( (sqRatio * q * sd) + mean ); - } - - double p, v; - do { - p = ((double)rng.rand() / rng.rand_max())*2-1; - q = ((double)rng.rand() / rng.rand_max())*2-1; - v = p*p + q*q; - } while(v > 1.0 || v <0.25); - - sqRatio = sqrt(-2*log((double)rand() / rng.rand_max()) / v); - phase = true; - return T( (sqRatio * p * sd) + mean ); - }; - - private: - T mean; - T sd; - bool phase; - double sqRatio, q; -}; - -//----------------------------------------------------------------------------- - -#endif - diff --git a/eo/src/obsolete/eoOpFactory.h b/eo/src/obsolete/eoOpFactory.h deleted file mode 100644 index 2d835d99..00000000 --- a/eo/src/obsolete/eoOpFactory.h +++ /dev/null @@ -1,87 +0,0 @@ -// eoOpFactory.h -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoMonOpFactory.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 _EOOPFACTORY_H -#define _EOOPFACTORY_H - -#include -#include -#include -#include -#include - -//----------------------------------------------------------------------------- - -/** EO Factory. An instance of the factory class to create monary operators. -@see eoSelect*/ -template< class EOT> -class eoOpFactory: public eoFactory< eoOp > { - -public: - - /// @name ctors and dtors - //{@ - /// constructor - eoOpFactory( ) {} - - /// destructor - virtual ~eoOpFactory() {} - //@} - - /** Another factory method: creates an object from an std::istream, reading from - it whatever is needed to create the object. Usually, the format for the std::istream will be\\ - objectType parameter1 parameter2 ... parametern\\ - If there are problems, an std::exception is raised; it should be caught at the - upper level, because it might be something for that level - @param _is an stream from where a single line will be read - @throw runtime_std::exception if the object type is not known - */ - virtual eoOp* make(std::istream& _is) { - eoOp * opPtr = NULL; - std::string objectTypeStr; - _is >> objectTypeStr; - if ( objectTypeStr == "eoDup") { - opPtr = new eoDup(); - } - if ( objectTypeStr == "eoKill" ) { - opPtr = new eoKill( ); - } - if ( objectTypeStr == "eoTranspose" ) { - opPtr = new eoTranspose( ); - } - if ( objectTypeStr == "eoXOver2" ) { - opPtr = new eoXOver2( ); - } - if ( !opPtr ) { - throw objectTypeStr; - } - return opPtr; - }; - - -}; - - -#endif _EOOPFACTORY_H diff --git a/eo/src/obsolete/eoOpSelector.h b/eo/src/obsolete/eoOpSelector.h deleted file mode 100644 index d15f620c..00000000 --- a/eo/src/obsolete/eoOpSelector.h +++ /dev/null @@ -1,94 +0,0 @@ -/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - - ----------------------------------------------------------------------------- - eoOpSelector.h - Base class for operator selectors, which return 1 operator according - to some criterium - - (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 EOOPSELECTOR_H -#define EOOPSELECTOR_H - -//----------------------------------------------------------------------------- - -#include // std::runtime_error - -#include -#include -#include - -//----------------------------------------------------------------------------- -/** An operator selector is an object that contains a set of EO operators, -and selects one based on whatever criteria. It will be used in the breeder objects.\\ -This class is basically a generic interface for operator selection -*/ -template -class eoOpSelector: public eoObject, public eoPrintable -{ -public: - - // Need virtual destructor for derived classes - virtual ~eoOpSelector() {} - - /// type of IDs assigned to each operators, used to handle them - typedef unsigned ID; - - /** add an operator to the operator set - @param _op a genetic operator, that will be applied in some way - @param _arg the operator rate, usually, or any other argument to the operator - @return an ID that will be used to identify the operator - */ - virtual ID addOp( eoOp& _op, float _arg ) = 0; - - /** Gets a non-const reference to an operator, so that it can be changed, - modified or whatever - @param _id a previously assigned ID - @throw runtime_std::exception if the ID does not exist*/ - virtual eoOp& getOp( ID _id ) = 0; - - /** Remove an operator from the operator set - @param _id a previously assigned ID - @throw runtime_std::exception if the ID does not exist - */ - virtual void deleteOp( ID _id ) = 0; - - /// Returns a genetic operator according to the established criteria - virtual eoOp* Op() = 0; - - /// Methods inherited from eoObject - //@{ - - /** Return the class id. - @return the class name as a std::string - */ - virtual std::string className() const { return "eoOpSelector"; }; - - /** - * Read object and print objects are left for subclasses to define. - */ - //@} -}; - -//----------------------------------------------------------------------------- - -#endif EO_H diff --git a/eo/src/obsolete/eoParser.h b/eo/src/obsolete/eoParser.h deleted file mode 100644 index fb837370..00000000 --- a/eo/src/obsolete/eoParser.h +++ /dev/null @@ -1,838 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -/* eoParser.h - some classes to parser either the command line or a parameter file - - (c) Marc Schoenauer and 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 _PARSER_H -#define _PARSER_H - -#include // for strcasecmp ... maybe there's a c++ way of doing it? - // Yep there is, but needs either a simple functor for the equal function - // or a hand-rolled std::string template class (this isn't that horrible as - // it sounds, it just means a new std::string_traits class with two changed - // function definitions. (Maarten) -#ifdef _MSC_VER -#define strcasecmp(a,b) _strnicmp(a,b,strlen(a)) -#endif - -// STL includes -#include -#include -#include -#include -#include -#include - -// include for std::exceptions -#include // std::logic_error - -//----------------------------------------------------------------------------- -// Class Param -//----------------------------------------------------------------------------- - -/** - * A param repesents an argument that can be passed to a program in the command line - */ -class Param { -public: - - /** - * Type of params - */ - enum valueType { INT, UL, FLOAT, STRING, BOOL, ARRAY, TITLE }; - - /** - * Construct an Param. - * @param _shortName Short name of the argument - * @param _longName Long name of the argument - * @param _default The default value - * @param _valueType Type of the parameter ("integer","unsigned long", "float","char", "bool" and so on) - * @param _description Description of the parameter. What is useful for. - * @param _required If it is a necessary parameter or not - */ - Param (std::string _shortName="-h", std::string _longName="--help", - std::string _default = "", valueType _valType= STRING, - std::string _description="Shows this help", - bool _required=false ) - : repShortName(_shortName), repLongName(_longName), - repDescription(_description ), repEnv(""), repDefault(_default), - repValue(_default), repValType( _valType), - repRequired( _required), repChanged(false) { - - const char *c = repLongName.c_str(); - for(unsigned i=0; i getArray (const std::string& _shortName, const std::string& _longName, - const std::string& _default = "", - const std::string& _description="", bool _required=false) { - Param param ( _shortName, _longName, _default, Param::ARRAY, _description, _required ); - parse( param ); - params.push_back( param ); - - istrstream is(param.value().c_str()); - std::vector retValue; - std::string tmpStr; - - is >> tmpStr; - while(is){ - retValue.push_back(tmpStr); - is >> tmpStr; - } - return retValue; - }; - - /** - * Gets the int value of a param given the full description of the parameter - * @param see above - * @std::exception BadType if the param's value isn't a correct int - */ - - int getInt (const std::string& _shortName, const std::string& _longName, - const std::string& _default = "", - const std::string& _description="", bool _required=false) { - Param param ( _shortName, _longName, _default, Param::INT, _description, _required ); - parse( param ); - params.push_back( param ); - - // now gets the value - istrstream is( param.value().c_str()); - int retValue; - is >> retValue; - - if (!is) { - throw Parser::BadType(param.longName().c_str(), param.value().c_str(), "float"); - return 0; - } else { - return retValue; - } - }; - - /** - * Gets the unsigned lon value of a param given ... - * @param see above - * @std::exception BadType if the param's value isn't a correct unsigned long - */ - - int getUnsignedLong (const std::string& _shortName, const std::string& _longName, - const std::string& _default = "", - const std::string& _description="", bool _required=false) { - Param param ( _shortName, _longName, _default, Param::UL, _description, _required ); - parse( param ); - params.push_back( param ); - - // now gets the value - istrstream is( param.value().c_str()); - unsigned long retValue; - is >> retValue; - - if (!is) { - throw Parser::BadType(param.longName().c_str(), param.value().c_str(), "float"); - return 0; - } else { - return retValue; - } - }; - - /** - * Gets the float value of a param given the description of the parameter - * @param see above - * @std::exception BadType if the param's value isn't a correct int - */ - - float getFloat (const std::string& _shortName, const std::string& _longName, - const std::string& _default = "", - const std::string& _description="", bool _required=false) { - Param param ( _shortName, _longName, _default, Param::FLOAT, _description, _required ); - parse( param ); - params.push_back( param ); - - // now gets the value - istrstream is( param.value().c_str()); - float retValue; - is >> retValue; - - if (!is) { - throw Parser::BadType(param.longName().c_str(), param.value().c_str(), "float"); - return 0; - } else { - return retValue; - } - }; - - - std::string parse_std::string (std::istream & _is) { - std::string paramValue; - _is >> paramValue; - //if the first character of the std::string or array is not a " => just one word or array-element. - if( paramValue[0] != '\"' ) - return paramValue; - - if( paramValue[1] == '\"' ) // the empty std::string - return "" ; - - //else => read until the next " (the end of the std::string). - const char *c = paramValue.c_str(); - std::string tmpStr = c+1;// skip the " - if (tmpStr[tmpStr.length()-1] == '\"') { // one word only - //tmpStr[tmpStr.length()-1] = '\0'; - tmpStr.erase( &tmpStr[tmpStr.length()-1] ); - return tmpStr; - } - - bool stop = false; - while (_is && !stop) { - _is >> paramValue; - // test last character of paramValue for " - if (paramValue[paramValue.length()-1] == '\"') { - paramValue.erase( ¶mValue[paramValue.length()-1] ); - //paramValue[paramValue.length()-1] = '\0'; - stop = true; - } - tmpStr = tmpStr + " " + paramValue ; - } - return tmpStr; - }; - - - void parse (Param & param) { - int i; - std::string tmpStr, ReadStr, FirstWord; - - // FIRST: look if the associated environment variables have any value, to use them. - if( getenv( param.environment().c_str() ) ) { - //std::cout <<"\t\t ENV param: ,"<shortName()<<", ,"<environment().c_str())<> tmpStr; - if ( ( !strcmp(tmpStr.c_str(), param.shortName().c_str()) ) || - ( !strcasecmp(tmpStr.c_str(), param.longName().c_str()) ) - ) { // found the keyword - - Param::valueType tmp = param.valType(); - switch ( tmp ) { - case Param::TITLE: - std::cerr << "Error, we should not be there" << std::endl; - exit(1); - break; - case Param::BOOL : - param.value("true" ); - break; - - case Param::INT: - case Param::UL: - case Param::FLOAT: - is >> tmpStr; - param.value(tmpStr); - break; - - case Param::STRING: - tmpStr = parse_std::string(is); - param.value(tmpStr); - break; - - case Param::ARRAY: - ReadStr = parse_std::string(is); - if ( ReadStr != "<" ) { // no "<" ">" --> a single std::string in the array - param.value(ReadStr); - break; - } - // read next word - and keep it in case of <> mismatch - FirstWord = parse_std::string(is); - // test for empty array - if (FirstWord == ">") { - param.value(""); - break; - } - // else, read all words until ">" - tmpStr = FirstWord; - ReadStr = parse_std::string(is); - while ( is && (ReadStr != ">") ) { - tmpStr = tmpStr + " " + ReadStr; - ReadStr = parse_std::string(is); - } - - if (!is) { // there was a "<" without the corresponding ">" - throw Parser::BadArrayParam( param.longName(), FirstWord ); - param.value(FirstWord); // assume unique std::string - } - else - param.value(tmpStr); - break; - } - } - } - } - - - // LAST (highest priority) parse the command line arguments - for (i=1 ; i" --> a single std::string in the array - param.value(ReadStr); - }else{ - // read next word - and keep it in case of <> mismatch - FirstWord = parse_argv[i++]; - - // test for empty array - if (FirstWord == ">") { - param.value(""); - }else{ - // else, read all words until ">" - tmpStr = FirstWord; - ReadStr = parse_argv[i++]; - while ( (i=parse_argc) && (ReadStr != ">") ) { // there was a "<" without the corresponding ">" - throw Parser::BadArrayParam( param.longName(), FirstWord ); - param.value(FirstWord); // assume unique std::string - }else{ - param.value(tmpStr); - } - } - } - } - } - break; - } - - //MS after trying all possibilities, and if the value has not changed - // though the parameter was required, protest! - if (param.required() && !param.changed()) - throw Parser::MissingReqParam(param.shortName()); - - }; - - /** - * Sets a new value for a param given its short name or its long name. - * @param _name One of the names of the param. - * @param _value Value to be assigned. - * @std::exception UnknownArg if the param doesn't exist - * @std::exception MissingVal if the param hasn't got a value - */ - Param::valueType setParamValue (const std::string& _name, const char* _value){ - std::vector::iterator pos; - - for (pos=params.begin() ; pos!=params.end() ; pos++) - if (pos->shortName()==_name || pos->longName()==_name) - break; - - // if found ... - if (pos!=params.end()) { - switch ( pos->valType() ) { - case Param::TITLE: - std::cerr << "Error, we should not be there" << std::endl; - exit(1); - break; - case Param::BOOL : - pos->value("true"); - break; - case Param::ARRAY : - case Param::INT: - case Param::UL: - case Param::FLOAT: - case Param::STRING: - if (_value != NULL){ - pos->value(_value); - }else{ - throw Parser::MissingVal(_name); - return Param::BOOL; - } - break; - } // switch - - return pos->valType(); - - }else{ - throw Parser::UnknownArg(_name); - return Param::BOOL; - } - }; - - /// the output method - generate the .status file (unless other name is given) - friend std::ostream & operator<< ( std::ostream & os, Parser & _parser ) - { - std::vector::iterator p; - //print every param with its value - for ( p=_parser.params.begin(); p!=_parser.params.end(); p++ ) { - switch ( p->valType() ) { - case Param::BOOL : - if( p->value() == (std::string) "true") - os << p->longName(); - else - os << "#" << p->longName() ; // so the name of the bool is commented out - break; - - case Param::INT: - case Param::UL: - case Param::FLOAT: - os << p->longName()<<" "<value(); - break; - - case Param::ARRAY : - os << p->longName() << " < " << p->value().c_str() << " >" ; - break; - case Param::STRING: - os << p->longName()<<" \""<value().c_str()<<"\" "; - break; - case Param::TITLE: - os << std::endl; // Title is in the description below - break; - } // switch - os << "\t #" << p->shortName() << " : " << p->description(); - if (p->valType() != Param::TITLE) - os << " [" << p->defValue() << "]" ; - os << std::endl; - } - return os; - }; - - /** - * Prints out the std::list of parameters in the output file (if specified) - */ - void outputParam(std::string _OutputFile="") - { - if (_OutputFile == "") { - _OutputFile = parse_argv[0]; - _OutputFile += ".status"; - } - - std::ofstream os(_OutputFile.c_str()); - os << "Parameters used by \"" << programName << "\" (" - << programDescription << ")" << std::endl << std::endl; - os << *this; - }; - - /** - * Prints an automatic help in the standard output using the information - * provided by parameters - */ - void printHelp() { - std::vector::iterator p; - // unsigned i; - - // print program name and description - std::cout << this->programName <<": "<valType() != Param::TITLE ) { - // if( p->valType() != Param::BOOL ){ - // std::cout << ( (!p->required())?"[":""); - // std::cout <shortName()<<" value"<required())?"]":"")<<" "; - // }else{ - // std::cout << "["<shortName()<<"] "; - // } - // } // for p - std::cout << "Where:"<valType() != Param::TITLE ) { - // Victor: 04-Jan-2000 - // Modified because the - and -- prefixes are not needed. - /* - std::cout << "-" << p->shortName() - <<", --"<longName()<<":\t" - <description()<shortName() - <<", " << p->longName()<<":\t" - <description()<valType() ) { - case Param::INT: std::cout <<"Integer"; break; - case Param::UL: std::cout <<"Unsigned Long Integer"; break; - case Param::FLOAT: std::cout <<"Float"; break; - case Param::STRING: std::cout <<"String"; break; - case Param::ARRAY: std::cout <<"An array of std::strings, enclosed within < >"; break; - case Param::BOOL: std::cout << "Flag"; break; - case Param::TITLE: break; - } // switch - if(p->valType() == Param::BOOL) - std::cout << ") True if present" << std::endl; - else - std::cout<<") "<<( (p->required())?"Required":"Optional" )<<". By default: "<defValue()<description() << std::endl; - } - } // for p - std::cout << std::endl; - }; - - /** - * This class managges unknown argument std::exceptions. - */ - class UnknownArg : public std::logic_error { - public: - - /** - * Constructor - * @param _arg std::string to be shown when the std::exception occurs - */ - UnknownArg( const std::string& _arg): std::logic_error( "Invalid argument: "+_arg ) { }; - }; - - /** - * This class managges bad param types. - */ - class BadType : public std::logic_error { - public: - - /** - * Constructor - * @param _param The param - * @param _value The value of the param - */ - BadType(const std::string& _param, const std::string& _value, const std::string& _correctType) - : std::logic_error("The value '" + _value + "' assigned to the argument " + _param + " isn't a correct "+_correctType) { }; - }; - - /** - * This class managges std::exceptions produced when there isn't a value for a parameter. - */ - class MissingVal : public std::logic_error { - public: - - /** - * Constructor - * @param _param The param - */ - MissingVal(const std::string& _param) : std::logic_error("Missing value for parameter " + _param) {}; - }; - - /** - * This class managges std::exceptions produced when the user forgot a required parameter. - */ - class MissingReqParam : public std::logic_error { - public: - - /** - * Constructor - * @param _shortName The param's short name - */ - MissingReqParam(const std::string& _shortName) : std::logic_error("Missing required parameter " + _shortName) {}; - }; - - /** - * This class managges std::exceptions du to < without a > in array value - */ - class BadArrayParam : public std::logic_error { - public: - - /** - * Constructor - * @param _param The param - * @param _first_word The first word read after the "<" - */ - BadArrayParam(const std::string& _param, const std::string &_first_word) : - std::logic_error("Array parameter " + _param + ": No matching > (" + _first_word - + "... )") {}; - }; - - void createParamFile( std::ostream& _os ) { - std::vector::iterator p; - for ( p=params.begin(); p!=params.end(); p++ ) { - switch( p->valType() ) { - case Param::TITLE: - _os << std::endl << "# -- "; - break; - case Param::BOOL: - _os << ((p->value()=="true" )?"":"#") - << p->longName(); - break; - case Param::STRING: - _os << p->longName()<<"\t\""<value()<<"\""; - break; - case Param::ARRAY: - _os << p->longName()<<"\t< "<value()<<" >"; - break; - default: - _os << p->longName()<<"\t"<value(); - break; - } // switch - _os << "\t #" << p->description() << std::endl; - } - } -private: - std::vector params; - std::string programName; - std::string programDescription; - int parse_argc; - char **parse_argv; - std::string InputFileName; - -}; - - - - -#endif diff --git a/eo/src/obsolete/eoParserUtils.cpp b/eo/src/obsolete/eoParserUtils.cpp deleted file mode 100644 index dea8ed09..00000000 --- a/eo/src/obsolete/eoParserUtils.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// See eoParserUtils.h - -#include -#include -/// Reproducible random seed - -// For the Mersenne-Twister used in EO, the entire rng needs to be saved - -//---------------------------------- -void InitRandom( Parser & parser) { -//---------------------------------- - unsigned long _seed; - try { - _seed = parser.getUnsignedLong("-S", "--seed", "0", - "Seed for Random number generator" ); - } - catch (logic_error & e) - { - cout << e.what() << endl; - parser.printHelp(); - exit(1); - } - - if (_seed == 0) { // use clock to get a "random" seed - _seed = (unsigned long)( time( 0 ) ); - ostrstream s; - s << _seed; - parser.setParamValue("--seed", s.str()); // so it will be printed out in the status file, and canbe later re-used to re-run EXACTLY the same run - } - //#error This does not work: load and save the entire state of the rng object. - rng.reseed(_seed); - - return; -} - diff --git a/eo/src/obsolete/eoParserUtils.h b/eo/src/obsolete/eoParserUtils.h deleted file mode 100644 index 742c4b58..00000000 --- a/eo/src/obsolete/eoParserUtils.h +++ /dev/null @@ -1,24 +0,0 @@ -/*------------------------------------------------------- -File..........: eoParserUtils.h -Author........: Geneura Team, Marc Shoenauer - (this file: Victor Rivas, vrivas@ujaen.es) -Date..........: 17-Dec-1999 -Description...: Some useful things that use eoParser. -Modifications.: -------------------- 1 ------------------- - Author.......: - Date.........: - Description..: -*/ - -#ifndef EO_PARSER_UTILS -#define EO_PARSER_UTILS - -#include "../utils/eoRNG.h" -#include "eoParser.h" -/// Reproducible random seed - -//---------------------------------- -void InitRandom( Parser & parser); -//---------------------------------- -#endif diff --git a/eo/src/obsolete/eoPopOps.h b/eo/src/obsolete/eoPopOps.h deleted file mode 100644 index bd1dbf68..00000000 --- a/eo/src/obsolete/eoPopOps.h +++ /dev/null @@ -1,142 +0,0 @@ -/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - - ----------------------------------------------------------------------------- - eoPopOps.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 _EOPOPOPS_H -#define _EOPOPOPS_H - -using namespace std; - -/** -@author Geneura Team -@version 0.0 - -@version 0.1 : -MS- 22/10/99 - added the added the derived class eoSelectOne for which you only have - to define the selection of 1 individual - (e.g. for tournament, age selection in SSGA, ...) - added at the BASE level (after all it's themost frequen case) - the pure virtual operator that selects one single individual: - EOT eoSelect::operator ( const eoPop& _parents, - const EOT& _first = 0) - added the optional second parameter to transform::operator() -*/ - -//----------------------------------------------------------------------------- -#include - -//----------------------------------------------------------------------------- -/** eoTransform is a class that transforms or does something on a population. - */ -template -class eoMonPopOp: public eoObject{ - - public: - /** ctor */ - eoMonPopOp() {}; - - /// Dtor - virtual ~eoMonPopOp(){}; - - /// Pure virtual transformation function. Does something on the population - virtual void operator () ( eoPop& _pop ) = 0; - - /** @name Methods from eoObject */ - //@{ - /** readFrom and printOn are not overriden - */ - /** Inherited from eoObject. Returns the class name. - @see eoObject - */ - virtual std::string className() const {return "eoMonPopOp";}; - //@} - -}; - -//----------------------------------------------------------------------------- - -/** eoSelect usually takes elements from one population, with or without transformation, and transfers them to the other population */ -template -class eoBinPopOp: public eoObject{ - - public: - /** ctor - */ - eoBinPopOp() {}; - - /// Dtor - virtual ~eoBinPopOp(){}; - - /** Pure virtual transformation function. Extracts something from the parents, - and transfers it to the siblings - @param _parents the initial generation. Will be kept constant - @param _siblings the created offspring. Will be usually an empty population - */ - virtual void operator () (eoPop& _parents, eoPop& _siblings ) = 0; - - /** @name Methods from eoObject */ - //@{ - /** readFrom and printOn are not overriden - */ - /** Inherited from eoObject. Returns the class name. - @see eoObject - */ - virtual std::string className() const {return "eoBinPopOp";}; - //@} - -}; - -//----------------------------------------------------------------------------- - -/** eoSelectone selects only one element from a whole population. Usually used to - select mates*/ -template -class eoSelectOne: public eoObject{ - - public: - /** ctor - */ - eoSelectOne() {}; - - /// Dtor - virtual ~eoSelectOne(){}; - - /** Pure virtual transformation function. Extracts something from the parents, - and transfers it to the siblings - @param _parents the initial generation. Will be kept constant - @param _siblings the created offspring. Will be usually an empty population - */ - virtual const EOT& operator () ( const eoPop& _parents ) = 0; - - /** @name Methods from eoObject */ - //@{ - /** readFrom and printOn are not overriden - */ - /** Inherited from eoObject. Returns the class name. - @see eoObject - */ - virtual std::string className() const {return "eoSelectOne";}; - //@} - -}; -#endif diff --git a/eo/src/obsolete/eoProblem.h b/eo/src/obsolete/eoProblem.h deleted file mode 100644 index 5c219123..00000000 --- a/eo/src/obsolete/eoProblem.h +++ /dev/null @@ -1,45 +0,0 @@ -//----------------------------------------------------------------------------- - -// eoProblem.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 EOPROBLEM_H -#define EOPROBLEM_H - -//----------------------------------------------------------------------------- - -template class Problem -{ - public: - typedef T Chrom; - typedef typename T::Gene Gene; - typedef typename T::Fitness Fitness; - - virtual Fitness operator()(const Chrom& chrom) = 0; -}; - -//----------------------------------------------------------------------------- - -#endif EOPROBLEM_H - diff --git a/eo/src/obsolete/eoProportional.h b/eo/src/obsolete/eoProportional.h deleted file mode 100644 index 7116e786..00000000 --- a/eo/src/obsolete/eoProportional.h +++ /dev/null @@ -1,71 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoProportional.h -// (c) GeNeura Team, 1998 - EEAAX 1999, Maarten Keijzer 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 - Marc.Schoenauer@polytechnique.fr - mak@dhi.dk - */ -//----------------------------------------------------------------------------- - -#ifndef eoProportional_h -#define eoProportional_h - -//----------------------------------------------------------------------------- - -#include -#include -#include - -//----------------------------------------------------------------------------- -/** eoProportional: select an individual proportional to her stored fitness - value - -*/ -//----------------------------------------------------------------------------- - -template class eoProportional: public eoSelectOne -{ -public: - /// Sanity check - eoProportional(const eoPop& pop = eoPop()): - total((pop.size() == 0) ? -1.0 : sum_fitness(pop)) - { - if (minimizing_fitness()) - throw std::logic_error("eoProportional: minimizing fitness"); - } - - void setup(const eoPop& _pop) - { - total = sum_fitness(_pop); - } - - /** do the selection, call roulette_wheel. - */ - const EOT& operator()(const eoPop& _pop) - { - return roulette_wheel(_pop, total) ; - } - -private : - typename EOT::Fitness total; -}; - -#endif - diff --git a/eo/src/obsolete/eoProportionalGOpSel.h b/eo/src/obsolete/eoProportionalGOpSel.h deleted file mode 100644 index a52bac60..00000000 --- a/eo/src/obsolete/eoProportionalGOpSel.h +++ /dev/null @@ -1,51 +0,0 @@ -/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - - ----------------------------------------------------------------------------- - eoProportionalGOpSel.h - Proportional operator selector, selects operators proportionally to its rate - - (c) Maarten Keijzer, 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 eoProportionalGOpSel_h -#define eoProportionalGOpSel_h - -//----------------------------------------------------------------------------- - -#include // eoOpSelector - -template -class eoProportionalGOpSel : public eoGOpSelector -{ -public : - eoProportionalGOpSel() : eoGOpSelector() {} - - /** Returns the operator proportionally selected */ - virtual eoGeneralOp& selectOp() - { - unsigned what = rng.roulette_wheel(getRates()); - return *operator[](what); - } - - /// - virtual std::string className() const { return "eoGOpSelector"; }; - -}; - -#endif eoProportionalGOpSel_h diff --git a/eo/src/obsolete/eoProportionalOpSel.h b/eo/src/obsolete/eoProportionalOpSel.h deleted file mode 100644 index 72c17dc2..00000000 --- a/eo/src/obsolete/eoProportionalOpSel.h +++ /dev/null @@ -1,158 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - - - -//----------------------------------------------------------------------------- - -// eoProportionalOpSel.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 EOPROPORTIONALOPSEL_H -#define EOPROPORTIONALOPSEL_H - -//----------------------------------------------------------------------------- - -#include // std::runtime_error -#include // greater -#include - -// Includes from EO -#include -#include -#include - -//----------------------------------------------------------------------------- -/** This class selects operators according to probability. All operator percentages -should add up to one; if not, an std::exception will be raised.\\ -Operators are represented as std::pairs (proportion,operator) -*/ -template -class eoProportionalOpSel: public eoOpSelector, - public multimap*,greater > -{ -public: - - typedef multimap*,greater > MMF; - - /// default ctor - eoProportionalOpSel() - : eoOpSelector(), MMF(), opID(1) {}; - - /// virtual dtor - virtual ~eoProportionalOpSel() {}; - - /** Gets a non-const reference to an operator, so that it can be changed, - modified or whatever - @param _id a previously assigned ID - @throw std::runtime_error if the ID does not exist*/ - - virtual eoOp& getOp( ID _id ) { - MMF::iterator i=begin(); - ID j = 1; - while ( (i++!=end()) && (j++ != _id) ); - if ( i == end() ) - throw std::runtime_error( "No such id in eoProportionalOpSel::op\n" ); - return *(i->second); - //return i->second; - } - - /** add an operator to the operator set - @param _op a genetic operator, that will be applied in some way - @param _arg an argument to the operator, usually operator rate - @return an ID that will be used to identify the operator - */ - virtual ID addOp( eoOp& _op, float _arg ) { - insert( MMF::value_type( _arg,& _op ) ); - return opID++; - } - - /** Remove an operator from the operator set - @param _id a previously assigned ID - @throw std::runtime_error if the ID does not exist - */ - virtual void deleteOp( ID _id ) { - unsigned j; - MMF::iterator i; - for ( i=begin(), j=1; i!=end(); i++,j++ ) { - if( j == _id ) - erase( i ); - return; - } - if ( i == end() ) - throw std::runtime_error( "No such id in eoProportionalOpSel::op\n" ); - }; - - /// Returns a genetic operator according to the established criteria - virtual eoOp* Op() { - // Check that all add up to one - float acc = 0; - MMF::iterator i; - unsigned j; - for ( i=begin(), j=1; i!=end(); i++,j++ ) { - acc +=i->first; - } - if ( acc != 1.0 ) - throw std::runtime_error( "Operator rates added up different from 1.0" ); - - // If here, operators ordered by rate and no problem - float aRnd = rng.uniform(); - i=begin(); - acc = 0; - do { - acc += i->first; - } while ( (acc <= aRnd ) && (i++!=end() ) ); - if ( i == end() ) - throw std::runtime_error( "Operator not found in eoProportionalOpSelector" ); - return i->second; - //return i->second; - } - - /// Methods inherited from eoObject - //@{ - - /** Return the class id. - @return the class name as a std::string - */ - virtual std::string className() const { return "eoProportionalOpSel"; }; - - /** Print itself: inherited from eoObject implementation. Declared virtual so that - it can be reimplemented anywhere. 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{ - _s << className().c_str() << std::endl; - for ( MMF::const_iterator i=begin(); i!=end(); i++ ) { - _s << i->first << "\t" << *(i->second )<< std::endl; - } - } - - - //@} - - private: - ID opID; - }; - - //----------------------------------------------------------------------------- - -#endif EO_H - diff --git a/eo/src/obsolete/eoRandomBreed.h b/eo/src/obsolete/eoRandomBreed.h deleted file mode 100644 index 61b76e08..00000000 --- a/eo/src/obsolete/eoRandomBreed.h +++ /dev/null @@ -1,200 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoRandomBreed.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 _EORANDOMBREED_H -#define _EORANDOMBREED_H - -#include - -/** Takes those on the selection std::list and creates a std::list of new individuals - * Destroys the genetic pool */ -template -class EORandomBreed: public EOBreeder{ -public: - - typedef std::vector< EOOp * > vecOpT; - - /// Ctor - EORandomBreed():vecOp() {}; - - /** Copy ctor - * Needs a copy ctor for the EO operators */ - EORandomBreed( const EORandomBreed& _rndBreeder) - :vecOp() { - copy( _rndBreeder.vecOp.begin(), _rndBreeder.vecOp.end(), - vecOp.begin() ); - }; - - /// Dtor - virtual ~EORandomBreed() {}; - - /// Adds a genetic operator to the Breeder with a rate - virtual void addOp( EOOp* _eop ) { - vecOp.push_back( _eop); - }; - - /// Takes the operator pointed to from the operator std::list - virtual void deleteOp( const EOOp* _eop); - - /** Takes the genetic pool, and returns next generation, destroying the - * genetic pool container - * Non-const because it might order the operator std::vector. In this case, - * it mates all members of the population randomly */ - virtual void operator() ( EOPop< EOT >& _ptVeo ); - -// I donīt like this, but I need it for the RandomBreedLog -protected: - vecOpT vecOp; - -}; - - -//_________________________ IMPLEMENTATIONS _____________________________ - -template< class EOT> -void EORandomBreed::deleteOp( const EOOp* _eop) { - vecOpT::iterator i; - for ( i = vecOp.begin(); i != vecOp.end(); i++ ) { - if ( *i == _eop ) { - vecOp.erase( i ); - } - } -} - -//________________________________________________________________________ -template -void EORandomBreed::operator() ( EOPop< EOT >& _ptVeo ) { - - unsigned select= _ptVeo.size(); // New population same size than old - sort( vecOp.begin(), vecOp.end(), SortEOpPt() ); - - unsigned i; - float totalPriority = 0; - for ( i = 0; i < vecOp.size(); i ++ ) { - totalPriority += vecOp[i]->Priority(); - } - - unsigned inLen = _ptVeo.size(); // size of in subPop - for ( i = 0; i < select; i ++ ) { - // Create an alias of a random input EO with copy ctor - EOT& newEO = _ptVeo[ i ]; - - // Choose operator - float randomDraw = totalPriority *(rand() % 1000) /1000.0; - vecOpT::const_iterator j; - float accumulated = 0; - for ( j = vecOp.begin(); - ( j != vecOp.end() ) && ( accumulated < randomDraw); - j ++ ) { - accumulated+= (*j)->Priority(); // the priority - } - - if ( j != vecOp.begin() ) - j--; // previous one - EOOp* thisOp = *j; - - if (thisOp->readArity() == unary ) { - MonOp* mopPt = dynamic_cast< MonOp* > ( thisOp ); - (*mopPt)( newEO ); - } else { - unsigned chosenMatch = rand() % inLen; - BinOp* bopPt = dynamic_cast< BinOp* > ( thisOp ); - (*bopPt)( newEO, _ptVeo[chosenMatch] ); - } - - } -} - -#include // For factory - -/** Exactly as RandomBreed, except that uses factories*/ -template -class EORandomBreedLog: public EORandomBreed{ -public: - - typedef std::vector< EOOp * > vecOpT; - - /// Ctor - EORandomBreedLog( EOFactory & _eof ):EORandomBreed(), factory( _eof ) {}; - - /** Copy ctor - * Needs a copy ctor for the EO operators */ - EORandomBreedLog( const EORandomBreedLog& _rndBreeder) - :EORandomBreed( _rndBreeder ), factory( _rndBreeder.factory) {}; - - /// Dtor - virtual ~EORandomBreedLog() {}; - - /** Takes the genetic pool, and returns next generation, destroying the - * genetic pool container - * Non-const because it might order the operator std::vector. In this case, it mates - * all population randomly */ - virtual void operator() ( EOPop< EOT >& _ptVeo ) { - - unsigned select= _ptVeo.size(); // New population same size than old - sort( vecOp.begin(), vecOp.end(), SortEOpPt() ); - - unsigned i; - float totalPriority = 0; - for ( i = 0; i < vecOp.size(); i ++ ) { - totalPriority += vecOp[i]->Priority(); - } - - unsigned inLen = _ptVeo.size(); // size of in subPop - for ( i = 0; i < select; i ++ ) { - // Create a copy of a random input EO with copy ctor - EOT* newEO = factory.make( _ptVeo[ i ] ); - - // Choose operator - float randomDraw = totalPriority *(rand() % 1000) /1000.0; - vecOpT::const_iterator j; - float accumulated = 0; - for ( j = vecOp.begin(); - ( j != vecOp.end() ) && ( accumulated < randomDraw); - j ++ ) { - accumulated+= (*j)->Priority(); // the priority - } - - if ( j != vecOp.begin() ) - j--; // previous one - EOOp* thisOp = *j; - - if (thisOp->readArity() == unary ) { - MonOp* mopPt = dynamic_cast< MonOp* > ( thisOp ); - (*mopPt)( *newEO ); - } else { - unsigned chosenMatch = rand() % inLen; - BinOp* bopPt = dynamic_cast< BinOp* > ( thisOp ); - (*bopPt)( *newEO, _ptVeo[chosenMatch] ); - } - - } - - }; -private: - EOFactory& factory; - -}; - -#endif diff --git a/eo/src/obsolete/eoRandomIndiSelector.h b/eo/src/obsolete/eoRandomIndiSelector.h deleted file mode 100644 index 990c6c4a..00000000 --- a/eo/src/obsolete/eoRandomIndiSelector.h +++ /dev/null @@ -1,53 +0,0 @@ -/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - - ----------------------------------------------------------------------------- - eoRandomIndiSelector.h - Selects individuals at random. - - (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 eoRandomIndiSelector_h -#define eoRandomIndiSelector_h - -#include - -/** -\ingroup selectors - * eoRandomSelector: just selects a random child -*/ -template -class eoRandomIndiSelector : public eoPopIndiSelector -{ - public : - - eoRandomIndiSelector(void) : eoPopIndiSelector() {} - virtual ~eoRandomIndiSelector(void) {} - - /// very complex function that returns just an individual - const EOT& do_select(void) - { - return operator[](rng.random(size())); - } - -}; - -#endif - - diff --git a/eo/src/obsolete/eoRandomSelect.h b/eo/src/obsolete/eoRandomSelect.h deleted file mode 100644 index 26faa9ea..00000000 --- a/eo/src/obsolete/eoRandomSelect.h +++ /dev/null @@ -1,130 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - - - -//----------------------------------------------------------------------------- -// eoRandomSelect.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 EORANDOMSELECT_H -#define EORANDOMSELECT_H - -//----------------------------------------------------------------------------- - -#include -#include // for accumulate - -#include - -#include -#include - -//----------------------------------------------------------------------------- - -/** - * eoRandomSelect: an selection operator, which selects randomly a percentage - - of the initial population. - */ -template class eoRandomSelect: public eoBinPopOp -{ - public: - /// - eoRandomSelect(const float& _percent = 0.4): - eoBinPopOp(), repRate(_percent) {}; - - /// - virtual ~eoRandomSelect() {}; - - /// Takes a percentage of the population randomly, and transfers it to siblings - virtual void operator() ( eoPop& _parents, eoPop& _siblings ) { - // generates random numbers - unsigned num_chroms = (unsigned)(repRate * _parents.size()); - - // selection of chromosomes - do { - _siblings.push_back(_parents[rng.random(_parents.size())]); - } while (_siblings.size() < num_chroms); - } - - - - /// @name Methods from eoObject - - //@{ - - /** - - * Read object. Reads the percentage - - * Should call base class, just in case. - - * @param _s A std::istream. - - */ - - virtual void readFrom(std::istream& _s) { - - _s >> repRate; - - } - - - - /** Print itself: inherited from eoObject implementation. Declared virtual so that - - it can be reimplemented anywhere. 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{ - - _s << repRate; - - } - - - - /** Inherited from eoObject - - @see eoObject - - */ - - std::string className() const {return "eoRandomSelect";}; - - - - //@} - - - - - private: - float repRate; -}; - -//----------------------------------------------------------------------------- - -#endif EOGSRANDOMSELECT_H diff --git a/eo/src/obsolete/eoRank.h b/eo/src/obsolete/eoRank.h deleted file mode 100644 index 588fb1da..00000000 --- a/eo/src/obsolete/eoRank.h +++ /dev/null @@ -1,140 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - - - -//----------------------------------------------------------------------------- - -// eoRank.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 _eoRank_H - -#define _eoRank_H - - -#include - -#include - - -/** - * Takes those on the selection std::list and creates a std::list of new individuals - * Destroys the genetic pool. There's no requisite on EOT, other than the - * genetic operators can be instantiated with it, so it fully depstd::ends on - * the genetic operators used. If generic genetic operators are used, then - * EOT must be an EO - */ - -template -class eoRank: public eoSelect, public eoObject, public eoPrintable -{ - public: - - /// Ctor - eoRank( unsigned _newPopSize, eoOpSelector& _opSelector) - :eoSelect(), opSelector( _opSelector ), repNewPopSize( _newPopSize ) {}; - - /// Dtor - virtual ~eoRank() {}; - - /** Takes the genetic pool, and returns next generation, destroying the - * genetic pool container - * Non-const because it might order the operator std::vector*/ - virtual void operator() ( const eoPop< EOT >& _ptVeo, - - eoPop< EOT >& _siblings ) const { - - unsigned inLen = _ptVeo.size(); // size of subPop - if ( !inLen ) - throw std::runtime_error( "zero population in eoRank"); - - for ( unsigned i = 0; i < repNewPopSize; i ++ ) { - // Create a copy of a random input EO with copy ctor. The members of the - // population will be selected by rank, with a certain probability of - // being selected several times if the new population is bigger than the - // old - - EOT newEO = _ptVeo[ i%inLen ]; - - // Choose operator - - const eoOp& thisOp = opSelector.Op(); - if ( thisOp.readArity() == unary ) { - const eoMonOp& mopPt = dynamic_cast< const eoMonOp& > ( thisOp ); - mopPt( newEO ); - } else { - const eoBinOp& bopPt = dynamic_cast< const eoBinOp& > ( thisOp ); - - EOT mate = _ptVeo[ rng.random(inLen) ]; - bopPt( newEO, mate ); - } - - - _siblings.push_back( newEO ); - } - }; - - /** This is a _new_ function, non defined in the parent class - * Itīs used to set the selection rate */ - void select( unsigned _select ) { - repNewPopSize = _select; - } - - - - - /// Methods inherited from eoObject - - //@{ - - - - /** Return the class id. - - @return the class name as a std::string - - */ - - virtual std::string className() const { return "eoRank"; }; - - virtual void printOn( std::ostream& _s ) const - { - _s << repNewPopSize; - }; - - - - - - //@} - - -private: - eoOpSelector & opSelector; - unsigned repNewPopSize; - -}; - -#endif diff --git a/eo/src/obsolete/eoScheme.h b/eo/src/obsolete/eoScheme.h deleted file mode 100644 index a66695b0..00000000 --- a/eo/src/obsolete/eoScheme.h +++ /dev/null @@ -1,360 +0,0 @@ -// eoScheme.h -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoScheme.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 - */ -//----------------------------------------------------------------------------- - -#ifndef _EOSCHEME_H -#define _EOSCHEME_H - -using namespace std; - -/** -@author Geneura Team -- EEAAX 99 -@version 0.0 - Evolution scheme - - - It seems to me that some important conceptual object is missing - (and God knows I hate turning everything into objects! - - So here is the evolution scheme: - - regroups selection (nb of offspring to generate AND selection method - and replacement (from parents + offspring) - - allows to include elitism, eugenism of the worst, ... more easily - - a generation is then simply an evolution scheme and some operators - and a full algo is a generation + a termination condition - - this is mainly a container class -*/ - -//----------------------------------------------------------------------------- - -#include -#include "eoStochTournament.h" -#include "eoDetTournament.h" -#include "eoLottery.h" -#include "eoUniformSelect.h" -#include "eoInclusion.h" -#include "eoESReplace.h" -#include "eoEPTournament.h" - -/** eoScheme is a class that does more sophisticated evolution that eoEasyEA - */ -template -class eoScheme: public eoAlgo{ - - public: - - // Dtor - virtual ~eoScheme() {}; - - // copy ctor is impossible because of pointers to pure virual types. - // any idea???? --- leave the default copy ctor -- JJ - - /** the Parser-based constructor - these switch cases could be turned into as many subclasses - - but how do you return the subclass to the caller of the constructor??? - */ - eoScheme(Parser & parser) { - // read the popsize - parser.AddTitle("Description of evolution"); - std::string Evol; - std::string SelectString; - // temporary - float rate_offspring; - - try { - Evol = parser.getString("-EE", "--evolution", "GGA", - "Evolution scheme (GGA, SSGA, ESPlus, ESComma, EP, General)" ); - popsize = parser.getInt("-EP", "--population", "10", - "Population size" ); - } - catch (std::exception & e) - { - std::cout << e.what() << std::endl; - parser.printHelp(); - exit(1); - } - // now the big switch - if (! strcasecmp(Evol.c_str(), "GGA") ) { - // GGA parameters: popsize, selection method (and its parameters) - nb_offspring = 0; - rate_offspring = 1.0; // generational replacement: #offspring=popsize - try { - // parser.AddTitle("GGA Parameters"); - SelectString = parser.getString("-ES", "--selection", "Tournament", - "Selection method (Roulette, tournament)" ); - if (! strcasecmp(SelectString.c_str(), "roulette") ) { - ptselect = new eoLottery (); - ptselect_mate = new eoLottery (); - } - if (! strcasecmp(SelectString.c_str(), "tournament") ) { - float rate = parser.getFloat("-Et", "--TselectSize", "2", - "Tournament size or rate" ); - if (rate < 0.5) - throw out_of_range("Invalid tournament rate"); - else if ( rate < 1 ) { // binary stochastic tournament - ptselect = new eoStochTournament(rate); - ptselect_mate = new eoStochTournament(rate); - } else { // determeinistic tournament of size (int)rate - ptselect = new eoDetTournament((int)rate); - ptselect_mate = new eoDetTournament((int)rate); - } - } - // end choice of selection - ptreplace = new eoInclusion(); - // put here the choice of elitism - } - catch (std::exception & e) - { - std::cout << e.what() << std::endl; - parser.printHelp(); - exit(1); - } - } // end of GGA - - // SSGA - standard, one offspring only at the moment - if (! strcasecmp(Evol.c_str(), "SSGA") ) { - // SSGA parameters: popsize, selection tournament size - // the replacement is limited to repace_worst, though - // it could be easy to add the anti-tournament replacement method - nb_offspring = 1; - // NOTE: of course it's a bit of a waste to use the standard loop - // for one single offspring ... - try { - // parser.AddTitle("SSGA Parameters"); - float _rate = parser.getFloat("-ET", "--TSelectSize", "2", - "Selection tournament size" ); - if ( _rate < 1 ) { // binary stochastic tournament - ptselect = new eoStochTournament(_rate); - ptselect_mate = new eoStochTournament(_rate); - } else { // determeinistic tournament of size (int)rate - ptselect = new eoDetTournament((int)_rate); - ptselect_mate = new eoDetTournament((int)_rate); - } - } - catch (std::exception & e) - { - std::cout << e.what() << std::endl; - parser.printHelp(); - exit(1); - } - // end choice of selection - ptreplace = new eoInclusion(); - // put here the choice of elitism - } // end of SSGA - - if (! strcasecmp(Evol.c_str(), "ESPlus") ) { - // ES evolution parameters: lambda = _nb_offspring - - try { - // parser.AddTitle("ES Scheme parameters"); - nb_offspring = parser.getInt("-EL", "--lambda", "50", - "Lambda" ); - ptselect = new eoUniformSelect(); - ptselect_mate = new eoUniformSelect(); - ptreplace = new eoESPlus(); - } - catch (std::exception & e) - { - std::cout << e.what() << std::endl; - parser.printHelp(); - exit(1); - } - } // end of ESPlus - - if (! strcasecmp(Evol.c_str(), "ESComma") ) { - // ES evolution parameters: lambda = _nb_offspring - - try { - // parser.AddTitle("ES Scheme parameters"); - nb_offspring = parser.getInt("-EL", "--lambda", "50", - "Lambda" ); - ptselect = new eoUniformSelect(); - ptselect_mate = new eoUniformSelect(); - ptreplace = new eoESComma(); - } - catch (std::exception & e) - { - std::cout << e.what() << std::endl; - parser.printHelp(); - exit(1); - } - } // end of ESCOmma - - if (! strcasecmp(Evol.c_str(), "EP") ) { - // EP evoltion scheme: only the EP-tournament replacement size is neede - - try { - // parser.AddTitle("EP Scheme parameters"); - nb_offspring = popsize; - ptselect = new eoCopySelect; /* no selection */ - ptselect_mate = new eoUniformSelect(); - /* What, crossover in EP :-) */ - unsigned tsize = parser.getInt("-ET", "--TournamentSize", "6", - "Size of stocahstic replacement tournament" ); - ptreplace = new eoEPTournament(tsize); - } - catch (std::exception & e) - { - std::cout << e.what() << std::endl; - parser.printHelp(); - exit(1); - } - } // end of EP - - - // everyting is read: now the consistency checks and other preliminary steps - nb_offspring = (nb_offspring ? nb_offspring : - (int) (rate_offspring * popsize) ); - if (!nb_offspring) - nb_offspring = 1; /* al least one offspring */ - - } - - - // accessors - unsigned PopSize(){return popsize;} - unsigned NbOffspring(){return nb_offspring ;} - eoSelect* PtSelect(){return ptselect;} - eoSelect* PtSelectMate(){return ptselect_mate;} - eoMerge* PtMerge() {return ptreplace;} - // NOTE: need pointers otherwise you have many warnings when initializing - - /** @name Methods from eoObject */ - //@{ - /** Inherited from eoObject. Returns the class name. - @see eoObject - */ - std::string className() const {return "eoScheme";}; - //@} - private: - unsigned popsize; /* but should it be here ??? */ - unsigned nb_offspring; /* to generate through selection+operators */ - - // these are provisional for later use - - // float rate_offspring; /* or rate */ - // unsigned nb_survive; /* the best guys that are transmitted anyway */ - // float rate_survive; /* or rate */ - // unsigned nb_die; /* the worst guys that do not enev enter selection */ - // float rate_die; /* or rate */ - - eoSelect * ptselect; - eoSelect* ptselect_mate; - eoMerge* ptreplace; - bool elitism; /* put back old best in the new population if necessary */ -}; -/* examples: - for most populat schemes, nb_survive = nb_die = 0 - in GGA and EP, nb_offspring = pop.size() - in ES, nb_offspring = lambda - in SSGA, nb_offspring = 1 (usually) - - elitism can be used anywhere - though stupid in ES, EP and SSGA who are - estd::list by definition -*/ - -#endif _EOSCHEME_H - -/* - ///////////////////////////////// - /// Applies one generation of evolution to the population. - virtual void operator()(eoPop& pop) { - // Determine the number of offspring to create - // either prescribed, or given as a rate - unsigned nb_off_local = (nb_offspring ? nb_offspring : - (int) rint (rate_offspring * pop.size()) ); - nb_off_local = (nb_off_local ? nb_off_local : 1); // in case it is rounded to 0! - - // the worst die immediately - unsigned nb_die_local = (nb_die ? nb_die : - (int) rint (rate_die * pop.size()) ); - // and the best will survive without selection - unsigned nb_survive_local = (nb_survive ? nb_survive : - (int) rint (rate_survive * pop.size()) ); - - // before selection, erase the one to die - // sort old pop - just in case! - sort(pop.begin(), pop.end(), greater()); - Fitness oldBest = pop[0].fitness(); // store for elitism - eoPop fertilepop = pop; - if (nb_die_local) - erase(fertilepop.end()-nb_die_local, fertilepop.end()); - - eoPop offspring; // = select(fertilepop, nb_off_local); - select(fertilepop, offspring, nb_off_local); - - // now apply the operators to offspring - for (unsigned i=0; i* op = seqselop.Op(&id); - while (op) { // NULL if no more operator - EOT mate; - if (op->readArity() == binary) // can eventually be skipped - mate = select_mate(pop, tmp); // though useless ig mutation - else - mate = tmp; // assumed: mate will not be used! - std::cout << op->className() << " for offspring " << i << std::endl; - tmp = (*op)( tmp, mate, pop ); - op = seqselop.Op(&id); - } - offspring[i]=tmp; //* where it belongs - } - - eoPop::iterator i; - // Can't use foreach here since foreach takes the - // parameter by reference - for ( i = offspring.begin(); i != offspring.end(); i++) - evaluator(*i); - - //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - // not exact - later!!! - // -MS- - - // first, copy the ones that need to survive - // assumed: pop is still sorted! - eoPop finalPop; - // and the best survive without selection - if (nb_survive_local) { - finalPop.resize(nb_survive_local); - copy( finalPop.begin(), fertilepop.begin(), - fertilepop.begin()+nb_survive_local ); - } - - // now call the replacement method - replace(finalPop, tmpPop); - - // handle elitlism - sort(finalPop.begin(), finalPop.end(), greater()); - if (elitism) { - if ( finalPop[0].fitness() < oldBest ) // best fitness has decreased! - copy(finalPop.end()-1, pop[0]); - } - // return finalPop; - } -*/ diff --git a/eo/src/obsolete/eoSelectRandom.h b/eo/src/obsolete/eoSelectRandom.h deleted file mode 100644 index 84ea72f8..00000000 --- a/eo/src/obsolete/eoSelectRandom.h +++ /dev/null @@ -1,52 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoSelectRandom.h -// (c) GeNeura Team, 1998 - EEAAX 1999, Maarten Keijzer 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 - Marc.Schoenauer@polytechnique.fr - mak@dhi.dk - */ -//----------------------------------------------------------------------------- - -#ifndef eoSelectRandom_h -#define eoSelectRandom_h - -//----------------------------------------------------------------------------- - -#include -#include - -//----------------------------------------------------------------------------- -/** eoSelectRandom: a selection method that selects ONE individual randomly - -MS- 22/10/99 */ -//----------------------------------------------------------------------------- - -template class eoSelectRandom: public eoSelectOne -{ - public: - - /// not a big deal!!! - virtual const EOT& operator()(const eoPop& pop) - { - return pop[rng.random(pop.size())] ; - } -}; - -#endif eoSelectRandom_h - diff --git a/eo/src/obsolete/eoSequentialGOpSel.h b/eo/src/obsolete/eoSequentialGOpSel.h deleted file mode 100644 index 63acac43..00000000 --- a/eo/src/obsolete/eoSequentialGOpSel.h +++ /dev/null @@ -1,55 +0,0 @@ -/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - - ----------------------------------------------------------------------------- - eoSequentialGOpSel.h - Sequential Generalized Operator Selector. - - (c) Maarten Keijzer (mkeijzer@mad.scientist.com), 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 eoSequentialGOpSel_h -#define eoSequentialGOpSel_h - -//----------------------------------------------------------------------------- - -#include -/** eoSequentialGOpSel: return a sequence of - operations to be applied one after the other. The order of the - operators is significant. If for instance you first add a - quadratic operator and then a mutation operator, - - @see eoGeneralOp, eoCombinedOp -*/ -template -class eoSequentialGOpSel : public eoGOpSelector -{ -public : - - virtual eoGeneralOp& selectOp() - { - return combined.bind(*this, getRates()); - } - -private : - - eoCombinedOp combined; -}; - -#endif - diff --git a/eo/src/obsolete/eoSimpleDEA.h b/eo/src/obsolete/eoSimpleDEA.h deleted file mode 100644 index 3eef44c7..00000000 --- a/eo/src/obsolete/eoSimpleDEA.h +++ /dev/null @@ -1,105 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoSimpleDEA.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 _eoSimpleDEA_h -#define _eoSimpleDEA_h - -//----------------------------------------------------------------------------- - -#include -#include -#include -#include -#include - -/** eoSimpleDEA: a very simple Distribution Evolution Algorithm - * - * The algorithm that evolves a probability distribution - * on the spaces of populations with the loop - * generate a population from the current distribution - * evaluate that population - * update the distribution -*/ - -template class eoSimpleDEA: public eoDEA -{ - public: - - /** Ctor from an eoDistribUpdater - * ... plus an eoEval and eoContinue of course - */ - eoSimpleDEA(eoDistribUpdater& _update, - eoEvalFunc& _eval, - unsigned _popSize, - eoContinue& _continuator - ) : - update(_update), - eval(_eval), - popSize(_popSize), - continuator(_continuator) - {} - - /** The algorithm: - * generate pop from distrib, - * evaluate pop, - * update distrib - */ - virtual void operator()(eoDistribution& _distrib) - { - eoPop pop(popSize, _distrib); - do - { - try - { - apply(_distrib, pop); // re-init. of _pop from distrib - - apply(eval, pop); // eval of current population - - update(_distrib, pop); // updates distrib from _pop - - } - catch (std::exception& e) - { - std::string s = e.what(); - s.append( " in eoSimpleDEA"); - throw std::runtime_error( s ); - } - } while ( continuator( pop ) ); - } - - private: - eoDistribUpdater & update; - - eoEvalFunc& eval; - - unsigned popSize; - - eoContinue& continuator; -}; - -//----------------------------------------------------------------------------- - -#endif - diff --git a/eo/src/obsolete/eoSteadyStateEA.h b/eo/src/obsolete/eoSteadyStateEA.h deleted file mode 100644 index caa9ebed..00000000 --- a/eo/src/obsolete/eoSteadyStateEA.h +++ /dev/null @@ -1,84 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoSteadyStateEA.h -// (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 _eoSteadyStateEA_h -#define _eoSteadyStateEA_h - -//----------------------------------------------------------------------------- - -#include -#include - -/** EOSteadyStateEA: - An easy-to-use evolutionary algorithm, just supply - a general operator selector, a selector for choosing the ones - to reproduce and an eoSteadyStateInserter that takes care of evaluating - and inserter the guy/girl in the steady state population. -*/ -template class eoSteadyStateEA: public eoAlgo -{ - public: - /// Constructor. - eoSteadyStateEA( - eoGOpSelector& _opSelector, - eoSelectOne& _selector, - eoSteadyStateInserter& _inserter, - eoContinue& _continuator, - unsigned _steps = 0 ) - : step(_opSelector, _selector, _inserter, _steps), - continuator( _continuator) - {}; - - /// Constructor from an already created generation - eoSteadyStateEA(eoSteadyStateTransform& _gen, - eoContinue& _continuator): - step(_gen), - continuator( _continuator){}; - - /// Apply one generation of evolution to the population. - virtual void operator()(eoPop& pop) { - do { - try - { - step(pop); - } - catch (std::exception& e) - { - std::string s = e.what(); - s.append( " in eoSteadyStateEA "); - throw std::runtime_error( s ); - } - } while ( continuator( pop ) ); - - } - - private: - eoSteadyStateTransform step; - eoContinue& continuator; -}; - -//----------------------------------------------------------------------------- - -#endif eoEasyEA_h - diff --git a/eo/src/obsolete/eoSteadyStateInserter.h b/eo/src/obsolete/eoSteadyStateInserter.h deleted file mode 100644 index 57fd187e..00000000 --- a/eo/src/obsolete/eoSteadyStateInserter.h +++ /dev/null @@ -1,53 +0,0 @@ -/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - - ----------------------------------------------------------------------------- - eoSteadyStateInserter.h - Still abstract population insertion operator that is initialized with - and eoEvalFunc object to be able to evaluate individuals before inserting - them. - - (c) Maarten Keijzer (mak@dhi.dk) 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 eoSteadyStateInserter_h -#define eoSteadyStateInserter_h - - -#include -#include - -/** - * eoSteadyStateInserter: Interface class that enables an operator to update - * a population with a new individual... it contains an eoEvalFunc derived object to - * make sure that every individual is evaluated before it is inserted -*/ -template -class eoSteadyStateInserter : public eoPopInserter -{ -public : - eoSteadyStateInserter(eoEvalFunc& _eval): - eoPopInserter(), - eval(_eval) {} - -protected : - eoEvalFunc& eval; -}; - - -#endif diff --git a/eo/src/obsolete/eoSteadyStateTransform.h b/eo/src/obsolete/eoSteadyStateTransform.h deleted file mode 100644 index 890920a7..00000000 --- a/eo/src/obsolete/eoSteadyStateTransform.h +++ /dev/null @@ -1,88 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoSteadyStateTransform.h -// (c) Maarten Keijzer 2000, 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 eoSteadyStateTransform_h -#define eoSteadyStateTransform_h - -//----------------------------------------------------------------------------- - -#include // eoPop -#include - -#include -#include -#include - -//----------------------------------------------------------------------------- - -/** eoSteadyStateTransform - * Single step of a steady state evolutionary algorithm. - * Proceeds by updating one individual at a time, by first selecting parents, - * creating one or more children and subsequently overwrite (a) bad individual(s) -*/ -template class eoSteadyStateTransform: public eoTransform -{ - public: - /// Constructor. - eoSteadyStateTransform( - eoGOpSelector& _opSelector, - eoSelectOne& _selector, - eoSteadyStateInserter& _inserter, - unsigned _steps = 0) : - opSelector(_opSelector), - selector(_selector), - inserter(_inserter) , - steps(_steps) {}; - - - /// Apply one generation of evolution to the population. - virtual void operator()(eoPop& pop) - { - unsigned nSteps = steps; - if (nSteps == 0) - { - nSteps = pop.size(); // make a 'generation equivalent' - } - - for (unsigned i = 0; i < nSteps; ++i) - { - selector.bind(pop); - inserter.bind(pop); - - opSelector.selectOp()(selector, inserter); - } - - } - - private: - eoGOpSelector& opSelector; - eoSelectOneIndiSelector selector; - eoSteadyStateInserter& inserter; - unsigned steps; -}; - -//----------------------------------------------------------------------------- - -#endif eoGeneration_h - diff --git a/eo/src/obsolete/eoStochTournament.h b/eo/src/obsolete/eoStochTournament.h deleted file mode 100644 index 5569ce62..00000000 --- a/eo/src/obsolete/eoStochTournament.h +++ /dev/null @@ -1,69 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoStochTournament.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 eoStochTournament_h -#define eoStochTournament_h - -//----------------------------------------------------------------------------- - -#include -#include // accumulate -#include // eoSelectOne -#include // stochastic_tournament - -//----------------------------------------------------------------------------- -/** eoStochTournament: a selection method that selects ONE individual by - binary stochastic tournament - -MS- 24/10/99 */ -//----------------------------------------------------------------------------- - -template class eoStochTournament: public eoSelectOne -{ - public: - - /// - eoStochTournament(float _Trate = 1.0 ) : eoSelectOne(), Trate(_Trate) - { - // consistency check - if (Trate < 0.5) { - std::cerr << "Warning, Tournament rate should be > 0.5\nAdjusted to 0.55\n"; - Trate = 0.55; - } - } - - /** Perform the stochastic tournament */ - virtual const EOT& operator()(const eoPop& pop) - { - return stochastic_tournament(pop, Trate); - } - -private: - float Trate; -}; - -//----------------------------------------------------------------------------- - -#endif eoDetTournament_h - diff --git a/eo/src/obsolete/eoStochTournamentInserter.h b/eo/src/obsolete/eoStochTournamentInserter.h deleted file mode 100644 index 3856aecc..00000000 --- a/eo/src/obsolete/eoStochTournamentInserter.h +++ /dev/null @@ -1,75 +0,0 @@ -/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - - ----------------------------------------------------------------------------- - eoStochTournamentInserter.h - Concrete steady state inserter. It is initialized with a population and - inserts individuals in the population based on an inverse stochastic - 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 eoStochTournamentInserter_h -#define eoStochTournamentInserter_h - - -#include -#include - -/** -\ingroup inserters - * eoStochTournamentInserter: Uses an inverse stochastic tournament to figure - * out who gets overridden by the new individual. It resets the fitness of the - * individual. -*/ -template -class eoStochTournamentInserter : public eoSteadyStateInserter -{ -public : - - eoStochTournamentInserter(eoEvalFunc& _eval, double _t_rate): - eoSteadyStateInserter(_eval), t_rate(_t_rate) - { - if (t_rate < 0.5) - { // warning, error? - t_rate = 0.55; - } - - if (t_rate >= 1.0) - { - t_rate = 0.99; // 1.0 would mean deterministic tournament - } - } - - eoInserter& operator()(const EOT& _eot) - { - EOT& eo = inverse_stochastic_tournament(pop(), t_rate); - eo = _eot; // overwrite loser of tournament - - eo.invalidate(); - return *this; - } - - std::string className(void) const { return "eoStochTournamentInserter"; } - -private : - double t_rate; -}; - -#endif diff --git a/eo/src/obsolete/eoStringMutation.h b/eo/src/obsolete/eoStringMutation.h deleted file mode 100644 index 1612da4a..00000000 --- a/eo/src/obsolete/eoStringMutation.h +++ /dev/null @@ -1,77 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoStringMutation.h -// (c) GeNeura Team, 1999 -/* - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Contact: todos@geneura.ugr.es, http://geneura.ugr.es - */ -//----------------------------------------------------------------------------- - -#ifndef _EOSTRINGMUTATION_H -#define _EOSRTINGMUTATION_H - -#include -// EO includes -#include -#include -#include - -/** Mutation of an eoString. - The eoString's genes are changed by adding or substracting 1 to -*/ - -template -class eoStringMutation: public eoMutation { - public: - - /// - eoStringMutation(const double _rate=0.0) : eoMutation< EOT >(_rate) {}; - - /// - virtual ~eoStringMutation() {}; - - /** @name Methods from eoObject - */ - //@{ - /** Inherited from eoObject - @see eoObject - */ - std::string className() const {return "eoStringMutation";}; - //@} - - - private: - -#ifdef _MSC_VER - typedef EOT::Type Type; -#else - typedef typename EOT::Type Type; -#endif - - /// applies operator to one gene in the EO. It increments or decrements the value of that gene by one. - virtual void applyAt( EOT& _eo, unsigned _i ) const { - if( rate < uniform() ) { - _eo.gene(_i) += ( rng.flip(0.5))? (1) : (-1) ; - } - } - -}; - -//----------------------------------------------------------------------------- - -#endif diff --git a/eo/src/obsolete/eoTerm.h b/eo/src/obsolete/eoTerm.h deleted file mode 100644 index 198cb939..00000000 --- a/eo/src/obsolete/eoTerm.h +++ /dev/null @@ -1,56 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoTerm.h -// (c) 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 _EOTERM_H -#define _EOTERM_H - -//#include - -// forward definition for fast(er) compilation -template class eoPop; - - -/** Termination condition for the genetic algorithm - * Takes the population as input, returns true for continue, - * false for termination (although this begs the question why this - * terminator is not called a continuator) - * - */ -template< class EOT> -class eoTerm : public eoObject { -public: - - /// Ctors/dtors - virtual ~eoTerm() {}; - - /** Returns false if the training has to stop, true if it - continues \\ - It is non-const since it might change the internal state - of the object, for instance, updating local data. - */ - virtual bool operator() ( const eoPop< EOT >& _pop ) = 0 ; -}; - -#endif - diff --git a/eo/src/obsolete/eoTournament.h b/eo/src/obsolete/eoTournament.h deleted file mode 100644 index 01dc4619..00000000 --- a/eo/src/obsolete/eoTournament.h +++ /dev/null @@ -1,157 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - - - -//----------------------------------------------------------------------------- - -// eoTournament.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 _EOGSTOURN_H -#define _EOGSTOURN_H - - -//----------------------------------------------------------------------------- - - -#include -#include - - -//----------------------------------------------------------------------------- - - -/** Selects those who are going to reproduce using Tournament selection: - - a subset of the population of size tournamentSize is chosen, - - and the best is selected for the new population . -@author JJ Merelo, 1998 -*/ -template -class eoTournament:public eoBinPopOp{ -public: - - /// Proportion of guys that are going to be eliminated - eoTournament( float _perc, unsigned _tSize): - eoBinPopOp(), perc( _perc), repTournamentSize(_tSize){}; - - /// Virtual dtor - ~eoTournament(){}; - - /// Set tourn size - void tournamentSize( unsigned _size ) { repTournamentSize = _size; }; - - /** - * Selects from the initial pop using tournament selection, and copies it - - * to the other population. - */ - virtual void operator() ( eoPop& _vEO, eoPop& _aVEO) { - - unsigned thisSize = _vEO.size(); - - // Build std::vector - for ( unsigned j = 0; j < thisSize*perc; j ++ ) { - // Randomly select a tournamentSize set, and choose the best - eoPop veoTournament; - - for ( unsigned k = 0; k < repTournamentSize; k++ ) { - unsigned chosen = rng.random(thisSize); - EOT newEO = _vEO[chosen]; - veoTournament.push_back( newEO ); - } - - eoPop::const_iterator best = std::max_element(veoTournament.begin(), - veoTournament.end()); - if (best == veoTournament.end()) { - throw std::runtime_error("error in void eoTournament::operator(eoPop&, eoPop&)"); - } - - // The best individual is chosen for the new population - _aVEO.push_back( *best ); - } - }; - - - /// @name Methods from eoObject - - //@{ - - /** - - * Read object. Reads the percentage - - * Should call base class, just in case. - - * @param _s A std::istream. - - */ - - virtual void readFrom(std::istream& _s) { - - _s >> perc >> repTournamentSize; - - } - - - - /** Print itself: inherited from eoObject implementation. Declared virtual so that - - it can be reimplemented anywhere. 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{ - - _s << perc << std::endl << repTournamentSize << std::endl; - - } - - - - /** Inherited from eoObject - - @see eoObject - - */ - - std::string className() const {return "eoTournament";}; - - - - //@} - - - private: - - float perc; - unsigned repTournamentSize; - -}; - -#endif diff --git a/eo/src/obsolete/eoTranspose.h b/eo/src/obsolete/eoTranspose.h deleted file mode 100644 index 51671830..00000000 --- a/eo/src/obsolete/eoTranspose.h +++ /dev/null @@ -1,94 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoTranspose.h -// (c) GeNeura Team, 1998 Maarten Keijzer 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 _EOTRANSPOSE_h -#define _EOTRANSPOSE_h - -#include -#include - -#include -#include -#include -#include -/** -Transposition operator: interchanges the position of two genes -of an EO. -*/ -template -class eoTranspose: public eoMonOp -{ -public: - - // Specialization for a std::vector - void operator()(eoFixedLength& _eo ) - { - unsigned pos1 = rng.random(_eo.size()), - pos2 = rng.random(_eo.size()); - - if (pos1 != pos2) - swap(_eo[pos1], _eo[pos2]); - - if (_eo[pos1] != _eo[pos2]) - _eo.invalidate(); - } - - // Specialization for a std::list - void operator()(eoVariableLength& _eo ) - { - unsigned pos1 = rng.random(_eo.size()), - pos2 = rng.random(_eo.size()); - - if (pos1 == pos2) - return; - - if (pos1 > pos2) - swap(pos1,pos2); - - pos2 -= pos1; - - typename EOT::iterator it1 = _eo.begin(); - - while (pos1--) {it1++;} - - typename EOT::iterator it2 = it1; - - while (pos2--) {it2++;} - - swap(*it1, *it2); - - if (*it1 != *it2) - _eo.invalidate(); - } - - /** Inherited from eoObject - @see eoObject - */ - virtual std::string className() const {return "eoTranspose";}; - //@} - -}; - -#endif - diff --git a/eo/src/obsolete/eoUniformXOver.h b/eo/src/obsolete/eoUniformXOver.h deleted file mode 100644 index 76623a0e..00000000 --- a/eo/src/obsolete/eoUniformXOver.h +++ /dev/null @@ -1,176 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - - - -//----------------------------------------------------------------------------- - -// eoUniformXOver.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 _EOUNIFORMXOVER_h - -#define _EOUNIFORMXOVER_h - - - - - -// for swap - -#if defined( __BORLANDC__ ) - -#include - -#else - -#include - -#endif - - - -// EO includes - -#include - -#include - - - -//----------------------------------------------------------------------------- - -/** - - * EOUniformCrossover: operator for binary chromosomes - - * implementation of uniform crossover for EO - - * swaps ranges of bits between the parents - - */ - -//----------------------------------------------------------------------------- - - - -template - -class eoUniformXOver: public eoQuadraticOp< EOT > - -{ - - public: - - - - /// - - eoUniformXOver( float _rate = 0.5 ): - - eoQuadraticOp< EOT > ( ), rate( _rate ) { - - if (rate < 0 || rate > 1) - - std::runtime_error("UxOver --> invalid rate"); - - } - - - - - - /// - - void operator() ( EOT& chrom1, EOT& chrom2 ) const { - - unsigned end = min(chrom1.length(),chrom2.length()) - 1; - - // select bits to change - - // aply changes - - for (unsigned bit = 0; bit < end; bit++) - - if (rng.flip(rate)) - - swap(chrom1[ bit], chrom2[ bit]); - - } - - - - /** @name Methods from eoObject - - readFrom and printOn are directly inherited from eoOp - - */ - - //@{ - - /** Inherited from eoObject - - @see eoObject - - */ - - std::string className() const {return "eoUniformXOver";}; - - //@} - - - -private: - - float rate; /// rate of uniform crossover - -}; - - - -//----------------------------------------------------------------------------- - - - - - -#endif - diff --git a/eo/src/obsolete/eoVector.h b/eo/src/obsolete/eoVector.h deleted file mode 100644 index 315683f5..00000000 --- a/eo/src/obsolete/eoVector.h +++ /dev/null @@ -1,170 +0,0 @@ -/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - - ----------------------------------------------------------------------------- - eoVector.h - Turns an STL std::vector into an 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 _eoVector_H -#define _eoVector_H - -// STL libraries -#include // For std::vector -#include -#include - -#include -#include - -/** Adaptor that turns an STL std::vector into an EO - with the same gene type as the type with which - the std::vector has been instantiated -*/ -template -class eoVector: public eo1d, public std::vector { -public: - typedef T Type ; - - /// Canonical part of the objects: several ctors, copy ctor, dtor and assignment operator - //@{ - - /** Ctor. - @param _size Lineal length of the object - @param _val Common initial value - */ - eoVector( unsigned _size = 0, T _val = 0) - : eo1d(), std::vector( _size, _val ){ }; - - /** Ctor using a random number generator - @param _size Lineal length of the object - @param _rnd a random number generator, which returns a random value each time itīs called - */ - eoVector( unsigned _size, eoRnd& _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 - */ - eoVector( std::istream& _is); - - - /// copy ctor - eoVector( const eoVector & _eo ) - : eo1d( _eo ), std::vector( _eo ){ }; - - /// Assignment operator - const eoVector& operator =( const eoVector & _eo ) { - if ( this != &_eo ){ - eo1d::operator=( _eo ); - std::vector::operator=( _eo ); - } - return *this; - } - - /// dtor - virtual ~eoVector() {}; - - //@} - - /** methods that implement the eo1d protocol - @std::exception out_of_range if _i is larger than EOīs size - */ - virtual T getGene( unsigned _i ) const { - if ( _i >= length() ) - throw out_of_range( "out_of_range when reading gene"); - return (*this)[_i]; - }; - - /** methods that implement the eo1d protocol - @std::exception out_of_range if _i is larger than EOīs size - */ - virtual void setGene( unsigned _i, const T& _value ) { - if ( _i >= size() ) - throw out_of_range( "out_of_range when writing a gene"); - (*this)[_i] = _value; - }; - - /** methods that implement the eo1d protocol - @std::exception out_of_range if _i is larger than EOīs size - */ - virtual void insertGene( unsigned _i, T _val ) { - if (_i <= size() ) { - std::vector::iterator i = begin()+_i; - insert( i, _val ); - } else { - throw out_of_range( "out_of_range when inserting a gene"); - } - }; - - /** Eliminates the gene at position _i - @std::exception out_of_range if _i is larger than EOīs size - */ - virtual void deleteGene( unsigned _i ) { - if (_i < this->size() ) { - std::vector::iterator i = this->begin()+_i; - this->erase( i ); - } else { - throw out_of_range( "out_of_range when deleting a gene"); - }; - }; - - /// methods that implement the EO protocol - virtual unsigned length() const { return this->size(); }; - - /** @name Methods from eoObject - readFrom and printOn are directly inherited from eo1d - */ - //@{ - /** Inherited from eoObject - @see eoObject - */ - std::string className() const {return "eoVector";}; - //@} - -}; - - -//____________________________ Some method implementation _______________________ - -// Ctors______________________________________________________________________________ -//____________________________________________________________________________________ -template -eoVector::eoVector( unsigned _size, eoRnd& _rnd ) - : eo1d(), std::vector( _size ){ - for ( iterator i = begin(); i != end(); i ++ ) { - *i = _rnd(); - } -}; - -//____________________________________________________________________________________ -template -eoVector::eoVector( std::istream& _is) - : eo1d(), std::vector( ){ - while (_is ) { - T tmp; - _is >> tmp; - push_back( tmp ); - } - -}; - -#endif diff --git a/eo/src/obsolete/eoWrappedOps.h b/eo/src/obsolete/eoWrappedOps.h deleted file mode 100644 index 805bb29e..00000000 --- a/eo/src/obsolete/eoWrappedOps.h +++ /dev/null @@ -1,200 +0,0 @@ -/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - - ----------------------------------------------------------------------------- - eoWrappedOps.h - Derived from the General genetic operator, which can be used to wrap any unary or binary - operator. File also contains the eoCombinedOp, needed by the eoSequentialGOpSelector - - (c) Maarten Keijzer (mak@dhi.dk) 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 eoWrappedOps_h -#define eoWrappedOps_h - -//----------------------------------------------------------------------------- - -#include // eoOp, eoMonOp, eoBinOp -#include - -using namespace std; - -/// Wraps monary operators -template -class eoWrappedMonOp : public eoGeneralOp -{ -public : - /// - eoWrappedMonOp(eoMonOp& _op) : eoGeneralOp(), op(_op) {}; - - /// - virtual ~eoWrappedMonOp() {} - - /// Instantiates the abstract method - void operator()( eoIndiSelector& _in, - eoInserter& _out) - { - EOT result = _in(); - op( result ); - _out(result); - } - -private : - eoMonOp& op; -}; - - -/// Wraps binary operators -template -class eoWrappedBinOp : public eoGeneralOp -{ -public : - /// - eoWrappedBinOp(eoBinOp& _op) : eoGeneralOp(), op(_op) {} - - /// - virtual ~eoWrappedBinOp() {} - - /// Instantiates the abstract method. EOT should have copy ctor. - void operator()(eoIndiSelector& _in, - eoInserter& _out) - { - EOT out1 = _in(); - const EOT& out2 = _in(); - op(out1, out2); - _out(out1); - } - -private : - eoBinOp& op; -}; - -/// Wraps Quadratic operators -template -class eoWrappedQuadraticOp : public eoGeneralOp -{ -public : - /// - eoWrappedQuadraticOp(eoQuadraticOp& _op) : eoGeneralOp(), op(_op) {} - - /// - virtual ~eoWrappedQuadraticOp() {} - - /// Instantiates the abstract method. EOT should have copy ctor. - void operator()(eoIndiSelector& _in, - eoInserter& _out) - { - EOT out1 = _in(); - EOT out2 = _in(); - op(out1, out2); - _out(out1)(out2); - } - -private : - eoQuadraticOp& op; -}; - -#include - -template -class eoCombinedOp : public eoGeneralOp -{ - public : - eoCombinedOp& bind(const std::vector*>& _ops, const std::vector& _rates) - { - ops = &_ops; - rates = &_rates; - return *this; - } - - class eoDelayedSelector : public eoIndiSelector - { - public : - eoDelayedSelector(eoIndiSelector& _select, const eoPop& _pop) : select(_select), pop(_pop), it(pop.begin()) {} - - unsigned size() const { return select.size();} - const EOT& operator[](size_t i) const { return select[i]; } - - /// will first dispense all previously selected individuals before returning new ones - const EOT& operator()(void) - { - if (it == pop.end()) - { - return select(); - } - // else - return *it++; - } - - eoPop::const_iterator get_it(void) const { return it; } - private : - eoIndiSelector& select; - const eoPop& pop; - eoPop::const_iterator it; - }; - - /** Applies all ops in the combined op - It first applies the - */ - void operator()( eoIndiSelector& _in, - eoInserter& _out ) - { - eoPop intermediate; - eoPop next; - unsigned i; - - for (i = 0; i < ops->size(); ++i) - { - eoDelayedSelector delay(_in, intermediate); - inserter.bind(next); - - unsigned counter = 0; - - // apply operators until we have as many outputs as inputs - do - { - if (rng.flip(rates->operator[](i))) // should this flip be here? - (*ops->operator[](i))(delay, inserter); - - counter++; - if (counter > 1000) - { - throw std::logic_error("eoCombinedOp: no termination after 1000 tries, did you forget to insert individuals in your eoGeneralOp?"); - } - } - while (next.size() < intermediate.size()); - - intermediate.swap(next); - next.resize(0); - } - - // after last swap, results can be found in intermediate - for (i = 0; i < intermediate.size(); ++i) - _out(intermediate[i]); - } - - private : - const std::vector*>* ops; - const std::vector* rates; - eoBackInserter inserter; -}; - -#endif - diff --git a/eo/src/obsolete/eoXOver2.h b/eo/src/obsolete/eoXOver2.h deleted file mode 100644 index d1f53852..00000000 --- a/eo/src/obsolete/eoXOver2.h +++ /dev/null @@ -1,107 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoXOver2.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 _EOXOVER2_h -#define _EOXOVER2_h - - -// for swap -#if defined( __BORLANDC__ ) -#include -#else -#include -#endif - -// EO includes -#include -#include - -/** 2-point crossover: takes the genes in the central section of two EOs -and interchanges it -*/ -template -class eoXOver2: public eoQuadraticOp { -public: - /// - eoXOver2() - : eoQuadraticOp< EOT >(){}; - - /// - virtual ~eoXOver2() {}; - - /// - virtual void operator()( EOT& _eo1, - EOT& _eo2 ) const { - unsigned len1 = _eo1.length(), len2 = _eo2.length(), - len= (len1 > len2)?len2:len1; - - unsigned pos1 = rng.random(len), pos2 = rng.random(len) ; - - applyAt( _eo1, _eo2, pos1, pos2 ); - - } - - /** @name Methods from eoObject - readFrom and printOn are directly inherited from eoOp - */ - //@{ - /** Inherited from eoObject - @see eoObject - */ - std::string className() const {return "eoXOver2";}; - //@} - -private: - -#ifdef _MSC_VER - typedef EOT::Type Type; -#else - typedef typename EOT::Type Type; -#endif - - /// applies operator to one gene in the EO - virtual void applyAt( EOT& _eo, EOT& _eo2, - unsigned _i, unsigned _j = 0) const { - - if ( _j < _i ) - swap( _i, _j ); - - unsigned len1 = _eo.length(), len2 = _eo2.length(), - len= (len1 > len2)?len2:len1; - - if ( (_j > len) || (_i> len ) ) - throw std::runtime_error( "xOver2: applying xOver past boundaries"); - - for ( unsigned i = _i; i < _j; i++ ) { - Type tmp = _eo.gene( i ); - _eo.gene( i ) = _eo2.gene( i ); - _eo2.gene( i ) = tmp ; - } - - } - -}; - -#endif - diff --git a/eo/src/obsolete/evolution_strategies b/eo/src/obsolete/evolution_strategies deleted file mode 100644 index d1c729ba..00000000 --- a/eo/src/obsolete/evolution_strategies +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef _eoEs_h -#define _eoEs_h - -#include -#include -#include -#include - -#include -#include - -#include - - -#endif