33 std::ostream* logger_ptr,
37 bool preconditioning_for_infeasible_problems,
40 const bool box_constraints,
44 auto S = delta_.to_eigen();
45 auto H = qp.H.to_eigen();
46 auto g = qp.g.to_eigen();
47 auto A = qp.A.to_eigen();
48 auto b = qp.b.to_eigen();
49 auto C = qp.C.to_eigen();
50 auto u = qp.u.to_eigen();
51 auto l = qp.l.to_eigen();
53 auto l_box = qp.l_box.to_eigen();
54 auto u_box = qp.u_box.to_eigen();
55 auto i_scaled = qp.I.to_eigen();
58 static constexpr T machine_eps = std::numeric_limits<T>::epsilon();
67 isize n_eq = qp.A.rows;
68 isize n_in = qp.C.rows;
69 isize n_constraints(n_in);
70 if (box_constraints) {
77 while (infty_norm((1 - delta.array()).matrix()) > epsilon) {
79 if (logger_ptr !=
nullptr) {
84 << infty_norm((1 - delta.array()).matrix())
87 if (iter == max_iter) {
96 for (isize k = 0; k < n; ++k) {
97 T aux = sqrt(std::max({ n_eq > 0 ? infty_norm(A.col(k)) : T(0),
98 n_in > 0 ? infty_norm(C.col(k)) : T(0),
99 box_constraints ? i_scaled[k] : T(0) }));
103 delta(k) = T(1) / (aux + machine_eps);
108 for (isize k = 0; k < n; ++k) {
112 sqrt(std::max({ infty_norm(H.col(k).head(k)),
113 infty_norm(H.row(k).tail(n - k)),
114 n_eq > 0 ? infty_norm(A.col(k)) : T(0),
115 n_in > 0 ? infty_norm(C.col(k)) : T(0),
116 box_constraints ? i_scaled[k] : T(0) }));
120 delta(k) = T(1) / (aux + machine_eps);
127 sqrt(std::max({ infty_norm(H.col(k).head(k)),
128 infty_norm(H.col(k).tail(n - k)),
129 n_eq > 0 ? infty_norm(A.col(k)) : T(0),
130 n_in > 0 ? infty_norm(C.col(k)) : T(0),
131 box_constraints ? i_scaled[k] : T(0) }));
135 delta(k) = T(1) / (aux + machine_eps);
142 sqrt(std::max({ infty_norm(H.col(k)),
143 n_eq > 0 ? infty_norm(A.col(k)) : T(0),
144 n_in > 0 ? infty_norm(C.col(k)) : T(0),
145 box_constraints ? i_scaled[k] : T(0) }));
149 delta(k) = T(1) / (aux + machine_eps);
157 for (isize k = 0; k < n; ++k) {
158 T aux = sqrt(std::max({ std::abs(H(k, k)),
159 n_eq > 0 ? infty_norm(A.col(k)) : T(0),
160 n_in > 0 ? infty_norm(C.col(k)) : T(0),
161 box_constraints ? i_scaled[k] : T(0) }));
165 delta(k) = T(1) / (aux + machine_eps);
170 if (preconditioning_for_infeasible_problems) {
171 delta.tail(n_eq + n_constraints).setOnes();
173 for (isize k = 0; k < n_eq; ++k) {
174 T aux = sqrt(infty_norm(A.row(k)));
178 delta(n + k) = T(1) / (aux + machine_eps);
181 for (isize k = 0; k < n_in; ++k) {
182 T aux = sqrt(infty_norm(C.row(k)));
184 delta(k + n + n_eq) = T(1);
186 delta(k + n + n_eq) = T(1) / (aux + machine_eps);
189 if (box_constraints) {
190 for (isize k = 0; k < n; ++k) {
191 delta(k + n + n_eq + n_in) = T(1) / sqrt(i_scaled[k] + machine_eps);
205 A = delta.segment(n, n_eq).asDiagonal() * A * delta.head(n).asDiagonal();
206 C = delta.segment(n + n_eq, n_in).asDiagonal() * C *
207 delta.head(n).asDiagonal();
208 if (box_constraints) {
209 i_scaled.array() *= delta.head(n).array();
210 i_scaled.array() *= delta.tail(n).array();
211 u_box.array() *= delta.tail(n).array();
212 l_box.array() *= delta.tail(n).array();
215 g.array() *= delta.head(n).array();
216 b.array() *= delta.segment(n, n_eq).array();
217 u.array() *= delta.segment(n + n_eq, n_in).array();
218 l.array() *= delta.segment(n + n_eq, n_in).array();
228 for (isize j = 0; j < n; ++j) {
229 H.col(j).head(j + 1) *= delta(j);
232 for (isize i = 0; i < n; ++i) {
233 H.row(i).tail(n - i) *= delta(i);
239 for (isize j = 0; j < n; ++j) {
240 H.col(j).tail(n - j) *= delta(j);
243 for (isize i = 0; i < n; ++i) {
244 H.row(i).head(i + 1) *= delta(i);
250 H = delta.head(n).asDiagonal() * H * delta.head(n).asDiagonal();
261 for (isize j = 0; j < n; ++j) {
262 tmp += proxqp::dense::infty_norm(H.row(j).tail(n - j));
264 gamma = 1 / std::max(tmp / T(n), T(1));
270 for (isize j = 0; j < n; ++j) {
271 tmp += proxqp::dense::infty_norm(H.col(j).tail(n - j));
273 gamma = 1 / std::max(tmp / T(n), T(1));
281 (H.colwise().template lpNorm<Eigen::Infinity>()).mean());
291 H.diagonal().array() *=
294 H.diagonal().array() *=
300 (H.diagonal().template lpNorm<Eigen::Infinity>()) / T(n));
306 S.array() *= delta.array();