* indentations + whitespace cleanup
This commit is contained in:
parent
8457e39efe
commit
56c6edab04
285 changed files with 6068 additions and 6223 deletions
|
|
@ -4,7 +4,7 @@
|
|||
// eoReduceSplit.h
|
||||
// Base class for population-reducing classes - retaining the poor losers
|
||||
// (c) GeNeura Team, 1998, Marc Schoenauer, 2002
|
||||
/*
|
||||
/*
|
||||
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
|
||||
|
|
@ -47,16 +47,16 @@ template<class EOT> class eoReduceSplit: public eoBF<eoPop<EOT>&, eoPop<EOT> &,
|
|||
{};
|
||||
|
||||
/** deterministic truncation method using sort */
|
||||
template <class EOT>
|
||||
template <class EOT>
|
||||
class eoTruncateSplit : public eoReduceSplit<EOT>
|
||||
{
|
||||
public:
|
||||
/** Ctor: must provide amount of reduction,
|
||||
/** Ctor: must provide amount of reduction,
|
||||
and whether or not you need to return the eliminated guys
|
||||
*/
|
||||
eoTruncateSplit(eoHowMany _howMany, bool _returnEliminated = false):
|
||||
howMany(_howMany), returnEliminated(_returnEliminated) {}
|
||||
|
||||
|
||||
/** do the jonb */
|
||||
void operator()(eoPop<EOT>& _newgen, eoPop<EOT> & _eliminated)
|
||||
{
|
||||
|
|
@ -67,13 +67,13 @@ public:
|
|||
unsigned newsize = popSize - eliminated;
|
||||
if (newsize < 0)
|
||||
throw std::logic_error("eoTruncateSplit: Cannot truncate to a larger size!\n");
|
||||
|
||||
|
||||
_newgen.nth_element(newsize);
|
||||
|
||||
// save poor losers if necessary
|
||||
if (returnEliminated)
|
||||
for (unsigned i=0; i<eliminated; i++)
|
||||
_eliminated.push_back(_newgen[newsize+i]);
|
||||
_eliminated.push_back(_newgen[newsize+i]);
|
||||
// truncate
|
||||
_newgen.resize(newsize);
|
||||
return ;
|
||||
|
|
@ -87,16 +87,16 @@ private:
|
|||
/** a ReduceSplit class that does not sort, but repeatidely kills the worse.
|
||||
To be used in SSGA-like replacements (e.g. see eoSSGAWorseReplacement)
|
||||
*/
|
||||
template <class EOT>
|
||||
template <class EOT>
|
||||
class eoLinearTruncateSplit : public eoReduceSplit<EOT>
|
||||
{
|
||||
public:
|
||||
/** Ctor: must provide amount of reduction,
|
||||
/** Ctor: must provide amount of reduction,
|
||||
and whether or not you need to return the eliminated guys
|
||||
*/
|
||||
eoLinearTruncateSplit(eoHowMany _howMany, bool _returnEliminated = false):
|
||||
howMany(_howMany), returnEliminated(_returnEliminated) {}
|
||||
|
||||
|
||||
/** do the job */
|
||||
void operator()(eoPop<EOT>& _newgen, eoPop<EOT> & _eliminated)
|
||||
{
|
||||
|
|
@ -111,10 +111,10 @@ public:
|
|||
_eliminated.reserve(_eliminated.size()+eliminated); //in case not empty?
|
||||
for (unsigned i=0; i<eliminated; i++)
|
||||
{
|
||||
typename eoPop<EOT>::iterator it = _newgen.it_worse_element();
|
||||
if (returnEliminated)
|
||||
_eliminated.push_back(*it);
|
||||
_newgen.erase(it);
|
||||
typename eoPop<EOT>::iterator it = _newgen.it_worse_element();
|
||||
if (returnEliminated)
|
||||
_eliminated.push_back(*it);
|
||||
_newgen.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -124,16 +124,16 @@ private:
|
|||
};
|
||||
|
||||
/** random truncation - batch version */
|
||||
template <class EOT>
|
||||
template <class EOT>
|
||||
class eoRandomSplit : public eoReduceSplit<EOT>
|
||||
{
|
||||
public:
|
||||
/** Ctor: must provide amount of reduction,
|
||||
/** Ctor: must provide amount of reduction,
|
||||
and whether or not you need to return the eliminated guys
|
||||
*/
|
||||
eoRandomSplit(eoHowMany _howMany, bool _returnEliminated = false):
|
||||
howMany(_howMany), returnEliminated(_returnEliminated) {}
|
||||
|
||||
|
||||
/** do the job */
|
||||
void operator()(eoPop<EOT>& _newgen, eoPop<EOT> & _eliminated)
|
||||
{
|
||||
|
|
@ -150,7 +150,7 @@ public:
|
|||
// save poor losers if necessary
|
||||
if (returnEliminated)
|
||||
for (unsigned i=0; i<eliminated; i++)
|
||||
_eliminated.push_back(_newgen[newsize+i]);
|
||||
_eliminated.push_back(_newgen[newsize+i]);
|
||||
// truncate
|
||||
_newgen.resize(newsize);
|
||||
return ;
|
||||
|
|
@ -163,16 +163,16 @@ private:
|
|||
|
||||
|
||||
/** random truncation - linear version */
|
||||
template <class EOT>
|
||||
template <class EOT>
|
||||
class eoLinearRandomSplit : public eoReduceSplit<EOT>
|
||||
{
|
||||
public:
|
||||
/** Ctor: must provide amount of reduction,
|
||||
/** Ctor: must provide amount of reduction,
|
||||
and whether or not you need to return the eliminated guys
|
||||
*/
|
||||
eoLinearRandomSplit(eoHowMany _howMany, bool _returnEliminated = false):
|
||||
howMany(_howMany), returnEliminated(_returnEliminated) {}
|
||||
|
||||
|
||||
/** do the job */
|
||||
void operator()(eoPop<EOT>& _newgen, eoPop<EOT> & _eliminated)
|
||||
{
|
||||
|
|
@ -187,11 +187,11 @@ public:
|
|||
_eliminated.reserve(_eliminated.size()+eliminated); //in case not empty?
|
||||
for (unsigned i=0; i<eliminated; i++)
|
||||
{
|
||||
unsigned loser=random(_newgen.size());
|
||||
typename eoPop<EOT>::iterator it = _newgen.begin()+loser;
|
||||
if (returnEliminated)
|
||||
_eliminated.push_back(*it);
|
||||
_newgen.erase(it);
|
||||
unsigned loser=random(_newgen.size());
|
||||
typename eoPop<EOT>::iterator it = _newgen.begin()+loser;
|
||||
if (returnEliminated)
|
||||
_eliminated.push_back(*it);
|
||||
_newgen.erase(it);
|
||||
}
|
||||
return ;
|
||||
}
|
||||
|
|
@ -205,22 +205,22 @@ private:
|
|||
/** a ReduceSplit class based on a repeated deterministic (reverse!) tournament
|
||||
To be used in SSGA-like replacements (e.g. see eoSSGADetTournamentReplacement)
|
||||
*/
|
||||
template <class EOT>
|
||||
template <class EOT>
|
||||
class eoDetTournamentTruncateSplit : public eoReduceSplit<EOT>
|
||||
{
|
||||
public:
|
||||
/** Ctor: must provide amount of reduction,
|
||||
/** Ctor: must provide amount of reduction,
|
||||
and whether or not you need to return the eliminated guys
|
||||
*/
|
||||
eoDetTournamentTruncateSplit(unsigned _t_size, eoHowMany _howMany,
|
||||
bool _returnEliminated = false):
|
||||
t_size(_t_size), howMany(_howMany),
|
||||
returnEliminated(_returnEliminated)
|
||||
eoDetTournamentTruncateSplit(unsigned _t_size, eoHowMany _howMany,
|
||||
bool _returnEliminated = false):
|
||||
t_size(_t_size), howMany(_howMany),
|
||||
returnEliminated(_returnEliminated)
|
||||
{
|
||||
if (t_size < 2)
|
||||
{
|
||||
{
|
||||
eo::log << eo::warnings << "Warning, Size for eoDetTournamentTruncateSplit adjusted to 2" << std::endl;
|
||||
t_size = 2;
|
||||
t_size = 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -240,10 +240,10 @@ public:
|
|||
_eliminated.reserve(_eliminated.size()+eliminated); //in case not empty?
|
||||
for (unsigned i=0; i<eliminated; i++)
|
||||
{
|
||||
typename eoPop<EOT>::iterator it = inverse_deterministic_tournament(_newgen.begin(), _newgen.end(), t_size);
|
||||
if (returnEliminated)
|
||||
_eliminated.push_back(*it);
|
||||
_newgen.erase(it);
|
||||
typename eoPop<EOT>::iterator it = inverse_deterministic_tournament(_newgen.begin(), _newgen.end(), t_size);
|
||||
if (returnEliminated)
|
||||
_eliminated.push_back(*it);
|
||||
_newgen.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -256,27 +256,27 @@ private:
|
|||
/** a ReduceSplit class based on a repeated deterministic (reverse!) tournament
|
||||
To be used in SSGA-like replacements (e.g. see eoSSGAStochTournamentReplacement)
|
||||
*/
|
||||
template <class EOT>
|
||||
template <class EOT>
|
||||
class eoStochTournamentTruncateSplit : public eoReduce<EOT>
|
||||
{
|
||||
public:
|
||||
/** Ctor: must provide amount of reduction,
|
||||
/** Ctor: must provide amount of reduction,
|
||||
and whether or not you need to return the eliminated guys
|
||||
*/
|
||||
eoStochTournamentTruncateSplit(double _t_rate, eoHowMany _howMany,
|
||||
bool _returnEliminated = false):
|
||||
t_rate(_t_rate), howMany(_howMany),
|
||||
returnEliminated(_returnEliminated)
|
||||
eoStochTournamentTruncateSplit(double _t_rate, eoHowMany _howMany,
|
||||
bool _returnEliminated = false):
|
||||
t_rate(_t_rate), howMany(_howMany),
|
||||
returnEliminated(_returnEliminated)
|
||||
{
|
||||
if (t_rate <= 0.5)
|
||||
{
|
||||
{
|
||||
eo::log << eo::warnings << "Warning, Rate for eoStochTournamentTruncateSplit adjusted to 0.51" << std::endl;
|
||||
t_rate = 0.51;
|
||||
t_rate = 0.51;
|
||||
}
|
||||
if (t_rate > 1)
|
||||
{
|
||||
eo::log << eo::warnings << "Warning, Rate for eoStochTournamentTruncateSplit adjusted to 1" << std::endl;
|
||||
t_rate = 1;
|
||||
t_rate = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -285,7 +285,7 @@ public:
|
|||
//BUG??? void operator()(eoPop<EOT>& _newgen, unsigned _newsize)
|
||||
{
|
||||
/* old version
|
||||
if (!_eliminated.size()) // nothing to do
|
||||
if (!_eliminated.size()) // nothing to do
|
||||
return;
|
||||
unsigned oldSize = _newgen.size();
|
||||
unsigned newSize = oldSize - _eliminated.size();
|
||||
|
|
@ -308,10 +308,10 @@ end of old version */
|
|||
_eliminated.reserve(_eliminated.size()+eliminated); //in case not empty?
|
||||
for (unsigned i=0; i<_eliminated.size(); i++)
|
||||
{
|
||||
typename eoPop<EOT>::iterator it = inverse_stochastic_tournament(_newgen.begin(), _newgen.end(), t_rate);
|
||||
if (returnEliminated)
|
||||
_eliminated.push_back(*it);
|
||||
_newgen.erase(it);
|
||||
typename eoPop<EOT>::iterator it = inverse_stochastic_tournament(_newgen.begin(), _newgen.end(), t_rate);
|
||||
if (returnEliminated)
|
||||
_eliminated.push_back(*it);
|
||||
_newgen.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue