diff --git a/eo/doc/eo.cfg.cmake b/eo/doc/eo.cfg.cmake index 362102bb..f030f3b3 100644 --- a/eo/doc/eo.cfg.cmake +++ b/eo/doc/eo.cfg.cmake @@ -628,7 +628,7 @@ EXCLUDE_SYMBOLS = # directories that contain example code fragments that are included (see # the \include command). -EXAMPLE_PATH = +EXAMPLE_PATH = @CMAKE_SOURCE_DIR@/test # If the value of the EXAMPLE_PATH tag contains directories, you can use the # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp diff --git a/eo/doc/index.h b/eo/doc/index.h index f71a7c1f..7d7921fe 100644 --- a/eo/doc/index.h +++ b/eo/doc/index.h @@ -60,4 +60,3 @@ article in Lecture Notes In Computer Science, 2310, Selected Papers from the 5th - http://eodev.sourceforge.net/eo/doc/LeCreusot.pdf - http://eodev.sourceforge.net/eo/doc/EO_EA2001.pdf */ - diff --git a/eo/src/EO.h b/eo/src/EO.h index 7d8f5f55..2c43b2c8 100644 --- a/eo/src/EO.h +++ b/eo/src/EO.h @@ -55,6 +55,8 @@ @ref Operators that effectively modify EO objects must invalidate them. The fitness object must have, besides an void ctor, a copy ctor. + + @example t-eo.cpp */ template class EO: public eoObject, public eoPersistent { diff --git a/eo/src/do/make_algo_scalar.h b/eo/src/do/make_algo_scalar.h index 1a207626..5a63eb9d 100644 --- a/eo/src/do/make_algo_scalar.h +++ b/eo/src/do/make_algo_scalar.h @@ -307,5 +307,7 @@ eoAlgo & do_make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc // that's it! return *algo; } +/** @example t-eoGA.cpp + */ #endif diff --git a/eo/src/eoEasyEA.h b/eo/src/eoEasyEA.h index e8497707..4fc6d6e7 100644 --- a/eo/src/eoEasyEA.h +++ b/eo/src/eoEasyEA.h @@ -273,9 +273,11 @@ template class eoEasyEA: public eoAlgo // Friend classes friend class eoIslandsEasyEA ; friend class eoDistEvalEasyEA ; - }; - -//----------------------------------------------------------------------------- +}; +/** +@example t-eoEasyEA.cpp +Example of a test program building an EA algorithm. +*/ #endif diff --git a/eo/src/eoEasyPSO.h b/eo/src/eoEasyPSO.h index 7cdbf339..bcfc891a 100644 --- a/eo/src/eoEasyPSO.h +++ b/eo/src/eoEasyPSO.h @@ -188,6 +188,9 @@ protected: }dummyInit; }; - +/** + * @example t-eoEasyPSO.cpp + * Example of a test program building a PSO algorithm. + */ #endif /*_EOEASYPSO_H*/ diff --git a/eo/src/eoExtendedVelocity.h b/eo/src/eoExtendedVelocity.h index 687a11a8..5aec4c21 100644 --- a/eo/src/eoExtendedVelocity.h +++ b/eo/src/eoExtendedVelocity.h @@ -35,7 +35,9 @@ //----------------------------------------------------------------------------- -/** Extended velocity performer for particle swarm optimization. Derivated from abstract eoVelocity, +/** Extended velocity performer for particle swarm optimization. + * + * Derivated from abstract eoVelocity, * At step t: v(t+1)= w * v(t) + c1 * r1 * ( xbest(t)-x(t) ) + c2 * r2 * ( lbest(t) - x(t) ) + c3 * r3 * ( gbest(t) - x(t) ) * It includes both a "topology" best and a global best in the social knowledge. Each topology * provides a method to retrieve the global best <=> the best of all the neighborhood the topology contains. @@ -60,7 +62,7 @@ public: * @param _c3 - Learning factor used for the global best * @param _bounds - An eoRealBaseVectorBounds: real bounds for real velocities. * If the velocities are not real, they won't be bounded by default. Should have a eoBounds ? - * @param _boundsModifier - An eoRealBoundModifier used to modify the bounds (for real bounds only). + * @param _bndsModifier - An eoRealBoundModifier used to modify the bounds (for real bounds only). * @param _gen - The eo random generator, default=rng */ eoExtendedVelocity (eoTopology < POT > & _topology, @@ -204,7 +206,9 @@ protected: // If the bound modifier doesn't need to be used, use the dummy instance eoDummyRealBoundModifier dummyModifier; }; - - +/** @todo this example does not appear in the doc for an unknown reason + * @example t-eoExtendedVelocity.cpp + * Example of a test program using this class: +*/ #endif /*eoExtendedVelocity_H */ diff --git a/eo/src/eoFunctor.h b/eo/src/eoFunctor.h index 7b14d55f..17cbaca5 100644 --- a/eo/src/eoFunctor.h +++ b/eo/src/eoFunctor.h @@ -60,6 +60,8 @@ public : /// tag to identify a binary function in compile time function selection @see functor_category struct binary_function_tag {}; }; +/** @example t-eoFunctop.cpp + */ /** Basic Function. Derive from this class when defining diff --git a/eo/src/eoGenOp.h b/eo/src/eoGenOp.h index e3964905..86d4ebbd 100644 --- a/eo/src/eoGenOp.h +++ b/eo/src/eoGenOp.h @@ -81,6 +81,8 @@ class eoGenOp : public eoOp, public eoUF &, void> */ virtual void apply(eoPopulator& _pop) = 0; }; +/** @example t-eoGenOp.cpp + */ /** Wrapper for eoMonOp */ diff --git a/eo/src/eoInit.h b/eo/src/eoInit.h index f787b933..bfa616c2 100644 --- a/eo/src/eoInit.h +++ b/eo/src/eoInit.h @@ -183,6 +183,8 @@ class eoInitPermutation: public eoInit unsigned startFrom; UF_random_generator gen; }; +/** @example t-eoInitPermutation.cpp + */ /** diff --git a/eo/src/eoInt.h b/eo/src/eoInt.h index e4f35079..d3eb496c 100644 --- a/eo/src/eoInt.h +++ b/eo/src/eoInt.h @@ -54,6 +54,8 @@ template class eoInt: public eoVector } }; +/** @example t-eoInt.cpp + */ //----------------------------------------------------------------------------- diff --git a/eo/src/eoOp.h b/eo/src/eoOp.h index 849a6da0..bd9fe4e1 100644 --- a/eo/src/eoOp.h +++ b/eo/src/eoOp.h @@ -63,10 +63,16 @@ Variators are operators that modify individuals. Selectors are operators that select a subset of a population. +Example: +@include t-eoSelect.cpp + @defgroup Replacors Replacement operators Replacors are operators that replace a subset of a population by another set of individuals. + +Here is an example with several replacement operators: +@include t-eoReplacement.cpp */ /** Abstract data types for EO operators. diff --git a/eo/src/eoOrderXover.h b/eo/src/eoOrderXover.h index 211af69b..234d4311 100644 --- a/eo/src/eoOrderXover.h +++ b/eo/src/eoOrderXover.h @@ -84,5 +84,7 @@ template class eoOrderXover: public eoQuadOp } }; +/** @example t-eoOrderXover.cpp + */ #endif diff --git a/eo/src/eoProportionalSelect.h b/eo/src/eoProportionalSelect.h index c5a895ff..bd788048 100644 --- a/eo/src/eoProportionalSelect.h +++ b/eo/src/eoProportionalSelect.h @@ -81,5 +81,7 @@ private : typedef std::vector FitVec; FitVec cumulative; }; +/** @example t-eoRoulette.cpp + */ #endif diff --git a/eo/src/eoRingTopology.h b/eo/src/eoRingTopology.h index 352a6e2a..8d74a83a 100644 --- a/eo/src/eoRingTopology.h +++ b/eo/src/eoRingTopology.h @@ -188,5 +188,7 @@ protected: unsigned neighborhoodSize; bool isSetup; }; +/** @example t-eoRingTopology.cpp + */ #endif /*EORINGTOPOLOGY_H_*/ diff --git a/eo/src/eoScalarFitness.h b/eo/src/eoScalarFitness.h index 906c8c8e..aa8d57a1 100644 --- a/eo/src/eoScalarFitness.h +++ b/eo/src/eoScalarFitness.h @@ -79,6 +79,9 @@ class eoScalarFitness private : ScalarType value; }; +/** @example t-eofitness.cpp + * + */ /** Typedefs for fitness comparison, Maximizing Fitness compares with less, diff --git a/eo/src/eoScalarFitnessAssembled.h b/eo/src/eoScalarFitnessAssembled.h index c0d69f5a..f84a805d 100644 --- a/eo/src/eoScalarFitnessAssembled.h +++ b/eo/src/eoScalarFitnessAssembled.h @@ -77,6 +77,8 @@ public: private: static std::vector TermDescriptions; }; +/** @example t-eoFitnessAssembled.cpp + */ //! Implements fitness as std::vector, storing all values that might occur during fitness assembly /*! Properties: @@ -237,6 +239,10 @@ public: bool operator>=(const eoScalarFitnessAssembled& y ) const { return !(*this < y); } }; +/** + * @example t-eoFitnessAssembledEA.cpp +*/ + /** Typedefs for fitness comparison, Maximizing Fitness compares with less, diff --git a/eo/src/eoSecondsElapsedContinue.h b/eo/src/eoSecondsElapsedContinue.h index 819f7ab5..4a9d677f 100644 --- a/eo/src/eoSecondsElapsedContinue.h +++ b/eo/src/eoSecondsElapsedContinue.h @@ -64,6 +64,8 @@ public: } }; +/** @example t-eoSecondsElapsedContinue.cpp + */ #endif diff --git a/eo/src/eoSelectOne.h b/eo/src/eoSelectOne.h index 690fbca6..f4cde80c 100644 --- a/eo/src/eoSelectOne.h +++ b/eo/src/eoSelectOne.h @@ -53,6 +53,8 @@ class eoSelectOne : public eoUF&, const EOT&> (void)_pop; } }; +/** @example t-eoSelectOne.cpp + */ #endif diff --git a/eo/src/eoSharingSelect.h b/eo/src/eoSharingSelect.h index 9fdbfd14..75daa0ae 100644 --- a/eo/src/eoSharingSelect.h +++ b/eo/src/eoSharingSelect.h @@ -53,5 +53,7 @@ public: private : eoSharing sharing; // derived from eoPerf2Worth }; +/** @example t-eoSharing.cpp + */ #endif diff --git a/eo/src/eoShiftMutation.h b/eo/src/eoShiftMutation.h index 9f472360..cacb9b3d 100644 --- a/eo/src/eoShiftMutation.h +++ b/eo/src/eoShiftMutation.h @@ -83,6 +83,8 @@ template class eoShiftMutation: public eoMonOp } }; +/** @example t-eoShiftMutation.cpp + */ //----------------------------------------------------------------------------- diff --git a/eo/src/eoStochasticUniversalSelect.h b/eo/src/eoStochasticUniversalSelect.h index cd0c1973..003c7012 100644 --- a/eo/src/eoStochasticUniversalSelect.h +++ b/eo/src/eoStochasticUniversalSelect.h @@ -104,5 +104,7 @@ private : typedef std::vector IndexVec; IndexVec indices; }; +/** @example t-eoRoulette.cpp + */ #endif diff --git a/eo/src/eoSwapMutation.h b/eo/src/eoSwapMutation.h index aab729b2..63169a9b 100644 --- a/eo/src/eoSwapMutation.h +++ b/eo/src/eoSwapMutation.h @@ -75,6 +75,8 @@ template class eoSwapMutation: public eoMonOp private: unsigned int howManySwaps; }; +/** @example t-eoSwapMutation.cpp + */ //----------------------------------------------------------------------------- #endif diff --git a/eo/src/eoSyncEasyPSO.h b/eo/src/eoSyncEasyPSO.h index 849e9223..aa1c9130 100644 --- a/eo/src/eoSyncEasyPSO.h +++ b/eo/src/eoSyncEasyPSO.h @@ -253,6 +253,8 @@ private: }dummyInit; }; +/** @example t-eoSyncEasyPSO.cpp + */ #endif /*_EOSYNCEASYPSO_H*/ diff --git a/eo/src/eoTwoOptMutation.h b/eo/src/eoTwoOptMutation.h index 2cba79e3..49b199a0 100644 --- a/eo/src/eoTwoOptMutation.h +++ b/eo/src/eoTwoOptMutation.h @@ -69,6 +69,8 @@ public: } }; +/** @example t-eoTwoOptMutation.cpp + */ //----------------------------------------------------------------------------- diff --git a/eo/src/eoVariableInertiaWeightedVelocity.h b/eo/src/eoVariableInertiaWeightedVelocity.h index 9d039ee6..d281b39d 100644 --- a/eo/src/eoVariableInertiaWeightedVelocity.h +++ b/eo/src/eoVariableInertiaWeightedVelocity.h @@ -60,7 +60,7 @@ public: * @param _c2 - The second learning factor used for the local/global best(s). Type must be POT::ParticleVelocityType * @param _bounds - An eoRealBaseVectorBounds: real bounds for real velocities. * If the velocities are not real, they won't be bounded by default. Should have a eoBounds ? - * @param _boundsModifier - An eoRealBoundModifier used to modify the bounds (for real bounds only). + * @param _bndsModifier - An eoRealBoundModifier used to modify the bounds (for real bounds only). * @param _gen - The eo random generator, default=rng */ eoVariableInertiaWeightedVelocity (eoTopology < POT > & _topology, diff --git a/eo/src/eoVariableLengthMutation.h b/eo/src/eoVariableLengthMutation.h index 6845ce0c..aad778ba 100644 --- a/eo/src/eoVariableLengthMutation.h +++ b/eo/src/eoVariableLengthMutation.h @@ -56,7 +56,7 @@ public : /** default ctor - * @param nMax max number of atoms + * @param _nMax max number of atoms * @param _atomInit an Atom initializer */ eoVlAddMutation(unsigned _nMax, eoInit & _atomInit) : @@ -118,15 +118,15 @@ public : /** ctor with an external gene chooser - * @param nMin min number of atoms to leave in the individual - * @param _geneChooser an eoGeneCHooser to choose which one to delete + * @param _nMin min number of atoms to leave in the individual + * @param _chooser an eoGeneCHooser to choose which one to delete */ eoVlDelMutation(unsigned _nMin, eoGeneDelChooser & _chooser) : nMin(_nMin), uChooser(), chooser(_chooser) {} /** ctor with uniform gene chooser - the default - * @param nMin min number of atoms to leave in the individual + * @param _nMin min number of atoms to leave in the individual */ eoVlDelMutation(unsigned _nMin) : nMin(_nMin), uChooser(), chooser(uChooser) {} diff --git a/eo/src/eoVector.h b/eo/src/eoVector.h index c11b8be6..0e1b6d91 100644 --- a/eo/src/eoVector.h +++ b/eo/src/eoVector.h @@ -66,8 +66,8 @@ public: /** default constructor - @param size Length of vector (default is 0) - @param value Initial value of all elements (default is default value of type GeneType) + @param _size Length of vector (default is 0) + @param _value Initial value of all elements (default is default value of type GeneType) */ eoVector(unsigned _size = 0, GeneType _value = GeneType()) : EO(), std::vector(_size, _value) @@ -129,6 +129,8 @@ public: } } }; +/** @example t-eoVector.cpp + */ /** Less than diff --git a/eo/src/eoVectorParticle.h b/eo/src/eoVectorParticle.h index 31d9c981..4736639a 100644 --- a/eo/src/eoVectorParticle.h +++ b/eo/src/eoVectorParticle.h @@ -66,9 +66,9 @@ public: /** Default constructor. * @param _size Length of the tree vectors (we expect the same size), default is 0 - * @param position - * @param velocity - * @param bestPositions + * @param _position + * @param _velocity + * @param _bestPositions */ eoVectorParticle (unsigned _size = 0,PositionType _position = PositionType (), VelocityType _velocity = VelocityType (), PositionType _bestPositions = PositionType ()):PO < FitT > (),std::vector < PositionType > (_size, _position), bestPositions (_size, _bestPositions), velocities (_size, _velocity) diff --git a/eo/src/es/eoReal.h b/eo/src/es/eoReal.h index 5674e8ae..8c079c5f 100644 --- a/eo/src/es/eoReal.h +++ b/eo/src/es/eoReal.h @@ -54,6 +54,8 @@ template class eoReal: public eoVector } }; +/** @example t-eoReal.cpp + */ //----------------------------------------------------------------------------- diff --git a/eo/src/ga/eoBit.h b/eo/src/ga/eoBit.h index 758d1ee7..cf12e9e5 100644 --- a/eo/src/ga/eoBit.h +++ b/eo/src/ga/eoBit.h @@ -44,7 +44,10 @@ /** @defgroup bitstring Bit strings -Various functions for a bitstring representation +Various functions for a bitstring representation. + +Example of a complete test program that use various bitstrings operators: +@include t-eobin.cpp @ingroup Representations */ diff --git a/eo/src/gp/eoParseTree.h b/eo/src/gp/eoParseTree.h index cb5f32af..0c74d466 100644 --- a/eo/src/gp/eoParseTree.h +++ b/eo/src/gp/eoParseTree.h @@ -41,6 +41,9 @@ using namespace gp_parse_tree; Various functions for tree-based Genetic Programming +Example: +@include t-eoSymreg.cpp + @ingroup Representations */ @@ -166,6 +169,8 @@ public: */ } }; +/** @example t-eoSymreg.cpp + */ // friend function to print eoParseTree template diff --git a/eo/src/gp/parse_tree.h b/eo/src/gp/parse_tree.h index 0e85b576..8437c0c7 100644 --- a/eo/src/gp/parse_tree.h +++ b/eo/src/gp/parse_tree.h @@ -22,8 +22,9 @@ class Node (your node in the tree) must have the following implemented: ****** Arity ****** - + \code int arity(void) const + \endcode Note: the default constructor of a Node should provide a Node with arity 0! @@ -36,7 +37,9 @@ is the simplest evaluation, it will call + \code RetVal Node::operator()(RetVal, subtree::const_iterator) + \endcode (Unfortunately the first RetVal argument is mandatory (although you might not need it. This is because MSVC does not support member template @@ -50,7 +53,9 @@ will call: + \code RetVal Node::operator()(RetVal, subtree<... , It values) + \endcode where It is whatever type you desire (most of the time this will be a std::vector containing the values of your @@ -60,7 +65,9 @@ will call: + \code RetVal Node::operator()(RetVal, subtree<... , It values, It2 moreValues) + \endcode although I do not see the immediate use of this, however... @@ -68,7 +75,9 @@ that calls: + \code RetVal Node::operator()(subtree<... , It values, It2 args, It3 adfs) + \endcode can be useful for implementing adfs. @@ -77,8 +86,10 @@ arguments open so that different ways of evaluation remain possible. Implement the simplest eval as: + \code template RetVal operator()(RetVal dummy, It begin) const + \endcode ****** Internal Structure ****** @@ -144,7 +155,9 @@ or from an std::istream: - copy(std::istream_iterator(my_stream), std::istream_iterator(), back_inserter(tree)); +\code + copy(std::istream_iterator(my_stream), std::istream_iterator(), back_inserter(tree)); +\endcode Note that the back_inserter must be used as there is no resize member in the parse_tree. back_inserter will use diff --git a/eo/src/other/eoExternalEO.h b/eo/src/other/eoExternalEO.h index 219cf716..4440b428 100644 --- a/eo/src/other/eoExternalEO.h +++ b/eo/src/other/eoExternalEO.h @@ -74,6 +74,8 @@ public : } }; +/** @example t-eoExternalEO.cpp + */ /** To remove ambiguities between EO and External, streaming operators are defined yet again * @ingroup Utilities diff --git a/eo/src/utils/eoCheckPoint.h b/eo/src/utils/eoCheckPoint.h index 775c00fb..d6df8b78 100644 --- a/eo/src/utils/eoCheckPoint.h +++ b/eo/src/utils/eoCheckPoint.h @@ -39,10 +39,13 @@ * * Use them with eoStats, eoUpdater and eoMonitor to get statistics at each generation. * - * @see eoStats + * @see eoStat * @see eoMonitor * @see eoUpdater * + * Example of a test program using checkpointing: + * @include t-eoCheckpointing.cpp + * * @ingroup Utilities * * @{ diff --git a/eo/src/utils/eoLogger.h b/eo/src/utils/eoLogger.h index 5d66f376..c5ca7e3d 100644 --- a/eo/src/utils/eoLogger.h +++ b/eo/src/utils/eoLogger.h @@ -247,6 +247,8 @@ private: */ std::map< std::ostream*, int > _standard_io_streams; }; +/** @example t-eoLogger.cpp + */ namespace eo { diff --git a/eo/src/utils/eoRNG.h b/eo/src/utils/eoRNG.h index ad1e3aa1..3cad9fcc 100644 --- a/eo/src/utils/eoRNG.h +++ b/eo/src/utils/eoRNG.h @@ -438,6 +438,8 @@ private: */ eoRng& operator=(const eoRng&); }; +/** @example t-eoRNG.cpp + */ diff --git a/eo/src/utils/eoRealBounds.h b/eo/src/utils/eoRealBounds.h index 480df4bb..c8761978 100644 --- a/eo/src/utils/eoRealBounds.h +++ b/eo/src/utils/eoRealBounds.h @@ -33,6 +33,12 @@ /** \defgroup Real Vector of reals +Set of classes related to continuous black-box optimization problems. + +Here are several examples of test programs using eoReal, eoEsSimple, eoEsStdev or eoEsFull to build an Evoution Strategies algorithm: +@include t-eoESAll.cpp +@include t-eoESFull.cpp + @ingroup Representations */ diff --git a/eo/src/utils/eoRndGenerators.h b/eo/src/utils/eoRndGenerators.h index 96ec9c0c..16b03ec4 100644 --- a/eo/src/utils/eoRndGenerators.h +++ b/eo/src/utils/eoRndGenerators.h @@ -88,12 +88,16 @@ template class eoUniformGenerator : public eoRndGenerator for ints and unsigneds */ T operator()(void) { return minim+static_cast(uniform.uniform(range)); } + /** @example t-eoUniform.cpp + */ private : T minim; T range; eoRng& uniform; }; +/** @example t-eoRandom.cpp + */ /// Specialization for bool, does an unbiased coin flip diff --git a/eo/src/utils/eoStat.h b/eo/src/utils/eoStat.h index d72a86e6..d00657d8 100644 --- a/eo/src/utils/eoStat.h +++ b/eo/src/utils/eoStat.h @@ -407,6 +407,8 @@ private : } }; +/** @example t-eoSSGA.cpp + */ template class eoDistanceStat : public eoStat diff --git a/eo/src/utils/eoState.h b/eo/src/utils/eoState.h index a32dfefe..53c3a83d 100644 --- a/eo/src/utils/eoState.h +++ b/eo/src/utils/eoState.h @@ -132,5 +132,7 @@ private : eoState& operator=(const eoState&); }; +/** @example t-eoStateAndParser.cpp + */ #endif diff --git a/eo/test/t-eoAtomOps.cpp b/eo/test/t-eoAtomOps.cpp deleted file mode 100644 index d1c70de7..00000000 --- a/eo/test/t-eoAtomOps.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - - t-eoAtomOps.cpp - Program that tests the atomic operator classes - - (c) GeNeura Team, 1999 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; 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 - -*/ - -//-----------------------------------------------------------------------------// - -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif - -#include -#include -#include - -using namespace std; - -// Operators we are going to test -#include -#include -#include -#include - -// Several EOs -#include - -// RNGs -#include - -main(int argc, char *argv[]) { - eoString aString("123456"); - eoAtomCreep creeper; - eoAtomMutation< eoString > mutator( creeper, 0.5 ); - - eoNegExp charNE( 2 ); - eoAtomRandom randomer( charNE ); - eoAtomMutation< eoString > mutator2 ( randomer, 0.5 ); - - std::cout << "Before aString " << aString << std::endl; - mutator( aString); - std::cout << " after mutator " << aString << std::endl; - mutator2( aString); - std::cout << " after mutator2 " << aString << std::endl;; - return 0; // to avoid VC++ complaints -} - diff --git a/eo/test/t-eoBaseFunctions.cpp b/eo/test/t-eoBaseFunctions.cpp deleted file mode 100644 index 6f6745ac..00000000 --- a/eo/test/t-eoBaseFunctions.cpp +++ /dev/null @@ -1,26 +0,0 @@ - -#include - -#include - -using namespace std; - -struct eo1 : public eoF -{ - void operator()(void) {} -}; - -struct eo2 : public eoF -{ - int operator()(void) { return 1; } -}; - -int main() -{ - eo1 _1; _1(); - eo2 _2; - int i = _2(); - - std::cout << i << '\n'; - return i; -} diff --git a/eo/test/t-eoESOps.cpp b/eo/test/t-eoESOps.cpp deleted file mode 100644 index d583ada6..00000000 --- a/eo/test/t-eoESOps.cpp +++ /dev/null @@ -1,116 +0,0 @@ -// Program to test several EO-ES features - -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif - -#include -#include -#include - -using namespace std; - -// general -#include // though contained in all others! -// evolution specific -#include -//#include -//#include -// representation specific - -#include // though contained in following -//#include -#include -//#include -// this fitness -#include "real_value.h" // the sphere fitness - -// Now the main -/////////////// -typedef eoESFullChrom Ind; - -main(int argc, char *argv[]) { - unsigned mu, lambda; - bool comma; - - // Create the command-line parser - Parser parser( argc, argv, "Basic EA for vector with adaptive mutations"); - - //reproducible random seed - thanks, Maarten - InitRandom(parser); - - // a first Ind, reading its parameters from the parser - // will be used later to inialize the whole population - Ind FirstEO(parser); - - // Evaluation - // here we should call some parser-based constructor, - // as many evaluation function need parameters - // and also have some preliminary stuffs to do - eoEvalFuncPtr eval( real_value ); - - // recombination and mutation operators, reading their parameters from the parser - eoESMutate MyMut(parser, - FirstEO.StdDevLength(), FirstEO.size(), - FirstEO.CorCffLength() ); - - std::cout << "First EO " << FirstEO << std::endl; - MyMut(FirstEO); - std::cout << "First EO mutated" << FirstEO << std::endl; - - /* - // Evolution and population parameters - eoScheme the_scheme(parser); - - // recombination and mutation operators, reading their parameters from the parser - eoESReco MyReco(parser, FirstEO); - eoESMutate MyMut(parser, FirstEO); - - // termination conditions read by the parser - eoTermVector the_terms(parser); - - // Initialization of the population - // shoudl be called using the parser, in case you want to read from file(s) - eoESRandomize randomize; // an eoESInd randomnizer - eoPop pop(the_scheme.PopSize(), FirstEO, randomize); - // eval(pop); // shoudl we call it from inside the constructor??? - - // ALL parmeters have been read: write them out - // Writing the parameters on arv[0].status - // but of course this can be modified - see the example parser.cpp - parser.outputParam(); - // except the help parameter??? - if( parser.getBool("-h" , "--help" , "Shows this help")) { - parser.printHelp(); - exit(1); - } - - unsigned i, iind; - - - std::cout << "Initial population: \n" << std::endl; - for (i = 0; i < pop.size(); ++i) { - eval(pop[i]); - std::cout << pop[i].fitness() << "\t" << pop[i] << std::endl; - } - - // the Operators - eoSequentialOpHolder seqholder; - // seqholder.addOp(MyReco, 1.0); - seqholder.addOp(MyMut, 1.0); - - // One generation - eoEvolStep evol_scheme(the_scheme, seqholder, eval); - - // the algorithm: - eoFullEA ea(evol_scheme, the_terms); - - ea(pop); - - std::cout << "Final population: \n" << std::endl; - for (i = 0; i < pop.size(); ++i) - std::cout << pop[i].fitness() << "\t" << pop[i] << std::endl; - return 0; - */ -} - diff --git a/eo/test/t-eoGOpSel.cpp b/eo/test/t-eoGOpSel.cpp deleted file mode 100644 index 2606bab6..00000000 --- a/eo/test/t-eoGOpSel.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - - t-eoGOpSel.cpp - Testing proportional operator selectors - - (c) Maarten Keijzer and GeNeura Team, 2000 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; 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 __GNUG__ -// to avoid long name warnings -#pragma warning(disable:4786) -#endif // __GNUG__ - -#include - -#include // eoBin, eoPop, eoBreeder -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -#include -#include - -// Fitness evaluation -#include "binary_value.h" - -//----------------------------------------------------------------------------- - -typedef eoBin Chrom; - -//----------------------------------------------------------------------------- - -main() -{ - rng.reseed(42); // reproducible random seed - - const unsigned POP_SIZE = 8, CHROM_SIZE = 4; - unsigned i; - - eoBinRandom random; - eoPop pop; - - for (i = 0; i < POP_SIZE; ++i) - { - Chrom chrom(CHROM_SIZE); - random(chrom); - chrom.fitness(binary_value(chrom)); - pop.push_back(chrom); - } - - std::cout << "population:" << std::endl; - for (i = 0; i < pop.size(); ++i) - std::cout << pop[i] << " " << pop[i].fitness() << std::endl; - - eoBinBitFlip bitflip; - eoBinCrossover xover; - - eoEvalFuncPtr eval(binary_value); - - //Create the proportional operator selector and add the - // two operators creatd above to it. - - eoProportionalGOpSel propSel; - eoSequentialGOpSel seqSel; - - propSel.addOp(bitflip, 0.5); - propSel.addOp(xover, 0.5); - - // seqSel selects operator in sequence, creating a combined operator - // add a bitflip, an xover and another bitflip - seqSel.addOp(bitflip, 0.25); - seqSel.addOp(xover, 0.5); - seqSel.addOp(bitflip, 0.25); - - - eoRandomIndiSelector selector1; - eoDetTournamentIndiSelector selector2(2); - - eoBackInserter inserter1; - eoDetTournamentInserter inserter2(eval, 2); - eoStochTournamentInserter inserter3(eval, 0.9f); - - eoGOpBreeder breeder1(propSel, selector1); - eoGOpBreeder breeder2(seqSel, selector1); - eoGOpBreeder breeder3(propSel, selector2); - eoGOpBreeder breeder4(seqSel, selector2); - - // test the breeders - - breeder1(pop); - breeder2(pop); - breeder3(pop); - breeder4(pop); - - eoState state; - - state.registerObject(pop); - - state.save(std::std::cout); - - return 0; -} - -//----------------------------------------------------------------------------- diff --git a/eo/test/t-eoNonUniform.cpp b/eo/test/t-eoNonUniform.cpp deleted file mode 100644 index 3a59bc8c..00000000 --- a/eo/test/t-eoNonUniform.cpp +++ /dev/null @@ -1,31 +0,0 @@ -//----------------------------------------------------------------------------- -// t-eoNonUniform.cc -//----------------------------------------------------------------------------- - -#include -#include - -//----------------------------------------------------------------------------- - -main() -{ - eoNonUniform nu(1000); - - std::cout << "----------------------------------------------------------" << std::endl - << "nu.step() = " << nu.step() - << "\t nu.num_step() = " << nu.num_step() << std::endl - << "----------------------------------------------------------" << std::endl; - - eoLinear l1(0, 1, nu), l2(1, 0, nu); - eoNegExp2 n1(0.1, 8, nu), n2(0.75, 3, nu); - - for (; nu; ++nu) - { - std::cout << nu.step() - << "\t" << l1() << "\t" << l2() - << "\t" << n1() << "\t" << n2() - << std::endl; - } -} - -//----------------------------------------------------------------------------- diff --git a/eo/test/t-eoPareto.cpp b/eo/test/t-eoPareto.cpp deleted file mode 100644 index 559b661e..00000000 --- a/eo/test/t-eoPareto.cpp +++ /dev/null @@ -1,274 +0,0 @@ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - -//#include -#include -#include - -using namespace std; - -// Look: overloading the maximization without overhead (thing can be inlined) -class MinimizingFitnessTraits : public eoParetoFitnessTraits -{ - public : - static bool maximizing(int) { return false; } -}; - -typedef eoParetoFitness fitness_type; - -const unsigned chromsize=5; -const double minval = -15; -const double maxval = 15; - -struct eoDouble : public EO -{ - double value[chromsize]; -}; - -class Mutate : public eoMonOp -{ - bool operator()(eoDouble& _eo) - { - for (unsigned i = 0; i < chromsize; ++i) - { - if (rng.flip(1./chromsize)) - _eo.value[i] += rng.normal() * 0.1 * _eo.value[i]; - - if (_eo.value[i] < minval) - _eo.value[i] = minval; - else if (_eo.value[i] > maxval) - _eo.value[i] = maxval; - } - - return true; - } -}; - -class Eval : public eoEvalFunc -{ - void operator()(eoDouble& _eo) - { - vector x(_eo.value, _eo.value + chromsize); - fitness_type f; - - for (unsigned i = 0; i < chromsize; ++i) - { - if (i < chromsize-1) - { - f[0] += -10.0 * exp(-0.2 * sqrt(x[i]*x[i] + x[i+1]*x[i+1])); - } - - f[1] += pow(fabs(x[i]), 0.8) + 5 * pow(sin(x[i]),3.); - } - - _eo.fitness(f); - } -}; - -class Eval2 : public eoEvalFunc -{ - void operator()(eoDouble& _eo) - { - vector x(_eo.value, _eo.value + chromsize); - fitness_type f; - - for (unsigned i = 0; i < chromsize; ++i) - { - f[0] += x[i] * x[i]; - } - - f[1] = - 3 * x[0] + 2 * x[1] - - x[2]/3 + 0.01*pow(x[3] - x[4], 3); - - _eo.fitness(f); - } -}; - -class Init : public eoInit -{ - void operator()(eoDouble& _eo) - { - _eo.value[0] = rng.uniform(); - - double range = maxval - minval; - - for (unsigned i = 1; i < chromsize; ++i) - _eo.value[i] = rng.uniform() * range + minval; - _eo.invalidate(); - } -}; - -/** @brief An elitist non-dominated sorted replacement scheme. - -Trying out an elitist non-dominated sorted replacement scheme. -*/ -template -class eoNDPlusReplacement : public eoReplacement -{ -public: - - // using eoNDPlusReplacement< EOT, WorthT >::first; - - eoNDPlusReplacement(eoPerf2Worth& _perf2worth) - : perf2worth(_perf2worth) - {} - - struct WorthPair : public pair - { - bool operator<(const WorthPair& other) const - { return other.first < this->first; } - }; - - - void operator()(eoPop& _parents, eoPop& _offspring) - { - unsigned sz = _parents.size(); - _parents.reserve(_parents.size() + _offspring.size()); - std::copy(_offspring.begin(), _offspring.end(), back_inserter(_parents)); - - // calculate worths - perf2worth(_parents); - perf2worth.sort_pop(_parents); - perf2worth.resize(_parents, sz); - - _offspring.clear(); - } - -private : - eoPerf2Worth& perf2worth; -}; - -template -eoPerf2Worth& make_perf2worth(eoParser& parser, eoState& state) -{ - - unsigned what = parser.createParam(unsigned(1), "perf2worth", "worth mapping indicator : \n\t \ - 0: non_dominated sorting \n\t\ - 1: non_dominated sorting 2 \n\t\ - 2: simple ranking \n\t", 'w').value(); - - switch (what) - { - case 1 : return state.storeFunctor(new eoNDSorting_II()); - case 2 : - { - eoDominanceMap& dominance = state.storeFunctor(new eoDominanceMap); - return state.storeFunctor(new eoParetoRanking(dominance)); - } - } - //default - - if (what > 2) - { - std::cout << "Warning, need an integer < 3 for perf2worth" << std::endl; - // should actually set parser flag, but I don't care - } - - return state.storeFunctor(new eoNDSorting_I(0.5)); -} - -template -eoSelectOne& make_selector(eoParser& parser, eoState& state, eoPerf2Worth& perf2worth) -{ - unsigned tournamentsize = parser.createParam(unsigned(2), "tournament_size", "Tournament Size", 't').value(); - double stochtour = parser.createParam(unsigned(0.95), "tournament_prob", "Probability in stochastic tournament").value(); - - switch (parser.createParam(unsigned(0), "selector", "Which selector (too lazy to explain: use the source)", 's').value()) - { - case 1 : return state.storeFunctor(new eoStochTournamentWorthSelect(perf2worth, stochtour)); - case 2 : return state.storeFunctor(new eoRouletteWorthSelect(perf2worth)); - case 3 : return state.storeFunctor(new eoRandomSelect); - } - // default - - return state.storeFunctor(new eoDetTournamentWorthSelect(perf2worth, tournamentsize)); -} - -// Test pareto dominance and perf2worth, and while you're at it, test the eoGnuPlot monitor as well -void the_main(int argc, char* argv[]) -{ - Init init; - Eval eval; - Mutate mutate; - - eoParser parser(argc, argv); - eoState state; - - unsigned num_gen = parser.createParam(unsigned(50), "num_gen", "number of generations to run", 'g').value(); - unsigned pop_size = parser.createParam(unsigned(100), "pop_size", "population size", 'p').value(); - eoPop pop(pop_size, init); - - // Look, a factory function - eoPerf2Worth& perf2worth = make_perf2worth(parser, state); - - // Look: another factory function, now for selection - eoSelectOne& select = make_selector(parser, state, perf2worth); - - // One general operator - eoProportionalOp opsel; - opsel.add(mutate, 1.0); - - // the breeder - eoGeneralBreeder breeder(select, opsel); - - // replacement - eoNDPlusReplacement replace(perf2worth); - - unsigned long generation = 0; - eoGenContinue gen(num_gen, generation); - eoCheckPoint cp(gen); - - eoMOFitnessStat fitness0(0, "FirstObjective"); - eoMOFitnessStat fitness1(1, "SecondObjective"); - - cp.add(fitness0); - cp.add(fitness1); - -#ifdef HAVE_GNUPLOT - eoGnuplot1DSnapshot snapshot("pareto"); - //snapshot.with(eoGnuplot::Points(3)); - - cp.add(snapshot); - - snapshot.add(fitness0); - snapshot.add(fitness1); -#endif - - // the algo - eoEasyEA ea(cp, eval, breeder, replace); - - if (parser.userNeedsHelp()) - { - parser.printHelp(std::cout); - return; - } - - apply(eval, pop); - ea(pop); -} - - -int main(int argc, char* argv[]) -{ - try - { - the_main(argc, argv); - } - catch (std::exception& e) - { - std::cout << "Exception thrown: " << e.what() << std::endl; - throw e; // make sure it does not pass the test - } -} - - - -// Local Variables: -// mode: C++ -// c-file-style: "Stroustrup" -// End: diff --git a/eo/test/t-eoParetoFitness.cpp b/eo/test/t-eoParetoFitness.cpp deleted file mode 100644 index bd5d0d2b..00000000 --- a/eo/test/t-eoParetoFitness.cpp +++ /dev/null @@ -1,196 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// t-eoParetoFitness.cpp -// (c) Maarten Keijzer -/* - 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: mak@dhi.dk - -30/01/02 - MS - Added the eoVariableParetoTraits - and the compare Fn - */ -//----------------------------------------------------------------------------- - -#include -#include - -#include "eoParetoFitness.h" - -using namespace std; - -/** test program for Pareto Fitness */ - -class MinimizingTraits : public eoParetoFitnessTraits -{ -public : - - static bool maximizing(int) { return false; } -}; - -template -void compare(F & _eo1, F & _eo2) -{ - if (_eo1.dominates(_eo2)) - std::cout << _eo1 << " dominates " << _eo2 << std::endl; - else if (_eo2.dominates(_eo1)) - std::cout << _eo2 << " dominates " << _eo1 << std::endl; - else - std::cout << "None of " << _eo1 << " and " << _eo2 << "dominates the other" << std::endl; - return; -} - -int main() -{ - typedef eoParetoFitness<> MaxFitness; - typedef eoParetoFitness MinFitness; - - typedef eoParetoFitness VarFitness; - - try{ - - MaxFitness f0; - f0[0] = 0.0; - f0[1] = 1.0; - - MaxFitness f1; - f1[0] = 1.0; - f1[1] = 0.0; - - MaxFitness f2; - f2[0] = 0.0; - f2[1] = 0.5; - - // now f0 should dominate f2; - - if (!f0.dominates(f2)) - { - std::cout << f2 << " not dominated by " << f0; - throw; - } - - // f0 and f1 should not dominate each other - - if (f0.dominates(f1) || f1.dominates(f0)) - { - std::cout << f0 << " and " << f1 << " dominate"; - throw; - } - - if (! (f0 == f0)) - { - std::cout << "f0 == f0 failed" << std::endl; - throw; - } - - // test ctors and such - MaxFitness f3 = f0; - f3[0] += 1e-9; - - // test tolerance - assert(f3 == f0); - - MinFitness m0; - MinFitness m1; - MinFitness m2; - MinFitness m3; - - m0[0] = 0.0; - m0[1] = 1.0; - - m1[0] = 1.0; - m1[1] = 0.0; - - m2[0] = 0.0; - m2[1] = 0.5; - - m3[0] = 0.5; - m3[1] = 0.5; - - //m2 should dominate m0 - assert(m2.dominates(m0)); - - assert(!m1.dominates(m0)); - assert(!m0.dominates(m1)); - assert(!m0.dominates(m2)); // (m2 < m0)); - assert(m2.dominates(m3)); //m3 < m2); - assert(!m3.dominates(m2)); // (m2 < m3)); - assert(m2.dominates(m3)); //m2 > m3); - - - ////////////////////////////////////////// - // now the run-time set-able number of objectives - //////////////////////////////////////////// - - std::cout << "On y va" << std::endl; - - - // setup fitness WARNING do not try to allocate any EO before that (runtime error) - vector b(2, true); - b[0]=true; - b[1]=false; - VarFitness::setUp(2, b); - std::cout << "\nMAXimizing on Obj 0 and MINimizing on Obj 1\n"; - - VarFitness mv0; - VarFitness mv1; - VarFitness mv2; - VarFitness mv3; - - mv0[0] = 0.0; - mv0[1] = 1.0; - - mv1[0] = 1.0; - mv1[1] = 0.0; - - mv2[0] = 0.0; - mv2[1] = 0.5; - - mv3[0] = 0.5; - mv3[1] = 0.5; - - compare (mv0,mv1); - compare (mv0,mv2); - compare (mv0,mv3); - compare (mv1,mv2); - compare (mv1,mv3); - compare (mv2,mv3); - - std::cout << "\nChanging now the min <-> max\n"; - b[0]=false; - b[1]=true; - VarFitness::setUp(2, b); - std::cout << "\nMINimizing on Obj 0 and MAXimizing on Obj 1\n"; - compare (mv0,mv1); - compare (mv0,mv2); - compare (mv0,mv3); - compare (mv1,mv2); - compare (mv1,mv3); - compare (mv2,mv3); - - std::cout << "\nTesting WARNING\n"; - b.resize(3); - b[0]=false; - b[1]=true; - b[2]=true; - VarFitness::setUp(3, b); - - } - catch(std::exception& e) - { - std::cout << e.what() << std::endl; - } - -} diff --git a/eo/test/t-eobreeder.cpp b/eo/test/t-eobreeder.cpp deleted file mode 100644 index 3127bd4e..00000000 --- a/eo/test/t-eobreeder.cpp +++ /dev/null @@ -1,87 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// t-eobreeder.cpp -// This program test the breeder object -// (c) GeNeura Team, 1998 -/* - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU 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 __GNUG__ -// to avoid long name warnings -#pragma warning(disable:4786) -#endif // __GNUG__ - -#include // eoBin, eoPop, eoBreeder -#include -#include -#include -#include - -//----------------------------------------------------------------------------- - -typedef eoBin Chrom; - -#include "binary_value.h" - -//----------------------------------------------------------------------------- - -main() -{ - const unsigned POP_SIZE = 8, CHROM_SIZE = 4; - unsigned i; - - eoBinRandom random; - eoPop pop; - - BinaryValue eval; - - for (i = 0; i < POP_SIZE; ++i) - { - Chrom chrom(CHROM_SIZE); - random(chrom); - eval(chrom); - pop.push_back(chrom); - } - - std::cout << "population:" << std::endl; - for (i = 0; i < pop.size(); ++i) - std::cout << pop[i] << " " << pop[i].fitness() << std::endl; - - eoBinBitFlip bitflip; - eoBinCrossover xover; - eoProportionalOpSel propSel; - eoBreeder breeder( propSel ); - propSel.addOp(bitflip, 0.25); - propSel.addOp(xover, 0.75); - - breeder(pop); - - // reevaluation of fitness - for_each(pop.begin(), pop.end(), BinaryValue()); - - std::cout << "new population:" << std::endl; - for (i = 0; i < pop.size(); ++i) - std::cout << pop[i] << " " << pop[i].fitness() << std::endl; - - return 0; -} - -//----------------------------------------------------------------------------- diff --git a/eo/test/t-eogeneration.cpp b/eo/test/t-eogeneration.cpp deleted file mode 100644 index 43cc9c8e..00000000 --- a/eo/test/t-eogeneration.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - - t-eogeneration.cpp - Testing the eoGeneration classes, and classes related to it - - (c) GeNeura Team, 1999, 2000 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; 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 - -*/ - -//-----------------------------------------------------------------------------// - - -// to avoid long name warnings -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif - -#include -#include - -#include "binary_value.h" - -//----------------------------------------------------------------------------- - -typedef eoBin Chrom; - -//----------------------------------------------------------------------------- - -main() -{ - const unsigned POP_SIZE = 8, CHROM_SIZE = 16; - unsigned i; - - eoBinRandom random; - eoPop pop; - - // Evaluation - eoEvalFuncPtr eval( binary_value ); - - for (i = 0; i < POP_SIZE; ++i) - { - Chrom chrom(CHROM_SIZE); - random(chrom); - eval(chrom); - pop.push_back(chrom); - } - - std::cout << "population:" << std::endl; - for (i = 0; i < pop.size(); ++i) - std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl; - - - // selection - eoLottery lottery; - - // breeder - eoBinBitFlip bitflip; - eoBinCrossover xover; - eoProportionalOpSel propSel; - eoBreeder breeder( propSel ); - propSel.addOp(bitflip, 0.25); - propSel.addOp(xover, 0.75); - - // replacement - eoInclusion inclusion; - - - - // GA generation - eoGeneration generation(lottery, breeder, inclusion, eval); - - // evolution - unsigned g = 0; - do { - try - { - generation(pop); - } - catch (std::exception& e) - { - std::cout << "exception: " << e.what() << std::endl;; - exit(EXIT_FAILURE); - } - - std::cout << "pop[" << ++g << "]" << std::endl; - for (i = 0; i < pop.size(); ++i) - std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl; - - } while (pop[0].fitness() < pow(2.0, CHROM_SIZE) - 1); - - // Try again, with a "counted" evaluation function - // GA generation - // Evaluation - eoEvalFuncPtrCnt eval2( binary_value ); - eoPop pop2; - - for (i = 0; i < POP_SIZE; ++i) - { - Chrom chrom(CHROM_SIZE); - random(chrom); - binary_value(chrom); - eval2(chrom); - pop2.push_back(chrom); - } - eoGeneration generation2(lottery, breeder, inclusion, eval2); - - // evolution - do { - try - { - generation2(pop2); - } - catch (std::exception& e) - { - std::cout << "exception: " << e.what() << std::endl;; - exit(EXIT_FAILURE); - } - - std::cout << "pop[" << ++g << "]" << std::endl; - for (i = 0; i < pop2.size(); ++i) - std::cout << "\t" << pop2[i] << " " << pop[i].fitness() << std::endl; - - } while (pop2[0].fitness() < pow(2.0, CHROM_SIZE) - 1); - - std::cout << "Number of evaluations " << eval2.getNumOfEvaluations() << std::endl; - return 0; -} - -//----------------------------------------------------------------------------- diff --git a/eo/test/t-eoinclusion.cpp b/eo/test/t-eoinclusion.cpp deleted file mode 100644 index 217f2eff..00000000 --- a/eo/test/t-eoinclusion.cpp +++ /dev/null @@ -1,97 +0,0 @@ -//----------------------------------------------------------------------------- -// t-eoinclusion.cpp -//----------------------------------------------------------------------------- - -#include -#include -#include - -//----------------------------------------------------------------------------- - -typedef eoBin Chrom; - -#include "binary_value.h" - -//----------------------------------------------------------------------------- - -main() -{ - const unsigned CHROM_SIZE = 4; - - eoBinRandom random; - BinaryValue eval; - - for (unsigned POP_SIZE = 4; POP_SIZE <=6; POP_SIZE++) - { - eoPop pop; - unsigned i; - for ( i = 0; i < POP_SIZE; i++) - { - Chrom chrom(CHROM_SIZE); - random(chrom); - eval(chrom); - pop.push_back(chrom); - } - - for (unsigned POP2_SIZE = 4; POP2_SIZE <=6; POP2_SIZE++) - { - eoPop pop2, pop3, pop4, pop5; - - for (i = 0; i < POP2_SIZE; i++) - { - Chrom chrom(CHROM_SIZE); - random(chrom); - eval(chrom); - pop2.push_back(chrom); - } - - std::cout << "--------------------------------------------------" << std::endl - << "breeders \tpop" << std::endl - << "--------------------------------------------------" << std::endl; - for (i = 0; i < max(pop.size(), pop2.size()); i++) - { - if (pop.size() > i) - std::cout << pop[i] << " " << pop[i].fitness() << " \t"; - else - std::cout << "\t\t"; - if (pop2.size() > i) - std::cout << pop2[i] << " " << pop2[i].fitness(); - std::cout << std::endl; - } - - eoInclusion inclusion(0.75); - pop3 = pop2; - inclusion(pop, pop3); - - eoInclusion inclusion2; - pop4 = pop2; - inclusion2(pop, pop4); - - eoInclusion inclusion3(1.5); - pop5 = pop2; - inclusion3(pop, pop5); - - std::cout << std::endl - << "0.75 \t\t1.0 \t\t1.5" << std::endl - << "---- \t\t--- \t\t---" << std::endl; - for (i = 0; i < pop5.size(); i++) - { - if (pop3.size() > i) - std::cout << pop3[i] << " " << pop3[i].fitness() << " \t"; - else - std::cout << " \t\t"; - if (pop4.size() > i) - std::cout << pop4[i] << " " << pop4[i].fitness() << " \t"; - else - std::cout << " \t\t"; - if (pop5.size() > i) - std::cout << pop5[i] << " " << pop5[i].fitness(); - std::cout << std::endl; - } - } - } - - return 0; -} - -//----------------------------------------------------------------------------- diff --git a/eo/test/t-eoinsertion.cpp b/eo/test/t-eoinsertion.cpp deleted file mode 100644 index 051ca821..00000000 --- a/eo/test/t-eoinsertion.cpp +++ /dev/null @@ -1,108 +0,0 @@ -//----------------------------------------------------------------------------- -// t-eoinsertion.cpp -//----------------------------------------------------------------------------- - -#include // eoBin, eoPop, eoInsertion - -//----------------------------------------------------------------------------- - -typedef eoBin Chrom; - -//----------------------------------------------------------------------------- - -void binary_value(Chrom& chrom) -{ - float sum = 0; - for (unsigned i = 0; i < chrom.size(); i++) - if (chrom[i]) - sum += pow(2, chrom.size() - i - 1); - chrom.fitness(sum); -} - -//----------------------------------------------------------------------------- - -main() -{ - const unsigned CHROM_SIZE = 4; - unsigned i; - - eoBinRandom random; - - for (unsigned POP_SIZE = 4; POP_SIZE <=6; POP_SIZE++) - { - eoPop pop; - - for (i = 0; i < POP_SIZE; i++) - { - Chrom chrom(CHROM_SIZE); - random(chrom); - binary_value(chrom); - pop.push_back(chrom); - } - - for (unsigned POP2_SIZE = 4; POP2_SIZE <=6; POP2_SIZE++) - { - eoPop pop2, pop3, pop4, pop5, popx; - - for (i = 0; i < POP2_SIZE; i++) - { - Chrom chrom(CHROM_SIZE); - random(chrom); - binary_value(chrom); - pop2.push_back(chrom); - } - - std::cout << "--------------------------------------------------" << std::endl - << "breeders \tpop" << std::endl - << "--------------------------------------------------" << std::endl; - for (i = 0; i < max(pop.size(), pop2.size()); i++) - { - if (pop.size() > i) - std::cout << pop[i] << " " << pop[i].fitness() << " \t"; - else - std::cout << "\t\t"; - if (pop2.size() > i) - std::cout << pop2[i] << " " << pop2[i].fitness(); - std::cout << std::endl; - } - - eoInsertion insertion(0.75); - popx = pop; - pop3 = pop2; - insertion(popx, pop3); - - eoInsertion insertion2; - popx = pop; - pop4 = pop2; - insertion2(popx, pop4); - - eoInsertion insertion3(1.5); - popx = pop; - pop5 = pop2; - insertion3(popx, pop5); - - std::cout << std::endl - << "0.75 \t\t1.0 \t\t1.5" << std::endl - << "---- \t\t--- \t\t---" << std::endl; - for (i = 0; i < pop5.size(); i++) - { - if (pop3.size() > i) - std::cout << pop3[i] << " " << pop3[i].fitness() << " \t"; - else - std::cout << " \t\t"; - if (pop4.size() > i) - std::cout << pop4[i] << " " << pop4[i].fitness() << " \t"; - else - std::cout << " \t\t"; - if (pop5.size() > i) - std::cout << pop5[i] << " " << pop5[i].fitness(); - std::cout << std::endl; - } - } - } - - return 0; -} - -//----------------------------------------------------------------------------- - diff --git a/eo/test/t-eolottery.cpp b/eo/test/t-eolottery.cpp deleted file mode 100644 index e0392638..00000000 --- a/eo/test/t-eolottery.cpp +++ /dev/null @@ -1,54 +0,0 @@ -//----------------------------------------------------------------------------- -// t-eolottery.cpp -//----------------------------------------------------------------------------- - -#include // eoBin, eoPop, eoLottery - -//----------------------------------------------------------------------------- - -typedef eoBin Chrom; - -void binary_value(Chrom& chrom) -{ - float sum = 0; - for (unsigned i = 0; i < chrom.size(); i++) - if (chrom[i]) - sum += pow(2, i); - chrom.fitness(sum); -} - -//----------------------------------------------------------------------------- - -main() -{ - const unsigned POP_SIZE = 8, CHROM_SIZE = 4; - - eoPop pop, pop2; - eoBinRandom random; - unsigned i; - - for (i = 0; i < POP_SIZE; i++) - { - Chrom chrom(CHROM_SIZE); - random(chrom); - binary_value(chrom); - pop.push_back(chrom); - } - - std::cout << "original population:" << std::endl; - sort(pop.begin(), pop.end()); - for (i = 0; i < pop.size(); i++) - std::cout << pop[i] << " " << pop[i].fitness() << std::endl; - - eoLottery lottery; - lottery(pop, pop2); - - std::cout << "selected by lottery population:" << std::endl; - sort(pop2.begin(), pop2.end()); - for (i = 0; i < pop2.size(); i++) - std::cout << pop2[i] << " " << pop2[i].fitness() << std::endl; - - return 0; -} - -//----------------------------------------------------------------------------- diff --git a/eo/test/t-eoproblem.cpp b/eo/test/t-eoproblem.cpp deleted file mode 100644 index 066efb62..00000000 --- a/eo/test/t-eoproblem.cpp +++ /dev/null @@ -1,55 +0,0 @@ -//----------------------------------------------------------------------------- -// t-eoproblem.cpp -// (c) GeNeura Team 1998 -//----------------------------------------------------------------------------- - -#include // time -#include // fabs -#include // std::cout -#include // eoVector, eoProblem - -//----------------------------------------------------------------------------- - -typedef eoVector Chrom; - -//----------------------------------------------------------------------------- - -std::ostream& operator<<(std::ostream& os, const Chrom& chrom) -{ - copy(chrom.begin(), chrom.end(), std::ostream_iterator(os)); - return os; -} - -//----------------------------------------------------------------------------- - -class Easy//: public eoProblem -{ -public: - static const unsigned size; - - float operator()(const Chrom& chrom) - { - return 1.0 / (fabs(chrom[0]) + 1.0); - } -}; -const unsigned Easy::size = 1; - -//----------------------------------------------------------------------------- - -int main() -{ - Easy easy; - Chrom chrom(Easy::size); - - srand(time(0)); - - chrom[0] = ((float)rand()) / ((float)RAND_MAX); - chrom.fitness(easy(chrom)); - - std::cout << "chrom = " << chrom << std::endl - << "chrom.fitness() = " << chrom.fitness() << std::endl; - - return 0; -} - -//-----------------------------------------------------------------------------