proxsuite
0.7.3
The Advanced Proximal Optimization Toolbox
Toggle main menu visibility
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>
9
#include "
proxsuite/linalg/veg/type_traits/core.hpp
"
10
#include "
proxsuite/proxqp/dense/fwd.hpp
"
11
#include "
proxsuite/proxqp/sparse/model.hpp
"
12
#include "
proxsuite/proxqp/dense/backward_data.hpp
"
13
namespace
proxsuite
{
14
namespace
proxqp
{
15
namespace
dense
{
19
22
template
<
typename
T>
23
struct
Model
24
{
25
27
Mat<T>
H
;
28
Vec<T>
g
;
29
Mat<T>
A
;
30
Mat<T>
C
;
31
Vec<T>
b
;
32
Vec<T>
u
;
33
Vec<T>
l
;
34
Vec<T>
u_box
;
35
Vec<T>
l_box
;
36
38
isize
dim
;
39
isize
n_eq
;
40
isize
n_in
;
41
isize
n_total
;
42
44
BackwardData<T>
backward_data
;
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
{
65
PROXSUITE_THROW_PRETTY
(
dim
== 0,
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
94
proxsuite::proxqp::sparse::SparseModel<T>
to_sparse
()
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."
)
109
PROXSUITE_CHECK_ARGUMENT_SIZE
(
110
b
.size(),
n_eq
,
"b has not the expected size."
)
111
PROXSUITE_CHECK_ARGUMENT_SIZE
(
112
l
.size(),
n_in
,
"l has not the expected size."
)
113
PROXSUITE_CHECK_ARGUMENT_SIZE
(
114
u
.size(),
n_in
,
"u has not the expected size."
)
115
if
(box_constraints) {
116
PROXSUITE_CHECK_ARGUMENT_SIZE
(
117
u_box
.size(),
dim
,
"u_box has not the expected size"
);
118
PROXSUITE_CHECK_ARGUMENT_SIZE
(
119
l_box
.size(),
dim
,
"l_box has not the expected size"
);
120
}
121
if
(
H
.size()) {
122
PROXSUITE_CHECK_ARGUMENT_SIZE
(
123
H
.rows(),
dim
,
"H has not the expected number of rows."
);
124
PROXSUITE_CHECK_ARGUMENT_SIZE
(
125
H
.cols(),
dim
,
"H has not the expected number of cols."
);
126
PROXSUITE_THROW_PRETTY
(
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()) {
134
PROXSUITE_CHECK_ARGUMENT_SIZE
(
135
A
.rows(),
n_eq
,
"A has not the expected number of rows."
);
136
PROXSUITE_CHECK_ARGUMENT_SIZE
(
137
A
.cols(),
dim
,
"A has not the expected number of cols."
);
138
}
139
if
(
C
.size()) {
140
PROXSUITE_CHECK_ARGUMENT_SIZE
(
141
C
.rows(),
n_in
,
"C has not the expected number of rows."
);
142
PROXSUITE_CHECK_ARGUMENT_SIZE
(
143
C
.cols(),
dim
,
"C has not the expected number of cols."
);
144
PROXSUITE_THROW_PRETTY
(
145
C
.isZero(), std::invalid_argument,
"C is zero, while n_in != 0."
);
146
}
147
return
true
;
148
}
149
};
150
151
template
<
typename
T>
152
bool
153
operator==
(
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
165
template
<
typename
T>
166
bool
167
operator!=
(
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 */
backward_data.hpp
PROXSUITE_CHECK_ARGUMENT_SIZE
#define PROXSUITE_CHECK_ARGUMENT_SIZE(size, expected_size, message)
Definition
macros.hpp:28
PROXSUITE_THROW_PRETTY
#define PROXSUITE_THROW_PRETTY(condition, exception, message)
Definition
macros.hpp:18
proxsuite::linalg::veg::isize
_detail::_meta::make_signed< usize >::Type isize
Definition
typedefs.hpp:43
proxsuite::proxqp::dense
Definition
backward_data.hpp:17
proxsuite::proxqp::dense::SparseMat
Eigen::SparseMatrix< T, 1 > SparseMat
Definition
fwd.hpp:21
proxsuite::proxqp::dense::operator==
bool operator==(const Model< T > &model1, const Model< T > &model2)
Definition
model.hpp:153
proxsuite::proxqp::dense::Vec
Eigen::Matrix< T, DYN, 1 > Vec
Definition
fwd.hpp:24
proxsuite::proxqp::dense::Mat
Eigen::Matrix< T, DYN, DYN, l > Mat
Definition
fwd.hpp:31
proxsuite::proxqp::dense::operator!=
bool operator!=(const Model< T > &model1, const Model< T > &model2)
Definition
model.hpp:167
proxsuite::proxqp
Definition
backward_data.hpp:16
proxsuite
Definition
common.hpp:14
fwd.hpp
model.hpp
proxsuite::helpers::infinite_bound::value
static Scalar value()
Definition
common.hpp:20
proxsuite::proxqp::dense::BackwardData
This class stores the jacobians of PROXQP solvers with dense backends at a solutions wrt model parame...
Definition
backward_data.hpp:28
proxsuite::proxqp::dense::Model
This class stores the model of the QP problem.
Definition
model.hpp:24
proxsuite::proxqp::dense::Model::l_box
Vec< T > l_box
Definition
model.hpp:35
proxsuite::proxqp::dense::Model::l
Vec< T > l
Definition
model.hpp:33
proxsuite::proxqp::dense::Model::A
Mat< T > A
Definition
model.hpp:29
proxsuite::proxqp::dense::Model::u_box
Vec< T > u_box
Definition
model.hpp:34
proxsuite::proxqp::dense::Model::b
Vec< T > b
Definition
model.hpp:31
proxsuite::proxqp::dense::Model::H
Mat< T > H
Definition
model.hpp:27
proxsuite::proxqp::dense::Model::dim
isize dim
Definition
model.hpp:38
proxsuite::proxqp::dense::Model::n_total
isize n_total
Definition
model.hpp:41
proxsuite::proxqp::dense::Model::backward_data
BackwardData< T > backward_data
Definition
model.hpp:44
proxsuite::proxqp::dense::Model::to_sparse
proxsuite::proxqp::sparse::SparseModel< T > to_sparse()
Definition
model.hpp:94
proxsuite::proxqp::dense::Model::g
Vec< T > g
Definition
model.hpp:28
proxsuite::proxqp::dense::Model::Model
Model(isize dim, isize n_eq, isize n_in, bool box_constraints=false)
Definition
model.hpp:52
proxsuite::proxqp::dense::Model::u
Vec< T > u
Definition
model.hpp:32
proxsuite::proxqp::dense::Model::n_in
isize n_in
Definition
model.hpp:40
proxsuite::proxqp::dense::Model::C
Mat< T > C
Definition
model.hpp:30
proxsuite::proxqp::dense::Model::n_eq
isize n_eq
Definition
model.hpp:39
proxsuite::proxqp::dense::Model::is_valid
bool is_valid(const bool box_constraints)
Definition
model.hpp:104
proxsuite::proxqp::sparse::SparseModel
Definition
model.hpp:154
core.hpp
include
proxsuite
proxqp
dense
model.hpp
Generated by
1.17.0