aligator  0.10.0
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
expose-utils.cpp
Go to the documentation of this file.
3
4#include <eigenpy/std-array.hpp>
5
6namespace aligator::python {
7using namespace gar;
8
10using context::VectorXs;
11using lqr_t = LQRProblemTpl<context::Scalar>;
12
13bp::dict lqr_sol_initialize_wrap(const lqr_t &problem) {
14 bp::dict out;
15 auto ss = lqrInitializeSolution(problem);
16 auto &[xs, us, vs, lbdas] = ss;
17 out["xs"] = xs;
18 out["us"] = us;
19 out["vs"] = vs;
20 out["lbdas"] = lbdas;
21 return out;
22}
23
24bp::tuple lqr_create_sparse_wrap(const lqr_t &problem, const Scalar mudyn,
25 const Scalar mueq, bool update) {
26 Eigen::SparseMatrix<Scalar> mat;
27 VectorXs rhs;
28 lqrCreateSparseMatrix(problem, mudyn, mueq, mat, rhs, update);
29 mat.makeCompressed();
30 return bp::make_tuple(mat, rhs);
31}
32
34
35 bp::def(
36 "lqrDenseMatrix",
37 +[](const lqr_t &problem, Scalar mudyn, Scalar mueq) {
38 auto mat_rhs = lqrDenseMatrix(problem, mudyn, mueq);
39 return bp::make_tuple(std::get<0>(mat_rhs), std::get<1>(mat_rhs));
40 },
41 ("problem"_a, "mudyn", "mueq"));
42
43 bp::def("lqrCreateSparseMatrix", lqr_create_sparse_wrap,
44 ("problem"_a, "mudyn", "mueq", "update"),
45 "Create or update a sparse matrix from an LQRProblem.");
46
47 bp::def("lqrInitializeSolution", lqr_sol_initialize_wrap, ("problem"_a));
48
49 bp::def("lqrComputeKktError", lqrComputeKktError<Scalar>,
50 ("problem"_a, "xs", "us", "vs", "lbdas", "mudyn", "mueq", "theta",
51 "verbose"_a = false),
52 "Compute the KKT residual of the LQR problem.");
53}
54} // namespace aligator::python
auto lqrInitializeSolution(const LQRProblemTpl< Scalar > &problem)
Definition utils.hpp:140
bool lqrDenseMatrix(const LQRProblemTpl< Scalar > &problem, Scalar mudyn, Scalar mueq, typename math_types< Scalar >::MatrixXs &mat, typename math_types< Scalar >::VectorXs &rhs)
Fill in a KKT constraint matrix and vector for the given LQ problem with the given dual-regularizatio...
void lqrCreateSparseMatrix(const LQRProblemTpl< Scalar > &problem, const Scalar mudyn, const Scalar mueq, Eigen::SparseMatrix< Scalar > &mat, Eigen::Matrix< Scalar, -1, 1 > &rhs, bool update)
std::array< Scalar, 3 > lqrComputeKktError(const LQRProblemTpl< Scalar > &problem, boost::span< const typename math_types< Scalar >::VectorXs > xs, boost::span< const typename math_types< Scalar >::VectorXs > us, boost::span< const typename math_types< Scalar >::VectorXs > vs, boost::span< const typename math_types< Scalar >::VectorXs > lbdas, const Scalar mudyn, const Scalar mueq, const std::optional< typename math_types< Scalar >::ConstVectorRef > &theta_, bool verbose=false)
The Python bindings.
Definition blk-matrix.hpp:5
bp::dict lqr_sol_initialize_wrap(const lqr_t &problem)
LQRProblemTpl< context::Scalar > lqr_t
bp::tuple lqr_create_sparse_wrap(const lqr_t &problem, const Scalar mudyn, const Scalar mueq, bool update)