Changed some includes for the new dir structure
This commit is contained in:
parent
340edc2420
commit
6c79787c43
16 changed files with 348 additions and 26 deletions
10
eo/src/eo
10
eo/src/eo
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <eoData.h>
|
#include <utils/eoData.h>
|
||||||
#include <eoObject.h>
|
#include <eoObject.h>
|
||||||
#include <eoPrintable.h>
|
#include <eoPrintable.h>
|
||||||
#include <eoPersistent.h>
|
#include <eoPersistent.h>
|
||||||
|
|
@ -33,13 +33,11 @@
|
||||||
#include <EO.h>
|
#include <EO.h>
|
||||||
|
|
||||||
#include <eoID.h>
|
#include <eoID.h>
|
||||||
#include <eoAged.h>
|
|
||||||
|
|
||||||
#include <eoVector.h>
|
#include <eoVector.h>
|
||||||
#include <eo1d.h>
|
#include <eo1d.h>
|
||||||
#include <eoString.h>
|
#include <other/eoString.h>
|
||||||
#include <eoESChrom.h>
|
#include <ga/eoBin.h>
|
||||||
#include <eoBin.h>
|
|
||||||
|
|
||||||
#include <eoRnd.h>
|
#include <eoRnd.h>
|
||||||
#include <eoUniform.h>
|
#include <eoUniform.h>
|
||||||
|
|
@ -58,7 +56,7 @@
|
||||||
#include <eoPop.h>
|
#include <eoPop.h>
|
||||||
#include <eoPopOps.h>
|
#include <eoPopOps.h>
|
||||||
#include <eoMerge.h>
|
#include <eoMerge.h>
|
||||||
#include <eoBitOp.h>
|
#include <ga/eoBitOp.h>
|
||||||
|
|
||||||
// Evaluation functions
|
// Evaluation functions
|
||||||
#include <eoEvalFunc.h>
|
#include <eoEvalFunc.h>
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
#include <functional> //
|
#include <functional> //
|
||||||
#include <numeric> // accumulate
|
#include <numeric> // accumulate
|
||||||
#include "eoPopOps.h" // eoPop eoSelect MINFLOAT
|
#include "eoPopOps.h" // eoPop eoSelect MINFLOAT
|
||||||
#include "selectors.h"
|
#include "utils/selectors.h"
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
/** eoDetTournament: a selection method that selects ONE individual by
|
/** eoDetTournament: a selection method that selects ONE individual by
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
#include <functional> //
|
#include <functional> //
|
||||||
#include <numeric> // accumulate
|
#include <numeric> // accumulate
|
||||||
#include "selectors.h"
|
#include "utils/selectors.h"
|
||||||
#include <eo> // eoPop eoSelect MINFLOAT
|
#include <eo> // eoPop eoSelect MINFLOAT
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include <eoRnd.h> // for base class
|
#include <eoRnd.h> // for base class
|
||||||
#include <eoRNG.h> // for base class
|
#include <utils/eoRNG.h> // for base class
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Class eoNegExp
|
// Class eoNegExp
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <eoRnd.h> // for base class
|
#include <eoRnd.h> // for base class
|
||||||
#include <eoRNG.h> // for random number generator
|
#include <utils/eoRNG.h> // for random number generator
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Class eoNormal
|
// Class eoNormal
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,11 @@
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <eoData.h> // For limits definition
|
#include <utils/eoData.h> // For limits definition
|
||||||
#include <iostream> // istream, ostream
|
#include <iostream> // istream, ostream
|
||||||
#include <string> // string
|
#include <string> // string
|
||||||
|
|
||||||
#include "compatibility.h"
|
#include "utils/compatibility.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
@ -57,11 +57,15 @@ class eoObject
|
||||||
/// Virtual dtor. They are needed in virtual class hierarchies.
|
/// Virtual dtor. They are needed in virtual class hierarchies.
|
||||||
virtual ~eoObject() {}
|
virtual ~eoObject() {}
|
||||||
|
|
||||||
/** Return the class id. This should be redefined in each class; but
|
/** Return the class id. This should be redefined in each class.
|
||||||
it's got code as an example of implementation. Only "leaf" classes
|
Only "leaf" classes can be non-virtual.
|
||||||
can be non-virtual.
|
|
||||||
|
Maarten: removed the default implementation as this proved to
|
||||||
|
be too error-prone: I found several classes that had a typo in
|
||||||
|
className (like classname), which would print eoObject instead of
|
||||||
|
their own...
|
||||||
*/
|
*/
|
||||||
virtual string className() const { return "eoObject"; }
|
virtual string className() const = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
#include <functional> //
|
#include <functional> //
|
||||||
#include <numeric> // accumulate
|
#include <numeric> // accumulate
|
||||||
#include <eoPopOps.h> // eoPop eoSelect MINFLOAT
|
#include <eoPopOps.h> // eoPop eoSelect MINFLOAT
|
||||||
#include <eoRNG.h>
|
#include <utils/eoRNG.h>
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
/** eoStochTournament: a selection method that selects ONE individual by
|
/** eoStochTournament: a selection method that selects ONE individual by
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <eoRnd.h>
|
#include <eoRnd.h>
|
||||||
#include <eoRNG.h>
|
#include <utils/eoRNG.h>
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Class eoUniform
|
// Class eoUniform
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@
|
||||||
#include <functional> //
|
#include <functional> //
|
||||||
#include <numeric> // accumulate
|
#include <numeric> // accumulate
|
||||||
#include <eoPopOps.h> // eoPop eoSelect MINFLOAT
|
#include <eoPopOps.h> // eoPop eoSelect MINFLOAT
|
||||||
#include <eoRNG.h>
|
#include <utils/eoRNG.h>
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
/** eoUniformSelect: a selection method that selects ONE individual randomly
|
/** eoUniformSelect: a selection method that selects ONE individual randomly
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
#include <algorithm> // swap_ranges
|
#include <algorithm> // swap_ranges
|
||||||
#include <eoUniform.h> // eoUniform
|
#include <eoUniform.h> // eoUniform
|
||||||
#include <eoBin.h> // eoBin
|
#include <ga/eoBin.h> // eoBin
|
||||||
#include <eoOp.h> // eoMonOp
|
#include <eoOp.h> // eoMonOp
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@
|
||||||
#include "eoRnd.h"
|
#include "eoRnd.h"
|
||||||
|
|
||||||
template <class F, class External>
|
template <class F, class External>
|
||||||
class eoExternalInitFunc
|
class eoExternalInitFunc
|
||||||
{
|
{
|
||||||
|
|
||||||
public :
|
public :
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ nasty habit of #define min and max in stdlib.h (and windows.h)
|
||||||
I'm trying to undo this horrible macro magic (microsoft yet macrohard)
|
I'm trying to undo this horrible macro magic (microsoft yet macrohard)
|
||||||
here. Sure hope it works
|
here. Sure hope it works
|
||||||
*/
|
*/
|
||||||
|
#pragma warning(disable:4786)
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning(disable:4786)
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
@ -6,6 +10,11 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
void eoWarning(std::string str)
|
||||||
|
{
|
||||||
|
cout << str << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
std::ostream& printSectionHeader(std::ostream& os, std::string section)
|
std::ostream& printSectionHeader(std::ostream& os, std::string section)
|
||||||
{
|
{
|
||||||
os << '\n' << setw(10) << "###### " << setw(20) << section << setw(10) << " ######\n";
|
os << '\n' << setw(10) << "###### " << setw(20) << section << setw(10) << " ######\n";
|
||||||
|
|
|
||||||
|
|
@ -56,11 +56,6 @@ public :
|
||||||
virtual void processParam(eoParam& param, std::string section = "") = 0;
|
virtual void processParam(eoParam& param, std::string section = "") = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
void eoWarning(std::string str)
|
|
||||||
{
|
|
||||||
cout << str << '\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
eoParser: command line parser and configuration file reader
|
eoParser: command line parser and configuration file reader
|
||||||
This class is persistent, so it can be stored and reloaded to restore
|
This class is persistent, so it can be stored and reloaded to restore
|
||||||
|
|
|
||||||
|
|
@ -240,6 +240,7 @@ public :
|
||||||
_is >> cacheValue;
|
_is >> cacheValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string className(void) const { return "Mersenne-Twister"; }
|
||||||
|
|
||||||
private :
|
private :
|
||||||
uint32 restart(void);
|
uint32 restart(void);
|
||||||
|
|
|
||||||
314
eo/src/utils/selectors.h
Normal file
314
eo/src/utils/selectors.h
Normal file
|
|
@ -0,0 +1,314 @@
|
||||||
|
/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
selectors.h
|
||||||
|
A bunch of useful selector functions. They generally have three forms:
|
||||||
|
|
||||||
|
template <class It>
|
||||||
|
It select(It begin, It end, params, eoRng& gen = rng);
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
const EOT& select(const eoPop<EOT>& pop, params, eoRng& gen = rng);
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
EOT& select(eoPop<EOT>& pop, params, eoRng& gen = rng);
|
||||||
|
|
||||||
|
where select is one of: roulette_wheel, deterministic_tournament
|
||||||
|
and stochastic_tournament (at the moment).
|
||||||
|
|
||||||
|
(c) Maarten Keijzer (mak@dhi.dk) and 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 SELECT__H
|
||||||
|
#define SELECT__H
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include "eoRNG.h"
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
bool minimizing_fitness()
|
||||||
|
{
|
||||||
|
EOT eo1; // Assuming people don't do anything fancy in the default constructor!
|
||||||
|
EOT eo2;
|
||||||
|
|
||||||
|
/* Dear user, when the two line below do not compile you are most
|
||||||
|
likely not working with scalar fitness values. In that case we're sorry
|
||||||
|
but you cannot use lottery or roulette_wheel selection...
|
||||||
|
*/
|
||||||
|
eo1.fitness(0.0); // tried to cast it to an EOT::Fitness, but for some reason GNU barfs on this
|
||||||
|
eo2.fitness(1.0);
|
||||||
|
|
||||||
|
return eo2 < eo1; // check whether we have a minimizing fitness
|
||||||
|
};
|
||||||
|
|
||||||
|
inline double scale_fitness(const std::pair<double, double>& _minmax, double _value)
|
||||||
|
{
|
||||||
|
if (_minmax.first == _minmax.second)
|
||||||
|
{
|
||||||
|
return 0.0; // no differences in fitness, population converged!
|
||||||
|
}
|
||||||
|
// else
|
||||||
|
|
||||||
|
return (_value - _minmax.first) / (_minmax.second - _minmax.first);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class It>
|
||||||
|
double sum_fitness(It begin, It end)
|
||||||
|
{
|
||||||
|
double sum = 0.0;
|
||||||
|
|
||||||
|
for (; begin != end; ++begin)
|
||||||
|
{
|
||||||
|
double v = static_cast<double>(begin->fitness());
|
||||||
|
if (v < 0.0)
|
||||||
|
throw std::logical_error("Negative Fitness Encountered");
|
||||||
|
sum += v;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
double sum_fitness(const eoPop<EOT>& _pop)
|
||||||
|
{
|
||||||
|
return sum_fitness(_pop.begin(), _pop.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
double sum_fitness(const eoPop<EOT>& _pop, std::pair<double, double>& _minmax)
|
||||||
|
{
|
||||||
|
eoPop<EOT>::const_iterator it = _pop.begin();
|
||||||
|
|
||||||
|
_minmax.first = it->fitness();
|
||||||
|
_minmax.second = it++->fitness();
|
||||||
|
|
||||||
|
for(; it != _pop.end(); ++it)
|
||||||
|
{
|
||||||
|
double v = static_cast<double>(it->fitness());
|
||||||
|
|
||||||
|
_minmax.first = std::min(_minmax.first, v);
|
||||||
|
_minmax.second = std::max(_minmax.second, v);
|
||||||
|
|
||||||
|
rawTotal += v;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minimizing_fitness<EOT>())
|
||||||
|
{
|
||||||
|
std::swap(_minmax.first, _minmax.second);
|
||||||
|
}
|
||||||
|
|
||||||
|
scaledTotal = 0.0;
|
||||||
|
|
||||||
|
// unfortunately a second loop is neccessary to scale the fitness
|
||||||
|
for (it = _pop.begin(); it != _pop.end(); ++it)
|
||||||
|
{
|
||||||
|
double v = scale_fitness(static_cast<double>(it->fitness()));
|
||||||
|
|
||||||
|
scaledTotal += v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class It>
|
||||||
|
It roulette_wheel(It _begin, It _end, double total, eoRng& _gen = rng)
|
||||||
|
{
|
||||||
|
float roulette = _gen.uniform(total);
|
||||||
|
|
||||||
|
It i = _begin;
|
||||||
|
|
||||||
|
while (roulette > 0.0)
|
||||||
|
{
|
||||||
|
roulette -= static_cast<double>(*(i++));
|
||||||
|
}
|
||||||
|
|
||||||
|
return --i;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
const EOT& roulette_wheel(const eoPop<EOT>& _pop, double total, eoRng& _gen = rng)
|
||||||
|
{
|
||||||
|
float roulette = _gen.uniform(total);
|
||||||
|
|
||||||
|
eoPop<EOT>::const_iterator i = _pop.begin();
|
||||||
|
|
||||||
|
while (roulette > 0.0)
|
||||||
|
{
|
||||||
|
roulette -= static_cast<double>((i++)->fitness());
|
||||||
|
}
|
||||||
|
|
||||||
|
return *--i;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
EOT& roulette_wheel(eoPop<EOT>& _pop, double total, eoRng& _gen = rng)
|
||||||
|
{
|
||||||
|
float roulette = _gen.uniform(total);
|
||||||
|
|
||||||
|
eoPop<EOT>::iterator i = _pop.begin();
|
||||||
|
|
||||||
|
while (roulette > 0.0)
|
||||||
|
{
|
||||||
|
roulette -= static_cast<double>((i++)->fitness());
|
||||||
|
}
|
||||||
|
|
||||||
|
return *--i;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class It>
|
||||||
|
It deterministic_tournament(It _begin, It _end, unsigned _t_size, eoRng& _gen = rng)
|
||||||
|
{
|
||||||
|
It best = _begin + _gen.random(_end - _begin);
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < _t_size - 1; ++i)
|
||||||
|
{
|
||||||
|
It competitor = _begin + _gen.random(_end - _begin);
|
||||||
|
|
||||||
|
if (*best < *competitor)
|
||||||
|
{
|
||||||
|
best = competitor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return best;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
const EOT& deterministic_tournament(const eoPop<EOT>& _pop, unsigned _t_size, eoRng& _gen = rng)
|
||||||
|
{
|
||||||
|
return *deterministic_tournament(_pop.begin(), _pop.end(), _t_size, _gen);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
EOT& deterministic_tournament(eoPop<EOT>& _pop, unsigned _t_size, eoRng& _gen = rng)
|
||||||
|
{
|
||||||
|
return *deterministic_tournament(_pop.begin(), _pop.end(), _t_size, _gen);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class It>
|
||||||
|
It inverse_deterministic_tournament(It _begin, It _end, unsigned _t_size, eoRng& _gen = rng)
|
||||||
|
{
|
||||||
|
It worst = _begin + _gen.random(_end - _begin);
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < _t_size - 1; ++i)
|
||||||
|
{
|
||||||
|
It competitor = _begin + _gen.random(_end - _begin);
|
||||||
|
|
||||||
|
if (competitor == worst)
|
||||||
|
{
|
||||||
|
--i;
|
||||||
|
continue; // try again
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*competitor < *worst)
|
||||||
|
{
|
||||||
|
worst = competitor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return worst;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
const EOT& inverse_deterministic_tournament(const eoPop<EOT>& _pop, unsigned _t_size, eoRng& _gen = rng)
|
||||||
|
{
|
||||||
|
return *inverse_deterministic_tournament<EOT>(_pop.begin(), _pop.end(), _t_size, _gen);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
EOT& inverse_deterministic_tournament(eoPop<EOT>& _pop, unsigned _t_size, eoRng& _gen = rng)
|
||||||
|
{
|
||||||
|
return *inverse_deterministic_tournament(_pop.begin(), _pop.end(), _t_size, _gen);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class It>
|
||||||
|
It stochastic_tournament(It _begin, It _end, double _t_rate, eoRng& _gen = rng)
|
||||||
|
{
|
||||||
|
It i1 = _begin + _gen.random(_end - _begin);
|
||||||
|
It i2 = _begin + _gen.random(_end - _begin);
|
||||||
|
|
||||||
|
bool return_better = _gen.flip(_t_rate);
|
||||||
|
|
||||||
|
if (*i1 < *i2)
|
||||||
|
{
|
||||||
|
if (return_better) return i2;
|
||||||
|
// else
|
||||||
|
|
||||||
|
return i1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (return_better) return i1;
|
||||||
|
// else
|
||||||
|
}
|
||||||
|
// else
|
||||||
|
|
||||||
|
return i2;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
const EOT& stochastic_tournament(const eoPop<EOT>& _pop, double _t_rate, eoRng& _gen = rng)
|
||||||
|
{
|
||||||
|
return *stochastic_tournament(_pop.begin(), _pop.end(), _t_rate, _gen);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
EOT& stochastic_tournament(eoPop<EOT>& _pop, double _t_rate, eoRng& _gen = rng)
|
||||||
|
{
|
||||||
|
return *stochastic_tournament(_pop.begin(), _pop.end(), _t_rate, _gen);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class It>
|
||||||
|
It inverse_stochastic_tournament(It _begin, It _end, double _t_rate, eoRng& _gen = rng)
|
||||||
|
{
|
||||||
|
It i1 = _begin + _gen.random(_end - _begin);
|
||||||
|
It i2 = _begin + _gen.random(_end - _begin);
|
||||||
|
|
||||||
|
bool return_worse = _gen.flip(_t_rate);
|
||||||
|
|
||||||
|
if (*i1 < *i2)
|
||||||
|
{
|
||||||
|
if (return_worse) return i1;
|
||||||
|
// else
|
||||||
|
|
||||||
|
return i2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (return_worse) return i2;
|
||||||
|
// else
|
||||||
|
}
|
||||||
|
// else
|
||||||
|
|
||||||
|
return i1;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
const EOT& inverse_stochastic_tournament(const eoPop<EOT>& _pop, double _t_rate, eoRng& _gen = rng)
|
||||||
|
{
|
||||||
|
return *inverse_stochastic_tournament(_pop.begin(), _pop.end(), _t_rate, _gen);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
EOT& inverse_stochastic_tournament(eoPop<EOT>& _pop, double _t_rate, eoRng& _gen = rng)
|
||||||
|
{
|
||||||
|
return *inverse_stochastic_tournament(_pop.begin(), _pop.end(), _t_rate, _gen);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in a new issue