From c0e85685f80ef72fa7c51ac759ff2f52c49e1eac Mon Sep 17 00:00:00 2001 From: gustavo Date: Tue, 11 Jan 2000 12:13:18 +0000 Subject: [PATCH] bug fix in eoTournament --- eo/src/eoTournament.h | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/eo/src/eoTournament.h b/eo/src/eoTournament.h index dad956540..5a754b7ff 100644 --- a/eo/src/eoTournament.h +++ b/eo/src/eoTournament.h @@ -61,17 +61,23 @@ public: // Build vector for ( unsigned j = 0; j < thisSize*perc; j ++ ) { - // Randomly select a tournamentSize set, and choose the best - eoPop veoTournament; - eoUniform u( 0, thisSize); - for ( unsigned k = 0; k < repTournamentSize; k++ ) { - unsigned chosen = u(); - EOT newEO = _vEO[chosen]; - veoTournament.push_back( newEO ); - } - sort( veoTournament.begin(), veoTournament.end() ); - // The first is chosen for the new population - _aVEO.push_back( veoTournament.front() ); + // Randomly select a tournamentSize set, and choose the best + eoPop veoTournament; + eoUniform u( 0, thisSize); + for ( unsigned k = 0; k < repTournamentSize; k++ ) { + unsigned chosen = u(); + EOT newEO = _vEO[chosen]; + veoTournament.push_back( newEO ); + } + + eoPop::const_iterator best = max_element(veoTournament.begin(), + veoTournament.end()); + if (best == veoTournament.end()) { + throw runtime_error("error in void eoTournament::operator(eoPop&, eoPop&)"); + } + + // The first is chosen for the new population + _aVEO.push_back( best ); } };