27 #ifndef SHARK_ALGORITHMS_DIRECTSEARCH_HYPERVOLUME_CONTRIBUTION_2D_H 28 #define SHARK_ALGORITHMS_DIRECTSEARCH_HYPERVOLUME_CONTRIBUTION_2D_H 47 Point(
double f1,
double f2, std::size_t index)
53 bool operator<(Point
const& rhs)
const{
54 if (f1 < rhs.f1)
return true;
55 if (f1 > rhs.f1)
return false;
72 template<
class Comparator>
73 std::vector<KeyValuePair<double,std::size_t> > bestContributors( std::vector<Point>
const& front, std::size_t k, Comparator comp)
const{
75 std::vector<KeyValuePair<double,std::size_t> > bestK(k+1);
76 auto heapStart = bestK.begin();
77 auto heapEnd = bestK.begin();
82 for(std::size_t i = 1; i < front.size()-1;++i){
83 double contribution = (front[i+1].f1 - front[i].f1)*(front[i-1].f2 - front[i].f2);
86 std::push_heap(heapStart,heapEnd,pointComp);
88 if(heapEnd == bestK.end()){
89 std::pop_heap(heapStart,heapEnd,pointComp);
93 std::sort_heap(heapStart,heapEnd,pointComp);
103 template<
typename Set,
typename VectorType>
104 std::vector<KeyValuePair<double,std::size_t> >
smallest( Set
const& points, std::size_t k,
VectorType const& referencePoint)
const{
106 std::vector<Point> front;
107 front.emplace_back(0,referencePoint[1],points.size()+1);
108 for(std::size_t i = 0; i != points.size(); ++i)
109 front.emplace_back(points[i][0],points[i][1],i);
110 front.emplace_back(referencePoint[0],0,points.size()+1);
111 std::sort(front.begin()+1,front.end()-1);
113 return bestContributors(front,k,[](
double con1,
double con2){
return con1 < con2;});
122 template<
typename Set>
123 std::vector<KeyValuePair<double,std::size_t> >
smallest( Set
const& points, std::size_t k)
const{
125 std::vector<Point> front;
126 for(std::size_t i = 0; i != points.size(); ++i)
127 front.emplace_back(points[i][0],points[i][1],i);
128 std::sort(front.begin(),front.end());
130 return bestContributors(front,k,[](
double con1,
double con2){
return con1 < con2;});
137 template<
typename Set,
typename VectorType>
138 std::vector<KeyValuePair<double,std::size_t> >
largest( Set
const& points, std::size_t k,
VectorType const& referencePoint)
const{
140 std::vector<Point> front;
141 front.emplace_back(0,referencePoint[1],points.size()+1);
142 for(std::size_t i = 0; i != points.size(); ++i)
143 front.emplace_back(points[i][0],points[i][1],i);
144 front.emplace_back(referencePoint[0],0,points.size()+1);
145 std::sort(front.begin()+1,front.end()-1);
147 return bestContributors(front,k,[](
double con1,
double con2){
return con1 > con2;});
156 template<
typename Set>
157 std::vector<KeyValuePair<double,std::size_t> >
largest( Set
const& points, std::size_t k)
const{
159 std::vector<Point> front;
160 for(std::size_t i = 0; i != points.size(); ++i)
161 front.emplace_back(points[i][0],points[i][1],i);
162 std::sort(front.begin(),front.end());
164 return bestContributors(front,k,[](
double con1,
double con2){
return con1 > con2;});