From 9968fc3bbd8481e47de0e5e4fdbd0e772f754b51 Mon Sep 17 00:00:00 2001 From: Dimitri Rusin Date: Fri, 10 Nov 2023 17:44:29 +0100 Subject: [PATCH] include dynamic bin val into this branch, fix function identifier --- include/ioh/problem.hpp | 3 +- .../dynamic_bin_val/dynamic_bin_val.hpp | 100 ------------------ tests/cpp/problem/binval.cpp | 2 +- 3 files changed, 2 insertions(+), 103 deletions(-) delete mode 100644 include/ioh/problem/dynamic_bin_val/dynamic_bin_val.hpp diff --git a/include/ioh/problem.hpp b/include/ioh/problem.hpp index cb453f90c..650798db9 100644 --- a/include/ioh/problem.hpp +++ b/include/ioh/problem.hpp @@ -1,10 +1,9 @@ #pragma once -#include "problem/bbob.hpp" #include "problem/bbob.hpp" #include "problem/dynamic_bin_val.hpp" #include "problem/pbo.hpp" -#include "problem/pbo.hpp" +#include "problem/cec.hpp" #include "problem/problem.hpp" #include "problem/single.hpp" #include "problem/submodular.hpp" diff --git a/include/ioh/problem/dynamic_bin_val/dynamic_bin_val.hpp b/include/ioh/problem/dynamic_bin_val/dynamic_bin_val.hpp deleted file mode 100644 index d5b2f07f9..000000000 --- a/include/ioh/problem/dynamic_bin_val/dynamic_bin_val.hpp +++ /dev/null @@ -1,100 +0,0 @@ -/** - * @file dynamic_bin_val.hpp - * @brief Contains the declaration of the DynamicBinVal class, which represents dynamic binary value - * problems in the context of IOH. - */ - -#pragma once - -#include -#include -#include -#include - -#include "ioh/problem/single.hpp" -#include "ioh/problem/transformation.hpp" - -namespace ioh::problem -{ - /** - * @class DynamicBinVal - * @brief This class serves to represent dynamic binary value problems within the context of Iterative - * Optimization Heuristics (IOH). - * - * Inheriting functionalities from the IntegerSingleObjective, it also integrates functionalities - * for automatic registration of the problem type into various data structures. This facilitates - * easier management and retrieval of problem instances, while encapsulating characteristics and - * behaviours specific to dynamic binary value problems. It holds vital data members such as - * timestep and weights, which are crucial in depicting the dynamic aspects and unique features - * of these problem instances. - */ - class DynamicBinVal : public - IntegerSingleObjective, - AutomaticProblemRegistration, - AutomaticProblemRegistration - { - public: - - int timestep; /**< The current timestep in the dynamic binary value problem scenario. */ - std::vector weights; /**< A vector of weights used in the evaluation of the problem. */ - std::mt19937 random_generator; - - /** - * @brief Constructs a new instance of DynamicBinVal. - * - * @param n_variables The dimension of the problem, representing the size of the search space and - * indicating the number of variables in the problem. - */ - DynamicBinVal(const int instance, const int n_variables) : - IntegerSingleObjective - ( - MetaData(10001, 1, "DynamicBinVal", n_variables, common::OptimizationType::MAX), - Bounds(n_variables, 0, 1) - ), - random_generator(instance) - { - if (n_variables == 1) { return; } - - this->timestep = 0; - - // Initialize the weights vector with random numbers between 0 and 1 - this->weights.resize(n_variables); - for(int i = 0; i < n_variables; ++i) - { - this->weights[i] = std::generate_canonical(this->random_generator); - } - } - - int step() - { - this->timestep += 1; - - // Reinitialize the weights with random numbers between 0 and 1 after shuffling - for(size_t i = 0; i < this->weights.size(); ++i) - { - this->weights[i] = std::generate_canonical(this->random_generator); - } - - return this->timestep; - } - - protected: - - /** - * @brief Evaluates the problem instance using the given input vector. - * - * @param x The input vector which represents a potential solution to the problem. - * @return The evaluation result as a double value. - */ - double evaluate(const std::vector &x) override - { - double value = 0; - for(size_t i = 0; i < x.size(); ++i) - { - value += x[i] * this->weights[i]; - } - - return value; - } - }; -} // namespace ioh::problem diff --git a/tests/cpp/problem/binval.cpp b/tests/cpp/problem/binval.cpp index 023c06870..767fb268b 100644 --- a/tests/cpp/problem/binval.cpp +++ b/tests/cpp/problem/binval.cpp @@ -18,7 +18,7 @@ int main() { const auto &dyn_problem_factory = ioh::problem::ProblemRegistry::instance(); - auto d = dyn_problem_factory.create(10002, 1, 5); + auto d = dyn_problem_factory.create(10003, 1, 5); auto x = std::vector{1, 0, 1, 1, 1}; double value = (*d)(x);