aligator  0.6.1
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
expose-functions.cpp
Go to the documentation of this file.
1
5
10
11namespace aligator {
12namespace python {
13
14using context::ConstMatrixRef;
15using context::ConstVectorRef;
17using context::MatrixXs;
18using context::Scalar;
21using context::VectorXs;
22using internal::PyStageFunction;
23using FunctionPtr = shared_ptr<StageFunction>;
24using StateErrorResidual = StateErrorResidualTpl<Scalar>;
25using ControlErrorResidual = ControlErrorResidualTpl<Scalar>;
26
28struct FunctionDataWrapper : StageFunctionData, bp::wrapper<StageFunctionData> {
29 using StageFunctionData::StageFunctionData;
30};
31
33
34 bp::register_ptr_to_python<FunctionPtr>();
35
36 bp::class_<PyStageFunction<>, boost::noncopyable>(
37 "StageFunction",
38 "Base class for ternary functions f(x,u,x') on a stage of the problem.",
39 bp::no_init)
40 .def(bp::init<const int, const int, const int, const int>(
41 bp::args("self", "ndx1", "nu", "ndx2", "nr")))
42 .def(bp::init<const int, const int, const int>(
43 bp::args("self", "ndx", "nu", "nr")))
44 .def("evaluate", bp::pure_virtual(&StageFunction::evaluate),
45 bp::args("self", "x", "u", "y", "data"))
46 .def("computeJacobians",
47 bp::pure_virtual(&StageFunction::computeJacobians),
48 bp::args("self", "x", "u", "y", "data"))
49 .def("computeVectorHessianProducts",
50 &StageFunction::computeVectorHessianProducts,
51 bp::args("self", "x", "u", "y", "lbda", "data"))
52 .def_readonly("ndx1", &StageFunction::ndx1, "Current state space.")
53 .def_readonly("ndx2", &StageFunction::ndx2, "Next state space.")
54 .def_readonly("nu", &StageFunction::nu, "Control dimension.")
55 .def_readonly("nr", &StageFunction::nr, "Function codimension.")
56 .def(SlicingVisitor<StageFunction>())
57 .def(CreateDataPolymorphicPythonVisitor<StageFunction,
58 PyStageFunction<>>());
59
60 bp::register_ptr_to_python<shared_ptr<StageFunctionData>>();
61
62 bp::class_<FunctionDataWrapper, boost::noncopyable>(
63 "StageFunctionData", "Data struct for holding data about functions.",
64 bp::init<int, int, int, int>(
65 bp::args("self", "ndx1", "nu", "ndx2", "nr")))
66 .add_property(
67 "value",
68 bp::make_getter(&StageFunctionData::valref_,
69 bp::return_value_policy<bp::return_by_value>()),
70 "Function value.")
71 .add_property("jac_buffer",
72 make_getter_eigen_matrix(&StageFunctionData::jac_buffer_),
73 "Buffer of the full function Jacobian wrt (x,u,y).")
74 .add_property(
75 "vhp_buffer",
76 make_getter_eigen_matrix(&StageFunctionData::vhp_buffer_),
77 "Buffer of the full function vector-Hessian product wrt (x,u,y).")
78 .add_property(
79 "Jx",
80 bp::make_getter(&StageFunctionData::Jx_,
81 bp::return_value_policy<bp::return_by_value>()),
82 "Jacobian with respect to $x$.")
83 .add_property(
84 "Ju",
85 bp::make_getter(&StageFunctionData::Ju_,
86 bp::return_value_policy<bp::return_by_value>()),
87 "Jacobian with respect to $u$.")
88 .add_property(
89 "Jy",
90 bp::make_getter(&StageFunctionData::Jy_,
91 bp::return_value_policy<bp::return_by_value>()),
92 "Jacobian with respect to $y$.")
93 .add_property(
94 "Hxx",
95 bp::make_getter(&StageFunctionData::Hxx_,
96 bp::return_value_policy<bp::return_by_value>()),
97 "Hessian with respect to $(x, x)$.")
98 .add_property(
99 "Hxu",
100 bp::make_getter(&StageFunctionData::Hxu_,
101 bp::return_value_policy<bp::return_by_value>()),
102 "Hessian with respect to $(x, u)$.")
103 .add_property(
104 "Hxy",
105 bp::make_getter(&StageFunctionData::Hxy_,
106 bp::return_value_policy<bp::return_by_value>()),
107 "Hessian with respect to $(x, y)$.")
108 .add_property(
109 "Huu",
110 bp::make_getter(&StageFunctionData::Huu_,
111 bp::return_value_policy<bp::return_by_value>()),
112 "Hessian with respect to $(u, u)$.")
113 .add_property(
114 "Huy",
115 bp::make_getter(&StageFunctionData::Huy_,
116 bp::return_value_policy<bp::return_by_value>()),
117 "Hessian with respect to $(x, y)$.")
118 .add_property(
119 "Hyy",
120 bp::make_getter(&StageFunctionData::Hyy_,
121 bp::return_value_policy<bp::return_by_value>()),
122 "Hessian with respect to $(y, y)$.")
123 .def(PrintableVisitor<StageFunctionData>())
124 .def(PrintAddressVisitor<StageFunctionData>())
125 .def(ClonePythonVisitor<StageFunctionData>());
126
127 StdVectorPythonVisitor<std::vector<FunctionPtr>, true>::expose(
128 "StdVec_StageFunction");
129 StdVectorPythonVisitor<std::vector<shared_ptr<StageFunctionData>>,
130 true>::expose("StdVec_StageFunctionData");
131}
132
133// fwd-decl exposeUnaryFunctions()
135
136// fwd-decl exposeFunctionExpressions()
138
143
144 bp::class_<StateErrorResidual, bp::bases<context::UnaryFunction>>(
145 "StateErrorResidual", bp::init<const shared_ptr<context::Manifold> &,
146 const int, const context::VectorXs &>(
147 bp::args("self", "space", "nu", "target")))
148 .def_readonly("space", &StateErrorResidual::space_)
149 .def_readwrite("target", &StateErrorResidual::target_);
150
151 bp::class_<ControlErrorResidual, bp::bases<StageFunction>>(
152 "ControlErrorResidual",
153 bp::init<const int, const shared_ptr<context::Manifold> &,
154 const context::VectorXs &>(
155 bp::args("self", "ndx", "uspace", "target")))
156 .def(bp::init<const int, const context::VectorXs &>(
157 bp::args("self", "ndx", "target")))
158 .def(bp::init<int, int>(bp::args("self", "ndx", "nu")))
159 .def_readonly("space", &ControlErrorResidual::space_)
160 .def_readwrite("target", &ControlErrorResidual::target_);
161
162 using LinearFunction = LinearFunctionTpl<Scalar>;
163 bp::class_<LinearFunction, bp::bases<StageFunction>>(
164 "LinearFunction", bp::init<const int, const int, const int, const int>(
165 bp::args("self", "ndx1", "nu", "ndx2", "nr")))
166 .def(bp::init<const ConstMatrixRef, const ConstMatrixRef,
167 const ConstMatrixRef, const ConstVectorRef>(
168 "Constructor with given matrices.",
169 bp::args("self", "A", "B", "C", "d")))
170 .def(bp::init<const ConstMatrixRef, const ConstMatrixRef,
171 const ConstVectorRef>("Constructor with C=0.",
172 bp::args("self", "A", "B", "d")))
173 .def_readonly("A", &LinearFunction::A_)
174 .def_readonly("B", &LinearFunction::B_)
175 .def_readonly("C", &LinearFunction::C_)
176 .def_readonly("d", &LinearFunction::d_);
177
178 bp::class_<ControlBoxFunctionTpl<Scalar>, bp::bases<StageFunction>>(
179 "ControlBoxFunction",
180 bp::init<const int, const VectorXs &, const VectorXs &>(
181 bp::args("self", "ndx", "umin", "umax")))
182 .def(bp::init<const int, const int, const Scalar, const Scalar>(
183 bp::args("self", "ndx", "nu", "umin", "umax")));
184}
185
186} // namespace python
187} // namespace aligator
DynamicsModelTpl< Scalar > DynamicsModel
Definition context.hpp:28
StageFunctionTpl< Scalar > StageFunction
Definition context.hpp:17
StageFunctionDataTpl< Scalar > StageFunctionData
Definition context.hpp:19
ControlErrorResidualTpl< Scalar > ControlErrorResidual
StateErrorResidualTpl< Scalar > StateErrorResidual
shared_ptr< StageFunction > FunctionPtr
bp::object make_getter_eigen_matrix(MatrixType C::*v)
Create a getter for Eigen::Matrix type objects which returns an Eigen::Ref.
void exposeUnaryFunctions()
Expose the UnaryFunction type and its member function overloads.
void exposeFunctions()
Expose stagewise function classes.
Main package namespace.