C/C++

Main solver API

QOCOInt qoco_setup(QOCOSolver *solver, QOCOInt n, QOCOInt m, QOCOInt p, QOCOCscMatrix *P, QOCOFloat *c, QOCOCscMatrix *A, QOCOFloat *b, QOCOCscMatrix *G, QOCOFloat *h, QOCOInt l, QOCOInt nsoc, QOCOInt *q, QOCOSettings *settings)

Allocates all memory needed for QOCO to solve the SOCP.

Parameters:
  • solver – Pointer to solver.

  • n – Number of optimization variables.

  • m – Number of conic constraints.

  • p – Number of affine equality constraints.

  • P – Upper triangular part of quadratic cost Hessian in CSC form.

  • c – Linear cost vector.

  • A – Affine equality constraint matrix in CSC form.

  • b – Affine equality constraint offset vector.

  • G – Conic constraint matrix in CSC form.

  • h – Conic constraint offset vector.

  • l – Dimension of non-negative orthant.

  • nsoc – Number of second-order cones.

  • q – Dimension of each second-order cone.

  • settings – Settings struct.

Returns:

0 if no error or flag containing error code.

QOCOInt qoco_solve(QOCOSolver *solver)

Solves SOCP.

Parameters:

solver – Pointer to solver.

Returns:

Exitflag to check (0 for success, failure otherwise)

QOCOInt qoco_cleanup(QOCOSolver *solver)

Frees all memory allocated by qoco_setup.

Parameters:

solver – Pointer to solver.

Returns:

Exitflag to check (0 for success, failure otherwise)

Helper functions

void qoco_set_csc(QOCOCscMatrix *A, QOCOInt m, QOCOInt n, QOCOInt Annz, QOCOFloat *Ax, QOCOInt *Ap, QOCOInt *Ai)

Sets the data for a compressed sparse column matrix.

Parameters:
  • A – Pointer to the CSC matrix.

  • m – Number of rows in the matrix.

  • n – Number of columns in the matrix.

  • Annz – Number of nonzero elements in the matrix.

  • Ax – Array of data for the matrix.

  • Ap – Array of column pointers for the data.

  • Ai – Array of row indices for data.

void set_default_settings(QOCOSettings *settings)

Set the default settings struct.

Parameters:

settings – Pointer to settings struct.

QOCOInt qoco_update_settings(QOCOSolver *solver, const QOCOSettings *new_settings)

Updates settings struct.

Parameters:
  • solver – Pointer to solver.

  • new_settings – New settings struct.

Returns:

0 if update is successful.

void qoco_update_vector_data(QOCOSolver *solver, QOCOFloat *cnew, QOCOFloat *bnew, QOCOFloat *hnew)

Updates data vectors. NULL can be passed in for any vector if that data will not be updated.

Parameters:
  • solver – Pointer to solver.

  • cnew – New c vector.

  • bnew – New b vector.

  • hnew – New h vector.

void qoco_set_x0(QOCOSolver *solver, const QOCOFloat *x0)

Sets an optional primal starting point after qoco_setup. The x0 vector is copied and should be supplied in the original, unequilibrated problem scaling. Pass NULL to clear a previously set custom starting point.

Parameters:
  • solver – Pointer to solver.

  • x0 – Primal starting point of length n, or NULL to use default initialization.

void qoco_update_matrix_data(QOCOSolver *solver, QOCOFloat *Pxnew, QOCOFloat *Axnew, QOCOFloat *Gxnew)

Updates data matrices. NULL can be passed in for any matrix data pointers if that matrix will not be updated. It is assumed that the new matrix will have the same sparsity structure as the existing matrix.

Parameters:
  • solver – Pointer to solver.

  • Pxnew – New data for P->x.

  • Axnew – New data for A->x.

  • Gxnew – New data for G->x.

QOCO data types

struct QOCOSolver

QOCO Solver struct. Contains all information about the state of the solver.

Public Members

QOCOSettings *settings

Solver settings.

QOCOWorkspace *work

Solver workspace.

LinSysBackend *linsys

Linear system backend.

LinSysData *linsys_data

Linear system backend.

QOCOSolution *sol

Solution struct.

struct QOCOSettings

QOCO solver settings.

Public Members

QOCOInt max_iters

Maximum number of IPM iterations.

QOCOInt ruiz_iters

Number of Ruiz equilibration iterations.

QOCOInt max_ir_iters

Maximum number of iterative refinement iterations.

QOCOFloat ir_tol

Iterative refinement stopping tolerance: stop when norm(K*x-b) < ir_tol.

