MCPcopy Create free account
hub / github.com/cvanaret/Uno / define_UnoSolver

Function define_UnoSolver

interfaces/Python/python_modules/UnoSolver.cpp:17–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15
16namespace uno {
17 void define_UnoSolver(py::module& module) {
18 py::class_<UnoSolverWrapper>(module, "UnoSolver")
19 // constructor
20 .def(py::init<>(), "Constructor")
21
22 // methods
23 .def("set_option", [](UnoSolverWrapper& solver, const std::string& option_name, bool option_value) {
24 const auto type = Options::option_types.find(option_name);
25 if (type != Options::option_types.end()) { // key found
26 if (type->second == OptionType::BOOL) { // correct type
27 solver.options.set_bool(option_name, option_value);
28 }
29 else { // incorrect type
30 throw py::type_error(option_name + " is not of type bool");
31 }
32 }
33 else { // key not found
34 throw py::key_error(option_name + " does not exist");
35 }
36 }, py::arg("option_name"), py::arg("option_value"))
37
38 .def("set_option", [](UnoSolverWrapper& solver, const std::string& option_name, uno_int option_value) {
39 const auto type = Options::option_types.find(option_name);
40 if (type != Options::option_types.end()) { // key found
41 if (type->second == OptionType::INTEGER) { // correct type
42 solver.options.set_integer(option_name, option_value);
43 }
44 else { // incorrect type
45 throw py::type_error(option_name + " is not of type int");
46 }
47 }
48 else { // key not found
49 throw py::key_error(option_name + " does not exist");
50 }
51 }, py::arg("option_name"), py::arg("option_value"))
52
53 .def("set_option", [](UnoSolverWrapper& solver, const std::string& option_name, double option_value) {
54 const auto type = Options::option_types.find(option_name);
55 if (type != Options::option_types.end()) { // key found
56 if (type->second == OptionType::DOUBLE) { // correct type
57 solver.options.set_double(option_name, option_value);
58 }
59 else { // incorrect type
60 throw py::type_error(option_name + " is not of type double");
61 }
62 }
63 else { // key not found
64 throw py::key_error(option_name + " does not exist");
65 }
66 }, py::arg("option_name"), py::arg("option_value"))
67
68 .def("set_option", [](UnoSolverWrapper& solver, const std::string& option_name, const std::string& option_value) {
69 const auto type = Options::option_types.find(option_name);
70 if (type != Options::option_types.end()) { // key found
71 if (type->second == OptionType::STRING) { // correct type
72 solver.options.set_string(option_name, option_value);
73 }
74 else { // incorrect type

Callers 1

PYBIND11_MODULEFunction · 0.85

Calls 8

set_boolMethod · 0.80
set_integerMethod · 0.80
set_doubleMethod · 0.80
set_stringMethod · 0.80
optimizeMethod · 0.80
endMethod · 0.45

Tested by

no test coverage detected