QPALM main
Proximal Augmented Lagrangian method for Quadratic Programs
Loading...
Searching...
No Matches
qpalm.cpp
Go to the documentation of this file.
1#include <qpalm.hpp>
2
3#include <qpalm.h> // qpalm_setup, qpalm_solve, etc.
4
5#include <stdexcept>
6
7namespace qpalm {
8
9const ::QPALMData *Data::get_c_data_ptr() const {
10 data.n = static_cast<size_t>(n);
11 data.m = static_cast<size_t>(m);
12 data.Q = Q.get();
13 data.A = A.get();
14 // Casting away const is fine, since we know that the QPALM C API doesn't
15 // write to these vectors (it even creates a copy of them in the workspace).
16 data.q = const_cast<c_float *>(q.data());
17 data.c = c;
18 data.bmin = const_cast<c_float *>(bmin.data());
19 data.bmax = const_cast<c_float *>(bmax.data());
20 return &data;
21}
22
24
26
27Solver::Solver(const ::QPALMData *data, const Settings &settings)
28 : work{::qpalm_setup(data, &settings)} {
29 if (!work)
30 throw std::invalid_argument(
31 "Solver initialization using qpalm_setup failed, please check "
32 "problem bounds and solver settings"
33#ifndef QPALM_PRINTING
34 ", recompile QPALM with QPALM_PRINTING=1 for more information"
35#endif
36 );
37}
38
39void Solver::update_settings(const Settings &settings) {
40 ::qpalm_update_settings(work.get(), &settings);
41}
42
43void Solver::update_bounds(std::optional<const_ref_vec_t> bmin,
44 std::optional<const_ref_vec_t> bmax) {
45 ::qpalm_update_bounds(work.get(), bmin ? bmin->data() : nullptr,
46 bmax ? bmax->data() : nullptr);
47}
48
50 ::qpalm_update_q(work.get(), q.data());
51}
52
54 ::qpalm_update_Q_A(work.get(), Q_vals.data(), A_vals.data());
55}
56
57void Solver::warm_start(std::optional<const_ref_vec_t> x,
58 std::optional<const_ref_vec_t> y) {
59 ::qpalm_warm_start(work.get(), x ? x->data() : nullptr,
60 y ? y->data() : nullptr);
61}
62
63void Solver::solve() { ::qpalm_solve(work.get()); }
64
65void Solver::cancel() { ::qpalm_cancel(work.get()); }
66
68 assert(work->solution);
69 assert(work->solution->x);
70 assert(work->solution->y);
71 auto en = static_cast<Eigen::Index>(work->data->n);
72 auto em = static_cast<Eigen::Index>(work->data->m);
73 return {
74 {work->solution->x, en},
75 {work->solution->y, em},
76 };
77}
78
80 assert(work->info);
81 return *work->info;
82}
83
85 auto em = static_cast<Eigen::Index>(work->data->m);
86 return {work->delta_y, em};
87}
88
90 auto en = static_cast<Eigen::Index>(work->data->n);
91 return {work->delta_x, en};
92}
93
97
98} // namespace qpalm
index_t m
Number of constraints (size of bmin and bmax, number of rows of A).
Definition qpalm.hpp:46
index_t n
Problem dimension (size of x and q, number rows and columns of Q, number of columns of A).
Definition qpalm.hpp:43
ladel_sparse_matrix_ptr Q
Definition qpalm.hpp:47
c_float c
Definition qpalm.hpp:49
vec_t bmax
Definition qpalm.hpp:52
ladel_sparse_matrix_ptr A
Definition qpalm.hpp:48
const ::QPALMData * get_c_data_ptr() const
Get a pointer to the underlying C data structure.
Definition qpalm.cpp:9
vec_t q
Definition qpalm.hpp:50
vec_t bmin
Definition qpalm.hpp:51
SolutionView get_solution() const
Get the solution computed by solve().
Definition qpalm.cpp:67
void update_Q_A(const_ref_vec_t Q_vals, const_ref_vec_t A_vals)
Definition qpalm.cpp:53
const QPALMInfo & get_info() const
Get the solver information from the last call to solve().
Definition qpalm.cpp:79
void update_q(const_ref_vec_t q)
Definition qpalm.cpp:49
void warm_start(std::optional< const_ref_vec_t > x, std::optional< const_ref_vec_t > y)
Definition qpalm.cpp:57
void update_bounds(std::optional< const_ref_vec_t > bmin, std::optional< const_ref_vec_t > bmax)
Definition qpalm.cpp:43
void solve()
Solve the problem.
Definition qpalm.cpp:63
void update_settings(const Settings &settings)
Definition qpalm.cpp:39
const_borrowed_vec_t get_dual_inf_certificate() const
Get the certificate of dual infeasibility of the problem.
Definition qpalm.cpp:89
Solver(const ::QPALMData *data, const Settings &settings)
Create a new solver for the problem defined by data and with the parameters defined by settings.
Definition qpalm.cpp:27
void cancel()
Cancel the ongoing call to solve.
Definition qpalm.cpp:65
const_borrowed_vec_t get_prim_inf_certificate() const
Get the certificate of primal infeasibility of the problem.
Definition qpalm.cpp:84
ladel_double c_float
type for floating point numbers
Definition global_opts.h:41
void qpalm_solve(QPALMWorkspace *work)
Solve the quadratic program.
Definition qpalm.c:483
QPALMWorkspace * qpalm_setup(const QPALMData *data, const QPALMSettings *settings)
Initialize QPALM solver allocating memory.
Definition qpalm.c:68
void qpalm_update_settings(QPALMWorkspace *work, const QPALMSettings *settings)
Update the settings to the new settings.
Definition qpalm.c:610
void qpalm_set_default_settings(QPALMSettings *settings)
Set default settings from constants.h file.
Definition qpalm.c:33
void qpalm_update_bounds(QPALMWorkspace *work, const c_float *bmin, const c_float *bmax)
Update the lower and upper bounds.
Definition qpalm.c:643
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:711
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:260
void qpalm_cleanup(QPALMWorkspace *work)
Cleanup the workspace by deallocating memory.
Definition qpalm.c:735
void qpalm_cancel(QPALMWorkspace *work)
Cancel the ongoing call to qpalm_solve.
Definition qpalm.c:479
void qpalm_update_q(QPALMWorkspace *work, const c_float *q)
Update the linear part of the cost.
Definition qpalm.c:690
Eigen::Ref< const vec_t > const_ref_vec_t
Read-only reference to a dense vector (vector view).
Definition sparse.hpp:38
Eigen::Map< const vec_t > const_borrowed_vec_t
Read-only borrowed dense vector type (vector view).
Definition sparse.hpp:34
::QPALMInfo QPALMInfo
Definition qpalm.cpp:25
QPALM main solver API.
Solver return information.
Definition types.h:81
QPALM Workspace.
Definition types.h:204
Settings and parameters for the QPALM solver.
Definition qpalm.hpp:110
Settings()
Construct with default settings.
Definition qpalm.cpp:23
View on the solution returned by the solver.
Definition qpalm.hpp:129
void operator()(::QPALMWorkspace *) const
Definition qpalm.cpp:94