37 #ifndef SHARK_ALGORITHMS_DIRECTSEARCH_OPERATORS_SELECTION_LINEARRANKING_H 38 #define SHARK_ALGORITHMS_DIRECTSEARCH_OPERATORS_SELECTION_LINEARRANKING_H 56 template<
typename Ordering >
74 template<
typename RngType,
typename InIterator,
typename OutIterator>
77 InIterator individuals,
78 InIterator individualsE,
84 std::size_t size = std::distance( individuals, individualsE );
85 std::vector<InIterator> sortedIndividuals(size);
86 std::iota(sortedIndividuals.begin(),sortedIndividuals.end(),individuals);
88 sortedIndividuals.begin(),
89 sortedIndividuals.end(),
90 [](InIterator lhs, InIterator rhs){
92 return ordering(*lhs,*rhs);
96 RealVector selectionProbability(size);
97 double a = 2. * (
etaMax - 1.)/(size - 1.);
98 for( std::size_t i = 0; i != size; ++i ) {
99 selectionProbability[i] = (
etaMax - a*i);
101 selectionProbability /=sum(selectionProbability);
104 for( ; out != outE; ++out ){
105 InIterator individuals = rws(rng, sortedIndividuals.begin(), sortedIndividuals.end(), selectionProbability)->value;