27 #ifndef SHARK_ALGORITHMS_DIRECTSEARCH_HYPERVOLUME_CONTRIBUTION_MD_H 28 #define SHARK_ALGORITHMS_DIRECTSEARCH_HYPERVOLUME_CONTRIBUTION_MD_H 52 template<
class Set,
typename VectorType>
53 std::vector<KeyValuePair<double,std::size_t> >
smallest(Set
const& points, std::size_t k,
VectorType const& ref)
const{
56 std::vector<KeyValuePair<double,std::size_t> > result( points.size() );
58 auto const& point = points[i];
61 std::vector<RealVector> pointset( points.begin(), points.end() );
62 pointset.erase( pointset.begin() + i );
63 restrictSet(pointset,point);
65 double baseVol = std::exp(sum(log(ref-point)));
66 result[i].key = baseVol - hv(pointset,ref);
69 std::sort(result.begin(),result.end());
70 result.erase(result.begin()+k,result.end());
79 template<
class Set,
typename VectorType>
80 std::vector<KeyValuePair<double,std::size_t> >
largest(Set
const& points, std::size_t k,
VectorType const& ref)
const{
83 std::vector<KeyValuePair<double,std::size_t> > result( points.size() );
85 auto const& point = points[i];
88 std::vector<RealVector> pointset( points.begin(), points.end() );
89 pointset.erase( pointset.begin() + i );
90 restrictSet(pointset,point);
92 double baseVol = std::exp(sum(log(ref-point)));
93 result[i].key = baseVol - hv(pointset,ref);
96 std::sort(result.begin(),result.end());
97 result.erase(result.begin(),result.end()-k);
98 std::reverse(result.begin(),result.end());
109 std::vector<KeyValuePair<double,std::size_t> >
smallest(Set
const& points, std::size_t k)
const{
112 std::vector<std::size_t> minIndex(points[0].size(),0);
113 RealVector minVal = points[0];
114 RealVector ref=points[0];
115 for(std::size_t i = 1; i != points.size(); ++i){
116 noalias(ref) = max(ref,points[i]);
117 for(std::size_t j = 0; j != minVal.size(); ++j){
118 if(points[i](j)< minVal[j]){
119 minVal[j] = points[i](j);
125 std::vector<KeyValuePair<double,std::size_t> > result;
127 if(std::find(minIndex.begin(),minIndex.end(),i) != minIndex.end())
130 auto const& point = points[i];
133 std::vector<RealVector> pointset( points.begin(), points.end() );
134 pointset.erase( pointset.begin() + i );
135 restrictSet(pointset,point);
137 double baseVol = std::exp(sum(log(ref-point)));
138 double volume = baseVol - hv(pointset,ref);
140 result.emplace_back(volume,i);
143 std::sort(result.begin(),result.end());
144 result.erase(result.begin()+k,result.end());
156 std::vector<KeyValuePair<double,std::size_t> >
largest(Set
const& points, std::size_t k)
const{
159 std::vector<std::size_t> minIndex(points[0].size(),0);
160 RealVector minVal = points[0];
161 RealVector ref=points[0];
162 for(std::size_t i = 1; i != points.size(); ++i){
163 noalias(ref) = max(ref,points[i]);
164 for(std::size_t j = 0; j != minVal.size(); ++j){
165 if(points[i](j)< minVal[j]){
166 minVal[j] = points[i](j);
173 std::vector<KeyValuePair<double,std::size_t> > result;
175 if(std::find(minIndex.begin(),minIndex.end(),i) != minIndex.end())
177 auto const& point = points[i];
180 std::vector<RealVector> pointset( points.begin(), points.end() );
181 pointset.erase( pointset.begin() + i );
182 restrictSet(pointset,point);
184 double baseVol = std::exp(sum(log(ref-point)));
185 double volume = baseVol - hv(pointset,ref);
187 result.emplace_back(volume,i);
190 std::sort(result.begin(),result.end());
191 result.erase(result.begin(),result.end()-k);
192 std::reverse(result.begin(),result.end());
197 template<
class Po
intset,
class Po
int>
198 void restrictSet(Pointset& pointset, Point
const& point)
const{
199 for(
auto& p: pointset){
200 noalias(p) = max(p,point);
202 std::vector<std::size_t>
ranks(pointset.size());
204 std::size_t end = pointset.size();
217 pointset.erase(pointset.begin() +end, pointset.end());