32 #ifndef SHARK_ALGORITHMS_DIRECT_SEARCH_OPERATORS_SELECTION_INDICATOR_BASED_SELECTION_H 33 #define SHARK_ALGORITHMS_DIRECT_SEARCH_OPERATORS_SELECTION_INDICATOR_BASED_SELECTION_H 53 template<
typename Indicator>
63 template<
typename PopulationType>
64 void operator()( PopulationType & population, std::size_t mu ){
65 if(population.empty())
return;
70 typedef std::vector< view_reference<typename PopulationType::value_type > > View;
72 unsigned int maxRank = 0;
73 std::map< unsigned int, View > fronts;
75 for(
unsigned int i = 0; i < population.size(); i++ ) {
76 maxRank = std::max( maxRank, population[i].rank());
77 fronts[population[i].rank()].push_back( population[i] );
78 population[i].selected() =
true;
82 unsigned int rank = maxRank;
83 std::size_t popSize = population.size();
85 while(popSize-fronts[rank].size() >= mu){
87 View & front = fronts[rank];
88 for(std::size_t i = 0; i != front.size(); ++i){
89 front[i].selected() =
false;
91 popSize -= front.size();
95 View& front = fronts[rank];
99 archive.reserve(popSize - front.size());
100 for(
unsigned int r = 1; r != rank; ++r){
101 archive.insert(archive.end(),fronts[r].begin(), fronts[r].end());
105 for(
auto lc:deselected){
106 front[lc].selected() =
false;
116 template<
typename Archive>
117 void serialize( Archive & archive,
const unsigned int version )
119 archive & BOOST_SERIALIZATION_NVP( m_indicator );
128 Indicator m_indicator;
132 struct view_reference {
135 typedef RealVector FitnessType;
137 view_reference() : mep_value( NULL ){}
138 view_reference(T & value) : mep_value( &value ){}
142 return( *mep_value );
145 operator const T & ()
const 147 return( *mep_value );
150 view_reference<T> operator=(
const T & rhs )
157 return mep_value->penalizedFitness();
161 return mep_value->unpenalizedFitness();
165 return mep_value->penalizedFitness();
169 return mep_value->unpenalizedFitness();
173 return mep_value->selected();