Extreme cleanup, see src/obsolete for details
This commit is contained in:
parent
7f04d616e6
commit
6d8e3a6504
141 changed files with 3937 additions and 1815 deletions
|
|
@ -6,10 +6,9 @@
|
||||||
|
|
||||||
SUBDIRS = src test win doc
|
SUBDIRS = src test win doc
|
||||||
#Directory for documents
|
#Directory for documents
|
||||||
|
DOCDIR = ~/public_html/eodocs
|
||||||
#Directory for indices -- not useful for the user
|
#Directory for indices -- not useful for the user
|
||||||
IDXDIR = ~/index
|
IDXDIR = ~/index
|
||||||
|
|
||||||
EXTRA_DIST=LICENSE
|
EXTRA_DIST=LICENSE
|
||||||
|
|
||||||
docs:
|
|
||||||
doxygen doc/eo.cfg
|
|
||||||
|
|
|
||||||
|
|
@ -179,7 +179,7 @@ INLINE_INFO = YES
|
||||||
# alphabetically by member name. If set to NO the members will appear in
|
# alphabetically by member name. If set to NO the members will appear in
|
||||||
# declaration order.
|
# declaration order.
|
||||||
|
|
||||||
SORT_MEMBER_DOCS = YES
|
SORT_MEMBER_DOCS = NO
|
||||||
|
|
||||||
# The TAB_SIZE tag can be used to set the number of spaces in a tab.
|
# The TAB_SIZE tag can be used to set the number of spaces in a tab.
|
||||||
# Doxygen uses this value to replace tabs by spaces in code fragments.
|
# Doxygen uses this value to replace tabs by spaces in code fragments.
|
||||||
|
|
@ -214,7 +214,7 @@ RECURSIVE = YES
|
||||||
# excluded from the INPUT source files. This way you can easily exclude a
|
# excluded from the INPUT source files. This way you can easily exclude a
|
||||||
# subdirectory from a directory tree whose root is specified with the INPUT tag.
|
# subdirectory from a directory tree whose root is specified with the INPUT tag.
|
||||||
|
|
||||||
EXCLUDE =
|
EXCLUDE = ../src/obsolete ../src/gp
|
||||||
|
|
||||||
# If the value of the INPUT tag contains directories, you can use the
|
# If the value of the INPUT tag contains directories, you can use the
|
||||||
# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
|
# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,7 @@ public:
|
||||||
@return true if the fitness is higher
|
@return true if the fitness is higher
|
||||||
*/
|
*/
|
||||||
bool operator<(const EO& _eo2) const { return fitness() < _eo2.fitness(); }
|
bool operator<(const EO& _eo2) const { return fitness() < _eo2.fitness(); }
|
||||||
|
bool operator>(const EO& _eo2) const { return !(fitness() <= _eo2.fitness()); }
|
||||||
|
|
||||||
/// Methods inherited from eoObject
|
/// Methods inherited from eoObject
|
||||||
//@{
|
//@{
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,11 @@
|
||||||
##
|
##
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
SUBDIRS = es ga gp obsolete utils other
|
SUBDIRS = es ga utils other
|
||||||
|
|
||||||
lib_LIBRARIES = libeo.a
|
lib_LIBRARIES = libeo.a
|
||||||
libeo_a_SOURCES = eoPrintable.cpp eoPersistent.cpp
|
libeo_a_SOURCES = eoPrintable.cpp eoPersistent.cpp eoFunctorStore.cpp
|
||||||
|
|
||||||
libeoincdir = $(includedir)/eo
|
libeoincdir = $(includedir)/eo
|
||||||
libeoinc_HEADERS = eo EO.h eoDup.h eoKill.h eoTournament.h eo1d.h eoEasyEA.h eoLottery.h eoProportionalOpSel.h eoTranspose.h eo1dWDistance.h eoEvalFunc.h eoMerge.h eoRandomBreed.h eoUniform.h eo2d.h eoEvalFuncPtr.h eoMutation.h eoRandomIndiSelector.h eoUniformSelect.h eo2dVector.h eoEvalFuncPtrCnt.h eoNegExp.h eoRandomSelect.h eoUniformXOver.h eoAlgo.h eoFactory.h eoNonUniform.h eoRank.h eoVector.h eoAtomBitFlip.h eoFitTerm.h eoNormal.h eoRnd.h eoWrappedOps.h eoAtomCreep.h eoFitness.h eoObject.h eoScalarFitness.h eoXOver2.h eoAtomMutation.h eoGOpBreeder.h eoOp.h eoScheme.h eoAtomMutator.h eoGOpSelector.h eoOpFactory.h eoSelectFactory.h eoBreeder.h eoID.h eoPersistent.h eoSteadyStateGeneration.h eoAtomRandom.h eoGenTerm.h eoOpSelMason.h eoSequentialGOpSelector.h eoBackInserter.h eoGeneration.h eoOpSelector.h eoSteadyStateEA.h eoDetTournament.h eoInclusion.h eoInit.h eoPop.h eoSteadyStateInserter.h eoDetTournamentIndiSelector.h eoIndiSelector.h eoPopOps.h eoStochTournament.h eoDetTournamentInserter.h eoInserter.h eoPrintable.h eoStochTournamentInserter.h eoDistance.h eoInsertion.h eoProportionalGOpSel.h eoTerm.h
|
libeoinc_HEADERS = eo EO.h apply.h eoAlgo.h eoBackInserter.h eoBreed.h eoCombinedContinue.h eoContinue.h eoCopyElite.h eoCounter.h eoDetTournament.h eoDetTournamentInserter.h eoEasyEA.h eoEvalFunc.h eoEvalFuncPtr.h eoEvolutionStrategy.h eoFactory.h eoFitContinue.h eoFixedLength.h eoFunctor.h eoFunctorStore.h eoGOpBreeder.h eoGOpSelector.h eoGenContinue.h eoIndiSelector.h eoInit.h eoInplaceTransform.h eoInserter.h eoMerge.h eoObject.h eoOp.h eoOpFactory.h eoOpSelMason.h eoOpSelector.h eoPersistent.h eoPop.h eoPrintable.h eoProportional.h eoProportionalGOpSel.h eoProportionalOpSel.h eoReduce.h eoReplacement.h eoSGA.h eoScalarFitness.h eoSelect.h eoSelectFactory.h eoSelectOne.h eoSelectPerc.h eoSelectRandom.h eoSequentialGOpSel.h eoSteadyStateEA.h eoSteadyStateInserter.h eoSteadyStateTransform.h eoStochTournament.h eoStochTournamentInserter.h eoTransform.h eoVariableLength.h eoWrappedOps.h
|
||||||
|
|
||||||
|
|
|
||||||
41
eo/src/apply.h
Normal file
41
eo/src/apply.h
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// eoApply.h
|
||||||
|
// (c) 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
|
||||||
|
mak@dhi.dk
|
||||||
|
*/
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef _apply_h
|
||||||
|
#define _apply_h
|
||||||
|
|
||||||
|
#include <eoFunctor.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
void apply(eoUnaryFunctor<void, EOT&>& _proc, std::vector<EOT>& _pop)
|
||||||
|
{
|
||||||
|
for (unsigned i = 0; i < _pop.size(); ++i)
|
||||||
|
{
|
||||||
|
_proc(_pop[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
83
eo/src/eo
83
eo/src/eo
|
|
@ -20,6 +20,11 @@
|
||||||
*/
|
*/
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef __GNUG__
|
||||||
|
// to avoid long name warnings
|
||||||
|
#pragma warning(disable:4786)
|
||||||
|
#endif // __GNUG__
|
||||||
|
|
||||||
#ifndef _eo_
|
#ifndef _eo_
|
||||||
#define _eo_
|
#define _eo_
|
||||||
|
|
||||||
|
|
@ -29,68 +34,88 @@
|
||||||
#include <eoObject.h>
|
#include <eoObject.h>
|
||||||
#include <eoPrintable.h>
|
#include <eoPrintable.h>
|
||||||
#include <eoPersistent.h>
|
#include <eoPersistent.h>
|
||||||
#include <eoFitness.h>
|
#include <eoScalarFitness.h>
|
||||||
#include <EO.h>
|
#include <EO.h>
|
||||||
|
|
||||||
#include <eoID.h>
|
#include <utils/rnd_generators.h>
|
||||||
|
#include <eoFunctor.h>
|
||||||
|
#include <apply.h>
|
||||||
|
|
||||||
#include <eoVector.h>
|
// eo's
|
||||||
#include <eo1d.h>
|
#include <eoVariableLength.h>
|
||||||
|
#include <eoFixedLength.h>
|
||||||
|
|
||||||
|
//#include <eoID.h>
|
||||||
|
|
||||||
|
//#include <eoVector.h>
|
||||||
|
//#include <eo1d.h>
|
||||||
#include <other/eoString.h>
|
#include <other/eoString.h>
|
||||||
#include <ga/eoBin.h>
|
#include <ga/eoBin.h>
|
||||||
|
|
||||||
#include <eoRnd.h>
|
#include <eoInit.h>
|
||||||
#include <eoUniform.h>
|
//#include <eoUniform.h>
|
||||||
#include <eoNormal.h>
|
//#include <eoNormal.h>
|
||||||
#include <eoNegExp.h>
|
//#include <eoNegExp.h>
|
||||||
|
|
||||||
#include <eoOp.h>
|
#include <eoOp.h>
|
||||||
|
|
||||||
#include <eoDup.h>
|
//#include <eoDup.h>
|
||||||
#include <eoKill.h>
|
//#include <eoKill.h>
|
||||||
#include <eoTranspose.h>
|
//#include <eoTranspose.h>
|
||||||
#include <eoXOver2.h>
|
//#include <eoXOver2.h>
|
||||||
#include <eoUniformXOver.h>
|
//#include <eoUniformXOver.h>
|
||||||
#include <eoMutation.h>
|
//#include <eoMutation.h>
|
||||||
|
|
||||||
#include <eoPop.h>
|
#include <eoPop.h>
|
||||||
#include <eoPopOps.h>
|
|
||||||
#include <eoMerge.h>
|
|
||||||
#include <ga/eoBitOp.h>
|
#include <ga/eoBitOp.h>
|
||||||
|
|
||||||
// Evaluation functions
|
// Evaluation functions
|
||||||
#include <eoEvalFunc.h>
|
#include <eoEvalFunc.h>
|
||||||
#include <eoEvalFuncPtr.h>
|
#include <eoEvalFuncPtr.h>
|
||||||
|
|
||||||
// Terminators
|
// Continuators
|
||||||
#include <eoTerm.h>
|
#include <eoContinue.h>
|
||||||
#include <eoGenTerm.h>
|
#include <eoCombinedContinue.h>
|
||||||
#include <eoFitTerm.h>
|
#include <eoGenContinue.h>
|
||||||
|
#include <eoFitContinue.h>
|
||||||
|
|
||||||
// Selection and reproduction stuff
|
// Selection and reproduction stuff
|
||||||
#include <eoUniformSelect.h>
|
#include <eoSelectOne.h>
|
||||||
|
#include <eoSelectRandom.h>
|
||||||
#include <eoDetTournament.h>
|
#include <eoDetTournament.h>
|
||||||
|
#include <eoProportional.h>
|
||||||
#include <eoStochTournament.h>
|
#include <eoStochTournament.h>
|
||||||
#include <eoLottery.h>
|
|
||||||
#include <eoBreeder.h>
|
|
||||||
#include <eoInsertion.h>
|
|
||||||
#include <eoInclusion.h>
|
|
||||||
#include <eoGeneration.h>
|
|
||||||
|
|
||||||
#include <eoProportionalOpSel.h>
|
#include <eoProportionalOpSel.h>
|
||||||
|
#include <eoProportionalGOpSel.h>
|
||||||
|
#include <eoSequentialGOpSel.h>
|
||||||
|
|
||||||
|
//#include <eoLottery.h>
|
||||||
|
//#include <eoBreeder.h>
|
||||||
|
//#include <eoInsertion.h>
|
||||||
|
//#include <eoInclusion.h>
|
||||||
|
//#include <eoGeneration.h>
|
||||||
|
|
||||||
|
//#include <eoProportionalOpSel.h>
|
||||||
|
|
||||||
// Algorithms
|
// Algorithms
|
||||||
#include <eoEasyEA.h>
|
#include <eoEasyEA.h>
|
||||||
|
#include <eoSGA.h>
|
||||||
|
#include <eoSteadyStateEA.h>
|
||||||
|
#include <eoEvolutionStrategy.h>
|
||||||
|
|
||||||
|
// Utils
|
||||||
|
#include <utils/checkpointing>
|
||||||
|
|
||||||
// aliens
|
// aliens
|
||||||
#include <eoNonUniform.h>
|
//#include <eoNonUniform.h>
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// to be continued ...
|
// to be continued ...
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
/*
|
/*
|
||||||
#include <eoFitness.h>
|
//#include <eoFitness.h>
|
||||||
#include <eoProblem.h>
|
//#include <eoProblem.h>
|
||||||
*/
|
*/
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,30 +26,18 @@
|
||||||
#define _EOALGO_H
|
#define _EOALGO_H
|
||||||
|
|
||||||
#include <eoPop.h> // for population
|
#include <eoPop.h> // for population
|
||||||
|
#include <eoFunctor.h>
|
||||||
|
|
||||||
/** This is a generic class for population-transforming algorithms. There
|
/**
|
||||||
|
This is a generic class for population-transforming algorithms. There
|
||||||
is only one operator defined, which takes a population and does stuff to
|
is only one operator defined, which takes a population and does stuff to
|
||||||
it. It needn't be a complete algorithm, can be also a step of an
|
it. It needn't be a complete algorithm, can be also a step of an
|
||||||
algorithm. This class just gives a common interface to linear
|
algorithm. This class just gives a common interface to linear
|
||||||
population-transforming algorithms.
|
population-transforming algorithms.
|
||||||
@author GeNeura Team
|
|
||||||
@version 0.0
|
|
||||||
*/
|
*/
|
||||||
template< class EOT >
|
template< class EOT >
|
||||||
class eoAlgo {
|
class eoAlgo : public eoUnaryFunctor<void, eoPop<EOT>&>
|
||||||
public:
|
{};
|
||||||
|
|
||||||
/// Dtor
|
|
||||||
virtual ~eoAlgo() {};
|
|
||||||
|
|
||||||
/** Run the algorithm on a population. This operation is not constant,
|
|
||||||
because somebody would want to change stuff in the algorithm each
|
|
||||||
time it's applied.
|
|
||||||
* @param _pop is the population that the algorithm is acting on
|
|
||||||
*/
|
|
||||||
virtual void operator() ( eoPop<EOT>& _pop ) = 0;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
69
eo/src/eoBreed.h
Normal file
69
eo/src/eoBreed.h
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
eoBreed.h
|
||||||
|
(c) Maarten Keijzer, 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 _eoBreed_h
|
||||||
|
#define _eoBreed_h
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
#include <eoPop.h>
|
||||||
|
#include <eoFunctor.h>
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
eoBreed: breeding is thought of a combination of selecting and transforming
|
||||||
|
a population. For efficiency reasons you might want to build your own
|
||||||
|
eoBreed derived class rather than relying on a seperate select and transform
|
||||||
|
function.
|
||||||
|
|
||||||
|
@see eoSelect, eoTransform, eoSelectTransform
|
||||||
|
*/
|
||||||
|
template<class EOT>
|
||||||
|
class eoBreed : public eoBinaryFunctor<void, const eoPop<EOT>&, eoPop<EOT>&>
|
||||||
|
{};
|
||||||
|
|
||||||
|
/**
|
||||||
|
eoSelectTransform: special breeder that is just an application of an embedded select,
|
||||||
|
followed by an embedded transform
|
||||||
|
*/
|
||||||
|
template <class EOT>
|
||||||
|
class eoSelectTransform : public eoBreed<EOT>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
eoSelectTransform(eoSelect<EOT>& _select, eoTransform<EOT>& _transform) :
|
||||||
|
select(_select), transform(_transform)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void operator()(const eoPop<EOT>& _parents, eoPop<EOT>& _offspring)
|
||||||
|
{
|
||||||
|
select(_parents, _offspring);
|
||||||
|
transform(_offspring);
|
||||||
|
}
|
||||||
|
|
||||||
|
private :
|
||||||
|
eoSelect<EOT>& select;
|
||||||
|
eoTransform<EOT>& transform;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
59
eo/src/eoCombinedContinue.h
Normal file
59
eo/src/eoCombinedContinue.h
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// eoCombinedContinue.h
|
||||||
|
// (c) Maarten Keijzer, 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 _eoCombinedContinue_h
|
||||||
|
#define _eoCombinedContinue_h
|
||||||
|
|
||||||
|
#include <eoContinue.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
Fitness continuation:
|
||||||
|
|
||||||
|
Continues until one of the embedded continuators says halt!
|
||||||
|
*/
|
||||||
|
template< class EOT>
|
||||||
|
class eoCombinedContinue: public eoContinue<EOT> {
|
||||||
|
public:
|
||||||
|
|
||||||
|
/// Define Fitness
|
||||||
|
typedef typename EOT::Fitness FitnessType;
|
||||||
|
|
||||||
|
/// Ctor
|
||||||
|
eoCombinedContinue( eoContinue<EOT>& _arg1, eoContinue<EOT>& _arg2)
|
||||||
|
: eoContinue<EOT> (), arg1(_arg1), arg2(_arg2) {};
|
||||||
|
|
||||||
|
/** Returns false when one of the embedded continuators say so (logical and)
|
||||||
|
*/
|
||||||
|
virtual bool operator() ( const eoPop<EOT>& _pop )
|
||||||
|
{
|
||||||
|
return arg1(_pop) && arg2(_pop);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
eoContinue<EOT>& arg1;
|
||||||
|
eoContinue<EOT>& arg2;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
39
eo/src/eoContinue.h
Normal file
39
eo/src/eoContinue.h
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// eoContinue.h
|
||||||
|
// (c) Maarten Keijzer, 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 _eoContinue_h
|
||||||
|
#define _eoContinue_h
|
||||||
|
|
||||||
|
#include <eoFunctor.h>
|
||||||
|
#include <eoPop.h>
|
||||||
|
|
||||||
|
/** Termination condition for the genetic algorithm
|
||||||
|
* Takes the population as input, returns true for continue,
|
||||||
|
* false for termination
|
||||||
|
*/
|
||||||
|
template< class EOT>
|
||||||
|
class eoContinue : public eoUnaryFunctor<bool, const eoPop<EOT>&> {};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
110
eo/src/eoCopyElite.h
Normal file
110
eo/src/eoCopyElite.h
Normal file
|
|
@ -0,0 +1,110 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// eoCopyElite.h
|
||||||
|
// Base class for elitist-merging classes
|
||||||
|
// (c) GeNeura Team, 1998
|
||||||
|
/*
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||||
|
*/
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef eoCopyElite_h
|
||||||
|
#define eoCopyElite_h
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// EO includes
|
||||||
|
#include <eoPop.h> // eoPop
|
||||||
|
#include <eoFunctor.h> // eoCopyElite
|
||||||
|
|
||||||
|
/**
|
||||||
|
* eoCopyElite: Base class for elitist replacement algorithms.
|
||||||
|
* Merges the old population (first argument), with the new generation
|
||||||
|
*
|
||||||
|
* Its signature is exactly
|
||||||
|
* that of the selection base eoSelect, but its purpose is to merge the
|
||||||
|
* two populations into one (the second argument).
|
||||||
|
* Note that the algorithms assume that the second argument denotes the
|
||||||
|
* next generation.
|
||||||
|
*/
|
||||||
|
|
||||||
|
template<class Chrom> class eoCopyElite: public eoBinaryFunctor<void, const eoPop<Chrom>&, eoPop<Chrom>&>
|
||||||
|
{};
|
||||||
|
|
||||||
|
/**
|
||||||
|
Straightforward elitism class, specify the number of individuals to copy
|
||||||
|
into new geneneration
|
||||||
|
*/
|
||||||
|
template <class EOT> class eoElitism : public eoCopyElite<EOT>
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
eoElitism(unsigned _howmany) : howmany(_howmany) {}
|
||||||
|
|
||||||
|
void operator()(const eoPop<EOT>& _pop, eoPop<EOT>& offspring)
|
||||||
|
{
|
||||||
|
if (howmany == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (howmany > _pop.size())
|
||||||
|
throw logical_error("Elite larger than population");
|
||||||
|
|
||||||
|
vector<const EOT*> result;
|
||||||
|
_pop.nth_element(howmany, result);
|
||||||
|
|
||||||
|
for (int i = 0; i < result.size(); ++i)
|
||||||
|
{
|
||||||
|
offspring.push_back(*result[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private :
|
||||||
|
unsigned howmany;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
No elite
|
||||||
|
*/
|
||||||
|
template <class EOT> class eoNoElitism : public eoElitism<EOT>
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
eoNoElitism() : eoElitism(0) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Very elitist class, copies entire population into next gen
|
||||||
|
*/
|
||||||
|
template <class EOT> class eoPlus : public eoCopyElite<EOT>
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
void operator()(const eoPop<EOT>& _pop, eoPop<EOT>& offspring)
|
||||||
|
{
|
||||||
|
offspring.reserve(offspring.size() + _pop.size());
|
||||||
|
|
||||||
|
for (int i = 0; i < _pop.size(); ++i)
|
||||||
|
{
|
||||||
|
offspring.push_back(*result[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private :
|
||||||
|
unsigned howmany;
|
||||||
|
};
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#endif
|
||||||
219
eo/src/eoCounter.h
Normal file
219
eo/src/eoCounter.h
Normal file
|
|
@ -0,0 +1,219 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// eoCounter.h
|
||||||
|
// (c) 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
|
||||||
|
mak@dhi.dk
|
||||||
|
*/
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef _eoCounter_h
|
||||||
|
#define _eoCounter_h
|
||||||
|
|
||||||
|
#include <eoFunctor.h>
|
||||||
|
#include <eoFunctorStore.h>
|
||||||
|
#include <utils/eoParam.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
Generic counter class that counts the number of times
|
||||||
|
a procedure is used. Add a procedure through its ctor and
|
||||||
|
use this class instead of it.
|
||||||
|
|
||||||
|
It is derived from eoValueParam so you can add it to a monitor.
|
||||||
|
*/
|
||||||
|
template <class Procedure>
|
||||||
|
class eoProcedureCounter : public Procedure, public eoValueParam<unsigned long>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
eoProcedureCounter(Procedure& _proc, std::string _name = "proc_counter")
|
||||||
|
: proc(_proc), eoValueParam<unsigned long>(0, _name) {}
|
||||||
|
|
||||||
|
/** Calls the embedded function and increments the counter
|
||||||
|
|
||||||
|
Note for MSVC users, if this code does not compile, you are quite
|
||||||
|
likely trying to count a function that has a non-void return type.
|
||||||
|
Don't look at us, look at the MSVC builders. Code like "return void;"
|
||||||
|
is perfectly legal according to the ANSI standard, but the guys at
|
||||||
|
Microsoft didn't get to implementing it yet.
|
||||||
|
|
||||||
|
We had two choices: assuming (and compiling ) code that returns void or code that returns non-void.
|
||||||
|
Given that in EO most functors return void, it was chosen to support void.
|
||||||
|
|
||||||
|
But also please let me know if you have a compiler that defines _MSC_VER (lot's of windows compilers do), but is quite
|
||||||
|
capable of compiling return void; type of code. We'll try to change the signature then.
|
||||||
|
|
||||||
|
You happy GNU (and other compiler) users will not have a problem with this..
|
||||||
|
*/
|
||||||
|
typename Procedure::result_type operator()(void)
|
||||||
|
{
|
||||||
|
value()++;
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
proc();
|
||||||
|
#else
|
||||||
|
return proc();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
private :
|
||||||
|
|
||||||
|
Procedure& proc;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
Generic counter class that counts the number of times
|
||||||
|
a unary function is used. Add a unary function through its ctor and
|
||||||
|
use this class instead of it.
|
||||||
|
|
||||||
|
It is derived from eoValueParam so you can add it to a monitor.
|
||||||
|
|
||||||
|
Example: suppose you have an eoEvalFunc called myeval, to count the
|
||||||
|
number of evaluations, just define:
|
||||||
|
|
||||||
|
eoUnaryFunctorCounter<void, EoType> evalCounter(myeval);
|
||||||
|
|
||||||
|
and use evalCounter now instead of myeval.
|
||||||
|
*/
|
||||||
|
|
||||||
|
template <class UnaryFunctor>
|
||||||
|
class eoUnaryFunctorCounter : public UnaryFunctor, public eoValueParam<unsigned long>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
eoUnaryFunctorCounter(UnaryFunctor& _func, std::string _name = "uf_counter")
|
||||||
|
: func(_func), eoValueParam<unsigned long>(0, _name) {}
|
||||||
|
|
||||||
|
/** Calls the embedded function and increments the counter
|
||||||
|
|
||||||
|
Note for MSVC users, if this code does not compile, you are quite
|
||||||
|
likely trying to count a function that has a non-void return type.
|
||||||
|
Don't look at us, look at the MSVC builders. Code like "return void;"
|
||||||
|
is perfectly legal according to the ANSI standard, but the guys at
|
||||||
|
Microsoft didn't get to implementing it yet.
|
||||||
|
|
||||||
|
We had two choices: assuming (and compiling ) code that returns void or code that returns non-void.
|
||||||
|
Given that in EO most functors return void, it was chosen to support void.
|
||||||
|
|
||||||
|
But also please let me know if you have a compiler that defines _MSC_VER (lot's of windows compilers do), but is quite
|
||||||
|
capable of compiling return void; type of code. We'll try to change the signature then.
|
||||||
|
|
||||||
|
You happy GNU (and other compiler) users will not have a problem with this.
|
||||||
|
*/
|
||||||
|
typename UnaryFunctor::result_type operator()
|
||||||
|
(typename UnaryFunctor::first_argument_type _arg1)
|
||||||
|
{
|
||||||
|
value()++;
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
func(_arg1);
|
||||||
|
#else
|
||||||
|
return func(_arg1);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
private :
|
||||||
|
|
||||||
|
UnaryFunctor& func;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
Generic counter class that counts the number of times
|
||||||
|
a binary function is used. Add a binary function through its ctor and
|
||||||
|
use this class instead of it.
|
||||||
|
|
||||||
|
It is derived from eoValueParam so you can add it to a monitor.
|
||||||
|
|
||||||
|
*/
|
||||||
|
template <class BinaryFunctor>
|
||||||
|
class eoBinaryFunctorCounter : public BinaryFunctor, public eoValueParam<unsigned long>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
eoBinaryFunctorCounter(BinaryFunctor& _func, std::string _name = "proc_counter")
|
||||||
|
: func(_func), eoValueParam<unsigned long>(0, _name) {}
|
||||||
|
|
||||||
|
/** Calls the embedded function and increments the counter
|
||||||
|
|
||||||
|
Note for MSVC users, if this code does not compile, you are quite
|
||||||
|
likely trying to count a function that has a non-void return type.
|
||||||
|
Don't look at us, look at the MSVC builders. Code like "return void;"
|
||||||
|
is perfectly legal according to the ANSI standard, but the guys at
|
||||||
|
Microsoft didn't get to implementing it yet.
|
||||||
|
|
||||||
|
We had two choices: assuming (and compiling ) code that returns void or code that returns non-void.
|
||||||
|
Given that in EO most functors return void, it was chosen to support void.
|
||||||
|
|
||||||
|
|
||||||
|
But also please let me know if you have a compiler that defines _MSC_VER (lot's of windows compilers do), but is quite
|
||||||
|
capable of compiling return void; type of code. We'll try to change the signature then.
|
||||||
|
|
||||||
|
You happy GNU (and other compiler) users will not have a problem with this.
|
||||||
|
*/
|
||||||
|
typename BinaryFunctor::result_type operator()
|
||||||
|
(typename BinaryFunctor::first_argument_type _arg1,
|
||||||
|
typename BinaryFunctor::second_argument_type _arg2)
|
||||||
|
{
|
||||||
|
value()++;
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
func(_arg1, _arg2);
|
||||||
|
#else
|
||||||
|
return func(_arg1, _arg2);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
private :
|
||||||
|
|
||||||
|
BinaryFunctor& func;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** make_counter: overloaded function to make a counter out of a function
|
||||||
|
|
||||||
|
how it works...
|
||||||
|
|
||||||
|
by using the xxx_function_tag structure defined in eoFunctionBase, you
|
||||||
|
can easily create a counter from a general class (say eoEval<EOT>), by
|
||||||
|
simply stating:
|
||||||
|
|
||||||
|
eoEval<EOT>& myCounted = make_counter(functor_category(myEval), myEval, store)
|
||||||
|
|
||||||
|
@see eoFunctorBase, functor_category, eoFunctorStore
|
||||||
|
|
||||||
|
*/
|
||||||
|
template <class Procedure>
|
||||||
|
eoProcedureCounter<Procedure>& make_counter(eoFunctorBase::procedure_tag, Procedure& _proc, eoFunctorStore& store, std::string _name = "proc_counter")
|
||||||
|
{
|
||||||
|
eoProcedureCounter<Procedure>* result = new eoProcedureCounter<Procedure>(_proc, _name);
|
||||||
|
store.add(result);
|
||||||
|
return *result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class UnaryFunctor>
|
||||||
|
eoUnaryFunctorCounter<UnaryFunctor>& make_counter(eoFunctorBase::unary_function_tag, UnaryFunctor& _proc, eoFunctorStore& store, std::string _name = "uf_counter")
|
||||||
|
{
|
||||||
|
eoUnaryFunctorCounter<UnaryFunctor>* result = new eoUnaryFunctorCounter<UnaryFunctor>(_proc, _name);
|
||||||
|
store.add(result);
|
||||||
|
return *result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class BinaryFunctor>
|
||||||
|
eoBinaryFunctorCounter<BinaryFunctor>& make_counter(eoFunctorBase::binary_function_tag, BinaryFunctor& _proc, eoFunctorStore& store, std::string _name = "uf_counter")
|
||||||
|
{
|
||||||
|
eoBinaryFunctorCounter<BinaryFunctor>* result = new eoBinaryFunctorCounter<BinaryFunctor>(_proc, _name);
|
||||||
|
store.add(result);
|
||||||
|
return *result;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -30,8 +30,10 @@
|
||||||
|
|
||||||
#include <functional> //
|
#include <functional> //
|
||||||
#include <numeric> // accumulate
|
#include <numeric> // accumulate
|
||||||
#include "eoPopOps.h" // eoPop eoSelect MINFLOAT
|
|
||||||
#include "utils/selectors.h"
|
#include <eoFunctor.h>
|
||||||
|
#include <eoPop.h>
|
||||||
|
#include <utils/selectors.h>
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
/** eoDetTournament: a selection method that selects ONE individual by
|
/** eoDetTournament: a selection method that selects ONE individual by
|
||||||
|
|
@ -51,15 +53,11 @@ template <class EOT> class eoDetTournament: public eoSelectOne<EOT>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Perform deterministic tournament
|
||||||
virtual const EOT& operator()(const eoPop<EOT>& pop)
|
virtual const EOT& operator()(const eoPop<EOT>& pop)
|
||||||
{
|
{
|
||||||
return deterministic_tournament(pop, Tsize);
|
return deterministic_tournament(pop, Tsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Inherited from eoObject
|
|
||||||
@see eoObject
|
|
||||||
*/
|
|
||||||
string className() const {return "eoDetTournament";};
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned Tsize;
|
unsigned Tsize;
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,6 @@ public :
|
||||||
EOT& eo = inverse_deterministic_tournament<EOT>(pop(), t_size);
|
EOT& eo = inverse_deterministic_tournament<EOT>(pop(), t_size);
|
||||||
eo = _eot; // overwrite loser of tournament
|
eo = _eot; // overwrite loser of tournament
|
||||||
|
|
||||||
eo.invalidate(); // This line should probably be removed when all genetic operators do this themselves
|
|
||||||
eval(eo); // Evaluate after insert
|
eval(eo); // Evaluate after insert
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,59 +27,139 @@
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <eoGeneration.h> // eoPop
|
#include <eoAlgo.h>
|
||||||
#include <eoTerm.h>
|
#include <eoContinue.h>
|
||||||
|
#include <eoSelect.h>
|
||||||
|
#include <eoTransform.h>
|
||||||
|
#include <eoBreed.h>
|
||||||
|
#include <eoMerge.h>
|
||||||
|
#include <eoReduce.h>
|
||||||
|
#include <eoReplacement.h>
|
||||||
|
|
||||||
/** EOEasyEA:
|
/** eoEasyEA:
|
||||||
An easy-to-use evolutionary algorithm; you can use any chromosome,
|
An easy-to-use evolutionary algorithm; you can use any chromosome,
|
||||||
and any selection transformation, merging and evaluation
|
and any selection transformation, merging and evaluation
|
||||||
algorithms; you can even change in runtime parameters of those
|
algorithms; you can even change in runtime parameters of those
|
||||||
sub-algorithms
|
sub-algorithms
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template<class Chrom> class eoEasyEA: public eoAlgo<Chrom>
|
template<class EOT> class eoEasyEA: public eoAlgo<EOT>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// Constructor.
|
|
||||||
eoEasyEA(eoBinPopOp<Chrom>& _select,
|
|
||||||
eoMonPopOp<Chrom>& _transform,
|
|
||||||
eoBinPopOp<Chrom>& _replace,
|
|
||||||
eoEvalFunc<Chrom>& _evaluator,
|
|
||||||
eoTerm<Chrom>& _terminator)
|
|
||||||
:step(_select, _transform, _replace, _evaluator),
|
|
||||||
terminator( _terminator){};
|
|
||||||
|
|
||||||
/// Constructor from an already created generation
|
/// Ctor taking a breed and merge.
|
||||||
eoEasyEA(eoGeneration<Chrom>& _gen,
|
eoEasyEA(
|
||||||
eoTerm<Chrom>& _terminator):
|
eoContinue<EOT>& _continuator,
|
||||||
step(_gen),
|
eoEvalFunc<EOT>& _eval,
|
||||||
terminator( _terminator){};
|
eoBreed<EOT>& _breed,
|
||||||
|
eoReplacement<EOT>& _replace
|
||||||
/// Apply one generation of evolution to the population.
|
) : continuator(_continuator),
|
||||||
virtual void operator()(eoPop<Chrom>& pop) {
|
eval(_eval),
|
||||||
while ( terminator( pop ) ) {
|
selectTransform(0),
|
||||||
|
breed(_breed),
|
||||||
|
mergeReduce(0),
|
||||||
|
replace(_replace)
|
||||||
|
{}
|
||||||
|
|
||||||
|
/// Ctor eoBreed, eoMerge and eoReduce.
|
||||||
|
eoEasyEA(
|
||||||
|
eoContinue<EOT>& _continuator,
|
||||||
|
eoEvalFunc<EOT>& _eval,
|
||||||
|
eoBreed<EOT>& _breed,
|
||||||
|
eoMerge<EOT>& _merge,
|
||||||
|
eoReduce<EOT>& _reduce
|
||||||
|
) : continuator(_continuator),
|
||||||
|
eval(_eval),
|
||||||
|
selectTransform(0),
|
||||||
|
breed(_breed),
|
||||||
|
mergeReduce(new eoMergeReduce<EOT>(_merge, _reduce)),
|
||||||
|
replace(mergeReduce)
|
||||||
|
{}
|
||||||
|
|
||||||
|
/// Ctor eoSelect, eoTransform, and eoReplacement
|
||||||
|
eoEasyEA(
|
||||||
|
eoContinue<EOT>& _continuator,
|
||||||
|
eoEvalFunc<EOT>& _eval,
|
||||||
|
eoSelect<EOT>& _select,
|
||||||
|
eoTransform<EOT>& _transform,
|
||||||
|
eoReplacement<EOT>& _replace
|
||||||
|
) : continuator(_continuator),
|
||||||
|
eval(_eval),
|
||||||
|
selectTransform(new eoSelectTransform<EOT>(_select, _transform)),
|
||||||
|
breed(selectTransform),
|
||||||
|
mergeReduce(0),
|
||||||
|
replace(_replace)
|
||||||
|
{}
|
||||||
|
|
||||||
|
/// Ctor eoSelect, eoTransform, eoMerge and eoReduce.
|
||||||
|
eoEasyEA(
|
||||||
|
eoContinue<EOT>& _continuator,
|
||||||
|
eoEvalFunc<EOT>& _eval,
|
||||||
|
eoSelect<EOT>& _select,
|
||||||
|
eoTransform<EOT>& _transform,
|
||||||
|
eoMerge<EOT>& _merge,
|
||||||
|
eoReduce<EOT>& _reduce
|
||||||
|
) : continuator(_continuator),
|
||||||
|
eval(_eval),
|
||||||
|
selectTransform(new eoSelectTransform<EOT>(_select, _transform)),
|
||||||
|
breed(*selectTransform),
|
||||||
|
mergeReduce(new eoMergeReduce<EOT>(_merge, _reduce)),
|
||||||
|
replace(*mergeReduce)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
~eoEasyEA() { delete selectTransform; delete mergeReduce; }
|
||||||
|
|
||||||
|
/// Apply a few generation of evolution to the population.
|
||||||
|
virtual void operator()(eoPop<EOT>& _pop)
|
||||||
|
{
|
||||||
|
eoPop<EOT> offspring;
|
||||||
|
|
||||||
|
while ( continuator( _pop ) )
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
step(pop);
|
breed(_pop, offspring);
|
||||||
}
|
|
||||||
|
apply<EOT>(eval, offspring);
|
||||||
|
|
||||||
|
replace(_pop, offspring);
|
||||||
|
|
||||||
|
if (offspring.size() < _pop.size())
|
||||||
|
throw runtime_error("Population shrinking!");
|
||||||
|
else if (offspring.size() > _pop.size())
|
||||||
|
throw runtime_error("Population growing!");
|
||||||
|
|
||||||
|
_pop.swap(offspring);
|
||||||
|
|
||||||
|
}
|
||||||
catch (exception& e)
|
catch (exception& e)
|
||||||
{
|
{
|
||||||
string s = e.what();
|
string s = e.what();
|
||||||
s.append( " in eoEasyEA ");
|
s.append( " in eoSelectTransformReduce ");
|
||||||
throw runtime_error( s );
|
throw runtime_error( s );
|
||||||
}
|
}
|
||||||
} // while
|
} // while
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Class name.
|
|
||||||
string className() const { return "eoEasyEA"; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
eoGeneration<Chrom> step;
|
|
||||||
eoTerm<Chrom>& terminator;
|
/// dissallow copying cuz of pointer stuff
|
||||||
|
eoEasyEA(const eoEasyEA&);
|
||||||
|
/// dissallow copying cuz of pointer stuff
|
||||||
|
const eoEasyEA& operator=(const eoEasyEA&);
|
||||||
|
|
||||||
|
eoContinue<EOT>& continuator;
|
||||||
|
eoEvalFunc<EOT>& eval;
|
||||||
|
eoSelectTransform<EOT>* selectTransform;
|
||||||
|
eoBreed<EOT>& breed;
|
||||||
|
eoMergeReduce<EOT>* mergeReduce;
|
||||||
|
eoReplacement<EOT>& replace;
|
||||||
};
|
};
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#endif eoEasyEA_h
|
#endif eoSelectTransformReduce_h
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@
|
||||||
#ifndef eoEvalFunc_H
|
#ifndef eoEvalFunc_H
|
||||||
#define eoEvalFunc_H
|
#define eoEvalFunc_H
|
||||||
|
|
||||||
|
#include <eoFunctor.h>
|
||||||
|
|
||||||
/** Evaluate: takes one EO and sets its "fitness" property
|
/** Evaluate: takes one EO and sets its "fitness" property
|
||||||
* returning this fitness also. That is why EOT is passed by
|
* returning this fitness also. That is why EOT is passed by
|
||||||
* non-const reference: it must be altered within evaluate.\\
|
* non-const reference: it must be altered within evaluate.\\
|
||||||
|
|
@ -35,25 +37,11 @@
|
||||||
on it. If you subclass this abstract class, and use it to evaluate an
|
on it. If you subclass this abstract class, and use it to evaluate an
|
||||||
EO, the requirements on this EO will depend on the evaluator.
|
EO, the requirements on this EO will depend on the evaluator.
|
||||||
*/
|
*/
|
||||||
template<class EOT> struct eoEvalFunc {
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
template<class EOT> class eoEvalFunc : public eoUnaryFunctor<void, EOT&>
|
||||||
typedef EOT::Fitness EOFitT;
|
{
|
||||||
#else
|
public :
|
||||||
typedef typename EOT::Fitness EOFitT;
|
typedef typename EOT::Fitness EOFitT;
|
||||||
#endif
|
|
||||||
|
|
||||||
/// Effectively applies the evaluation function to an EO
|
|
||||||
virtual void operator() ( EOT & _eo ) const = 0;
|
|
||||||
|
|
||||||
template <class It>
|
|
||||||
void range(It begin, It end) const
|
|
||||||
{
|
|
||||||
for (;begin != end; ++begin)
|
|
||||||
{
|
|
||||||
operator()(*begin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -35,7 +35,7 @@
|
||||||
* function class. That way, old style C or C++ functions can be adapted to EO
|
* function class. That way, old style C or C++ functions can be adapted to EO
|
||||||
* function classes.
|
* function classes.
|
||||||
*/
|
*/
|
||||||
template< class EOT >
|
template< class EOT, class FitT = typename EOT::Fitness, class FunctionArg = const EOT& >
|
||||||
struct eoEvalFuncPtr: public eoEvalFunc<EOT> {
|
struct eoEvalFuncPtr: public eoEvalFunc<EOT> {
|
||||||
|
|
||||||
/** Applies the function to the chromosome and sets the fitness of the
|
/** Applies the function to the chromosome and sets the fitness of the
|
||||||
|
|
@ -44,16 +44,18 @@ struct eoEvalFuncPtr: public eoEvalFunc<EOT> {
|
||||||
argument and returns the fitness
|
argument and returns the fitness
|
||||||
@return the evaluated fitness for that object.
|
@return the evaluated fitness for that object.
|
||||||
*/
|
*/
|
||||||
eoEvalFuncPtr( EOFitT (* _eval)( const EOT& ) )
|
eoEvalFuncPtr( FitT (* _eval)( FunctionArg ) )
|
||||||
: eoEvalFunc<EOT>(), evalFunc( _eval ) {};
|
: eoEvalFunc<EOT>(), evalFunc( _eval ) {};
|
||||||
|
|
||||||
/// Effectively applies the evaluation function to an EO
|
/// Effectively applies the evaluation function to an EO
|
||||||
virtual void operator() ( EOT & _eo ) const {
|
virtual void operator() ( EOT & _eo )
|
||||||
_eo.fitness((*evalFunc)( _eo ));
|
{
|
||||||
|
if (_eo.invalid())
|
||||||
|
_eo.fitness((*evalFunc)( _eo ));
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EOFitT (* evalFunc )( const EOT& );
|
FitT (* evalFunc )( FunctionArg );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
87
eo/src/eoEvolutionStrategy.h
Normal file
87
eo/src/eoEvolutionStrategy.h
Normal file
|
|
@ -0,0 +1,87 @@
|
||||||
|
// -*- 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 <eoEasyEA.h>
|
||||||
|
#include <eoInplaceTransform.h>
|
||||||
|
/** eoEvolutionStrategy:
|
||||||
|
*/
|
||||||
|
|
||||||
|
template<class EOT>
|
||||||
|
class eoEvolutionStrategy: public eoAlgo<EOT>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
struct plus_strategy{};
|
||||||
|
struct comma_strategy{};
|
||||||
|
|
||||||
|
eoEvolutionStrategy(
|
||||||
|
eoContinue<EOT>& _continuator,
|
||||||
|
eoEvalFunc<EOT>& _eval,
|
||||||
|
eoGOpSelector<EOT>& _opSel,
|
||||||
|
float _lambdaRate,
|
||||||
|
comma_strategy)
|
||||||
|
: selectPerc(randomSelect, _lambdaRate),
|
||||||
|
transform(_opSel),
|
||||||
|
easyEA(_continuator, _eval, selectPerc, transform, noElitism, truncate)
|
||||||
|
{}
|
||||||
|
|
||||||
|
eoEvolutionStrategy(
|
||||||
|
eoContinue<EOT>& _continuator,
|
||||||
|
eoEvalFunc<EOT>& _eval,
|
||||||
|
eoGOpSelector<EOT>& _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<EOT>& _pop)
|
||||||
|
{
|
||||||
|
easyEA(_pop);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
eoPlus<EOT> plus;
|
||||||
|
eoNoElitism<EOT> noElitism;
|
||||||
|
eoTruncate<EOT> truncate;
|
||||||
|
eoSelectRandom<EOT> randomSelect;
|
||||||
|
eoSelectPerc<EOT> selectPerc;
|
||||||
|
eoInplaceTransform2<EOT> transform;
|
||||||
|
|
||||||
|
/// easyEA is contained rather than a base because of member initialization order!
|
||||||
|
eoEasyEA<EOT> easyEA;
|
||||||
|
};
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#endif eoSelectTransformReduce_h
|
||||||
|
|
||||||
58
eo/src/eoFitContinue.h
Normal file
58
eo/src/eoFitContinue.h
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// eoFitContinue.h
|
||||||
|
// (c) Maarten Keijzer, 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 _eoFitContinue_h
|
||||||
|
#define _eoFitContinue_h
|
||||||
|
|
||||||
|
#include <eoContinue.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
Fitness continuation:
|
||||||
|
|
||||||
|
Continues until the maximum fitness level is reached.
|
||||||
|
*/
|
||||||
|
template< class EOT>
|
||||||
|
class eoFitContinue: public eoContinue<EOT> {
|
||||||
|
public:
|
||||||
|
|
||||||
|
/// Define Fitness
|
||||||
|
typedef typename EOT::Fitness FitnessType;
|
||||||
|
|
||||||
|
/// Ctor
|
||||||
|
eoFitContinue( const FitnessType _maximum)
|
||||||
|
: eoContinue<EOT> (), maximum( _maximum ) {};
|
||||||
|
|
||||||
|
/** Returns false when a fitness criterium is
|
||||||
|
* reached. Assumes pop is not sorted! */
|
||||||
|
virtual bool operator() ( const eoPop<EOT>& _pop )
|
||||||
|
{
|
||||||
|
return (_pop.nth_element_fitness(0) < maximum);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
FitnessType maximum;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
@ -28,7 +28,7 @@
|
||||||
#define _eoFixedLength_h
|
#define _eoFixedLength_h
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <EO.h>
|
||||||
/**
|
/**
|
||||||
|
|
||||||
Base class for fixed length chromosomes, just derives from EO and vector and
|
Base class for fixed length chromosomes, just derives from EO and vector and
|
||||||
|
|
@ -40,7 +40,11 @@ class eoFixedLength : public EO<FitT>, public std::vector<GeneType>
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
||||||
typedef GeneType Type;
|
typedef GeneType AtomType;
|
||||||
|
typedef std::vector<GeneType> ContainerType;
|
||||||
|
|
||||||
|
eoFixedLength(unsigned size = 0, GeneType value = GeneType()) : EO<FitT>(), std::vector<GeneType>(size, value)
|
||||||
|
{}
|
||||||
|
|
||||||
/// to avoid conflicts between EO::operator< and vector<double>::operator<
|
/// to avoid conflicts between EO::operator< and vector<double>::operator<
|
||||||
bool operator<(const eoFixedLength<FitT, GeneType>& _eo) const
|
bool operator<(const eoFixedLength<FitT, GeneType>& _eo) const
|
||||||
|
|
@ -71,7 +75,11 @@ class eoFixedLength : public EO<FitT>, public std::vector<GeneType>
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
|
||||||
for (i = 0; i < sz; ++i)
|
for (i = 0; i < sz; ++i)
|
||||||
is >> operator[](i);
|
{
|
||||||
|
AtomType atom;
|
||||||
|
is >> atom;
|
||||||
|
operator[](i) = atom;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Reference in a new issue