30 #ifndef SHARK_ALGORITHMS_DIRECTSEARCH_INDICATORS_CROWDING_DISTANCE_H 31 #define SHARK_ALGORITHMS_DIRECTSEARCH_INDICATORS_CROWDING_DISTANCE_H 51 template<
typename ParetofrontType,
typename ParetoArchive>
52 std::size_t
leastContributor(ParetofrontType
const& front, ParetoArchive
const& archive)
const{
55 std::size_t numDims = front[0].size();
56 double keep = std::numeric_limits<double>::max();
58 std::vector<double> distances(front.size(),0.0);
59 std::vector<KeyValuePair<double, unsigned int > > order(front.size() + archive.size());
60 for( std::size_t i = 0; i != numDims; ++i ) {
62 for( std::size_t j = 0; j != front.size(); ++j ) {
63 order[j].key = front[j][i];
66 for( std::size_t j = 0; j != archive.size(); ++j ) {
67 order[j+front.size()].key = archive[j][i];
68 order[j+front.size()].value = j+front.size();
71 std::sort(order.begin(),order.end());
74 if(order.front().value < front.size())
75 distances[order.front().value] = keep;
76 if(order.back().value < front.size())
77 distances[order.back().value] = keep;
78 double normalizer = order.back().key - order.front().key;
79 for( std::size_t j = 1; j != order.size()-1; ++j ) {
80 std::size_t index = order[j].value;
82 if (index >= front.size() || distances[index] == keep)
86 distances[index] += (order[j+1].key - order[j-1].key)/normalizer;
91 return std::min_element(distances.begin(), distances.end()) - distances.begin();
94 template<
typename ParetoFrontType,
typename ParetoArchive>
95 std::vector<std::size_t>
leastContributors( ParetoFrontType
const& front, ParetoArchive
const& archive, std::size_t K)
const{
96 std::vector<std::size_t> indices;
97 std::vector<RealVector> points(front.begin(),front.end());
98 std::vector<std::size_t> activeIndices(points.size());
99 std::iota(activeIndices.begin(),activeIndices.end(),0);
100 for(std::size_t k=0; k != K; ++k){
103 points.erase(points.begin()+index);
104 indices.push_back(activeIndices[index]);
105 activeIndices.erase(activeIndices.begin()+index);
110 template<
class random>
111 void init(std::size_t , std::size_t , random& ){}
113 template<
typename Archive>