proxsuite 0.6.7
The Advanced Proximal Optimization Toolbox
Loading...
Searching...
No Matches
model.hpp
Go to the documentation of this file.
1//
2// Copyright (c) 2022 INRIA
3//
5#ifndef PROXSUITE_PROXQP_DENSE_MODEL_HPP
6#define PROXSUITE_PROXQP_DENSE_MODEL_HPP
7
8#include <Eigen/Core>
13namespace proxsuite {
14namespace proxqp {
15namespace dense {
19
22template<typename T>
23struct Model
24{
25
36
38 isize dim;
39 isize n_eq;
40 isize n_in;
41 isize n_total;
42
45
52 Model(isize dim, isize n_eq, isize n_in, bool box_constraints = false)
53 : H(dim, dim)
54 , g(dim)
55 , A(n_eq, dim)
56 , C(n_in, dim)
57 , b(n_eq)
58 , u(n_in)
59 , l(n_in)
60 , dim(dim)
61 , n_eq(n_eq)
62 , n_in(n_in)
63 , n_total(dim + n_eq + n_in)
64 {
66 std::invalid_argument,
67 "wrong argument size: the dimension wrt the primal "
68 "variable x should be strictly positive.");
69
70 const T infinite_bound_value = helpers::infinite_bound<T>::value();
71
72 H.setZero();
73 g.setZero();
74 A.setZero();
75 C.setZero();
76 b.setZero();
77 u.fill(+infinite_bound_value); // in case it appears u is nullopt (i.e., the
78 // problem is only lower bounded)
79 l.fill(-infinite_bound_value); // in case it appears l is nullopt (i.e., the
80 // problem is only upper bounded)
81
82 if (box_constraints) {
83 u_box.resize(dim);
84 l_box.resize(dim);
85 u_box.fill(
86 +infinite_bound_value); // in case it appears u is nullopt (i.e., the
87 // problem is only lower bounded)
88 l_box.fill(
89 -infinite_bound_value); // in case it appears l is nullopt (i.e., the
90 // problem is only upper bounded)
91 }
92 }
93
95 {
96 SparseMat<T> H_sparse = H.sparseView();
97 SparseMat<T> A_sparse = A.sparseView();
98 SparseMat<T> C_sparse = C.sparseView();
99 proxsuite::proxqp::sparse::SparseModel<T> res{ H_sparse, g, A_sparse, b,
100 C_sparse, u, l };
101 return res;
102 }
103
104 bool is_valid(const bool box_constraints)
105 {
106 // check that all matrices and vectors of qpmodel have the correct size
107 // and that H and C have expected properties
108 PROXSUITE_CHECK_ARGUMENT_SIZE(g.size(), dim, "g has not the expected size.")
110 b.size(), n_eq, "b has not the expected size.")
112 l.size(), n_in, "l has not the expected size.")
114 u.size(), n_in, "u has not the expected size.")
115 if (box_constraints) {
117 u_box.size(), dim, "u_box has not the expected size");
119 l_box.size(), dim, "l_box has not the expected size");
120 }
121 if (H.size()) {
123 H.rows(), dim, "H has not the expected number of rows.");
125 H.cols(), dim, "H has not the expected number of cols.");
127 (!H.isApprox(
128 H.transpose(),
129 std::numeric_limits<typename decltype(H)::Scalar>::epsilon())),
130 std::invalid_argument,
131 "H is not symmetric.");
132 }
133 if (A.size()) {
135 A.rows(), n_eq, "A has not the expected number of rows.");
137 A.cols(), dim, "A has not the expected number of cols.");
138 }
139 if (C.size()) {
141 C.rows(), n_in, "C has not the expected number of rows.");
143 C.cols(), dim, "C has not the expected number of cols.");
145 C.isZero(), std::invalid_argument, "C is zero, while n_in != 0.");
146 }
147 return true;
148 }
149};
150
151template<typename T>
152bool
153operator==(const Model<T>& model1, const Model<T>& model2)
154{
155 bool value = model1.dim == model2.dim && model1.n_eq == model2.n_eq &&
156 model1.n_in == model2.n_in && model1.n_total == model2.n_total &&
157 model1.H == model2.H && model1.g == model2.g &&
158 model1.A == model2.A && model1.b == model2.b &&
159 model1.C == model2.C && model1.l == model2.l &&
160 model1.u == model2.u && model1.l_box == model2.l_box &&
161 model1.u_box == model2.u_box;
162 return value;
163}
164
165template<typename T>
166bool
167operator!=(const Model<T>& model1, const Model<T>& model2)
168{
169 return !(model1 == model2);
170}
171
172} // namespace dense
173} // namespace proxqp
174} // namespace proxsuite
175
176#endif /* end of include guard PROXSUITE_PROXQP_DENSE_MODEL_HPP */
#define PROXSUITE_CHECK_ARGUMENT_SIZE(size, expected_size, message)
Definition macros.hpp:28
#define PROXSUITE_THROW_PRETTY(condition, exception, message)
Definition macros.hpp:18
Eigen::SparseMatrix< T, 1 > SparseMat
Definition fwd.hpp:21
bool operator==(const Model< T > &model1, const Model< T > &model2)
Definition model.hpp:153
Eigen::Matrix< T, DYN, 1 > Vec
Definition fwd.hpp:24
Eigen::Matrix< T, DYN, DYN, l > Mat
Definition fwd.hpp:31
bool operator!=(const Model< T > &model1, const Model< T > &model2)
Definition model.hpp:167
This class stores the jacobians of PROXQP solvers with dense backends at a solutions wrt model parame...
This class stores the model of the QP problem.
Definition model.hpp:24
BackwardData< T > backward_data
Definition model.hpp:44
proxsuite::proxqp::sparse::SparseModel< T > to_sparse()
Definition model.hpp:94
Model(isize dim, isize n_eq, isize n_in, bool box_constraints=false)
Definition model.hpp:52
bool is_valid(const bool box_constraints)
Definition model.hpp:104