Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ out/
*.dll
*.pyd


aux/
# Ignore Vagrant runtime files.

.vagrant/
Expand Down Expand Up @@ -185,11 +185,11 @@ compile_commands.json
debug
release
ioh_data
run.py
py10/

gsemo.cpp

run.py
py10/
gsemo.cpp
2022-SO-BO-main
.conda_environment
concepts
Expand Down
5 changes: 4 additions & 1 deletion include/ioh/problem/submodular/graph_problem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace ioh::problem::submodular
// added by saba
//! File with constraint variances
std::string constraint_variances;


//! The root path of the files
fs::path root;
Expand Down Expand Up @@ -71,6 +72,8 @@ namespace ioh::problem::submodular
meta.root = common::file::utils::get_static_root();
return meta;
}


};

//! Abstraction of graph data
Expand Down Expand Up @@ -273,7 +276,7 @@ namespace ioh::problem::submodular
const std::shared_ptr<graph::Graph> &graph) :
IntegerSingleObjective(
MetaData(problem_id, instance, name, graph->dimension(), common::OptimizationType::MAX),
Bounds<int>(graph->dimension()), ConstraintSet<int>(std::make_shared<GraphConstraint>(graph))),
Bounds<int>(graph->dimension(),0,1), ConstraintSet<int>(std::make_shared<GraphConstraint>(graph))),
graph(graph)
{
}
Expand Down
26 changes: 24 additions & 2 deletions ioh/src/integer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,28 @@ void define_submodular_problems(py::module &m)
py::class_<pwt::PWTConstraint, Constraint<int>, std::shared_ptr<pwt::PWTConstraint>>(m, "PWTConstraint")
.def("__repr__", &pwt::PWTConstraint::repr);

py::class_<graph::Meta>(m, "GraphMeta", "Graph metadata")
.def_readonly("edge_file", &graph::Meta::edge_file, "File with edge data")
.def_readonly("edge_weights", &graph::Meta::edge_weights, "File with edge weights")
.def_readonly("vertex_weights", &graph::Meta::vertex_weights, "File with vertex weights")
.def_readonly("constraint_weights", &graph::Meta::constraint_weights, "File with constraint weights")
.def_readonly("constraint_variances", &graph::Meta::constraint_variances, "File with constraint variances")
.def_readonly("is_edge", &graph::Meta::is_edge, "Edge type flag")
.def_readonly("digraph", &graph::Meta::digraph, "Is digraph flag")
.def_readonly("constraint_limit", &graph::Meta::constraint_limit, "Maximum value of the constraint")
.def_readonly("n_vertices", &graph::Meta::n_vertices, "Number of vertices");

py::class_<graph::Graph, std::shared_ptr<graph::Graph>>(m, "Graph", "Graph data structure")
.def("__repr__", &graph::Graph::repr)
.def("dimension", &graph::Graph::dimension, "Get the dimension of the graph")
.def_readonly("meta", &graph::Graph::meta, "Graph metadata")
.def_readonly("loaded", &graph::Graph::loaded, "Whether the graph is loaded in memory")
.def_readonly("adjacency_list", &graph::Graph::adjacency_list, "Adjacency list representation of the graph")
.def_readonly("edges", &graph::Graph::edges, "Edge list representation of the graph")
.def_readonly("constraint_weights", &graph::Graph::constraint_weights, "Constraint weights")
.def_readonly("constraint_variances", &graph::Graph::constraint_variances, "Constraint variances")
.def_readonly("edge_weights", &graph::Graph::edge_weights, "Edge weights")
.def_readonly("vertex_weights", &graph::Graph::vertex_weights, "Vertex weights");

py::class_<GraphProblem, IntegerSingleObjective, std::shared_ptr<GraphProblem>>(m, "GraphProblem",
"Graph type problem",
Expand Down Expand Up @@ -415,8 +437,8 @@ void define_submodular_problems(py::module &m)
)pbdoc")
.def_property_readonly_static(
"problems", [](py::object) { return ioh::common::Factory<GraphProblem, int, int>::instance().map(); },
"All registered problems");

"All registered problems")
.def_property_readonly("graph", [](const GraphProblem& self) { return self.graph; }, "The underlying graph structure");

py::class_<MaxCut, GraphProblem, std::shared_ptr<MaxCut>>(m, "MaxCut", py::is_final(), R"pbdoc(
Max-Cut problems
Expand Down
12 changes: 12 additions & 0 deletions ioh/src/numpy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
namespace py = pybind11;


template<typename T>
py::array_t<T> make_mutable_array(std::vector<T>& v, py::object owner)
{
return py::array_t<T>(
{v.size()}, // shape
{sizeof(T)}, // stride
v.data(), // pointer
owner // keep the parent (e.g. Solution) alive
);
}


template<typename T>
py::array_t<T> make_array(const std::vector<T>& x)
{
Expand Down
6 changes: 3 additions & 3 deletions ioh/src/problem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ void define_wrapper_functions(py::module &m, const std::string &class_name, cons
if (tx)
{
static bool r = register_python_fn(tx.value());
py::gil_scoped_acquire gil;
py::list px = py::cast<py::list>(tx.value()(make_array(x), iid));

py::gil_scoped_acquire gil;
py::list px = py::cast<py::list>(tx.value()(make_mutable_array(x, py::cast(&x)), iid));
if (px.size() == x.size())
return px.cast<std::vector<T>>();
else
Expand Down
4 changes: 2 additions & 2 deletions ioh/src/problem_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ void define_solution(py::module &m, const std::string &name)
)pbdoc")
.def_property(
"x",
[](const Class &c) {
return make_array(c.x);
[](Class &c) {
return make_mutable_array(c.x, py::cast(&c));
},
[](Class &self, const std::vector<T> &x) { self.x = x; },
"The search point in a search space, e.g., R^d or {0,1}^d")
Expand Down
Loading