QOCOFloat kkt_static_reg_P

Static regularization for the (1,1) P block of the KKT system.

QOCOFloat kkt_static_reg_A

Static regularization for the (2,2) A block of the KKT system.

QOCOFloat kkt_static_reg_G

Static regularization for the (3,3) G block of the KKT system.

QOCOFloat kkt_dynamic_reg

Dynamic regularization parameter for KKT system.

QOCOFloat abstol

Absolute tolerance.

QOCOFloat reltol

Relative tolerance.

QOCOFloat abstol_inacc

Low tolerance stopping criteria.

QOCOFloat reltol_inacc

Low tolerance stopping criteria.

unsigned char verbose

0 for quiet anything else for verbose.

struct QOCOWorkspace

QOCO Workspace.

Public Members

QOCOProblemData *data

Contains SOCP problem data.

QOCOTimer solve_timer

Solve timer.

QOCOScaling *scaling

Contains all data related problem scaling.

QOCOVectorf *x

Iterate of primal variables.

QOCOVectorf *x0

Primal starting point in original problem scaling.

unsigned char use_x0

Whether to use x0 during initialization.

QOCOVectorf *s

Iterate of slack variables associated with conic constraint.

QOCOVectorf *y

Iterate of dual variables associated with affine equality constraint.

QOCOVectorf *z

Iterate of dual variables associated with conic constraint.

QOCOFloat mu

Gap (s’*z / m)

QOCOFloat a

Newton Step-size

QOCOFloat sigma

Centering parameter

QOCOInt Wnnz

Number of nonzeros in upper triangular part of Nesterov-Todd Scaling.

QOCOInt Wnnzfull

Number of nonzeros in full Nesterov-Todd Scaling.

QOCOVectorf *W

Upper triangular part of Nesterov-Todd Scaling

QOCOVectorf *Wfull

Full Nesterov-Todd Scaling

QOCOVectorf *Winv

Upper triangular part of inverse of Nesterov-Todd Scaling

QOCOVectorf *Winvfull

Full inverse of Nesterov-Todd Scaling

QOCOVectorf *WtW

Nesterov-Todd Scaling squared

QOCOVectori *Wsoc_idx

Vector which points to the start of the ith soc block in Wfull

QOCOVectori *soc_idx

Vector which points to the start of the start of the ith soc variable block

QOCOVectorf *lambda

Scaled variables.

QOCOVectorf *sbar

Temporary array needed in Nesterov-Todd scaling calculations. Length of max(q).

QOCOVectorf *zbar

Temporary array needed in Nesterov-Todd scaling calculations. Length of max(q).

QOCOVectorf *xbuff

Temporary variable of length n.

QOCOVectorf *ybuff

Temporary variable of length p.

QOCOVectorf *ubuff1

Temporary variable of length m.

QOCOVectorf *ubuff2

Temporary variable of length m.

QOCOVectorf *ubuff3

Temporary variable of length m.

QOCOVectorf *Ds

Search direction for slack variables. Length of m.

QOCOVectorf *rhs

RHS of KKT system.

QOCOVectorf *xyz

Solution of KKT system.

QOCOVectorf *xyzbuff1

Buffer of size n + m + p.

QOCOVectorf *kktres

Residual of KKT condition.

QOCOInt ir_iters

Total iterative refinement iterations used in the current IPM step.

QOCOVectorf *best_x

Best iterate found so far (scaled space), saved by composite residual metric. Restored on numerical-error / max-iter exits.

QOCOFloat best_pres

Residuals associated with the saved best iterate.

struct QOCOCscMatrix

Compressed sparse column format matrices.

Public Members

QOCOInt m

Number of rows.

QOCOInt n

Number of columns.

QOCOInt nnz

Number of nonzero elements.

QOCOInt *i

Row indices (length: nnz).

QOCOInt *p

Column pointers (length: n+1).

QOCOFloat *x

Data (length: nnz).

struct QOCOSolution

Public Members

QOCOFloat *x

Primal solution.

QOCOFloat *s

Slack variable for conic constraints.

QOCOFloat *y

Dual variables for affine equality constraints.

QOCOFloat *z

Dual variables for conic constraints.

QOCOInt iters

Number of iterations.

QOCOInt ir_iters

Total iterative refinement iterations across all IPM steps.

QOCOFloat setup_time_sec

Setup time.

QOCOFloat solve_time_sec

Solve time.

QOCOFloat obj

Optimal objective value.

QOCOFloat pres

Primal residual.

QOCOFloat dres

Dual residual.

QOCOFloat gap

Duality gap.

QOCOInt status

Solve status.