hypervolume_algorithms.cpp
Go to the documentation of this file.
1 #include <shark/Algorithms/DirectSearch/Operators/Hypervolume/HypervolumeCalculatorMD.h>
3 
4 #include <shark/Core/Timer.h>
5 #include <shark/Core/Random.h>
6 #include <iostream>
7 using namespace shark;
8 
9 std::vector<RealVector> createRandomFront(std::size_t numPoints, std::size_t numObj, double p){
10  std::vector<RealVector> points(numPoints);
11  for (std::size_t i = 0; i != numPoints; ++i) {
12  points[i].resize(numObj);
13  double norm = 0;
14  double sum = 0;
15  for(std::size_t j = 0; j != numObj; ++j){
16  points[i](j) = 1- random::uni(0.0, 1.0-sum);
17  sum += 1-points[i](j);
18  norm += std::pow(points[i](j),p);
19  }
20  norm = std::pow(norm,1/p);
21  points[i] /= norm;
22  }
23  return points;
24 }
25 
26 int main(int argc, char **argv) {
27 
28 
29  random::seed(42);
30  for(std::size_t dim = 4; dim != 9; ++dim){
31  std::cout<<"dimensions = " <<dim<<std::endl;
32  RealVector reference(dim,1.0);
33  for(unsigned int numPoints = 10; numPoints != 110; numPoints +=10){
34  auto set = createRandomFront(numPoints,dim,2);
35 
36  HypervolumeCalculatorMD algorithm1;
37  HypervolumeCalculatorMDWFG algorithm2;
38 
39  double val1= 0;
40  double stop1 = 0;
41  {
42  Timer time;
43  val1 = algorithm1(set, reference);
44  stop1 = time.stop();
45  }
46  double val2= 0;
47  double stop2 = 0;
48  {
49  Timer time;
50  val2 = algorithm2(set, reference);
51  stop2 = time.stop();
52  }
53  std::cout<<numPoints<<"\t"<<stop1<<"\t"<<stop2<<"\t"<<val1-val2<<"\t"<<std::endl;
54  }
55  std::cout<<std::endl;
56  }
57 }