34 bp::register_ptr_to_python<FunctionPtr>();
36 bp::class_<PyStageFunction<>, boost::noncopyable>(
38 "Base class for ternary functions f(x,u,x') on a stage of the problem.",
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>())
58 PyStageFunction<>>());
60 bp::register_ptr_to_python<shared_ptr<StageFunctionData>>();
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")))
68 bp::make_getter(&StageFunctionData::valref_,
69 bp::return_value_policy<bp::return_by_value>()),
71 .add_property(
"jac_buffer",
73 "Buffer of the full function Jacobian wrt (x,u,y).")
77 "Buffer of the full function vector-Hessian product wrt (x,u,y).")
80 bp::make_getter(&StageFunctionData::Jx_,
81 bp::return_value_policy<bp::return_by_value>()),
82 "Jacobian with respect to $x$.")
85 bp::make_getter(&StageFunctionData::Ju_,
86 bp::return_value_policy<bp::return_by_value>()),
87 "Jacobian with respect to $u$.")
90 bp::make_getter(&StageFunctionData::Jy_,
91 bp::return_value_policy<bp::return_by_value>()),
92 "Jacobian with respect to $y$.")
95 bp::make_getter(&StageFunctionData::Hxx_,
96 bp::return_value_policy<bp::return_by_value>()),
97 "Hessian with respect to $(x, x)$.")
100 bp::make_getter(&StageFunctionData::Hxu_,
101 bp::return_value_policy<bp::return_by_value>()),
102 "Hessian with respect to $(x, u)$.")
105 bp::make_getter(&StageFunctionData::Hxy_,
106 bp::return_value_policy<bp::return_by_value>()),
107 "Hessian with respect to $(x, y)$.")
110 bp::make_getter(&StageFunctionData::Huu_,
111 bp::return_value_policy<bp::return_by_value>()),
112 "Hessian with respect to $(u, u)$.")
115 bp::make_getter(&StageFunctionData::Huy_,
116 bp::return_value_policy<bp::return_by_value>()),
117 "Hessian with respect to $(x, y)$.")
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>());
127 StdVectorPythonVisitor<std::vector<FunctionPtr>,
true>::expose(
128 "StdVec_StageFunction");
129 StdVectorPythonVisitor<std::vector<shared_ptr<StageFunctionData>>,
130 true>::expose(
"StdVec_StageFunctionData");
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_);
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_);
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_);
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")));
DynamicsModelTpl< Scalar > DynamicsModel
StageFunctionTpl< Scalar > StageFunction
StageFunctionDataTpl< Scalar > StageFunctionData