From 30542dea4ed370a625b204efe988a64cd485a132 Mon Sep 17 00:00:00 2001 From: jacobdenobel Date: Wed, 8 Nov 2023 20:30:51 +0100 Subject: [PATCH] disable directio for apple --- cec.hpp | 120 ++++++++++++++++++++++++++++++++++++ include/ioh/common/file.hpp | 2 +- 2 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 cec.hpp diff --git a/cec.hpp b/cec.hpp new file mode 100644 index 00000000..7d106325 --- /dev/null +++ b/cec.hpp @@ -0,0 +1,120 @@ +/** + * Feedback for the CEC functions: + * So what you did was indeed make a copy of the BBOB function. + * While the code that performs the function evaluation, the code in the evaluate method + * is indeed exactly the same for both the BBOB suite and the CEC suite, the stuff that happens in + * transform_variables is different. + * + * For your information, how a problem is evaluated in iohexperimenter is as follows: + * + * problem(x_raw) + * 1. x_transformed = transform_variables(x_raw) + * 2. y_raw = evaluate(y_raw) + * 3. y_transformed = transform_objectives(y_raw) + * 4. return y_transformed + * + * For BBOB, the code in transform_variables is based on "randomly" generated transformations, + * while for CEC, these transformation matrices/vectors are defined in a set of flat files. + * This also means that for BBOB problems in theory we can generate any number of transformations, + * while for the CEC problems there is only one officially defined transformation set for a given + * function. + * + * What I would suggest, since most of the file parsing code is shared amongst all CEC functions, + * is that you make a shared parent class for all CEC functions, which only performs such shared + * tasks, and put the function specific code, i.e. the rastrigin evaluation/transformation code + * in the function class. Take a look at the bbob_problem.hpp for an idea on how to this. + * + * Below I give an example of such a structure. This is not complete, nor fully working, but hope you get the idea. + */ + +#include +#include + +namespace ioh::problem::cec2022 +{ + + // ************************ Parent class *************************** // + + // Class which implements the methods shared for all cec functions + class CEC : public RealSingleObjective + { + public: + /** + * @brief Construct a new CEC object + * + * @param problem_id The id of the problem (should be unique) + * @param instance The instance of the problem (ignored for cec for now) + * @param n_variables the dimension of the problem (the size of the search space, how many x varables) + * @param name the name of the problem (should be unique) + * @param path the transformation file (just an example, maybe you want to do this differently) + */ + CEC(const int problem_id, const int instance, const int n_variables, const std::string &name, + const std::string &path) : + RealSingleObjective(MetaData(problem_id, instance, name, n_variables), + Bounds(n_variables, -5 /*Lower bound*/, 5 /*Upper bound*/)) + { + read_transformation_files(path); + set_optimum(); + } + + //! Method to set the value for the global optimum correctly. + void set_optimum(); + + //! Handler for reading all static data + void read_transformation_files(const std::string path); + + //! Method for applying the cec transformations. + std::vector apply_cec_transformation(const std::vector &x); + + protected: + //! The method which should be override in RealSingleObjective for applying the actual transformation correctly + std::vector transform_variables(std::vector x) override { return apply_cec_transformation(x); } + }; + + + // CRTP class for CEC problems. Inherit from this class when defining new CEC problems. This is needed for + // storing stuff in the hash maps. + template