1 /// \file f_sharp_ridge.hpp
2 /// \brief cpp file for class Sharp_Ridge.
3 ///
4 /// A detailed file description.
5 /// Refer "https://github.com/numbbo/coco/blob/master/code-experiments/src/f_sharp_ridge.c"
6 ///
7 /// \author Furong Ye
8 /// \date 2019-09-12
9 #ifndef _F_SHARP_RIDGE_HPP
10 #define _F_SHARP_RIDGE_HPP
11 
12 #include "IOHprofiler_problem.h"
13 #include "coco_transformation.hpp"
14 
15 class Sharp_Ridge : public IOHprofiler_problem<double> {
16 public:
Sharp_Ridge(int instance_id=DEFAULT_INSTANCE,int dimension=DEFAULT_DIMENSION)17   Sharp_Ridge(int instance_id = DEFAULT_INSTANCE, int dimension = DEFAULT_DIMENSION) {
18     IOHprofiler_set_instance_id(instance_id);
19     IOHprofiler_set_problem_id(13);
20     IOHprofiler_set_problem_name("Sharp_Ridge");
21     IOHprofiler_set_problem_type("bbob");
22     IOHprofiler_set_number_of_objectives(1);
23     IOHprofiler_set_lowerbound(-5.0);
24     IOHprofiler_set_upperbound(5.0);
25     IOHprofiler_set_best_variables(0);
26     IOHprofiler_set_number_of_variables(dimension);
27     IOHprofiler_set_as_minimization();
28   }
29 
~Sharp_Ridge()30   ~Sharp_Ridge() {}
31 
prepare_problem()32   void prepare_problem() {
33     std::vector<double> xopt;
34     double fopt;
35     std::vector<std::vector<double> > M;
36     std::vector<double> b;
37     /* compute xopt, fopt*/
38 
39     int n = this->IOHprofiler_get_number_of_variables();
40     const long rseed = (long) (13 + 10000 * this->IOHprofiler_get_instance_id());
41     bbob2009_compute_xopt(xopt, rseed, n);
42     fopt = bbob2009_compute_fopt(13, this->IOHprofiler_get_instance_id());
43 
44     /* compute M and b */
45     M = std::vector<std::vector<double> > (n);
46     for (int i = 0; i != n; i++) {
47       M[i] = std::vector<double> (n);
48     }
49     b = std::vector<double> (n);
50     std::vector<std::vector<double> > rot1;
51     std::vector<std::vector<double> > rot2;
52     bbob2009_compute_rotation(rot1, rseed + 1000000, n);
53     bbob2009_compute_rotation(rot2, rseed, n);
54     for (int i = 0; i < n; ++i) {
55       b[i] = 0.0;
56       for (int j = 0; j < n; ++j) {
57         M[i][j] = 0.0;
58         for (int k = 0; k < n; ++k) {
59           double exponent = 1.0 * (int) k / ((double) (long) n - 1.0);
60           M[i][j] += rot1[i][k] * pow(sqrt(10), exponent) * rot2[k][j];
61         }
62       }
63     }
64     Coco_Transformation_Data::fopt = fopt;
65     Coco_Transformation_Data::xopt = xopt;
66     Coco_Transformation_Data::M = M;
67     Coco_Transformation_Data::b = b;
68   }
69 
internal_evaluate(const std::vector<double> & x)70   double internal_evaluate(const std::vector<double> &x) {
71     int n = x.size();
72     static const double alpha = 100.0;
73     const double vars_40 = 1; /* generalized: number_of_variables <= 40 ? 1 : number_of_variables / 40.0; */
74     size_t i = 0;
75     std::vector<double> result(1);
76 
77 
78     result[0] = 0.0;
79     for (i = (size_t)(ceil(vars_40)); i < n; ++i) {
80       result[0] += x[i] * x[i];
81     }
82     result[0] = alpha * sqrt(result[0] / vars_40);
83     for (i = 0; i < (size_t)ceil(vars_40); ++i) {
84       result[0] += x[i] * x[i] / vars_40;
85     }
86 
87     return result[0];
88   }
89 
createInstance(int instance_id=DEFAULT_INSTANCE,int dimension=DEFAULT_DIMENSION)90   static Sharp_Ridge * createInstance(int instance_id = DEFAULT_INSTANCE, int dimension = DEFAULT_DIMENSION) {
91     return new Sharp_Ridge(instance_id, dimension);
92   }
93 };
94 
95 #endif
96