4#include <Eigen/Cholesky>
72 using mmat = Eigen::Map<mat>;
73 using Eigen::indexing::all;
74 auto [N, nx, nu] =
dim;
82 auto &&Ai = ABi.leftCols(nx);
83 auto &&Bi = ABi.rightCols(nu);
92 auto &&ti =
t.topRows(nJ);
94 auto &&ei =
e.col(i).topRows(nJ);
96 BiJ.noalias() = Bi(all, Ji);
97 PBiJ.noalias() =
P * BiJ;
98 R̅.noalias() = BiJ.transpose() * PBiJ;
101 PA.noalias() =
P * Ai;
102 S̅.noalias() = BiJ.transpose() *
PA;
105 c.noalias() = Bi(all, Ki) * ui(Ki);
109 ti.noalias() = BiJ.transpose() *
y;
111 R_prod(i)(Ji, Ki, ui, ti);
114#ifdef EIGEN_RUNTIME_NO_MALLOC
115 bool prev = Eigen::internal::is_malloc_allowed();
116 Eigen::internal::set_is_malloc_allowed(
true);
118 Eigen::LDLT<rmat> R̅LU{R̅};
120#ifdef EIGEN_RUNTIME_NO_MALLOC
121 Eigen::internal::set_is_malloc_allowed(prev);
124 gain_Ki.noalias() = R̅LU.solve(S̅);
126 ei.noalias() = R̅LU.solve(ti);
128#ifdef EIGEN_RUNTIME_NO_MALLOC
129 bool prev = Eigen::internal::is_malloc_allowed();
130 Eigen::internal::set_is_malloc_allowed(
true);
132 Eigen::PartialPivLU<rmat> R̅LU{R̅};
134#ifdef EIGEN_RUNTIME_NO_MALLOC
135 Eigen::internal::set_is_malloc_allowed(prev);
138 gain_Ki.noalias() = R̅LU.solve(S̅);
140 ei.noalias() = R̅LU.solve(ti);
146 P.noalias() = Ai.transpose() *
PA;
147 P.noalias() += S̅.transpose() * gain_Ki;
149 s.noalias() = S̅.transpose() * ei;
150 s.noalias() += Ai.transpose() *
y;
152 S_prod(i)(Ki, ui,
s);
159 auto [N, nx, nu] =
dim;
160 assert(Δx.size() == 2 * nx);
161 Δx.topRows(nx).setZero();
162 for (
index_t i = 0; i < N; ++i) {
164 auto &&Ai = ABi.leftCols(nx);
165 auto &&Bi = ABi.rightCols(nu);
167 auto &&Δxi = Δx.segment((i % 2) * nx, nx);
168 auto &&Δx_next = Δx.segment(((i + 1) % 2) * nx, nx);
171 auto &&ei =
e.col(i).topRows(nJ);
172 auto &&Δui = Δu_eq.segment(i * nu, nu);
173 ei.noalias() += Ki * Δxi;
174 Δui(Ji).noalias() = ei;
175 Δx_next.noalias() = Ai * Δxi;
176 Δx_next.noalias() += Bi * Δui;
#define USING_ALPAQA_CONFIG(Conf)
typename Conf::real_t real_t
typename Conf::index_t index_t
typename Conf::length_t length_t
const index_t & operator*() const
friend auto operator<=>(const Iter &, const Iter &)=default
Iter operator++(int) const
void factor_masked(auto &&AB, auto &&Q, auto &&R, auto &&S, auto &&R_prod, auto &&S_prod, auto &&q, auto &&r, auto &&u, auto &&J, auto &&K, bool use_cholesky)
void solve_masked(auto &&AB, auto &&J, rvec Δu_eq, rvec Δx)