diff --git a/include/ioh/problem/problem.hpp b/include/ioh/problem/problem.hpp index 0857d23c0..cb25873ca 100644 --- a/include/ioh/problem/problem.hpp +++ b/include/ioh/problem/problem.hpp @@ -226,6 +226,33 @@ namespace ioh constraintset_.remove(c); log_info_.allocate(optimum_, constraintset_); } + + //! Call this method after updating any fields on meta_data_ + void updated_metadata() { + if (logger_ != nullptr){ + if(state_.evaluations != 0) + IOH_DBG(warning, "Updated meta_data with logger attached and already evaluated problem. State will be reset.") + reset(); + } + } + + //! Accessor for problem id + void set_id(const int new_id) { + meta_data_.problem_id = new_id; + updated_metadata(); + } + + //! Accessor for problem instance + void set_instance(const int new_instance){ + meta_data_.instance = new_instance; + updated_metadata(); + } + + //! Accessor for problem name + void set_name(const std::string& new_name){ + meta_data_.name = new_name; + updated_metadata(); + } //! Stream operator friend std::ostream &operator<<(std::ostream &os, const Problem &obj) diff --git a/include/ioh/problem/structures.hpp b/include/ioh/problem/structures.hpp index ca9d82539..0b02882db 100644 --- a/include/ioh/problem/structures.hpp +++ b/include/ioh/problem/structures.hpp @@ -228,8 +228,6 @@ namespace ioh */ State(Solution initial) : initial_solution(std::move(initial)) { reset(); } - - //! reset the state void reset() { diff --git a/ioh/src/problem.cpp b/ioh/src/problem.cpp index eae90204f..499efa0af 100644 --- a/ioh/src/problem.cpp +++ b/ioh/src/problem.cpp @@ -433,6 +433,10 @@ void define_base_class(py::module &m, const std::string &name) how: The enforcement strategy, should be one of the 'ioh.ConstraintEnforcement' options exponent: The exponent for scaling the contraint )pbdoc") + + .def("set_id", &ProblemType::set_id, py::arg("new_problem_id"), "update the problem id") + .def("set_instance", &ProblemType::set_instance, py::arg("new_instance"), "update the problem instance") + .def("set_name", &ProblemType::set_name, py::arg("new_name"),"update the problem name") .def("__repr__", [=](const ProblemType &p) { using namespace ioh::common; const auto meta_data = p.meta_data();