-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolypod.cpp
More file actions
54 lines (47 loc) · 2.13 KB
/
polypod.cpp
File metadata and controls
54 lines (47 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "polypodimpl.h"
namespace py = pybind11;
PYBIND11_MODULE(polypod, m) {
m.doc() = "PolyPod solver module";
// Parameters class
py::class_<PolyPodParameters>(m, "PolyPodParameters")
.def(py::init<int, int, int, int, int>(),
py::arg("S"),
py::arg("b1"), py::arg("u1"),
py::arg("b2"), py::arg("u2"))
.def_readonly("S", &PolyPodParameters::S)
.def_readonly("b1", &PolyPodParameters::b1)
.def_readonly("u1", &PolyPodParameters::u1)
.def_readonly("b2", &PolyPodParameters::b2)
.def_readonly("u2", &PolyPodParameters::u2);
// Base class
py::class_<PolyPod>(m, "PolyPod")
.def("getT", &PolyPod::getT)
.def("setT", &PolyPod::setT)
.def("get_matrix", &PolyPod::get_matrix)
.def("find_shortest_solution", &PolyPod::find_shortest_solution)
.def("bfs_next_solution", &PolyPod::bfs_next_solution)
.def("bfs_reset", &PolyPod::bfs_reset)
.def("dfs_next_solution", &PolyPod::dfs_next_solution, py::arg("prefer_max") = true)
.def("dfs_reset", &PolyPod::dfs_reset)
.def("find_maximum_T_with_solution", &PolyPod::find_maximum_T_with_solution)
.def("find_maximum_T_with_solution_length", &PolyPod::find_maximum_T_with_solution_length,
py::arg("max_steps"),
"Find maximum T that has a solution with at most max_steps steps");
// Derived class - InPlacePolyPod
py::class_<InPlacePolyPod, PolyPod>(m, "InPlacePolyPod")
.def(py::init<PolyPodParameters, int>(),
py::arg("params"), py::arg("T"));
// Derived class - RecreatePolyPod
py::class_<RecreatePolyPod, PolyPod>(m, "RecreatePolyPod")
.def(py::init<PolyPodParameters, int>(),
py::arg("params"), py::arg("T"));
// Factory function
m.def("create_polypod", &create_polypod,
py::return_value_policy::take_ownership,
py::arg("params"),
py::arg("T"),
py::arg("mode"),
"Factory function to create PolyPod instances. Mode can be 'inplace' or 'recreate'.");
}