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 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 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.

QOCOSolution *sol

Solution struct.

struct QOCOSettings

QOCO solver settings.

Public Members

QOCOInt max_iters

Maximum number of IPM iterations.

QOCOInt bisect_iters

Number of bisection iterations for linesearch.

QOCOInt ruiz_iters

Number of Ruiz equilibration iterations.

QOCOInt iter_ref_iters

Number of iterative refinement iterations performed.

QOCOFloat kkt_static_reg

Static regularization parameter for 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.

QOCOKKT *kkt

Contains all data related to KKT system.

QOCOFloat *x

Iterate of primal variables.

QOCOFloat *s

Iterate of slack variables associated with conic constraint.

QOCOFloat *y

Iterate of dual variables associated with affine equality constraint.

QOCOFloat *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.

QOCOFloat *W

Upper triangular part of Nesterov-Todd Scaling

QOCOFloat *Wfull

Full Nesterov-Todd Scaling

QOCOFloat *Winv

Upper triangular part of inverse of Nesterov-Todd Scaling

QOCOFloat *Winvfull

Full inverse of Nesterov-Todd Scaling

QOCOFloat *WtW

Nesterov-Todd Scaling squared

QOCOFloat *lambda

Scaled variables.

QOCOFloat *sbar

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

QOCOFloat *zbar

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

QOCOFloat *xbuff

Temporary variable of length n.

QOCOFloat *ybuff

Temporary variable of length p.

QOCOFloat *ubuff1

Temporary variable of length m.

QOCOFloat *ubuff2

Temporary variable of length m.

QOCOFloat *ubuff3

Temporary variable of length m.

QOCOFloat *Ds

Search direction for slack variables. Length of m.

struct QOCOKKT

Contains all data needed for constructing and modifying KKT matrix and performing predictor-corrector step.

Public Members

QOCOCscMatrix *K

KKT matrix in CSC form.

QOCOFloat *delta

Diagonal of scaling matrix.

QOCOFloat *Druiz

Diagonal of scaling matrix.

QOCOFloat *Eruiz

Diagonal of scaling matrix.

QOCOFloat *Fruiz

Diagonal of scaling matrix.

QOCOFloat *Dinvruiz

Inverse of Druiz.

QOCOFloat *Einvruiz

Inverse of Eruiz.

QOCOFloat *Finvruiz

Inverse of Fruiz.

QOCOFloat k

Cost scaling factor.

QOCOFloat kinv

Inverse of cost scaling factor.

QOCOInt *p

Permutation vector.

QOCOInt *pinv

Inverse of permutation vector.

QOCOInt *etree

Elimination tree for LDL factorization of K.

QOCOFloat *rhs

RHS of KKT system.

QOCOFloat *xyz

Solution of KKT system.

QOCOFloat *xyzbuff1

Buffer of size n + m + p.

QOCOFloat *xyzbuff2

Buffer of size n + m + p.

QOCOFloat *kktres

Residual of KKT condition.

QOCOInt *nt2kkt

Mapping from elements in the Nesterov-Todd scaling matrix to elements in the KKT matrix.

QOCOInt *ntdiag2kkt

Mapping from elements on the main diagonal of the Nesterov-Todd scaling matrices to elements in the KKT matrix. Used for regularization.

QOCOInt *PregtoKKT

Mapping from elements in regularized P to elements in the KKT matrix.

QOCOInt *Pnzadded_idx

Indices of P->x that were added due to regularization.

QOCOInt Pnum_nzadded

Number of elements of P->x that were added due to regularization.

QOCOInt *AtoKKT

Mapping from elements in A to elements in the KKT matrix.

QOCOInt *GtoKKT

Mapping from elements in G to elements in the KKT matrix.

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.

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.