* eoEPReduce: moved the vector tmPop in attribute in order to keep memory capacity and avoir allocation/deallocation at each call to this function
This commit is contained in:
parent
41b73f7834
commit
cdd2a0dc5f
1 changed files with 59 additions and 51 deletions
|
|
@ -90,7 +90,7 @@ Softer selective pressure than pure truncate
|
|||
template <class EOT> class eoEPReduce : public eoReduce<EOT>
|
||||
{
|
||||
public:
|
||||
typedef typename EOT::Fitness Fitness;
|
||||
typedef typename EOT::Fitness Fitness;
|
||||
|
||||
eoEPReduce(unsigned _t_size ):
|
||||
t_size(_t_size)
|
||||
|
|
@ -144,27 +144,33 @@ typedef typename EOT::Fitness Fitness;
|
|||
std::nth_element(scores.begin(), it, scores.end(), Cmp());
|
||||
// sort(scores.begin(), scores.end(), Cmp());
|
||||
unsigned j;
|
||||
// std::cout << "Les scores apres tri\n";
|
||||
// for (j=0; j<scores.size(); j++)
|
||||
// {
|
||||
// std::cout << scores[j].first << " " << *scores[j].second << std::endl;
|
||||
// }
|
||||
eoPop<EOT> tmPop;
|
||||
// std::cout << "Les scores apres tri\n";
|
||||
// for (j=0; j<scores.size(); j++)
|
||||
// {
|
||||
// std::cout << scores[j].first << " " << *scores[j].second << std::endl;
|
||||
// }
|
||||
|
||||
tmPop.reserve(presentSize);
|
||||
tmPop.clear();
|
||||
|
||||
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 std::vector ??????
|
||||
// this would avoid all copies here
|
||||
|
||||
// it = scores.begin() + _newsize;
|
||||
// while (it < scores.end())
|
||||
// _newgen.erase(it->second);
|
||||
// it = scores.begin() + _newsize;
|
||||
// while (it < scores.end())
|
||||
// _newgen.erase(it->second);
|
||||
}
|
||||
private:
|
||||
unsigned t_size;
|
||||
eoPop<EOT> tmPop;
|
||||
};
|
||||
|
||||
/** a truncate class that does not sort, but repeatidely kills the worse.
|
||||
|
|
@ -220,7 +226,9 @@ public:
|
|||
if (oldSize < _newsize)
|
||||
throw std::logic_error("eoDetTournamentTruncate: Cannot truncate to a larger size!\n");
|
||||
|
||||
|
||||
// Now OK to erase some losers
|
||||
std::cout << "oldSize - _newsize: " << oldSize - _newsize << std::endl;
|
||||
for (unsigned i=0; i<oldSize - _newsize; i++)
|
||||
{
|
||||
//OLDCODE EOT & eo = inverse_deterministic_tournament<EOT>(_newgen, t_size);
|
||||
|
|
|
|||
Reference in a new issue