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
|
|
@ -7,17 +7,7 @@
|
||||||
#include <iostream> // cerr cout
|
#include <iostream> // cerr cout
|
||||||
#include <fstream> // ifstream
|
#include <fstream> // ifstream
|
||||||
#include <string> // string
|
#include <string> // string
|
||||||
#include <utils/eoParser.h> // eoParser
|
#include <eo> // all usefull eo stuff
|
||||||
#include <eoPop.h> // eoPop
|
|
||||||
#include <eoEvalFuncPtr.h> // eoEvalFunc
|
|
||||||
#include <eoStochTournament.h> // eoStochTournament
|
|
||||||
#include <eoGenContinue.h> // eoGenContinue
|
|
||||||
#include <eoFitContinue.h> // eoFitContinue
|
|
||||||
#include <eoCombinedContinue.h> // eoCombinedContinue
|
|
||||||
#include <utils/eoCheckPoint.h> // eoCheckPoint
|
|
||||||
#include <utils/eoStat.h> // eoBestFitnessStat
|
|
||||||
#include <utils/eoStdoutMonitor.h> // eoStdoutMonitor
|
|
||||||
#include <eoSGA.h> // eoSGA
|
|
||||||
#include "gprop.h" // Chrom eoChromInit eoChromMutation eoChromXover eoChromEvaluator
|
#include "gprop.h" // Chrom eoChromInit eoChromMutation eoChromXover eoChromEvaluator
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
@ -134,7 +124,7 @@ void ga()
|
||||||
apply<Chrom>(evaluator, pop);
|
apply<Chrom>(evaluator, pop);
|
||||||
|
|
||||||
// selector
|
// selector
|
||||||
eoStochTournament<Chrom> select;
|
eoStochTournamentSelect<Chrom> select;
|
||||||
|
|
||||||
// genetic operators
|
// genetic operators
|
||||||
eoChromMutation mutation;
|
eoChromMutation mutation;
|
||||||
|
|
|
||||||
|
|
@ -7,17 +7,7 @@
|
||||||
#include <iostream> // cerr cout
|
#include <iostream> // cerr cout
|
||||||
#include <fstream> // ifstream
|
#include <fstream> // ifstream
|
||||||
#include <string> // string
|
#include <string> // string
|
||||||
#include <utils/eoParser.h> // eoParser
|
#include <eo> // all usefull eo stuff
|
||||||
#include <eoPop.h> // eoPop
|
|
||||||
#include <eoEvalFuncPtr.h> // eoEvalFunc
|
|
||||||
#include <eoProportional.h> // eoProportional
|
|
||||||
#include <eoGenContinue.h> // eoGenContinue
|
|
||||||
#include <eoFitContinue.h> // eoFitContinue
|
|
||||||
#include <eoCombinedContinue.h> // eoCombinedContinue
|
|
||||||
#include <utils/eoCheckPoint.h> // eoCheckPoint
|
|
||||||
#include <utils/eoStat.h> // eoBestFitnessStat
|
|
||||||
#include <utils/eoStdoutMonitor.h> // eoStdoutMonitor
|
|
||||||
#include <eoSGA.h> // eoSGA
|
|
||||||
#include "mastermind.h" // Chrom eoChromInit eoChromMutation eoChromXover eoChromEvaluator
|
#include "mastermind.h" // Chrom eoChromInit eoChromMutation eoChromXover eoChromEvaluator
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
@ -103,7 +93,7 @@ void ga()
|
||||||
apply<Chrom>(evaluator, pop);
|
apply<Chrom>(evaluator, pop);
|
||||||
|
|
||||||
// selector
|
// selector
|
||||||
eoProportional<Chrom> select(pop);
|
eoProportionalSelect<Chrom> select(pop);
|
||||||
|
|
||||||
// genetic operators
|
// genetic operators
|
||||||
eoChromMutation mutation;
|
eoChromMutation mutation;
|
||||||
|
|
|
||||||
17
eo/src/eo
17
eo/src/eo
|
|
@ -92,21 +92,24 @@
|
||||||
#include <eoEvalFuncPtr.h>
|
#include <eoEvalFuncPtr.h>
|
||||||
|
|
||||||
// Continuators
|
// Continuators
|
||||||
#include <eoContinue.h>
|
// #include <eoContinue.h> // already included in the following
|
||||||
#include <eoCombinedContinue.h>
|
#include <eoCombinedContinue.h>
|
||||||
#include <eoGenContinue.h>
|
#include <eoGenContinue.h>
|
||||||
#include <eoSteadyFitContinue.h>
|
#include <eoSteadyFitContinue.h>
|
||||||
#include <eoFitContinue.h>
|
#include <eoFitContinue.h>
|
||||||
|
|
||||||
// Selection
|
// Selection
|
||||||
#include <eoSelectOne.h>
|
// the eoSelectOne
|
||||||
#include <eoSelectRandom.h>
|
#include <eoRandomSelect.h>
|
||||||
#include <eoDetTournament.h>
|
#include <eoDetTournamentSelect.h>
|
||||||
#include <eoProportional.h>
|
#include <eoProportionalSelect.h>
|
||||||
#include <eoStochTournament.h>
|
#include <eoStochTournamentSelect.h>
|
||||||
|
// the batch selection - from an eoSelectOne
|
||||||
#include <eoSelectPerc.h>
|
#include <eoSelectPerc.h>
|
||||||
#include <eoSelectNumber.h>
|
#include <eoSelectNumber.h>
|
||||||
#include <eoSelectMany.h>
|
#include <eoSelectMany.h>
|
||||||
|
// other batch selections
|
||||||
|
#include <eoDetSelect.h>
|
||||||
|
|
||||||
|
|
||||||
// Replacement
|
// Replacement
|
||||||
|
|
@ -129,6 +132,8 @@
|
||||||
|
|
||||||
//#include <eoProportionalOpSel.h>
|
//#include <eoProportionalOpSel.h>
|
||||||
|
|
||||||
|
#include <eoSGATransform.h>
|
||||||
|
|
||||||
// Algorithms
|
// Algorithms
|
||||||
#include <eoEasyEA.h>
|
#include <eoEasyEA.h>
|
||||||
#include <eoSGA.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;
|
eoPlus<EOT> plus;
|
||||||
eoNoElitism<EOT> noElitism;
|
eoNoElitism<EOT> noElitism;
|
||||||
eoTruncate<EOT> truncate;
|
eoTruncate<EOT> truncate;
|
||||||
eoSelectRandom<EOT> randomSelect;
|
eoRandomSelect<EOT> randomSelect;
|
||||||
eoSelectPerc<EOT> selectPerc;
|
eoSelectPerc<EOT> selectPerc;
|
||||||
eoInplaceTransform2<EOT> transform;
|
eoInplaceTransform2<EOT> transform;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@ template<class Chrom> class eoInplaceTransform1 : public eoTransform<Chrom>
|
||||||
|
|
||||||
private:
|
private:
|
||||||
eoOpSelector<Chrom>& opSel;
|
eoOpSelector<Chrom>& opSel;
|
||||||
eoSelectRandom<Chrom> defaultSelect;
|
eoRandomSelect<Chrom> defaultSelect;
|
||||||
eoSelectOne<Chrom>& select;
|
eoSelectOne<Chrom>& select;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
@ -181,7 +181,7 @@ template<class Chrom> class eoInplaceTransform2 : public eoTransform<Chrom>
|
||||||
|
|
||||||
private:
|
private:
|
||||||
eoGOpSelector<Chrom>& opSel;
|
eoGOpSelector<Chrom>& opSel;
|
||||||
eoSelectRandom<Chrom> defaultSelect;
|
eoRandomSelect<Chrom> defaultSelect;
|
||||||
eoSelectOne<Chrom>& select;
|
eoSelectOne<Chrom>& select;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -94,5 +94,22 @@ class eoCommaReplacement : public eoMergeReduce<EOT>
|
||||||
eoTruncate<EOT> truncate;
|
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
|
#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:
|
public:
|
||||||
typedef typename EOT::Fitness Fitness;
|
typedef typename EOT::Fitness Fitness;
|
||||||
|
|
||||||
eoEPReduce(unsigned _t_size):
|
eoEPReduce(unsigned _t_size ):
|
||||||
t_size(_t_size)
|
t_size(_t_size)
|
||||||
{
|
{
|
||||||
if (t_size < 2)
|
if (t_size < 2)
|
||||||
|
|
@ -79,17 +79,24 @@ typedef typename EOT::Fitness Fitness;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// helper struct for comparing on pairs
|
/// helper struct for comparing on pairs
|
||||||
|
// compares the scores
|
||||||
|
// uses the fitness if scores are equals ????
|
||||||
typedef pair<float, eoPop<EOT>::iterator> EPpair;
|
typedef pair<float, eoPop<EOT>::iterator> EPpair;
|
||||||
struct Cmp {
|
struct Cmp {
|
||||||
bool operator()(const EPpair a, const EPpair b) const
|
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 (b.first == a.first)
|
||||||
if (presentSize == _newsize)
|
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;
|
return;
|
||||||
if (presentSize < _newsize)
|
if (presentSize < _newsize)
|
||||||
throw std::logic_error("eoTruncate: Cannot truncate to a larger size!\n");
|
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;
|
scores[i].first += 0.5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// now we have the scores
|
// now we have the scores
|
||||||
typename vector<EPpair>::iterator it = scores.begin() + _newsize;
|
typename vector<EPpair>::iterator it = scores.begin() + _newsize;
|
||||||
std::nth_element(scores.begin(), it, scores.end(), Cmp());
|
std::nth_element(scores.begin(), it, scores.end(), Cmp());
|
||||||
it = scores.begin() + _newsize; // just in case ???
|
// sort(scores.begin(), scores.end(), Cmp());
|
||||||
while (it < scores.end())
|
unsigned j;
|
||||||
_newgen.erase(it->second);
|
// 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:
|
private:
|
||||||
unsigned t_size;
|
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
|
* It is the Dynamic version of the above eoSGATransform
|
||||||
* i.e. the operators probabilities can be passed as an eoValueParam,
|
* i.e. the operators probabilities can be passed as an eoValueParam,
|
||||||
* and hence can be modified from outside
|
* and hence can be modified from outside
|
||||||
|
|
@ -109,15 +109,15 @@ template<class EOT> class eoDynSGATransform : public eoTransform<EOT>
|
||||||
mutate(_mutate),
|
mutate(_mutate),
|
||||||
mutationProbaHolder(_mProba), mutationProba(mutationProbaHolder) {}
|
mutationProbaHolder(_mProba), mutationProba(mutationProbaHolder) {}
|
||||||
|
|
||||||
/// This constructor receives references
|
/// This constructor receives pointers
|
||||||
// these will usually be some eoValueParam<double>.value()
|
// these will usually be some eoValueParam<double>.value()
|
||||||
// the ...Holder will bever be used in this object
|
// hence the ...Holder data will bever be used in this case
|
||||||
eoDynSGATransform(eoQuadraticOp<EOT>& _cross, double& _cProbaRef,
|
eoDynSGATransform(eoQuadraticOp<EOT>& _cross, double* _cProbaRef,
|
||||||
eoMonOp<EOT>& _mutate, double& _mProbaRef)
|
eoMonOp<EOT>& _mutate, double* _mProbaRef)
|
||||||
: cross(_cross),
|
: cross(_cross),
|
||||||
crossoverProbaHolder(0), crossoverProba(_cProbaRef),
|
crossoverProbaHolder(0), crossoverProba(*_cProbaRef),
|
||||||
mutate(_mutate),
|
mutate(_mutate),
|
||||||
mutationProbaHolder(0), mutationProba(_mProbaRef) {}
|
mutationProbaHolder(0), mutationProba(*_mProbaRef) {}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -146,8 +146,11 @@ template<class EOT> class eoDynSGATransform : public eoTransform<EOT>
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// accessors - mainly for EASEA
|
||||||
|
double & PCrossHandle() { return crossoverProba;}
|
||||||
|
double & PMutHandle() { return mutationProba;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// difference with eoSGATransform: the operator probabilities
|
// difference with eoSGATransform: the operator probabilities
|
||||||
// they can be passed by reference or by value.
|
// they can be passed by reference or by value.
|
||||||
// hence we need here to use a reference, and to eventually store a 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
|
||||||
|
|
||||||
69
eo/src/obsolete/eoDetTournament.h
Normal file
69
eo/src/obsolete/eoDetTournament.h
Normal 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>
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
/** eoDetTournament: a selection method that selects ONE individual by
|
||||||
|
deterministic tournament
|
||||||
|
-MS- 24/10/99 */
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
template <class EOT> class eoDetTournament: public eoSelectOne<EOT>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/// (Default) Constructor.
|
||||||
|
eoDetTournament(unsigned _Tsize = 2 ):eoSelectOne<EOT>(), Tsize(_Tsize) {
|
||||||
|
// consistency check
|
||||||
|
if (Tsize < 2) {
|
||||||
|
cout << "Warning, Tournament size should be >= 2\nAdjusted\n";
|
||||||
|
Tsize = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Perform deterministic tournament
|
||||||
|
virtual const EOT& operator()(const eoPop<EOT>& pop)
|
||||||
|
{
|
||||||
|
return deterministic_tournament(pop, Tsize);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
unsigned Tsize;
|
||||||
|
};
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#endif eoDetTournament_h
|
||||||
|
|
||||||
71
eo/src/obsolete/eoProportional.h
Normal file
71
eo/src/obsolete/eoProportional.h
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// eoProportional.h
|
||||||
|
// (c) GeNeura Team, 1998 - EEAAX 1999, Maarten Keijzer 2000
|
||||||
|
/*
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||||
|
Marc.Schoenauer@polytechnique.fr
|
||||||
|
mak@dhi.dk
|
||||||
|
*/
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef eoProportional_h
|
||||||
|
#define eoProportional_h
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <utils/eoRNG.h>
|
||||||
|
#include <utils/selectors.h>
|
||||||
|
#include <eoSelectOne.h>
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
/** eoProportional: select an individual proportional to her stored fitness
|
||||||
|
value
|
||||||
|
|
||||||
|
*/
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
template <class EOT> class eoProportional: public eoSelectOne<EOT>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/// Sanity check
|
||||||
|
eoProportional(const eoPop<EOT>& pop = eoPop<EOT>()):
|
||||||
|
total((pop.size() == 0) ? -1.0 : sum_fitness(pop))
|
||||||
|
{
|
||||||
|
if (minimizing_fitness<EOT>())
|
||||||
|
throw logic_error("eoProportional: 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/obsolete/eoSelectRandom.h
Normal file
52
eo/src/obsolete/eoSelectRandom.h
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// eoSelectRandom.h
|
||||||
|
// (c) GeNeura Team, 1998 - EEAAX 1999, Maarten Keijzer 2000
|
||||||
|
/*
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||||
|
Marc.Schoenauer@polytechnique.fr
|
||||||
|
mak@dhi.dk
|
||||||
|
*/
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef eoSelectRandom_h
|
||||||
|
#define eoSelectRandom_h
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <utils/eoRNG.h>
|
||||||
|
#include <eoSelectOne.h>
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
/** eoSelectRandom: a selection method that selects ONE individual randomly
|
||||||
|
-MS- 22/10/99 */
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
template <class EOT> class eoSelectRandom: public eoSelectOne<EOT>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/// not a big deal!!!
|
||||||
|
virtual const EOT& operator()(const eoPop<EOT>& pop)
|
||||||
|
{
|
||||||
|
return pop[rng.random(pop.size())] ;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif eoSelectRandom_h
|
||||||
|
|
||||||
69
eo/src/obsolete/eoStochTournament.h
Normal file
69
eo/src/obsolete/eoStochTournament.h
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// eoStochTournament.h
|
||||||
|
// (c) GeNeura Team, 1998 - EEAAX 1999
|
||||||
|
/*
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||||
|
Marc.Schoenauer@polytechnique.fr
|
||||||
|
*/
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef eoStochTournament_h
|
||||||
|
#define eoStochTournament_h
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <numeric> // accumulate
|
||||||
|
#include <eoSelectOne.h> // eoSelectOne
|
||||||
|
#include <utils/selectors.h> // stochastic_tournament
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
/** eoStochTournament: a selection method that selects ONE individual by
|
||||||
|
binary stochastic tournament
|
||||||
|
-MS- 24/10/99 */
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
template <class EOT> class eoStochTournament: public eoSelectOne<EOT>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
///
|
||||||
|
eoStochTournament(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 eoDetTournament_h
|
||||||
|
|
||||||
|
|
@ -103,6 +103,7 @@ cout << "Initial parents (odd)\n" << orgParents << "\n And initial offsprings (e
|
||||||
// the replacement procedures under test
|
// the replacement procedures under test
|
||||||
eoGenerationalReplacement<Dummy> genReplace;
|
eoGenerationalReplacement<Dummy> genReplace;
|
||||||
eoPlusReplacement<Dummy> plusReplace;
|
eoPlusReplacement<Dummy> plusReplace;
|
||||||
|
eoEPReplacement<Dummy> epReplace(tSize);
|
||||||
eoCommaReplacement<Dummy> commaReplace;
|
eoCommaReplacement<Dummy> commaReplace;
|
||||||
eoWeakElitistReplacement<Dummy> weakElitistReplace(commaReplace);
|
eoWeakElitistReplacement<Dummy> weakElitistReplace(commaReplace);
|
||||||
// the SSGA replacements
|
// the SSGA replacements
|
||||||
|
|
@ -129,6 +130,15 @@ cout << "Parents (originally odd)\n" << parents << "\n And offsprings (orogonall
|
||||||
plusReplace(parents, offspring);
|
plusReplace(parents, offspring);
|
||||||
cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << endl;
|
cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << endl;
|
||||||
|
|
||||||
|
// EP (proche d'un PLUS
|
||||||
|
parents = orgParents;
|
||||||
|
offspring = orgOffspring;
|
||||||
|
|
||||||
|
cout << "eoEPReplacement\n";
|
||||||
|
cout << "===============\n";
|
||||||
|
epReplace(parents, offspring);
|
||||||
|
cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << endl;
|
||||||
|
|
||||||
// Comma
|
// Comma
|
||||||
parents = orgParents;
|
parents = orgParents;
|
||||||
offspring = orgOffspring;
|
offspring = orgOffspring;
|
||||||
|
|
|
||||||
|
|
@ -235,7 +235,7 @@ int main()
|
||||||
seqSel.addOp(mutation, 0.25);
|
seqSel.addOp(mutation, 0.25);
|
||||||
seqSel.addOp(xover, 0.75);
|
seqSel.addOp(xover, 0.75);
|
||||||
|
|
||||||
eoDetTournament<EoType> selector(5);
|
eoDetTournamentSelect<EoType> selector(5);
|
||||||
|
|
||||||
eoDetTournamentInserter<EoType> inserter(eval, 5);
|
eoDetTournamentInserter<EoType> inserter(eval, 5);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ void main_function()
|
||||||
monitor.add(stats);
|
monitor.add(stats);
|
||||||
checkpoint.add(stats);
|
checkpoint.add(stats);
|
||||||
|
|
||||||
eoProportional<Chrom> select;
|
eoProportionalSelect<Chrom> select;
|
||||||
eoEvalFuncPtr<Chrom> eval(binary_value);
|
eoEvalFuncPtr<Chrom> eval(binary_value);
|
||||||
|
|
||||||
eoSGA<Chrom> sga(select, xover, 0.8f, bitflip, 0.1f, eval, checkpoint);
|
eoSGA<Chrom> sga(select, xover, 0.8f, bitflip, 0.1f, eval, checkpoint);
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ void main_function(int argc, char **argv)
|
||||||
////////////////////////////////////
|
////////////////////////////////////
|
||||||
// SELECT
|
// SELECT
|
||||||
// The robust tournament selection
|
// The robust tournament selection
|
||||||
eoDetTournament<Indi> select(T_SIZE); // T_SIZE in [2,POP_SIZE]
|
eoDetTournamentSelect<Indi> select(T_SIZE); // T_SIZE in [2,POP_SIZE]
|
||||||
|
|
||||||
// REPLACE
|
// REPLACE
|
||||||
// The simple GA evolution engine uses generational replacement
|
// The simple GA evolution engine uses generational replacement
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Reference in a new issue