* 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 @@
|
|||
// eoMerge.h
|
||||
// Base class for elitist-merging classes
|
||||
// (c) GeNeura Team, 1998
|
||||
/*
|
||||
/*
|
||||
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
|
||||
|
|
@ -36,13 +36,13 @@
|
|||
#include <utils/eoLogger.h>
|
||||
|
||||
/**
|
||||
* eoMerge: Base class for elitist replacement algorithms.
|
||||
* eoMerge: Base class for elitist replacement algorithms.
|
||||
* Merges the old population (first argument), with the new generation
|
||||
*
|
||||
* Its signature is exactly
|
||||
* that of the selection base eoSelect, but its purpose is to merge the
|
||||
* that of the selection base eoSelect, but its purpose is to merge the
|
||||
* two populations into one (the second argument).
|
||||
* Note that the algorithms assume that the second argument denotes the
|
||||
* Note that the algorithms assume that the second argument denotes the
|
||||
* next generation.
|
||||
*
|
||||
* @ingroup Core
|
||||
|
|
@ -55,7 +55,7 @@ template<class Chrom> class eoMerge: public eoBF<const eoPop<Chrom>&, eoPop<Chro
|
|||
/**
|
||||
Straightforward elitism class, specify the number of individuals to copy
|
||||
into new geneneration or the rate w.r.t. pop size
|
||||
|
||||
|
||||
@ingroup Replacors
|
||||
*/
|
||||
template <class EOT> class eoElitism : public eoMerge<EOT>
|
||||
|
|
@ -66,42 +66,42 @@ public :
|
|||
{
|
||||
if (_interpret_as_rate)
|
||||
{
|
||||
if ( (_rate<0) || (_rate>1) )
|
||||
throw std::logic_error("eoElitism: rate shoud be in [0,1]");
|
||||
rate = _rate;
|
||||
if ( (_rate<0) || (_rate>1) )
|
||||
throw std::logic_error("eoElitism: rate shoud be in [0,1]");
|
||||
rate = _rate;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_rate<0)
|
||||
throw std::logic_error("Negative number of offspring in eoElitism!");
|
||||
combien = (unsigned int)_rate;
|
||||
if (combien != _rate)
|
||||
eo::log << eo::warnings << "Warning: Number of guys to merge in eoElitism was rounded" << std::endl;
|
||||
if (_rate<0)
|
||||
throw std::logic_error("Negative number of offspring in eoElitism!");
|
||||
combien = (unsigned int)_rate;
|
||||
if (combien != _rate)
|
||||
eo::log << eo::warnings << "Warning: Number of guys to merge in eoElitism was rounded" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void operator()(const eoPop<EOT>& _pop, eoPop<EOT>& _offspring)
|
||||
{
|
||||
if ((combien == 0) && (rate == 0.0))
|
||||
return;
|
||||
unsigned combienLocal;
|
||||
if (combien == 0) // rate is specified
|
||||
if (combien == 0) // rate is specified
|
||||
combienLocal = (unsigned int) (rate * _pop.size());
|
||||
else
|
||||
combienLocal = combien;
|
||||
|
||||
|
||||
if (combienLocal > _pop.size())
|
||||
throw std::logic_error("Elite larger than population");
|
||||
|
||||
|
||||
std::vector<const EOT*> result;
|
||||
_pop.nth_element(combienLocal, result);
|
||||
|
||||
|
||||
for (size_t i = 0; i < result.size(); ++i)
|
||||
{
|
||||
_offspring.push_back(*result[i]);
|
||||
_offspring.push_back(*result[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private :
|
||||
double rate;
|
||||
unsigned combien;
|
||||
|
|
@ -139,4 +139,4 @@ template <class EOT> class eoPlus : public eoMerge<EOT>
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
Reference in a new issue