The solver is initialized by creating an OSQP object
m = osqp;
The problem is specified in the setup phase by running
m.setup(P, q, A, l, u, varargin)
u are arrays. The elements of
u can be \(\pm \infty\) ( using
Inf). The arguments
A are sparse matrices.
There is no need to specify all the problem data. They can be omitted by writing
The last argument
varargin specifies the solver options. You can pass the options in two ways. You can either set the individual parameters as field-value pairs, e.g.,
m.setup(P, q, A, l, u, 'eps_abs', 1e-04, 'eps_rel', 1e-04);
Alternatively, you can create a structure containing all the settings, change some of the fields and then pass it as the last argument
settings = m.default_settings(); settings.eps_abs = 1e-04; settings.eps_rel = 1e-04; m.setup(P, q, A, l, u, settings);
The allowed settings are defined in Solver settings.
The problem can be solved by
results = m.solve();
results structure contains the primal solution
x, the dual solution
y, certificate of primal infeasibility
prim_inf_cert, certificate of dual infeasibility
dual_inf_cert and the
info structure containing the solver statistics defined in the following table
||Number of iterations|
||Solver status value as in Status values|
||Total run time: setup + solve + polish|
||Optimal rho estimate|
||Number of rho updates|
Note that if multiple solves are executed from single setup, then after the
run_time includes only
Part of problem data and settings can be updated without requiring a new problem setup.
Update problem data¶
u can be updated with new values
u_new by just running
m.update('q', q_new, 'l', l_new, 'u', u_new);
The user does not have to specify all the arguments.
OSQP automatically warm starts primal and dual variables from the previous QP solution. If you would like to warm start their values manually, you can use
m.warm_start('x', x0, 'y', y0)
y0 are the new primal and dual variables.