5#ifndef PROXSUITE_PROXQP_SPARSE_HELPERS_HPP
6#define PROXSUITE_PROXQP_SPARSE_HELPERS_HPP
18template<
typename T,
typename I>
24 T power_iteration_accuracy,
25 isize nb_power_iteration)
31 rhs.array() += 1. / std::sqrt(dim);
38 for (isize i = 0; i < nb_power_iteration; i++) {
48 err_v = dw - eig * rhs;
49 T err = proxsuite::proxqp::dense::infty_norm(err_v);
52 if (err <= power_iteration_accuracy) {
58template<
typename T,
typename I>
65 T power_iteration_accuracy,
66 isize nb_power_iteration)
74 rhs.array() += 1. / std::sqrt(dim);
80 dw.noalias() = H * rhs;
82 dw += max_eigen_value * rhs;
84 for (isize i = 0; i < nb_power_iteration; i++) {
91 dw.noalias() = H * rhs;
93 dw += max_eigen_value * rhs;
97 err_v = dw - eig * rhs;
98 T err = proxsuite::proxqp::dense::infty_norm(err_v);
101 if (err <= power_iteration_accuracy) {
105 T minimal_eigenvalue = max_eigen_value - eig;
106 return minimal_eigenvalue;
116template<
typename T,
typename I>
119 T power_iteration_accuracy,
120 isize nb_power_iteration)
123 (!H.isApprox(H.transpose(), std::numeric_limits<T>::epsilon())),
124 std::invalid_argument,
125 "H is not symmetric.");
129 "H has a number of rows different of the number of columns.");
130 isize dim = H.rows();
135 T dominant_eigen_value = power_iteration<T, I>(
136 H, dw, rhs, err, power_iteration_accuracy, nb_power_iteration);
138 min_eigen_value_via_modified_power_iteration<T, I>(H,
142 dominant_eigen_value,
143 power_iteration_accuracy,
147 res = std::min(min_eigenvalue, dominant_eigen_value);
164 if (manual_minimal_H_eigenvalue !=
nullopt) {
166 manual_minimal_H_eigenvalue.
value();
167 results.
info.minimal_H_eigenvalue_estimate =
170 settings.
default_rho += std::abs(results.
info.minimal_H_eigenvalue_estimate);
181template<
typename T,
typename I>
198 results.
info.mu_eq_inv = T(1) / results.
info.mu_eq;
204 results.
info.mu_in_inv = T(1) / results.
info.mu_in;
217template<
typename T,
typename I>
236 "the dimension wrt primal variable x for warm start is not valid.");
242 "the dimension wrt equality constrained "
243 "variables for warm start is not valid.");
250 "the dimension wrt inequality constrained variables for warm start "
255 results.
x = x_wm.value().eval();
259 results.
y = y_wm.value().eval();
263 results.
z = z_wm.value().eval();
280template<
typename T,
typename I,
typename P>
294 if (results.
x.rows() != n) {
298 if (results.
y.rows() != n_eq) {
299 results.
y.resize(n_eq);
302 if (results.
z.rows() != n_in) {
303 results.
z.resize(n_in);
308 for (isize i = 0; i < n_in; ++i) {
314 for (isize i = 0; i < n_in; ++i) {
320 for (isize i = 0; i < n_in; ++i) {
324 bool execute_preconditioner_or_not =
false;
325 switch (preconditioner_status) {
327 execute_preconditioner_or_not =
true;
330 execute_preconditioner_or_not =
false;
334 execute_preconditioner_or_not =
false;
342 execute_preconditioner_or_not,
412template<
typename T,
typename I>
417 if (a.nrows() != b.nrows())
419 if (a.ncols() != b.ncols())
421 for (usize j = 0; j < static_cast<usize>(a.ncols()); ++j) {
422 usize n_elems(a.col_end(j) - a.col_start(j));
423 usize n_elems_to_compare(b.col_end(j) - b.col_start(j));
424 if (n_elems != n_elems_to_compare)
426 for (usize p = 0; p < n_elems; ++p) {
427 isize i_a = a.row_indices()[a.col_start(j) + p];
428 isize i_b = b.row_indices()[b.col_start(j) + p];
441template<
typename T,
typename I>
448 for (usize j = 0; j < static_cast<usize>(a.ncols()); ++j) {
449 auto a_start = a.values_mut() + a.col_start(j);
450 auto b_start = b.values() + b.col_start(j);
452 usize n_elems =
static_cast<usize
>(a.col_end(j) - a.col_start(j));
454 for (usize p = 0; p < n_elems; ++p) {
455 a_start[p] = b_start[p];
TL_OPTIONAL_11_CONSTEXPR T & value() &
#define PROXSUITE_CHECK_ARGUMENT_SIZE(size, expected_size, message)
#define PROXSUITE_THROW_PRETTY(condition, exception, message)
void warm_start(optional< VecRef< T > > x_wm, optional< VecRef< T > > y_wm, optional< VecRef< T > > z_wm, Results< T > &results, Settings< T > &settings, Model< T, I > &model)
T estimate_minimal_eigen_value_of_symmetric_matrix(SparseMat< T, I > &H, T power_iteration_accuracy, isize nb_power_iteration)
void update_proximal_parameters(Settings< T > &settings, Results< T > &results, Workspace< T, I > &work, optional< T > rho_new, optional< T > mu_eq_new, optional< T > mu_in_new)
Eigen::SparseMatrix< T, Eigen::ColMajor, I > SparseMat
void copy(proxsuite::linalg::sparse::MatMut< T, I > a, proxsuite::linalg::sparse::MatRef< T, I > b)
Eigen::Ref< Eigen::Matrix< T, DYN, 1 > const > VecRef
auto have_same_structure(proxsuite::linalg::sparse::MatRef< T, I > a, proxsuite::linalg::sparse::MatRef< T, I > b) -> bool
T min_eigen_value_via_modified_power_iteration(SparseMat< T, I > &H, sparse::Vec< T > &dw, sparse::Vec< T > &rhs, sparse::Vec< T > &err_v, T max_eigen_value, T power_iteration_accuracy, isize nb_power_iteration)
Eigen::Matrix< T, DYN, 1 > Vec
T power_iteration(SparseMat< T, I > &H, sparse::Vec< T > &dw, sparse::Vec< T > &rhs, sparse::Vec< T > &err_v, T power_iteration_accuracy, isize nb_power_iteration)
void qp_setup(QpView< T, I > qp, Results< T > &results, Model< T, I > &data, Workspace< T, I > &work, Settings< T > &settings, P &precond, PreconditionerStatus &preconditioner_status)
void update_default_rho_with_minimal_Hessian_eigen_value(optional< T > manual_minimal_H_eigenvalue, Results< T > &results, Settings< T > &settings)
@ COLD_START_WITH_PREVIOUS_RESULT
@ EQUALITY_CONSTRAINED_INITIAL_GUESS
@ WARM_START_WITH_PREVIOUS_RESULT
constexpr nullopt_t nullopt
VEG_NODISCARD VEG_INLINE auto len() const VEG_NOEXCEPT -> isize
This class stores all the results of PROXQP solvers with sparse and dense backends.
void cold_start(optional< Settings< T > > settings=nullopt)
void cleanup(optional< Settings< T > > settings=nullopt)
void cleanup_statistics()
void cleanup_all_except_prox_parameters()
This class defines the settings of PROXQP solvers with sparse and dense backends.
SparseBackend sparse_backend
T default_H_eigenvalue_estimate
InitialGuessStatus initial_guess
This class stores the model of the QP problem.
proxsuite::linalg::sparse::MatRef< T, I > AT
proxsuite::linalg::sparse::MatRef< T, I > CT
proxsuite::linalg::sparse::MatRef< T, I > H
This class defines the workspace of the sparse solver.
bool proximal_parameter_update
proxsuite::linalg::veg::Vec< bool > active_inequalities
void setup_impl(const QpView< T, I > qp, Model< T, I > &data, const Settings< T > &settings, bool execute_or_not, P &precond, proxsuite::linalg::veg::dynstack::StackReq precond_req)
struct proxsuite::proxqp::sparse::Workspace::@16 internal