Logo Search packages:      
Sourcecode: gaffitter version File versions  Download package

pair< int, int > GeneticAlgorithm::TournamentN ( int  from,
int  to 
) const [protected]

Choose a individual via tournament (need 2 or more competitors). This is a 3+ competitors version.

See also:

Definition at line 379 of file GeneticAlgorithm.cc.

References m_tournament_size, Score(), and Select().

Referenced by GeneticAlgorithm().

   vector<pair<Params::Size_t,int> > candidates;

   int sel = Select(from,to);
   candidates.push_back(make_pair(Score(sel), sel));

   for(unsigned int i=1; i<m_tournament_size; ++i)
      sel = Select(from,to,sel);
      candidates.push_back(make_pair(Score(sel), sel));

   // sort by score (smaller is better)
   sort(candidates.begin(), candidates.end());

   // best and worse index, respectively
   return make_pair(candidates.front().second, candidates.back().second);

Generated by  Doxygen 1.6.0   Back to index