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:
evomarc 2001-01-05 05:42:08 +00:00
commit a998ad0a41
36 changed files with 922 additions and 226 deletions

View file

@ -7,17 +7,7 @@
#include <iostream> // cerr cout
#include <fstream> // ifstream
#include <string> // string
#include <utils/eoParser.h> // eoParser
#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 <eo> // all usefull eo stuff
#include "gprop.h" // Chrom eoChromInit eoChromMutation eoChromXover eoChromEvaluator
//-----------------------------------------------------------------------------
@ -134,7 +124,7 @@ void ga()
apply<Chrom>(evaluator, pop);
// selector
eoStochTournament<Chrom> select;
eoStochTournamentSelect<Chrom> select;
// genetic operators
eoChromMutation mutation;

View file

@ -7,17 +7,7 @@
#include <iostream> // cerr cout
#include <fstream> // ifstream
#include <string> // string
#include <utils/eoParser.h> // eoParser
#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 <eo> // all usefull eo stuff
#include "mastermind.h" // Chrom eoChromInit eoChromMutation eoChromXover eoChromEvaluator
//-----------------------------------------------------------------------------
@ -103,7 +93,7 @@ void ga()
apply<Chrom>(evaluator, pop);
// selector
eoProportional<Chrom> select(pop);
eoProportionalSelect<Chrom> select(pop);
// genetic operators
eoChromMutation mutation;

View file

@ -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
View 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

View file

@ -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;

View file

@ -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;
};

View file

@ -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
View 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
View 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

View file

@ -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;

View file

@ -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

View 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

View 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

View 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

View 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

View 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

View file

@ -103,6 +103,7 @@ cout << "Initial parents (odd)\n" << orgParents << "\n And initial offsprings (e
// the replacement procedures under test
eoGenerationalReplacement<Dummy> genReplace;
eoPlusReplacement<Dummy> plusReplace;
eoEPReplacement<Dummy> epReplace(tSize);
eoCommaReplacement<Dummy> commaReplace;
eoWeakElitistReplacement<Dummy> weakElitistReplace(commaReplace);
// the SSGA replacements
@ -129,6 +130,15 @@ cout << "Parents (originally odd)\n" << parents << "\n And offsprings (orogonall
plusReplace(parents, offspring);
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
parents = orgParents;
offspring = orgOffspring;

View file

@ -235,7 +235,7 @@ int main()
seqSel.addOp(mutation, 0.25);
seqSel.addOp(xover, 0.75);
eoDetTournament<EoType> selector(5);
eoDetTournamentSelect<EoType> selector(5);
eoDetTournamentInserter<EoType> inserter(eval, 5);

View file

@ -147,7 +147,7 @@ void main_function()
monitor.add(stats);
checkpoint.add(stats);
eoProportional<Chrom> select;
eoProportionalSelect<Chrom> select;
eoEvalFuncPtr<Chrom> eval(binary_value);
eoSGA<Chrom> sga(select, xover, 0.8f, bitflip, 0.1f, eval, checkpoint);

View file

@ -94,7 +94,7 @@ void main_function(int argc, char **argv)
////////////////////////////////////
// SELECT
// 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
// The simple GA evolution engine uses generational replacement

Some files were not shown because too many files have changed in this diff Show more