Checking in the name changes in selection procedures.
This impacts on many files, creating new entries in src (the old ones are moved to obsolete dir), modifying t-eoSymreg.cpp and t-eobin.cpp in test, as well as gprop.cc and mastermind.cc in app dir (not to mention almost all files in tutorial:-(
This commit is contained in:
parent
b6e9945028
commit
a998ad0a41
36 changed files with 922 additions and 226 deletions
17
eo/src/eo
17
eo/src/eo
|
|
@ -92,21 +92,24 @@
|
|||
#include <eoEvalFuncPtr.h>
|
||||
|
||||
// Continuators
|
||||
#include <eoContinue.h>
|
||||
// #include <eoContinue.h> // already included in the following
|
||||
#include <eoCombinedContinue.h>
|
||||
#include <eoGenContinue.h>
|
||||
#include <eoSteadyFitContinue.h>
|
||||
#include <eoFitContinue.h>
|
||||
|
||||
// Selection
|
||||
#include <eoSelectOne.h>
|
||||
#include <eoSelectRandom.h>
|
||||
#include <eoDetTournament.h>
|
||||
#include <eoProportional.h>
|
||||
#include <eoStochTournament.h>
|
||||
// the eoSelectOne
|
||||
#include <eoRandomSelect.h>
|
||||
#include <eoDetTournamentSelect.h>
|
||||
#include <eoProportionalSelect.h>
|
||||
#include <eoStochTournamentSelect.h>
|
||||
// the batch selection - from an eoSelectOne
|
||||
#include <eoSelectPerc.h>
|
||||
#include <eoSelectNumber.h>
|
||||
#include <eoSelectMany.h>
|
||||
// other batch selections
|
||||
#include <eoDetSelect.h>
|
||||
|
||||
|
||||
// Replacement
|
||||
|
|
@ -129,6 +132,8 @@
|
|||
|
||||
//#include <eoProportionalOpSel.h>
|
||||
|
||||
#include <eoSGATransform.h>
|
||||
|
||||
// Algorithms
|
||||
#include <eoEasyEA.h>
|
||||
#include <eoSGA.h>
|
||||
|
|
|
|||
69
eo/src/eoDetTournamentSelect.h
Executable file
69
eo/src/eoDetTournamentSelect.h
Executable file
|
|
@ -0,0 +1,69 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoDetTournament.h
|
||||
// (c) GeNeura Team, 1998 - EEAAX 1999
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef eoDetTournament_h
|
||||
#define eoDetTournament_h
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <functional> //
|
||||
#include <numeric> // accumulate
|
||||
|
||||
#include <eoFunctor.h>
|
||||
#include <eoPop.h>
|
||||
#include <utils/selectors.h>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** eoDetTournamentSelect: a selection method that selects ONE individual by
|
||||
deterministic tournament
|
||||
-MS- 24/10/99 */
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template <class EOT> class eoDetTournamentSelect: public eoSelectOne<EOT>
|
||||
{
|
||||
public:
|
||||
/// (Default) Constructor.
|
||||
eoDetTournamentSelect(unsigned _Tsize = 2 ):eoSelectOne<EOT>(), Tsize(_Tsize) {
|
||||
// consistency check
|
||||
if (Tsize < 2) {
|
||||
cout << "Warning, Tournament size should be >= 2\nAdjusted\n";
|
||||
Tsize = 2;
|
||||
}
|
||||
}
|
||||
|
||||
/// Perform deterministic tournament
|
||||
virtual const EOT& operator()(const eoPop<EOT>& pop)
|
||||
{
|
||||
return deterministic_tournament(pop, Tsize);
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned Tsize;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#endif eoDetTournamentSelect_h
|
||||
|
||||
|
|
@ -73,7 +73,7 @@ class eoEvolutionStrategy: public eoAlgo<EOT>
|
|||
eoPlus<EOT> plus;
|
||||
eoNoElitism<EOT> noElitism;
|
||||
eoTruncate<EOT> truncate;
|
||||
eoSelectRandom<EOT> randomSelect;
|
||||
eoRandomSelect<EOT> randomSelect;
|
||||
eoSelectPerc<EOT> selectPerc;
|
||||
eoInplaceTransform2<EOT> transform;
|
||||
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ template<class Chrom> class eoInplaceTransform1 : public eoTransform<Chrom>
|
|||
|
||||
private:
|
||||
eoOpSelector<Chrom>& opSel;
|
||||
eoSelectRandom<Chrom> defaultSelect;
|
||||
eoRandomSelect<Chrom> defaultSelect;
|
||||
eoSelectOne<Chrom>& select;
|
||||
|
||||
};
|
||||
|
|
@ -181,7 +181,7 @@ template<class Chrom> class eoInplaceTransform2 : public eoTransform<Chrom>
|
|||
|
||||
private:
|
||||
eoGOpSelector<Chrom>& opSel;
|
||||
eoSelectRandom<Chrom> defaultSelect;
|
||||
eoRandomSelect<Chrom> defaultSelect;
|
||||
eoSelectOne<Chrom>& select;
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -94,5 +94,22 @@ class eoCommaReplacement : public eoMergeReduce<EOT>
|
|||
eoTruncate<EOT> truncate;
|
||||
};
|
||||
|
||||
/**
|
||||
EP type of replacement strategy: first add parents to population,
|
||||
then truncate using EP tournament
|
||||
*/
|
||||
template <class EOT>
|
||||
class eoEPReplacement : public eoMergeReduce<EOT>
|
||||
{
|
||||
public :
|
||||
eoEPReplacement(int _tSize) : eoMergeReduce<EOT>(plus, truncate), truncate(_tSize)
|
||||
// {truncate.setSize(_tSize);}
|
||||
{}
|
||||
private :
|
||||
eoPlus<EOT> plus;
|
||||
eoEPReduce<EOT> truncate;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
71
eo/src/eoProportionalSelect.h
Executable file
71
eo/src/eoProportionalSelect.h
Executable file
|
|
@ -0,0 +1,71 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoProportionalSelect.h
|
||||
// (c) GeNeura Team, 1998 - EEAAX 1999, Maarten Keijzer 2000
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
mak@dhi.dk
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef eoProportionalSelect_h
|
||||
#define eoProportionalSelect_h
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <utils/eoRNG.h>
|
||||
#include <utils/selectors.h>
|
||||
#include <eoSelectOne.h>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** eoProportionalSelect: select an individual proportional to her stored fitness
|
||||
value
|
||||
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template <class EOT> class eoProportionalSelect: public eoSelectOne<EOT>
|
||||
{
|
||||
public:
|
||||
/// Sanity check
|
||||
eoProportionalSelect(const eoPop<EOT>& pop = eoPop<EOT>()):
|
||||
total((pop.size() == 0) ? -1.0 : sum_fitness(pop))
|
||||
{
|
||||
if (minimizing_fitness<EOT>())
|
||||
throw logic_error("eoProportionalSelect: minimizing fitness");
|
||||
}
|
||||
|
||||
void setup(const eoPop<EOT>& _pop)
|
||||
{
|
||||
total = sum_fitness(_pop);
|
||||
}
|
||||
|
||||
/** do the selection, call roulette_wheel.
|
||||
*/
|
||||
const EOT& operator()(const eoPop<EOT>& _pop)
|
||||
{
|
||||
return roulette_wheel(_pop, total) ;
|
||||
}
|
||||
|
||||
private :
|
||||
typename EOT::Fitness total;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
52
eo/src/eoRandomSelect.h
Normal file
52
eo/src/eoRandomSelect.h
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoRandomSelect.h
|
||||
// (c) GeNeura Team, 1998 - EEAAX 1999, Maarten Keijzer 2000
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
mak@dhi.dk
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef eoRandomSelect_h
|
||||
#define eoRandomSelect_h
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <utils/eoRNG.h>
|
||||
#include <eoSelectOne.h>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** eoRandomSelect: a selection method that selects ONE individual randomly
|
||||
-MS- 22/10/99 */
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template <class EOT> class eoRandomSelect: public eoSelectOne<EOT>
|
||||
{
|
||||
public:
|
||||
|
||||
/// not a big deal!!!
|
||||
virtual const EOT& operator()(const eoPop<EOT>& pop)
|
||||
{
|
||||
return pop[rng.random(pop.size())] ;
|
||||
}
|
||||
};
|
||||
|
||||
#endif eoRandomSelect_h
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ template <class EOT> class eoEPReduce : public eoReduce<EOT>
|
|||
public:
|
||||
typedef typename EOT::Fitness Fitness;
|
||||
|
||||
eoEPReduce(unsigned _t_size):
|
||||
eoEPReduce(unsigned _t_size ):
|
||||
t_size(_t_size)
|
||||
{
|
||||
if (t_size < 2)
|
||||
|
|
@ -79,17 +79,24 @@ typedef typename EOT::Fitness Fitness;
|
|||
}
|
||||
|
||||
/// helper struct for comparing on pairs
|
||||
// compares the scores
|
||||
// uses the fitness if scores are equals ????
|
||||
typedef pair<float, eoPop<EOT>::iterator> EPpair;
|
||||
struct Cmp {
|
||||
bool operator()(const EPpair a, const EPpair b) const
|
||||
{ return b.first < a.first; }
|
||||
};
|
||||
|
||||
|
||||
void operator()(eoPop<EOT>& _newgen, unsigned _newsize)
|
||||
{
|
||||
unsigned int presentSize = _newgen.size();
|
||||
if (presentSize == _newsize)
|
||||
struct Cmp {
|
||||
bool operator()(const EPpair a, const EPpair b) const
|
||||
{
|
||||
if (b.first == a.first)
|
||||
return (*b.second < *a.second);
|
||||
return b.first < a.first;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void operator()(eoPop<EOT>& _newgen, unsigned _newsize)
|
||||
{
|
||||
unsigned int presentSize = _newgen.size();
|
||||
|
||||
if (presentSize == _newsize)
|
||||
return;
|
||||
if (presentSize < _newsize)
|
||||
throw std::logic_error("eoTruncate: Cannot truncate to a larger size!\n");
|
||||
|
|
@ -107,12 +114,30 @@ typedef typename EOT::Fitness Fitness;
|
|||
scores[i].first += 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
// now we have the scores
|
||||
typename vector<EPpair>::iterator it = scores.begin() + _newsize;
|
||||
std::nth_element(scores.begin(), it, scores.end(), Cmp());
|
||||
it = scores.begin() + _newsize; // just in case ???
|
||||
while (it < scores.end())
|
||||
_newgen.erase(it->second);
|
||||
std::nth_element(scores.begin(), it, scores.end(), Cmp());
|
||||
// sort(scores.begin(), scores.end(), Cmp());
|
||||
unsigned j;
|
||||
// cout << "Les scores apres tri\n";
|
||||
// for (j=0; j<scores.size(); j++)
|
||||
// {
|
||||
// cout << scores[j].first << " " << *scores[j].second << endl;
|
||||
// }
|
||||
eoPop<EOT> tmPop;
|
||||
for (j=0; j<_newsize; j++)
|
||||
{
|
||||
tmPop.push_back(*scores[j].second);
|
||||
}
|
||||
_newgen.swap(tmPop);
|
||||
// erase does not work, but I'm sure there is a way in STL to mark
|
||||
// and later delete all inside a vector ??????
|
||||
// this would avoid all copies here
|
||||
|
||||
// it = scores.begin() + _newsize;
|
||||
// while (it < scores.end())
|
||||
// _newgen.erase(it->second);
|
||||
}
|
||||
private:
|
||||
unsigned t_size;
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ template<class EOT> class eoSGATransform : public eoTransform<EOT>
|
|||
};
|
||||
|
||||
/*****************************************************************************
|
||||
* eoSDynGATransform: transforms a population using genetic operators.
|
||||
* eoDynSGATransform: transforms a population using genetic operators.
|
||||
* It is the Dynamic version of the above eoSGATransform
|
||||
* i.e. the operators probabilities can be passed as an eoValueParam,
|
||||
* and hence can be modified from outside
|
||||
|
|
@ -109,15 +109,15 @@ template<class EOT> class eoDynSGATransform : public eoTransform<EOT>
|
|||
mutate(_mutate),
|
||||
mutationProbaHolder(_mProba), mutationProba(mutationProbaHolder) {}
|
||||
|
||||
/// This constructor receives references
|
||||
/// This constructor receives pointers
|
||||
// these will usually be some eoValueParam<double>.value()
|
||||
// the ...Holder will bever be used in this object
|
||||
eoDynSGATransform(eoQuadraticOp<EOT>& _cross, double& _cProbaRef,
|
||||
eoMonOp<EOT>& _mutate, double& _mProbaRef)
|
||||
// hence the ...Holder data will bever be used in this case
|
||||
eoDynSGATransform(eoQuadraticOp<EOT>& _cross, double* _cProbaRef,
|
||||
eoMonOp<EOT>& _mutate, double* _mProbaRef)
|
||||
: cross(_cross),
|
||||
crossoverProbaHolder(0), crossoverProba(_cProbaRef),
|
||||
crossoverProbaHolder(0), crossoverProba(*_cProbaRef),
|
||||
mutate(_mutate),
|
||||
mutationProbaHolder(0), mutationProba(_mProbaRef) {}
|
||||
mutationProbaHolder(0), mutationProba(*_mProbaRef) {}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -146,8 +146,11 @@ template<class EOT> class eoDynSGATransform : public eoTransform<EOT>
|
|||
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
// accessors - mainly for EASEA
|
||||
double & PCrossHandle() { return crossoverProba;}
|
||||
double & PMutHandle() { return mutationProba;}
|
||||
|
||||
private:
|
||||
// difference with eoSGATransform: the operator probabilities
|
||||
// they can be passed by reference or by value.
|
||||
// hence we need here to use a reference, and to eventually store a value
|
||||
|
|
|
|||
69
eo/src/eoStochTournamentSelect.h
Executable file
69
eo/src/eoStochTournamentSelect.h
Executable file
|
|
@ -0,0 +1,69 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoStochTournamentSelect.h
|
||||
// (c) GeNeura Team, 1998 - EEAAX 1999
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef eoStochTournamentSelect_h
|
||||
#define eoStochTournamentSelect_h
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <functional>
|
||||
#include <numeric> // accumulate
|
||||
#include <eoSelectOne.h> // eoSelectOne
|
||||
#include <utils/selectors.h> // stochastic_tournament
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** eoStochTournamentSelect: a selection method that selects ONE individual by
|
||||
binary stochastic tournament
|
||||
-MS- 24/10/99 */
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template <class EOT> class eoStochTournamentSelect: public eoSelectOne<EOT>
|
||||
{
|
||||
public:
|
||||
|
||||
///
|
||||
eoStochTournamentSelect(float _Trate = 1.0 ) : eoSelectOne<EOT>(), Trate(_Trate)
|
||||
{
|
||||
// consistency check
|
||||
if (Trate < 0.5) {
|
||||
cerr << "Warning, Tournament rate should be > 0.5\nAdjusted to 0.55\n";
|
||||
Trate = 0.55;
|
||||
}
|
||||
}
|
||||
|
||||
/** Perform the stochastic tournament */
|
||||
virtual const EOT& operator()(const eoPop<EOT>& pop)
|
||||
{
|
||||
return stochastic_tournament(pop, Trate);
|
||||
}
|
||||
|
||||
private:
|
||||
float Trate;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#endif eoStochTournamentSelect_h
|
||||
|
||||
Reference in a new issue