30 :
kktMat({nu, nc, nx2, nx2}, {nu, nc, nx2, nx2})
31 ,
fb({nu, nc, nx2, nx2}, {nx})
32 ,
ft({nu, nc, nx2, nx2}, {nth})
33 ,
ff({nu, nc, nx2, nx2})
34 ,
ldl{nu + nc + 2 * nx2} {
60 d.kktMat(0, 0) = knot.
R;
61 d.kktMat(0, 1) = knot.
D.transpose();
62 d.kktMat(1, 0) = knot.
D;
63 d.kktMat(1, 1).diagonal().array() = -mueq;
65 VectorRef kff = d.ff[0] = -knot.
r;
66 VectorRef zff = d.ff[1] = -knot.
d;
67 RowMatrixRef K = d.fb.
blockRow(0) = -knot.
S.transpose();
68 RowMatrixRef Z = d.fb.
blockRow(1) = -knot.
C;
70 d.ldl.compute(d.kktMat.
matrix());
71 d.ldl.solveInPlace(d.ff.
matrix());
72 d.ldl.solveInPlace(d.fb.
matrix());
74 RowMatrixRef Kth = d.ft.
blockRow(0) = -knot.
Gu;
75 RowMatrixRef Zth = d.ft.
blockRow(1) = -knot.
Gv;
76 d.ldl.solveInPlace(d.ft.
matrix());
78 Eigen::Transpose Ct = knot.
C.transpose();
80 v.Pxx.noalias() = knot.
Q + knot.
S * K;
81 v.Pxx.noalias() += Ct * Z;
83 v.Pxt.noalias() = knot.
Gx + K.transpose() * knot.
Gu;
84 v.Pxt.noalias() += Z.transpose() * knot.
Gv;
86 v.Ptt.noalias() = knot.
Gth + knot.
Gu.transpose() * Kth;
87 v.Ptt.noalias() += knot.
Gv.transpose() * Zth;
89 v.px.noalias() = knot.
q + knot.
S * kff;
90 v.px.noalias() += Ct * zff;
92 v.pt.noalias() = knot.
gamma + knot.
Gu.transpose() * kff;
93 v.pt.noalias() += knot.
Gv.transpose() * zff;
97 const value *vn,
Scalar mueq) {
99 d.kktMat(0, 0) = knot.
R;
100 d.kktMat(1, 0) = knot.
D;
101 d.kktMat(0, 1) = knot.
D.transpose();
102 d.kktMat(1, 1).diagonal().setConstant(-mueq);
104 d.kktMat(2, 0) = knot.
B;
105 d.kktMat(0, 2) = knot.
B.transpose();
107 d.kktMat(2, 3).setIdentity() *= -1;
108 d.kktMat(3, 2).setIdentity() *= -1;
110 d.kktMat(3, 3) = vn->Pxx;
113 d.ldl.compute(d.kktMat.
matrix());
117 VectorRef kff = d.ff[0] = -knot.
r;
118 VectorRef zff = d.ff[1] = -knot.
d;
119 VectorRef lff = d.ff[2] = -knot.
f;
120 VectorRef yff = d.ff[3];
125 RowMatrixRef K = d.fb.
blockRow(0) = -knot.
S.transpose();
126 RowMatrixRef Z = d.fb.
blockRow(1) = -knot.
C;
127 RowMatrixRef L = d.fb.
blockRow(2) = -knot.
A;
128 RowMatrixRef Y = d.fb.
blockRow(3).setZero();
131 RowMatrixRef Kth = d.ft.
blockRow(0) = -knot.
Gu;
132 RowMatrixRef Zth = d.ft.
blockRow(1) = -knot.
Gv;
134 RowMatrixRef Yth = d.ft.
blockRow(3);
138 d.ldl.solveInPlace(d.ff.
matrix());
139 d.ldl.solveInPlace(d.fb.
matrix());
140 d.ldl.solveInPlace(d.ft.
matrix());
143 Eigen::Transpose At = knot.
A.transpose();
144 Eigen::Transpose Ct = knot.
C.transpose();
146 v.Pxx.noalias() = knot.
Q + knot.
S * K;
147 v.Pxx.noalias() += Ct * Z;
148 v.Pxx.noalias() += At * L;
151 v.Pxt.noalias() += K.transpose() * knot.
Gu;
152 v.Pxt.noalias() += Z.transpose() * knot.
Gv;
154 v.Pxt.noalias() += Y.transpose() * vn->Pxt;
157 v.Ptt.noalias() += Kth.transpose() * knot.
Gu;
158 v.Ptt.noalias() += Zth.transpose() * knot.
Gv;
160 v.Ptt.noalias() += Yth.transpose() * vn->Pxt;
162 v.px.noalias() = knot.
q + knot.
S * kff;
163 v.px.noalias() += Ct * zff;
164 v.px.noalias() += At * lff;
166 v.pt.noalias() = knot.
gamma + knot.
Gu.transpose() * kff;
167 v.pt.noalias() += knot.
Gv.transpose() * zff;
169 v.pt.noalias() += vn->Pxt.transpose() * yff;
173 const Data &d, boost::span<VectorXs> xs,
174 boost::span<VectorXs> us, boost::span<VectorXs> vs,
175 boost::span<VectorXs> lbdas,
176 const std::optional<ConstVectorRef> &theta_) {
177 ConstVectorRef kff = d.ff[0];
178 ConstVectorRef zff = d.ff[1];
179 ConstVectorRef lff = d.ff[2];
180 ConstVectorRef yff = d.ff[3];
182 ConstRowMatrixRef K = d.fb.
blockRow(0);
183 ConstRowMatrixRef Z = d.fb.
blockRow(1);
184 ConstRowMatrixRef L = d.fb.
blockRow(2);
185 ConstRowMatrixRef Y = d.fb.
blockRow(3);
187 ConstRowMatrixRef Kth = d.ft.
blockRow(0);
188 ConstRowMatrixRef Zth = d.ft.
blockRow(1);
189 ConstRowMatrixRef Lth = d.ft.
blockRow(2);
190 ConstRowMatrixRef Yth = d.ft.
blockRow(3);
193 us[i].noalias() = kff + K * xs[i];
194 vs[i].noalias() = zff + Z * xs[i];
195 if (theta_.has_value()) {
197 us[i].noalias() += Kth * theta_.value();
198 vs[i].noalias() += Zth * theta_.value();
203 lbdas[i + 1].noalias() = lff + L * xs[i];
204 xs[i + 1].noalias() = yff + Y * xs[i];
205 if (theta_.has_value()) {
206 lbdas[i + 1].noalias() += Lth * theta_.value();
207 xs[i + 1].noalias() += Yth * theta_.value();
213#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
214extern template struct DenseKernel<context::Scalar>;
Block matrix class, with a fixed or dynamic-size number of row and column blocks.
BlkMatrix< VectorXs, 4, 1 > BlkVec4
BlkMatrix< MatrixXs, 4, 4 > BlkMat44
BlkMatrix< RowMatrixXs, 4, 1 > BlkRowMat41
Data(uint nx, uint nu, uint nc, uint nx2, uint nth)
BunchKaufman< MatrixXs > ldl
A dense Bunch-Kaufman based kernel.
static bool forwardStep(size_t i, bool isTerminal, const KnotType &knot, const Data &d, boost::span< VectorXs > xs, boost::span< VectorXs > us, boost::span< VectorXs > vs, boost::span< VectorXs > lbdas, const std::optional< ConstVectorRef > &theta_)
LqrKnotTpl< Scalar > KnotType
static void terminalSolve(const KnotType &knot, Data &d, value v, Scalar mueq)
ALIGATOR_DYNAMIC_TYPEDEFS_WITH_ROW_TYPES(Scalar)
static void stageKernelSolve(const KnotType &knot, Data &d, value v, const value *vn, Scalar mueq)
Struct describing a stage of a constrained LQ problem.
ArenaMatrix< MatrixXs > Gv
ArenaMatrix< MatrixXs > A
ArenaMatrix< MatrixXs > D
ArenaMatrix< MatrixXs > Q
ArenaMatrix< VectorXs > q
ArenaMatrix< MatrixXs > Gx
ArenaMatrix< MatrixXs > Gth
ArenaMatrix< MatrixXs > B
ArenaMatrix< MatrixXs > R
ArenaMatrix< MatrixXs > S
ArenaMatrix< VectorXs > d
ArenaMatrix< VectorXs > gamma
ArenaMatrix< MatrixXs > Gu
ArenaMatrix< MatrixXs > C
ArenaMatrix< VectorXs > r
ArenaMatrix< VectorXs > f