Skip to content

Commit

Permalink
added accessor for set_{id, name, instance} for all problems
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobdenobel committed Jul 3, 2023
1 parent fd3fe24 commit 565a626
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
27 changes: 27 additions & 0 deletions include/ioh/problem/problem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions include/ioh/problem/structures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,6 @@ namespace ioh
*/
State(Solution<T, double> initial) : initial_solution(std::move(initial)) { reset(); }



//! reset the state
void reset()
{
Expand Down
4 changes: 4 additions & 0 deletions ioh/src/problem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 565a626

Please sign in to comment.