1 /// \file f_Schaffers1000.hpp 2 /// \brief cpp file for class Schaffers1000. 3 /// 4 /// A detailed file description. 5 /// Refer "https://github.com/numbbo/coco/blob/master/code-experiments/src/f_schaffers.c" 6 /// 7 /// \author Furong Ye 8 /// \date 2019-09-12 9 #ifndef _F_SCHAFFERSTHOUSAND_HPP 10 #define _F_SCHAFFERSTHOUSAND_HPP 11 12 #include "IOHprofiler_problem.h" 13 #include "coco_transformation.hpp" 14 15 class Schaffers1000 : public IOHprofiler_problem<double> { 16 public: Schaffers1000(int instance_id=DEFAULT_INSTANCE,int dimension=DEFAULT_DIMENSION)17 Schaffers1000(int instance_id = DEFAULT_INSTANCE, int dimension = DEFAULT_DIMENSION) { 18 IOHprofiler_set_instance_id(instance_id); 19 IOHprofiler_set_problem_id(18); 20 IOHprofiler_set_problem_name("Schaffers1000"); 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 ~Schaffers1000()30 ~Schaffers1000() {} 31 32 const double conditioning = 1000; 33 prepare_problem()34 void prepare_problem() { 35 std::vector<double> xopt; 36 double fopt; 37 std::vector<std::vector<double> > M; 38 std::vector<std::vector<double> > M1; 39 std::vector<double> b; 40 std::vector<double> b1; 41 /* compute xopt, fopt*/ 42 43 int n = this->IOHprofiler_get_number_of_variables(); 44 const long rseed = (long) (17 + 10000 * this->IOHprofiler_get_instance_id()); 45 bbob2009_compute_xopt(xopt, rseed, n); 46 fopt = bbob2009_compute_fopt(18, this->IOHprofiler_get_instance_id()); 47 48 /* compute M and b */ 49 M = std::vector<std::vector<double> > (n); 50 M1 = std::vector<std::vector<double> > (n); 51 for (int i = 0; i != n; i++) { 52 M[i] = std::vector<double> (n); 53 M1[i] = std::vector<double> (n); 54 } 55 b = std::vector<double> (n); 56 b1 = std::vector<double> (n); 57 std::vector<std::vector<double> > rot1; 58 std::vector<std::vector<double> > rot2; 59 bbob2009_compute_rotation(rot1, rseed + 1000000, n); 60 bbob2009_compute_rotation(rot2, rseed, n); 61 for (int i = 0; i < n; ++i) { 62 b[i] = 0.0; 63 for (int j = 0; j < n; ++j) { 64 double exponent = 1.0 * (int) i / ((double) (long) n - 1.0); 65 M[i][j] = rot2[i][j] * pow(sqrt(conditioning), exponent); 66 } 67 } 68 bbob2009_copy_rotation_matrix(rot1,M1,b1,n); 69 70 Coco_Transformation_Data::fopt = fopt; 71 Coco_Transformation_Data::xopt = xopt; 72 Coco_Transformation_Data::M = M; 73 Coco_Transformation_Data::b = b; 74 Coco_Transformation_Data::M1 = M1; 75 Coco_Transformation_Data::b1 = b1; 76 Coco_Transformation_Data::penalty_factor = 10.0; 77 78 Coco_Transformation_Data::lower_bound = -5.0; 79 Coco_Transformation_Data::upper_bound = 5.0; 80 } 81 internal_evaluate(const std::vector<double> & x)82 double internal_evaluate(const std::vector<double> &x) { 83 int n = x.size(); 84 size_t i = 0; 85 std::vector<double> result(1); 86 87 /* Computation core */ 88 result[0] = 0.0; 89 for (i = 0; i < n - 1; ++i) { 90 const double tmp = x[i] * x[i] + x[i + 1] * x[i + 1]; 91 if (std::isinf(tmp) && std::isnan(sin(50.0 * pow(tmp, 0.1)))) /* sin(inf) -> nan */ 92 /* the second condition is necessary to pass the integration tests under Windows and Linux */ 93 return tmp; 94 result[0] += pow(tmp, 0.25) * (1.0 + pow(sin(50.0 * pow(tmp, 0.1)), 2.0)); 95 } 96 result[0] = pow(result[0] / ((double) (long) n - 1.0), 2.0); 97 98 return result[0]; 99 } 100 createInstance(int instance_id=DEFAULT_INSTANCE,int dimension=DEFAULT_DIMENSION)101 static Schaffers1000 * createInstance(int instance_id = DEFAULT_INSTANCE, int dimension = DEFAULT_DIMENSION) { 102 return new Schaffers1000(instance_id, dimension); 103 } 104 }; 105 106 #endif 107