QPALM 1.1.1
Proximal Augmented Lagrangian method for Quadratic Programs
qpalm.cpp
Go to the documentation of this file.
1#include <qpalm.hpp>
2
3#include <qpalm.h> // qpalm_setup, qpalm_solve, etc.
4
5namespace qpalm {
6
7const ::QPALMData *Data::get_c_data_ptr() const {
8 data.n = static_cast<size_t>(n);
9 data.m = static_cast<size_t>(m);
10 data.Q = Q.get();
11 data.A = A.get();
12 // Casting away const is fine, since we know that the QPALM C API doesn't
13 // write to these vectors (it even creates a copy of them in the workspace).
14 data.q = const_cast<c_float *>(q.data());
15 data.c = c;
16 data.bmin = const_cast<c_float *>(bmin.data());
17 data.bmax = const_cast<c_float *>(bmax.data());
18 return &data;
19}
20
22
24
25Solver::Solver(const Data &data, const Settings &settings)
26 : work{::qpalm_setup(data.get_c_data_ptr(), &settings)} {}
27
28void Solver::update_settings(const Settings &settings) {
29 ::qpalm_update_settings(work.get(), &settings);
30}
31
32void Solver::update_bounds(std::optional<const_ref_vec_t> bmin,
33 std::optional<const_ref_vec_t> bmax) {
34 ::qpalm_update_bounds(work.get(), bmin ? bmin->data() : nullptr,
35 bmax ? bmax->data() : nullptr);
36}
37
39 ::qpalm_update_q(work.get(), q.data());
40}
41
43 ::qpalm_update_Q_A(work.get(), Q_vals.data(), A_vals.data());
44}
45
46void Solver::warm_start(std::optional<const_ref_vec_t> x,
47 std::optional<const_ref_vec_t> y) {
48 ::qpalm_warm_start(work.get(), x ? x->data() : nullptr,
49 y ? y->data() : nullptr);
50}
51
52void Solver::solve() { ::qpalm_solve(work.get()); }
53
55 assert(work->solution);
56 assert(work->solution->x);
57 assert(work->solution->y);
58 auto en = static_cast<Eigen::Index>(work->data->n);
59 auto em = static_cast<Eigen::Index>(work->data->m);
60 return {
61 {work->solution->x, en},
62 {work->solution->y, em},
63 };
64}
65
67 assert(work->info);
68 return *work->info;
69}
70
72 auto em = static_cast<Eigen::Index>(work->data->m);
73 return {work->delta_y, em};
74}
75
77 auto en = static_cast<Eigen::Index>(work->data->n);
78 return {work->delta_x, en};
79}
80
83}
84
85} // namespace qpalm
Stores the matrices and vectors that define the problem.
Definition: qpalm.hpp:38
index_t m
Number of constraints (size of bmin and bmax, number of rows of A).
Definition: qpalm.hpp:45
index_t n
Problem dimension (size of x and q, number rows and columns of Q, number of columns of A).
Definition: qpalm.hpp:42
ladel_sparse_matrix_ptr Q
Definition: qpalm.hpp:46
c_float c
Definition: qpalm.hpp:48
vec_t bmax
Definition: qpalm.hpp:51
ladel_sparse_matrix_ptr A
Definition: qpalm.hpp:47
QPALM_CXX_EXPORTconst ::QPALMData * get_c_data_ptr() const
Get a pointer to the underlying C data structure.
Definition: qpalm.cpp:7
vec_t q
Definition: qpalm.hpp:49
vec_t bmin
Definition: qpalm.hpp:50
QPALM_CXX_EXPORT SolutionView get_solution() const
Get the solution computed by solve().
Definition: qpalm.cpp:54
QPALM_CXX_EXPORT void update_Q_A(const_ref_vec_t Q_vals, const_ref_vec_t A_vals)
Definition: qpalm.cpp:42
QPALM_CXX_EXPORT const QPALMInfo & get_info() const
Get the solver information from the last call to solve().
Definition: qpalm.cpp:66
QPALM_CXX_EXPORT void update_q(const_ref_vec_t q)
Definition: qpalm.cpp:38
QPALM_CXX_EXPORT Solver(const Data &data, const Settings &settings)
Create a new solver for the problem defined by data and with the parameters defined by settings.
Definition: qpalm.cpp:25
QPALM_CXX_EXPORT void warm_start(std::optional< const_ref_vec_t > x, std::optional< const_ref_vec_t > y)
Definition: qpalm.cpp:46
QPALM_CXX_EXPORT void update_bounds(std::optional< const_ref_vec_t > bmin, std::optional< const_ref_vec_t > bmax)
Definition: qpalm.cpp:32
QPALM_CXX_EXPORT void solve()
Solve the problem.
Definition: qpalm.cpp:52
QPALM_CXX_EXPORT void update_settings(const Settings &settings)
Definition: qpalm.cpp:28
QPALM_CXX_EXPORT const_borrowed_vec_t get_dual_inf_certificate() const
Get the certificate of dual infeasibility of the problem.
Definition: qpalm.cpp:76
QPALM_CXX_EXPORT const_borrowed_vec_t get_prim_inf_certificate() const
Get the certificate of primal infeasibility of the problem.
Definition: qpalm.cpp:71
ladel_double c_float
type for floating point numbers
Definition: global_opts.h:41
void qpalm_warm_start(QPALMWorkspace *work, const c_float *x_warm_start, const c_float *y_warm_start)
Warm start workspace variables x, x_0, x_prev, Ax, Qx, y and sigma.
Definition: qpalm.c:259
void qpalm_update_Q_A(QPALMWorkspace *work, const c_float *Qx, const c_float *Ax)
Update the matrix entries of Q and A.
Definition: qpalm.c:699
void qpalm_update_bounds(QPALMWorkspace *work, const c_float *bmin, const c_float *bmax)
Update the lower and upper bounds.
Definition: qpalm.c:631
void qpalm_set_default_settings(QPALMSettings *settings)
Set default settings from constants.h file.
Definition: qpalm.c:33
void qpalm_update_settings(QPALMWorkspace *work, const QPALMSettings *settings)
Update the settings to the new settings.
Definition: qpalm.c:598
void qpalm_cleanup(QPALMWorkspace *work)
Cleanup the workspace by deallocating memory.
Definition: qpalm.c:723
void qpalm_solve(QPALMWorkspace *work)
Solve the quadratic program.
Definition: qpalm.c:476
QPALMWorkspace * qpalm_setup(const QPALMData *data, const QPALMSettings *settings)
Initialize QPALM solver allocating memory.
Definition: qpalm.c:68
void qpalm_update_q(QPALMWorkspace *work, const c_float *q)
Update the linear part of the cost.
Definition: qpalm.c:678
Definition: qpalm.hpp:18
Eigen::Ref< const vec_t > const_ref_vec_t
Read-only reference to a dense vector (vector view).
Definition: sparse.hpp:36
Eigen::Map< const vec_t > const_borrowed_vec_t
Read-only borrowed dense vector type (vector view).
Definition: sparse.hpp:32
::QPALMInfo QPALMInfo
Definition: qpalm.cpp:23
QPALM main solver API.
Solver return information.
Definition: types.h:74
QPALM Workspace.
Definition: types.h:197
Settings and parameters for the QPALM solver.
Definition: qpalm.hpp:91
QPALM_CXX_EXPORT Settings()
Construct with default settings.
Definition: qpalm.cpp:21
View on the solution returned by the solver.
Definition: qpalm.hpp:110
QPALM_CXX_EXPORT void operator()(::QPALMWorkspace *) const
Definition: qpalm.cpp:81