MUQ  0.4.3
OptimizationWrapper.cpp
Go to the documentation of this file.
1 #include "AllClassWrappers.h"
2 
3 #include <pybind11/pybind11.h>
4 #include <pybind11/stl.h>
5 #include <pybind11/eigen.h>
6 #include <pybind11/iostream.h>
7 
8 #include <string>
9 
10 #include <functional>
11 #include <vector>
12 
15 #include "MUQ/Modeling/ModPiece.h"
16 
18 
20 
21 using namespace muq::Utilities;
22 using namespace muq::Optimization;
23 using namespace muq::Modeling;
24 namespace py = pybind11;
25 
26 void PythonBindings::OptimizationWrapper(pybind11::module &m) {
27 
28  py::class_<Optimizer, std::shared_ptr<Optimizer>>(m,"Optimizer")
29  .def_static("Construct", [](std::shared_ptr<ModPiece> const& cost, py::dict d){return Optimizer::Construct(cost, ConvertDictToPtree(d));})
30  .def("ListMethods", &Optimizer::ListMethods, py::call_guard<py::scoped_ostream_redirect,py::scoped_estream_redirect>())
31  .def("AddInequalityConstraint", (void (Optimizer::*)(std::vector<std::shared_ptr<muq::Modeling::ModPiece>> const&)) &Optimizer::AddInequalityConstraint)
32  .def("AddInequalityConstraint", (void (Optimizer::*)(std::shared_ptr<muq::Modeling::ModPiece> const&)) &Optimizer::AddInequalityConstraint)
33  .def("ClearInequalityConstraint", &Optimizer::ClearInequalityConstraint)
34  .def("AddEqualityConstraint", (void (Optimizer::*)(std::vector<std::shared_ptr<muq::Modeling::ModPiece>> const&)) &Optimizer::AddEqualityConstraint)
35  .def("AddEqualityConstraint", (void (Optimizer::*)(std::shared_ptr<muq::Modeling::ModPiece> const&)) &Optimizer::AddEqualityConstraint)
36  .def("ClearEqualityConstraint", &Optimizer::ClearEqualityConstraint)
37  .def("Solve", &Optimizer::Solve, py::call_guard<py::scoped_ostream_redirect, py::scoped_estream_redirect>());
38 
39  py::class_<NLoptOptimizer, Optimizer, std::shared_ptr<NLoptOptimizer>>(m, "NLoptOptimizer")
40  .def(py::init( [](std::shared_ptr<CostFunction> cost, py::dict d) { return new NLoptOptimizer(cost, ConvertDictToPtree(d)); }));
41 
42 }
Solve an optimization problem.
Definition: Optimizer.h:21
void OptimizationWrapper(pybind11::module &m)
boost::property_tree::ptree ConvertDictToPtree(pybind11::dict dict)