C / C++¶
Main solver API¶
The main C API is imported from the header scs.h
.
-
scs_int scs(const ScsData *d, const ScsCone *k, const ScsSettings *stgs, ScsSolution *sol, ScsInfo *info)¶
Solve quadratic cone program defined by data in d and cone k.
All the inputs must already be allocated in memory before calling.
- Parameters
d – Problem data.
k – Cone data.
stgs – SCS solver settings.
sol – Solution will be stored here.
info – Information about the solve will be stored here.
- Returns
Flag that determines solve type (see glbopts.h).
Helper functions¶
This sets the ScsSettings struct to the default values as specified in the Settings page.
-
void scs_set_default_settings(ScsSettings *stgs)¶
Helper function to set all settings to default values (see glbopts.h).
- Parameters
stgs – Settings struct that will be populated.
Primitive types¶
scs_int
: islong
if the compiler flagDLONG
is set, otherwise it isint
scs_float
: isfloat
if the compiler flagSFLOAT
is set, otherwise it isdouble
Input Types¶
The relevant input structs required by API are as follows.
Data¶
-
struct ScsData¶
Struct containing problem data.
Public Members
-
scs_int m¶
A has
m
rows.
-
scs_int n¶
A has
n
cols, P hasn
cols andn
rows.
-
ScsMatrix *P¶
P is supplied in CSC format (size
n
xn
), must be symmetric positive semidefinite. Only pass in the upper triangular entries. IfP = 0
then setP = SCS_NULL
.
-
scs_float *b¶
Dense array for b (size
m
).
-
scs_float *c¶
Dense array for c (size
n
).
-
scs_int m¶
Data Matrices¶
The matrices must be in Compressed Sparse Column (CSC) format using zero-based indexing. See Data matrices for more details on what SCS expects.
-
struct ScsMatrix¶
This defines the data matrices which should be supplied in column compressed format with zero based indexing.
Cone¶
See Cones for more details.
-
struct ScsCone¶
Cone data. Rows of data matrix
A
must be specified in this exact order.Public Members
-
scs_int z¶
Number of linear equality constraints (primal zero, dual free).
-
scs_int l¶
Number of positive orthant cones.
-
scs_float *bu¶
Upper box values,
len(bu) = len(bl) = max(bsize-1, 0)
.
-
scs_float *bl¶
Lower box values,
len(bu) = len(bl) = max(bsize-1, 0)
.
-
scs_int bsize¶
Total length of box cone (includes scale
t
).
-
scs_int *q¶
Array of second-order cone constraints.
-
scs_int qsize¶
Length of second-order cone array
q
.
-
scs_int *s¶
Array of semidefinite cone constraints.
-
scs_int ssize¶
Length of semidefinite constraints array
s
.
-
scs_int ep¶
Number of primal exponential cone triples.
-
scs_int ed¶
Number of dual exponential cone triples.
-
scs_float *p¶
Array of power cone params, must be in
[-1, 1]
, negative values are interpreted as specifying the dual cone.
-
scs_int psize¶
Number of (primal and dual) power cone triples.
-
scs_int z¶
Settings¶
See Settings for details on each of these.
-
struct ScsSettings¶
Struct containing all settings.
Public Members
-
scs_int normalize¶
Whether to heuristically rescale the data before solve.
-
scs_float scale¶
Initial dual scaling factor (may be updated if adaptive_scale is on).
-
scs_int adaptive_scale¶
Whether to adaptively update
scale
.
-
scs_float rho_x¶
Primal constraint scaling factor.
-
scs_int max_iters¶
Maximum iterations to take.
-
scs_float eps_abs¶
Absolute convergence tolerance.
-
scs_float eps_rel¶
Relative convergence tolerance.
-
scs_float eps_infeas¶
Infeasible convergence tolerance.
-
scs_float alpha¶
Douglas-Rachford relaxation parameter.
-
scs_float time_limit_secs¶
Time limit in secs (can be fractional).
-
scs_int verbose¶
Whether to log progress to stdout.
-
scs_int warm_start¶
Whether to use warm start (put initial guess in ScsSolution struct).
-
scs_int acceleration_lookback¶
Memory for acceleration.
-
scs_int acceleration_interval¶
Interval to apply acceleration.
-
const char *write_data_filename¶
String, if set will dump raw prob data to this file.
-
const char *log_csv_filename¶
String, if set will log data to this csv file (makes SCS very slow).
-
scs_int normalize¶
Output Types¶
The relevant output structs returned by SCS are as follows.
Solution¶
This will contain the solution as found by SCS or the certificate of primal or dual infeasibility (see Termination criteria). If the user wants to warm-start the solver, then the Solution struct is also used as an input to specify the warm-start points (see Warm-starting).
-
struct ScsSolution¶
Contains primal-dual solution arrays or a certificate of infeasibility. Check the exit flag to determine whether this contains a solution or a certificate.
Info¶
See Return information for details on each of these.
-
struct ScsInfo¶
Contains information about the solve run at termination.
Public Members
-
scs_int iter¶
Number of iterations taken.
-
char status[128]¶
Status string, e.g. ‘solved’.
-
scs_int status_val¶
Status as scs_int, defined in glbopts.h.
-
scs_int scale_updates¶
Number of updates to scale.
-
scs_float pobj¶
Primal objective.
-
scs_float dobj¶
Dual objective.
-
scs_float res_pri¶
Primal equality residual.
-
scs_float res_dual¶
Dual equality residual.
-
scs_float gap¶
Duality gap.
-
scs_float res_infeas¶
Infeasibility cert residual.
-
scs_float res_unbdd_a¶
Unbounded cert residual.
-
scs_float res_unbdd_p¶
Unbounded cert residual.
-
scs_float setup_time¶
Time taken for setup phase (milliseconds).
-
scs_float solve_time¶
Time taken for solve phase (milliseconds).
-
scs_float scale¶
Final scale parameter.
-
scs_float comp_slack¶
Complementary slackness.
-
scs_int rejected_accel_steps¶
Number of rejected AA steps.
-
scs_int accepted_accel_steps¶
Number of accepted AA steps.
-
scs_float lin_sys_time¶
Total time (milliseconds) spent in the linear system solver.
-
scs_float cone_time¶
Total time (milliseconds) spent in the cone projection.
-
scs_float accel_time¶
Total time (milliseconds) spent in the acceleration routine.
-
scs_int iter¶