31 #ifndef SHARK_ALGORITHMS_DIRECTSEARCH_OPERATORS_SELECTION_EP_TOURNAMENT_H 32 #define SHARK_ALGORITHMS_DIRECTSEARCH_OPERATORS_SELECTION_EP_TOURNAMENT_H 44 template<
typename Ordering >
53 template<
typename InIterator,
typename OutIterator>
56 InIterator it, InIterator itE,
57 OutIterator out, OutIterator outE
59 std::size_t outputSize = std::distance( out, outE );
60 std::vector<KeyValuePair<int, InIterator> > results = performTournament(rng, it, itE);
61 SHARK_RUNTIME_CHECK(results.size() > outputSize,
"Input range must be bigger than output range");
63 for(std::size_t i = 0; i != outputSize; ++i, ++out){
64 *out = *results[i].value;
74 template<
typename Population>
80 typedef typename Population::iterator InIterator;
81 std::vector<KeyValuePair<int, InIterator> > results = performTournament(rng, population.begin(),population.end());
84 for(std::size_t i = 0; i != mu; ++i){
85 individualPerform[i].value->select() =
true;
87 for(std::size_t i = mu; i != results.size()-1; ++i){
88 individualPerform[i].value->select() =
false;
97 template<
class InIterator>
98 std::vector<KeyValuePair<int, InIterator> > performTournament(rng_type& rng, InIterator it, InIterator itE){
99 std::size_t size = std::distance( it, itE );
100 UIntVector selectionProbability(size,0.0);
101 std::vector<KeyValuePair<int, InIterator> > individualPerformance(size);
103 for( std::size_t i = 0; i != size(); ++i ) {
104 individualPerformance[i].value = it+i;
107 if(smaller(*it, *(it+idx)){
108 individualPerformance[i].key -= 1;
113 std::sort( individualPerformance.begin(), individualPerformance.end());
114 return individualPerformance;