proxsuite-nlp  0.10.0
A primal-dual augmented Lagrangian-type solver for nonlinear programming on manifolds.
Loading...
Searching...
No Matches
workspace.hpp
Go to the documentation of this file.
1
3#pragma once
4
7
8#include <fmt/ostream.h>
9
10namespace proxsuite {
11namespace nlp {
12
13template <typename Scalar>
15 LDLTChoice choice) {
16 std::vector<isize> nduals(prob.getNumConstraints());
17 for (std::size_t i = 0; i < nduals.size(); ++i)
18 nduals[i] = prob.getConstraintDim(i);
19 return allocate_ldlt_from_sizes<Scalar>({prob.ndx()}, nduals, choice);
20}
21
25template <typename Scalar> struct WorkspaceTpl {
26public:
27 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
28
31
33
34 long nx;
35 long ndx;
36 std::size_t numblocks; // number of constraint blocks
37 long numdual; // total constraint dim
38
40 MatrixXs kkt_matrix;
42 VectorXs kkt_rhs;
44 VectorXs kkt_rhs_corr;
46 VectorXs kkt_err;
48 VectorXs pd_step;
49 VectorRef prim_step;
50 VectorRef dual_step;
52 Eigen::VectorXi signature;
53
56
58
59 VectorXs x_prev;
60 VectorXs x_trial;
63 VectorOfRef lams_prev;
64 VectorOfRef lams_trial;
65
66 VectorXs prox_grad;
67 MatrixXs prox_hess;
68
70
72 VectorXs dual_residual;
73
76 std::vector<VectorRef> cstr_values;
77
88
90 MatrixXs data_hessians;
92 std::vector<MatrixRef> cstr_jacobians;
93 std::vector<MatrixRef> cstr_vector_hessian_prod;
94 std::vector<MatrixRef> cstr_jacobians_proj;
95
102
104 std::vector<VectorRef> lams_plus;
106 std::vector<VectorRef> lams_plus_reproj;
108 std::vector<VectorRef> shift_cstr_values;
110 std::vector<VectorRef> lams_pdal;
111 std::vector<VectorRef> lams_pdal_reproj;
112 std::vector<VectorRef> shift_cstr_pdal;
113
114 std::vector<Scalar> ls_alphas;
115 std::vector<Scalar> ls_values;
117 Scalar alpha_opt;
119 Scalar dmerit_dir = 0.;
120
122
142
143 void init(const Problem &prob) {
144 kkt_matrix.setZero();
145 kkt_rhs.setZero();
146 kkt_rhs_corr.setZero();
147 pd_step.setZero();
148 signature.setZero();
149
150 x_prev.setZero();
151 x_trial.setZero();
154 prox_grad.setZero();
155 prox_hess.setZero();
156
157 dual_residual.setZero();
159 prob, data_cstr_values, cstr_values); // not multipliers but same dims
160
161 objective_gradient.setZero();
162 objective_hessian.setZero();
163 merit_gradient.setZero();
164 merit_dual_gradient.setZero();
165 data_jacobians.setZero();
166 data_hessians.setZero();
167
178 tmp_dx_scaled.setZero();
179
180 cstr_jacobians.reserve(numblocks);
182
184
185 int cursor = 0;
186 int nr = 0;
187 for (std::size_t i = 0; i < numblocks; i++) {
188 cursor = prob.getIndex(i);
189 nr = prob.getConstraintDim(i);
190 cstr_jacobians.emplace_back(data_jacobians.middleRows(cursor, nr));
191 cstr_jacobians_proj.emplace_back(
192 data_jacobians_proj.middleRows(cursor, nr));
193 cstr_vector_hessian_prod.emplace_back(
194 data_hessians.middleRows((int)i * ndx, ndx));
195 }
196 }
197};
198
199} // namespace nlp
200} // namespace proxsuite
201
202template <typename Scalar>
203struct fmt::formatter<proxsuite::nlp::WorkspaceTpl<Scalar>>
204 : fmt::ostream_formatter {};
205
206#ifdef PROXSUITE_NLP_ENABLE_TEMPLATE_INSTANTIATION
207#include "proxsuite-nlp/workspace.txx"
208#endif
Utility function to allocate an LDLT solver for the Newton iterations.
#define PROXSUITE_NLP_DYNAMIC_TYPEDEFS(Scalar)
Definition math.hpp:26
void allocateMultipliersOrResiduals(const ProblemTpl< Scalar > &prob, typename math_types< Scalar >::VectorXs &data, typename math_types< Scalar >::VectorOfRef &out)
Allocate a set of multipliers (or residuals) for a given problem instance.
LDLTVariant< Scalar > allocate_ldlt_from_sizes(const std::vector< isize > &nprims, const std::vector< isize > &nduals, LDLTChoice choice)
boost::variant< linalg::DenseLDLT< Scalar >, linalg::BlockLDLT< Scalar >, Eigen::LDLT< MatrixType >, Eigen::BunchKaufman< MatrixType > > LDLTVariant
auto allocate_ldlt_from_problem(const ProblemTpl< Scalar > &prob, LDLTChoice choice)
Definition workspace.hpp:14
@ DENSE
Use our dense LDLT.
Main package namespace.
Definition bcl-params.hpp:5
std::size_t getNumConstraints() const
Get the number of constraint blocks.
int getConstraintDim(std::size_t i) const
Get dimension of constraint i.
int getIndex(std::size_t i) const
std::vector< VectorRef > shift_cstr_pdal
void init(const Problem &prob)
Scalar objective_value
Objective value.
Definition workspace.hpp:79
VectorXs dual_residual
Residuals.
Definition workspace.hpp:72
WorkspaceTpl(const Problem &prob, LDLTChoice ldlt_choice=LDLTChoice::DENSE)
VectorXs merit_dual_gradient
Merit function gradient in the dual variables (if applicable)
Definition workspace.hpp:87
std::vector< Scalar > ls_values
std::vector< VectorRef > lams_plus
First-order multipliers .
VectorXs pd_step
Primal-dual step .
Definition workspace.hpp:48
std::vector< VectorRef > cstr_values
Values of each constraint.
Definition workspace.hpp:76
MatrixXs kkt_matrix
KKT iteration matrix.
Definition workspace.hpp:40
VectorXs merit_gradient
Merit function gradient.
Definition workspace.hpp:85
std::vector< VectorRef > lams_pdal_reproj
std::vector< Scalar > ls_alphas
Scalar dmerit_dir
Merit function derivative in descent direction.
VectorXs kkt_rhs
KKT iteration right-hand side.
Definition workspace.hpp:42
VectorXs kkt_rhs_corr
Correction for the kkt matrix.
Definition workspace.hpp:44
std::vector< VectorRef > lams_plus_reproj
Product of the projector Jacobians with the first-order multipliers.
VectorXs objective_gradient
Objective function gradient.
Definition workspace.hpp:81
Scalar alpha_opt
Optimal linesearch .
Eigen::VectorXi signature
Signature of the KKT matrix.
Definition workspace.hpp:52
std::vector< VectorRef > lams_pdal
Primal-dual multiplier estimates (from the pdBCL algorithm)
long nx
Newton iteration variables.
Definition workspace.hpp:34
MatrixXs objective_hessian
Objective function Hessian.
Definition workspace.hpp:83
std::vector< MatrixRef > cstr_jacobians_proj
Definition workspace.hpp:94
std::vector< MatrixRef > cstr_jacobians
Definition workspace.hpp:92
VectorXs kkt_err
KKT linear system error (for refinement)
Definition workspace.hpp:46
std::vector< VectorRef > shift_cstr_values
Buffer for shifted constraints.
std::vector< MatrixRef > cstr_vector_hessian_prod
Definition workspace.hpp:93
LDLTVariant< Scalar > ldlt_
LDLT storage.
Definition workspace.hpp:55