30 #ifndef SHARK_ALGORITHMS_DIRECTSEARCH_HYPERVOLUMECALCULATOR_MD_HOY_H 31 #define SHARK_ALGORITHMS_DIRECTSEARCH_HYPERVOLUMECALCULATOR_MD_HOY_H 53 template<
typename Set,
typename VectorType >
57 SIZE_CHECK( points.begin()->size() == refPoint.size() );
59 std::vector<VectorType>
set;
60 set.reserve(points.size());
61 for(std::size_t i = 0; i != points.size(); ++i){
62 set.push_back(points[i]);
64 std::sort(
set.begin(),
set.end(), [ ](
VectorType const& x,
VectorType const& y){
return x.back() < y.back();});
66 m_sqrtNoPoints =
static_cast< std::size_t
>( ::sqrt( static_cast<double>( points.size() ) ) );
69 for( std::size_t i = 0; i <
set.size(); i++ ){
70 noalias(regLow) = min(regLow,
set[i]);
72 return stream( regLow, refPoint,
set, 0, refPoint.back() );
75 template<
typename VectorType>
77 for( std::size_t i = 0; i < cuboid.size()-1; i++ ) {
78 if( cuboid[i] > regionLow[i] )
84 template<
typename VectorType>
86 for( std::size_t i = 0; i < cuboid.size()-1; i++) {
87 if (cuboid[i] >= regionUp[i])
93 template<
typename VectorType>
95 if( !( regLow[split] < cub[split] ) ) {
98 for (
int j = 0; j < split; j++) {
99 if (regLow[j] < cub[j]) {
107 template<
typename VectorType>
110 for( std::size_t i = 0; i < regionLow.size()-1; i++) {
111 volume *= (regionUp[i] - regionLow[i]);
116 template<
typename VectorType>
118 std::size_t pile = cuboid.size();
119 for( std::size_t i = 0; i < cuboid.size()-1; i++ ) {
120 if( cuboid[i] > regionLow[i] ) {
121 if( pile != cuboid.size() ) {
131 template<
typename VectorType>
135 for (i = 0; i < v.size(); i++) {
136 result += v[i] ? ( 1 << i ) : 0;
142 template<
typename VectorType>
144 for (std::size_t j = 0; j < result.size(); j++)
147 unsigned int rest = i;
151 result[idx] = (rest % 2);
158 template<
typename VectorType>
160 std::vector<int> bs( regLow.size()-1, 1 );
165 int oneCounter;
double summand;
167 for(
unsigned i = 1; i <= noSummands; i++ ) {
172 for(std::size_t j = 0; j < regLow.size()-1; j++ ) {
174 summand *= regUp[j] - trellis[j];
177 summand *= regUp[j] - regLow[j];
180 if (oneCounter % 2 == 0)
189 template<
typename VectorType>
193 }
else if( length == 2 ) {
198 std::copy( bounds.begin(), bounds.begin() + length, v.begin() );
199 std::sort( v.begin(), v.end() );
201 return (length % 2 == 1) ? v[length/2] : (v[length/2-1] + v[(length/2)]) / 2;
204 template<
typename Set,
typename VectorType>
211 std::size_t numObjectives = regionLow.size();
215 int coverIndexOld = -1;
220 double dMeasure =
getMeasure(regionLow, regionUp);
221 while( cover == coverOld && coverIndex < static_cast<int>( points.size() ) ) {
222 if( coverIndexOld == coverIndex )
225 coverIndexOld = coverIndex;
227 if(
covers( points[coverIndex], regionLow) ) {
228 cover = points[coverIndex][numObjectives-1];
229 result += dMeasure * (coverOld - cover);
235 for (c = coverIndex; c > 0; c--) {
236 if( points[c-1][numObjectives-1] == cover) {
244 bool allPiles =
true;
246 std::vector<int> piles( coverIndex );
248 for(
int i = 0; i < coverIndex; i++ ) {
249 piles[i] =
isPile( points[i], regionLow, regionUp );
250 if (piles[i] == -1) {
259 double current = 0.0;
263 current = points[i][numObjectives-1];
265 if( points[i][piles[i]] < trellis[piles[i]] ) {
266 trellis[piles[i]] = points[i][piles[i]];
269 if (i < coverIndex) {
270 next = points[i][numObjectives-1];
278 while (next == current);
280 result +=
computeTrellis(regionLow, regionUp, trellis) * (next - current);
281 }
while (next != cover);
285 std::vector<double> boundaries( coverIndex );
286 std::vector<double> noBoundaries( coverIndex );
287 unsigned boundIdx = 0;
288 unsigned noBoundIdx = 0;
291 for(
int i = 0; i < coverIndex; i++ ) {
293 if (contained == 1) {
294 boundaries[boundIdx] = points[i][split];
296 }
else if (contained == 0) {
297 noBoundaries[noBoundIdx] = points[i][split];
303 bound =
getMedian( boundaries, boundIdx );
305 bound =
getMedian( noBoundaries, noBoundIdx );
309 }
while (bound == -1.0);
311 Set pointsChildLow, pointsChildUp;
314 regionUpC[split] = bound;
316 regionLowC[split] = bound;
318 for(
int i = 0; i < coverIndex; i++) {
320 pointsChildUp.push_back( points[i] );
324 pointsChildLow.push_back( points[i] );
329 if( pointsChildUp.size() > 0 ) {
330 result +=
stream(regionLow, regionUpC, pointsChildUp, split, cover);
332 if (pointsChildLow.size() > 0) {
333 result +=
stream(regionLowC, regionUp, pointsChildLow, split, cover);