proxsuite 0.6.7
The Advanced Proximal Optimization Toolbox
Loading...
Searching...
No Matches
workspace.hpp
Go to the documentation of this file.
1//
2// Copyright (c) 2022 INRIA
3//
7#ifndef PROXSUITE_PROXQP_DENSE_WORKSPACE_HPP
8#define PROXSUITE_PROXQP_DENSE_WORKSPACE_HPP
9
10#include <Eigen/Core>
15namespace proxsuite {
16namespace proxqp {
17namespace dense {
21
24template<typename T>
26{
27
32
41
45
47
51
54
58
62
64
68
71
76
78
83
86
90
92 bool dirty;
96
97 sparse::isize n_c; // final number of active inequalities
104 Workspace(isize dim = 0,
105 isize n_eq = 0,
106 isize n_in = 0,
107 bool box_constraints = false,
109 : ldl{}
110 , H_scaled(dim, dim)
111 , g_scaled(dim)
112 , A_scaled(n_eq, dim)
113 , C_scaled(n_in, dim)
114 , b_scaled(n_eq)
115 , u_scaled(n_in)
116 , l_scaled(n_in)
117 , x_prev(dim)
118 , y_prev(n_eq)
119 , Hdx(dim)
120 , Adx(n_eq)
122 , CTz(dim)
123 , constraints_changed(false)
124 , dirty(false)
125 , refactorize(false)
127 , is_initialized(false)
128 {
129
130 if (box_constraints) {
131 u_box_scaled.resize(dim);
132 u_box_scaled.setZero();
133 l_box_scaled.resize(dim);
134 l_box_scaled.setZero();
135 i_scaled.resize(dim);
136 i_scaled.setOnes();
137
138 z_prev.resize(dim + n_in);
139 // TODO appropriate heuristic for automatic choice
140 switch (dense_backend) {
142 kkt.resize(dim + n_eq, dim + n_eq);
143 ldl.reserve_uninit(dim + n_eq + n_in + dim);
144 ldl_stack.resize_for_overwrite(
146 // optimize here
148 n_in + dim) |
149
151 proxsuite::linalg::veg::Tag<T>{}, n_eq + n_in + dim) &
153 isize{ sizeof(isize) } * (n_eq + n_in + dim),
154 alignof(isize) } &
156 dim + n_eq + n_in + dim, n_eq + n_in + dim)) |
157
160 dim + n_eq + n_in + dim,
161 n_in + dim) &
163 dim + n_eq + n_in + dim, n_in + dim)) |
164
166 n_in + dim))
167 // TODO optimize here
168 .alloc_req());
169 break;
171 kkt.resize(dim, dim);
172 ldl.reserve_uninit(dim);
173 ldl_stack.resize_for_overwrite(
175
177 // check simplification possible
179 proxsuite::linalg::veg::Tag<T>{}, n_eq + n_in + dim) &
181 isize{ sizeof(isize) } * (n_eq + n_in + dim),
182 alignof(isize) } &
184 dim + n_eq + n_in + dim, n_eq + n_in + dim)) |
185
188 dim + n_eq + n_in + dim,
189 n_in + dim) &
191 dim + n_eq + n_in + dim, n_in + dim)) |
192 // end check
194
195 .alloc_req());
196 break;
198 break;
199 }
200 current_bijection_map.resize(n_in + dim);
201 new_bijection_map.resize(n_in + dim);
202 for (isize i = 0; i < n_in + dim; i++) {
204 new_bijection_map(i) = i;
205 }
206 active_set_up.resize(n_in + dim);
207 active_set_low.resize(n_in + dim);
208 active_inequalities.resize(n_in + dim);
209 active_part_z.resize(n_in + dim);
210 dw_aug.resize(dim + n_eq + n_in + dim);
211 rhs.resize(dim + n_eq + n_in + dim);
212 err.resize(dim + n_eq + n_in + dim);
213 primal_residual_in_scaled_up.resize(dim + n_in);
216 Cdx.resize(n_in + dim);
217 alphas.reserve(2 * n_in + 2 * dim);
218 } else {
219 z_prev.resize(n_in);
220
221 switch (dense_backend) {
223 kkt.resize(dim + n_eq, dim + n_eq);
224 ldl.reserve_uninit(dim + n_eq + n_in);
225 ldl_stack.resize_for_overwrite(
227 // todo optimize here
229 n_in) |
230
232 proxsuite::linalg::veg::Tag<T>{}, n_eq + n_in) &
234 isize{ sizeof(isize) } * (n_eq + n_in), alignof(isize) } &
236 dim + n_eq + n_in, n_eq + n_in)) |
237
239 proxsuite::linalg::veg::Tag<T>{}, dim + n_eq + n_in, n_in) &
241 dim + n_eq + n_in, n_in)) |
242
244 n_in))
245 // end todo optimize here
246 .alloc_req());
247 break;
249 kkt.resize(dim, dim);
250 ldl.reserve_uninit(dim);
251 ldl_stack.resize_for_overwrite(
253
255 // check if it can be more simplified
257 proxsuite::linalg::veg::Tag<T>{}, n_eq + n_in) &
259 isize{ sizeof(isize) } * (n_eq + n_in), alignof(isize) } &
261 dim + n_eq + n_in, n_eq + n_in)) |
263 proxsuite::linalg::veg::Tag<T>{}, dim + n_eq + n_in, n_in) &
265 dim + n_eq + n_in, n_in)) |
266 // end check
268
269 .alloc_req());
270 break;
272 break;
273 }
274
275 current_bijection_map.resize(n_in);
276 new_bijection_map.resize(n_in);
277 for (isize i = 0; i < n_in; i++) {
279 new_bijection_map(i) = i;
280 }
281 active_set_up.resize(n_in);
282 active_set_low.resize(n_in);
283 active_inequalities.resize(n_in);
284 active_part_z.resize(n_in);
285 dw_aug.resize(dim + n_eq + n_in);
286 rhs.resize(dim + n_eq + n_in);
287 err.resize(dim + n_eq + n_in);
288 primal_residual_in_scaled_up.resize(n_in);
291 Cdx.resize(n_in);
292 alphas.reserve(2 * n_in);
293 }
294
295 H_scaled.setZero();
296 g_scaled.setZero();
297 A_scaled.setZero();
298 C_scaled.setZero();
299 b_scaled.setZero();
300 u_scaled.setZero();
301 l_scaled.setZero();
302 x_prev.setZero();
303 y_prev.setZero();
304 z_prev.setZero();
305 kkt.setZero();
306 Hdx.setZero();
307 Cdx.setZero();
308 Adx.setZero();
309 active_part_z.setZero();
310 dw_aug.setZero();
311 rhs.setZero();
312 err.setZero();
313
317 alpha = 1.;
318
319 dual_residual_scaled.setZero();
321
324 CTz.setZero();
325 n_c = 0;
326 }
330 void cleanup(const bool box_constraints)
331 {
332 isize n_in = C_scaled.rows();
333 isize dim = H_scaled.rows();
334 H_scaled.setZero();
335 g_scaled.setZero();
336 A_scaled.setZero();
337 C_scaled.setZero();
338 b_scaled.setZero();
339 u_scaled.setZero();
340 l_scaled.setZero();
341 Hdx.setZero();
342 Cdx.setZero();
343 Adx.setZero();
344 active_part_z.setZero();
345 dw_aug.setZero();
346 rhs.setZero();
347 err.setZero();
348
349 alpha = 1.;
350
351 dual_residual_scaled.setZero();
353
356 CTz.setZero();
357
358 x_prev.setZero();
359 y_prev.setZero();
360 z_prev.setZero();
361 isize n_constraints(n_in);
362 if (box_constraints) {
363 n_constraints += dim;
364 }
365 for (isize i = 0; i < n_constraints; i++) {
367 new_bijection_map(i) = i;
368 active_inequalities(i) = false;
369 }
370
371 constraints_changed = false;
372 dirty = false;
373 refactorize = false;
375 is_initialized = false;
376 n_c = 0;
377 }
378};
379} // namespace dense
380} // namespace proxqp
381} // namespace proxsuite
382
383#endif /* end of include guard PROXSUITE_PROXQP_DENSE_WORKSPACE_HPP */
auto temp_vec_req(proxsuite::linalg::veg::Tag< T >, isize rows) noexcept -> proxsuite::linalg::veg::dynstack::StackReq
Definition core.hpp:862
auto temp_mat_req(proxsuite::linalg::veg::Tag< T >, isize rows, isize cols) noexcept -> proxsuite::linalg::veg::dynstack::StackReq
Definition core.hpp:850
Eigen::Matrix< isize, DYN, 1 > VecISize
Definition fwd.hpp:48
Eigen::Matrix< bool, DYN, 1 > VecBool
Definition fwd.hpp:51
Eigen::Matrix< T, DYN, 1 > Vec
Definition fwd.hpp:24
Eigen::Matrix< T, DYN, DYN, l > Mat
Definition fwd.hpp:31
static auto diagonal_update_req(isize n, isize r) noexcept -> proxsuite::linalg::veg::dynstack::StackReq
Definition ldlt.hpp:484
This class mimics the way "boost/timer/timer.hpp" operates while using the modern std::chrono library...
Definition timings.hpp:36
This class defines the workspace of the dense solver.
Definition workspace.hpp:26
proxsuite::linalg::veg::Vec< unsigned char > ldl_stack
Definition workspace.hpp:30
void cleanup(const bool box_constraints)
Workspace(isize dim=0, isize n_eq=0, isize n_in=0, bool box_constraints=false, DenseBackend dense_backend=DenseBackend::PrimalDualLDLT)
proxsuite::linalg::veg::Vec< T > alphas
Definition workspace.hpp:70
proxsuite::linalg::dense::Ldlt< T > ldl
Definition workspace.hpp:29