scs 0.2.2 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/LICENSE.txt +18 -18
  4. data/README.md +19 -14
  5. data/lib/scs/ffi.rb +31 -20
  6. data/lib/scs/solver.rb +32 -9
  7. data/lib/scs/version.rb +1 -1
  8. data/vendor/scs/CITATION.cff +39 -0
  9. data/vendor/scs/CMakeLists.txt +320 -0
  10. data/vendor/scs/Makefile +32 -23
  11. data/vendor/scs/README.md +9 -218
  12. data/vendor/scs/include/aa.h +67 -23
  13. data/vendor/scs/include/cones.h +22 -19
  14. data/vendor/scs/include/glbopts.h +107 -79
  15. data/vendor/scs/include/linalg.h +3 -4
  16. data/vendor/scs/include/linsys.h +58 -44
  17. data/vendor/scs/include/normalize.h +6 -5
  18. data/vendor/scs/include/rw.h +8 -2
  19. data/vendor/scs/include/scs.h +257 -141
  20. data/vendor/scs/include/scs_types.h +34 -0
  21. data/vendor/scs/include/scs_work.h +83 -0
  22. data/vendor/scs/include/util.h +3 -15
  23. data/vendor/scs/linsys/cpu/direct/private.c +241 -232
  24. data/vendor/scs/linsys/cpu/direct/private.h +13 -7
  25. data/vendor/scs/linsys/cpu/indirect/private.c +194 -118
  26. data/vendor/scs/linsys/cpu/indirect/private.h +7 -4
  27. data/vendor/scs/linsys/csparse.c +87 -0
  28. data/vendor/scs/linsys/csparse.h +34 -0
  29. data/vendor/scs/linsys/external/amd/SuiteSparse_config.c +6 -6
  30. data/vendor/scs/linsys/external/amd/SuiteSparse_config.h +6 -1
  31. data/vendor/scs/linsys/external/amd/amd_internal.h +1 -1
  32. data/vendor/scs/linsys/external/amd/amd_order.c +5 -5
  33. data/vendor/scs/linsys/external/qdldl/changes +2 -0
  34. data/vendor/scs/linsys/external/qdldl/qdldl.c +29 -46
  35. data/vendor/scs/linsys/external/qdldl/qdldl.h +33 -41
  36. data/vendor/scs/linsys/external/qdldl/qdldl_types.h +11 -3
  37. data/vendor/scs/linsys/gpu/gpu.c +58 -21
  38. data/vendor/scs/linsys/gpu/gpu.h +70 -35
  39. data/vendor/scs/linsys/gpu/indirect/private.c +394 -157
  40. data/vendor/scs/linsys/gpu/indirect/private.h +27 -12
  41. data/vendor/scs/linsys/scs_matrix.c +478 -0
  42. data/vendor/scs/linsys/scs_matrix.h +70 -0
  43. data/vendor/scs/scs.mk +14 -10
  44. data/vendor/scs/src/aa.c +394 -110
  45. data/vendor/scs/src/cones.c +497 -359
  46. data/vendor/scs/src/ctrlc.c +15 -5
  47. data/vendor/scs/src/linalg.c +107 -26
  48. data/vendor/scs/src/normalize.c +30 -72
  49. data/vendor/scs/src/rw.c +202 -27
  50. data/vendor/scs/src/scs.c +769 -571
  51. data/vendor/scs/src/scs_version.c +11 -3
  52. data/vendor/scs/src/util.c +37 -106
  53. data/vendor/scs/test/minunit.h +22 -8
  54. data/vendor/scs/test/problem_utils.h +180 -25
  55. data/vendor/scs/test/problems/degenerate.h +130 -0
  56. data/vendor/scs/test/problems/hs21_tiny_qp.h +124 -0
  57. data/vendor/scs/test/problems/hs21_tiny_qp_rw.h +116 -0
  58. data/vendor/scs/test/problems/infeasible_tiny_qp.h +100 -0
  59. data/vendor/scs/test/problems/qafiro_tiny_qp.h +199 -0
  60. data/vendor/scs/test/problems/random_prob +0 -0
  61. data/vendor/scs/test/problems/random_prob.h +45 -0
  62. data/vendor/scs/test/problems/rob_gauss_cov_est.h +188 -31
  63. data/vendor/scs/test/problems/small_lp.h +14 -13
  64. data/vendor/scs/test/problems/small_qp.h +352 -0
  65. data/vendor/scs/test/problems/test_validation.h +43 -0
  66. data/vendor/scs/test/problems/unbounded_tiny_qp.h +82 -0
  67. data/vendor/scs/test/random_socp_prob.c +54 -53
  68. data/vendor/scs/test/rng.h +109 -0
  69. data/vendor/scs/test/run_from_file.c +20 -11
  70. data/vendor/scs/test/run_tests.c +35 -2
  71. metadata +29 -98
  72. data/vendor/scs/linsys/amatrix.c +0 -305
  73. data/vendor/scs/linsys/amatrix.h +0 -36
  74. data/vendor/scs/linsys/amatrix.o +0 -0
  75. data/vendor/scs/linsys/cpu/direct/private.o +0 -0
  76. data/vendor/scs/linsys/cpu/indirect/private.o +0 -0
  77. data/vendor/scs/linsys/external/amd/SuiteSparse_config.o +0 -0
  78. data/vendor/scs/linsys/external/amd/amd_1.o +0 -0
  79. data/vendor/scs/linsys/external/amd/amd_2.o +0 -0
  80. data/vendor/scs/linsys/external/amd/amd_aat.o +0 -0
  81. data/vendor/scs/linsys/external/amd/amd_control.o +0 -0
  82. data/vendor/scs/linsys/external/amd/amd_defaults.o +0 -0
  83. data/vendor/scs/linsys/external/amd/amd_dump.o +0 -0
  84. data/vendor/scs/linsys/external/amd/amd_global.o +0 -0
  85. data/vendor/scs/linsys/external/amd/amd_info.o +0 -0
  86. data/vendor/scs/linsys/external/amd/amd_order.o +0 -0
  87. data/vendor/scs/linsys/external/amd/amd_post_tree.o +0 -0
  88. data/vendor/scs/linsys/external/amd/amd_postorder.o +0 -0
  89. data/vendor/scs/linsys/external/amd/amd_preprocess.o +0 -0
  90. data/vendor/scs/linsys/external/amd/amd_valid.o +0 -0
  91. data/vendor/scs/linsys/external/qdldl/qdldl.o +0 -0
  92. data/vendor/scs/src/aa.o +0 -0
  93. data/vendor/scs/src/cones.o +0 -0
  94. data/vendor/scs/src/ctrlc.o +0 -0
  95. data/vendor/scs/src/linalg.o +0 -0
  96. data/vendor/scs/src/normalize.o +0 -0
  97. data/vendor/scs/src/rw.o +0 -0
  98. data/vendor/scs/src/scs.o +0 -0
  99. data/vendor/scs/src/scs_version.o +0 -0
  100. data/vendor/scs/src/util.o +0 -0
  101. data/vendor/scs/test/data/small_random_socp +0 -0
  102. data/vendor/scs/test/problems/small_random_socp.h +0 -33
  103. data/vendor/scs/test/run_tests +0 -2
@@ -1,3 +1,6 @@
1
+ /* This file contains the outward facing SCS API. */
2
+ /* It includes all the input/output data structs and the API functions. */
3
+
1
4
  #ifndef SCS_H_GUARD
2
5
  #define SCS_H_GUARD
3
6
 
@@ -5,155 +8,268 @@
5
8
  extern "C" {
6
9
  #endif
7
10
 
8
- #include <string.h>
9
- #include "glbopts.h"
10
- #include "aa.h"
11
+ /* Contains definitions of primitive types `scs_int` and `scs_float`. */
12
+ #include "scs_types.h"
11
13
 
12
- /* private data structs (that you define) containing any necessary data to solve
13
- * linear system, etc. this defines the matrix A, only the linear system solver
14
- * interacts with this struct */
15
- typedef struct SCS_A_DATA_MATRIX ScsMatrix;
16
- /* stores the necessary private workspace, only the linear system solver
17
- * interacts with this struct */
18
- typedef struct SCS_LIN_SYS_WORK ScsLinSysWork;
14
+ /* The following abstract structs are implemented later. */
19
15
 
20
- typedef struct SCS_PROBLEM_DATA ScsData;
21
- typedef struct SCS_SETTINGS ScsSettings;
22
- typedef struct SCS_SOL_VARS ScsSolution;
23
- typedef struct SCS_INFO ScsInfo;
24
- typedef struct SCS_SCALING ScsScaling;
25
- typedef struct SCS_WORK ScsWork;
26
- typedef struct SCS_RESIDUALS ScsResiduals;
27
- typedef struct SCS_CONE ScsCone;
28
- typedef struct SCS_ACCEL_WORK ScsAccelWork;
16
+ /** Struct containing acceleration workspace. Implemented by acceleration. */
17
+ typedef struct ACCEL_WORK AaWork;
18
+ /** Struct containing cone projection workspace. Implemented by cones. */
29
19
  typedef struct SCS_CONE_WORK ScsConeWork;
20
+ /** Struct containing linear system workspace. Implemented by linear solver. */
21
+ typedef struct SCS_LIN_SYS_WORK ScsLinSysWork;
22
+ /** Struct containing SCS workspace. Implemented in `scs_work.h`. */
23
+ typedef struct SCS_WORK ScsWork;
30
24
 
31
- /* struct containing problem data */
32
- struct SCS_PROBLEM_DATA {
33
- /* these cannot change for multiple runs for the same call to SCS(init) */
34
- scs_int m, n; /* A has m rows, n cols */
35
- ScsMatrix *A; /* A is supplied in data format specified by linsys solver */
36
-
37
- /* these can change for multiple runs for the same call to SCS(init) */
38
- scs_float *b, *c; /* dense arrays for b (size m), c (size n) */
39
-
40
- ScsSettings *stgs; /* contains solver settings specified by user */
41
- };
42
-
43
- /* ScsSettings struct */
44
- struct SCS_SETTINGS {
45
- /* settings parameters: default suggested input */
46
-
47
- /* these *cannot* change for multiple runs with the same call to SCS(init) */
48
- scs_int normalize; /* boolean, heuristic data rescaling: 1 */
49
- scs_float scale; /* if normalized, rescales by this factor: 5 */
50
- scs_float rho_x; /* x equality constraint scaling: 1e-3 */
51
-
52
- /* these can change for multiple runs with the same call to SCS(init) */
53
- scs_int max_iters; /* maximum iterations to take: 2500 */
54
- scs_float eps; /* convergence tolerance: 1e-3 */
55
- scs_float alpha; /* relaxation parameter: 1.8 */
56
- scs_float cg_rate; /* for indirect, tolerance goes down like
57
- (1/iter)^cg_rate: 2 */
58
- scs_int verbose; /* boolean, write out progress: 1 */
59
- scs_int warm_start; /* boolean, warm start (put initial guess in ScsSolution
60
- struct): 0 */
61
- scs_int acceleration_lookback; /* memory for acceleration */
62
- const char* write_data_filename; /* string, if set will dump data */
63
- };
64
-
65
- /* NB: rows of data matrix A must be specified in this exact order */
66
- struct SCS_CONE {
67
- scs_int f; /* number of linear equality constraints */
68
- scs_int l; /* length of LP cone */
69
- scs_int *q; /* array of second-order cone constraints */
70
- scs_int qsize; /* length of SOC array */
71
- scs_int *s; /* array of SD constraints */
72
- scs_int ssize; /* length of SD array */
73
- scs_int ep; /* number of primal exponential cone triples */
74
- scs_int ed; /* number of dual exponential cone triples */
75
- scs_float *p; /* array of power cone params, must be \in [-1, 1],
76
- negative values are interpreted as specifying the
77
- dual cone */
78
- scs_int psize; /* number of (primal and dual) power cone triples */
79
- };
80
-
81
- /* contains primal-dual solution arrays */
82
- struct SCS_SOL_VARS {
83
- scs_float *x, *y, *s;
84
- };
85
-
86
- /* contains terminating information */
87
- struct SCS_INFO {
88
- scs_int iter; /* number of iterations taken */
89
- char status[32]; /* status string, e.g. 'Solved' */
90
- scs_int status_val; /* status as scs_int, defined in glbopts.h */
91
- scs_float pobj; /* primal objective */
92
- scs_float dobj; /* dual objective */
93
- scs_float res_pri; /* primal equality residual */
94
- scs_float res_dual; /* dual equality residual */
95
- scs_float res_infeas; /* infeasibility cert residual */
96
- scs_float res_unbdd; /* unbounded cert residual */
97
- scs_float rel_gap; /* relative duality gap */
98
- scs_float setup_time; /* time taken for setup phase (milliseconds) */
99
- scs_float solve_time; /* time taken for solve phase (milliseconds) */
100
- };
101
-
102
- /* contains normalization variables */
103
- struct SCS_SCALING {
104
- scs_float *D, *E; /* for normalization */
105
- scs_float mean_norm_row_a, mean_norm_col_a;
106
- };
25
+ /* SCS returns one of the following integer exit flags: */
26
+ #define SCS_INFEASIBLE_INACCURATE (-7)
27
+ #define SCS_UNBOUNDED_INACCURATE (-6)
28
+ #define SCS_SIGINT (-5)
29
+ #define SCS_FAILED (-4)
30
+ #define SCS_INDETERMINATE (-3)
31
+ #define SCS_INFEASIBLE (-2) /* primal infeasible, dual unbounded */
32
+ #define SCS_UNBOUNDED (-1) /* primal unbounded, dual infeasible */
33
+ #define SCS_UNFINISHED (0) /* never returned, used as placeholder */
34
+ #define SCS_SOLVED (1)
35
+ #define SCS_SOLVED_INACCURATE (2)
107
36
 
108
- /*
109
- * main library api's:
110
- * SCS(init): allocates memory etc (e.g., factorize matrix [I A; A^T -I])
111
- * SCS(solve): can be called many times with different b,c data per init call
112
- * SCS(finish): cleans up the memory (one per init call)
37
+ /** This defines the data matrices which should be supplied in compressed
38
+ * sparse column format with zero based indexing.
113
39
  */
114
- ScsWork *SCS(init)(const ScsData *d, const ScsCone *k, ScsInfo *info);
115
- scs_int SCS(solve)(ScsWork *w, const ScsData *d, const ScsCone *k,
116
- ScsSolution *sol, ScsInfo *info);
117
- void SCS(finish)(ScsWork *w);
118
- /* scs calls SCS(init), SCS(solve), and SCS(finish) */
119
- scs_int scs(const ScsData *d, const ScsCone *k, ScsSolution *sol,
120
- ScsInfo *info);
121
-
122
- const char *SCS(version)(void);
123
- size_t SCS(sizeof_int)(void);
124
- size_t SCS(sizeof_float)(void);
125
-
126
- /* the following structs are not exposed to user */
127
-
128
- /* workspace for SCS */
129
- struct SCS_WORK {
130
- /* x_prev = x from previous iteration */
131
- scs_float *u, *u_best, *v, *v_best, *u_t, *u_prev, *v_prev;
132
- scs_float *h, *g, *pr, *dr;
133
- scs_float g_th, sc_b, sc_c, nm_b, nm_c, best_max_residual;
134
- scs_float *b, *c; /* (possibly normalized) b and c vectors */
135
- scs_int m, n; /* A has m rows, n cols */
136
- ScsMatrix *A; /* (possibly normalized) A matrix */
137
- ScsLinSysWork *p; /* struct populated by linear system solver */
138
- ScsSettings *stgs; /* contains solver settings specified by user */
139
- ScsScaling *scal; /* contains the re-scaling data */
140
- ScsConeWork *cone_work; /* workspace for the cone projection step */
141
- AaWork *accel; /* Struct for acceleration workspace */
142
- };
143
-
144
- /* to hold residual information (unnormalized) */
145
- struct SCS_RESIDUALS {
146
- scs_int last_iter;
147
- scs_float res_dual;
40
+ typedef struct {
41
+ /** Matrix values, size: number of non-zeros. */
42
+ scs_float *x;
43
+ /** Matrix row indices, size: number of non-zeros. */
44
+ scs_int *i;
45
+ /** Matrix column pointers, size: `n+1`. */
46
+ scs_int *p;
47
+ /** Number of rows. */
48
+ scs_int m;
49
+ /** Number of columns. */
50
+ scs_int n;
51
+ } ScsMatrix;
52
+
53
+ /** Struct containing all settings. */
54
+ typedef struct {
55
+ /** Whether to heuristically rescale the data before solve. */
56
+ scs_int normalize;
57
+ /** Initial dual scaling factor (may be updated if adaptive_scale is on). */
58
+ scs_float scale;
59
+ /** Whether to adaptively update `scale`. */
60
+ scs_int adaptive_scale;
61
+ /** Primal constraint scaling factor. */
62
+ scs_float rho_x;
63
+ /** Maximum iterations to take. */
64
+ scs_int max_iters;
65
+ /** Absolute convergence tolerance. */
66
+ scs_float eps_abs;
67
+ /** Relative convergence tolerance. */
68
+ scs_float eps_rel;
69
+ /** Infeasible convergence tolerance. */
70
+ scs_float eps_infeas;
71
+ /** Douglas-Rachford relaxation parameter. */
72
+ scs_float alpha;
73
+ /** Time limit in secs (can be fractional). */
74
+ scs_float time_limit_secs;
75
+ /** Whether to log progress to stdout. */
76
+ scs_int verbose;
77
+ /** Whether to use warm start (put initial guess in ScsSolution struct). */
78
+ scs_int warm_start;
79
+ /** Memory for acceleration. */
80
+ scs_int acceleration_lookback;
81
+ /** Interval to apply acceleration. */
82
+ scs_int acceleration_interval;
83
+ /** String, if set will dump raw prob data to this file. */
84
+ const char *write_data_filename;
85
+ /** String, if set will log data to this csv file (makes SCS very slow). */
86
+ const char *log_csv_filename;
87
+ } ScsSettings;
88
+
89
+ /** Struct containing problem data. */
90
+ typedef struct {
91
+ /** A has `m` rows. */
92
+ scs_int m;
93
+ /** A has `n` cols, P has `n` cols and `n` rows. */
94
+ scs_int n;
95
+ /** A is supplied in CSC format (size `m` x `n`). */
96
+ ScsMatrix *A;
97
+ /** P is supplied in CSC format (size `n` x `n`), must be symmetric positive
98
+ * semidefinite. Only pass in the upper triangular entries. If `P = 0` then
99
+ * set `P = SCS_NULL`. */
100
+ ScsMatrix *P;
101
+ /** Dense array for b (size `m`). */
102
+ scs_float *b;
103
+ /** Dense array for c (size `n`). */
104
+ scs_float *c;
105
+ } ScsData;
106
+
107
+ /** Cone data. Rows of data matrix `A` must be specified in this exact order. */
108
+ typedef struct {
109
+ /** Number of linear equality constraints (primal zero, dual free). */
110
+ scs_int z;
111
+ /** Number of positive orthant cones. */
112
+ scs_int l;
113
+ /** Upper box values, `len(bu) = len(bl) = max(bsize-1, 0)`. */
114
+ scs_float *bu;
115
+ /** Lower box values, `len(bu) = len(bl) = max(bsize-1, 0)`. */
116
+ scs_float *bl;
117
+ /** Total length of box cone (includes scale `t`). */
118
+ scs_int bsize;
119
+ /** Array of second-order cone constraints. */
120
+ scs_int *q;
121
+ /** Length of second-order cone array `q`. */
122
+ scs_int qsize;
123
+ /** Array of semidefinite cone constraints. */
124
+ scs_int *s;
125
+ /** Length of semidefinite constraints array `s`. */
126
+ scs_int ssize;
127
+ /** Number of primal exponential cone triples. */
128
+ scs_int ep;
129
+ /** Number of dual exponential cone triples. */
130
+ scs_int ed;
131
+ /** Array of power cone params, must be in `[-1, 1]`, negative values are
132
+ * interpreted as specifying the dual cone. */
133
+ scs_float *p;
134
+ /** Number of (primal and dual) power cone triples. */
135
+ scs_int psize;
136
+ } ScsCone;
137
+
138
+ /** Contains primal-dual solution arrays or a certificate of infeasibility.
139
+ * Check the exit flag to determine whether this contains a solution or a
140
+ * certificate. If when passed into SCS the members `x`, `y`, `s` are
141
+ * NULL then SCS will allocate memory for them which should be managed
142
+ * by the user to prevent memory leaks.
143
+ */
144
+ typedef struct {
145
+ /** Primal variable. */
146
+ scs_float *x;
147
+ /** Dual variable. */
148
+ scs_float *y;
149
+ /** Slack variable. */
150
+ scs_float *s;
151
+ } ScsSolution;
152
+
153
+ /** Contains information about the solve run at termination. */
154
+ typedef struct {
155
+ /** Number of iterations taken. */
156
+ scs_int iter;
157
+ /** Status string, e.g. 'solved'. */
158
+ char status[128];
159
+ /** Linear system solver used. */
160
+ char lin_sys_solver[128];
161
+ /** Status as scs_int, defined in glbopts.h. */
162
+ scs_int status_val;
163
+ /** Number of updates to scale. */
164
+ scs_int scale_updates;
165
+ /** Primal objective. */
166
+ scs_float pobj;
167
+ /** Dual objective. */
168
+ scs_float dobj;
169
+ /** Primal equality residual. */
148
170
  scs_float res_pri;
171
+ /** Dual equality residual. */
172
+ scs_float res_dual;
173
+ /** Duality gap. */
174
+ scs_float gap;
175
+ /** Infeasibility cert residual. */
149
176
  scs_float res_infeas;
150
- scs_float res_unbdd;
151
- scs_float rel_gap;
152
- scs_float ct_x_by_tau; /* not divided by tau */
153
- scs_float bt_y_by_tau; /* not divided by tau */
154
- scs_float tau;
155
- scs_float kap;
156
- };
177
+ /** Unbounded cert residual. */
178
+ scs_float res_unbdd_a;
179
+ /** Unbounded cert residual. */
180
+ scs_float res_unbdd_p;
181
+ /** Time taken for setup phase (milliseconds). */
182
+ scs_float setup_time;
183
+ /** Time taken for solve phase (milliseconds). */
184
+ scs_float solve_time;
185
+ /** Final scale parameter. */
186
+ scs_float scale;
187
+ /** Complementary slackness. */
188
+ scs_float comp_slack;
189
+ /** Number of rejected AA steps. */
190
+ scs_int rejected_accel_steps;
191
+ /** Number of accepted AA steps. */
192
+ scs_int accepted_accel_steps;
193
+ /** Total time (milliseconds) spent in the linear system solver. */
194
+ scs_float lin_sys_time;
195
+ /** Total time (milliseconds) spent in the cone projection. */
196
+ scs_float cone_time;
197
+ /** Total time (milliseconds) spent in the acceleration routine. */
198
+ scs_float accel_time;
199
+ } ScsInfo;
200
+
201
+ /*
202
+ * Main library API.
203
+ */
204
+
205
+ /**
206
+ * Initialize SCS and allocate memory.
207
+ *
208
+ * All the inputs must be already allocated in memory before calling.
209
+ *
210
+ * It performs:
211
+ * - data and settings validation
212
+ * - problem data scaling
213
+ * - automatic parameters tuning (if enabled)
214
+ * - setup linear system solver:
215
+ * - direct solver: KKT matrix factorization is performed here
216
+ * - indirect solver: KKT matrix preconditioning is performed here
217
+ * - solve the linear system for the `r` vector in the paper.
218
+ *
219
+ *
220
+ * @param d Problem data.
221
+ * @param k Cone data.
222
+ * @param stgs SCS solver settings.
223
+ * @return Solver work struct.
224
+ */
225
+ ScsWork *scs_init(const ScsData *d, const ScsCone *k, const ScsSettings *stgs);
226
+
227
+ /**
228
+ * Solve quadratic cone program initialized by scs_init.
229
+ *
230
+ * @param w Workspace allocated by init.
231
+ * @param sol Solver solution struct, will contain solution at termination.
232
+ * @param info Solver info reporting.
233
+ * @return Flag containing problem status (see \a glbopts.h).
234
+ */
235
+ scs_int scs_solve(ScsWork *w, ScsSolution *sol, ScsInfo *info);
236
+
237
+ /**
238
+ * Clean up allocated SCS workspace.
239
+ *
240
+ * @param w Workspace allocated by init, will be deallocated.
241
+ */
242
+ void scs_finish(ScsWork *w);
243
+
244
+ /**
245
+ * Solve quadratic cone program defined by data in d and cone k.
246
+ *
247
+ * All the inputs must already be allocated in memory before calling.
248
+ *
249
+ * @param d Problem data.
250
+ * @param k Cone data.
251
+ * @param stgs SCS solver settings.
252
+ * @param sol Solution will be stored here. If members `x`, `y`, `s` are
253
+ * NULL then SCS will allocate memory for them.
254
+ * @param info Information about the solve will be stored here.
255
+ * @return Flag that determines solve type (see \a glbopts.h).
256
+ */
257
+ scs_int scs(const ScsData *d, const ScsCone *k, const ScsSettings *stgs,
258
+ ScsSolution *sol, ScsInfo *info);
259
+
260
+ /**
261
+ * Helper function to set all settings to default values (see \a glbopts.h).
262
+ *
263
+ * @param stgs Settings struct that will be populated.
264
+ */
265
+ void scs_set_default_settings(ScsSettings *stgs);
266
+
267
+ /**
268
+ * Helper function simply returns the current version of SCS as a string.
269
+ *
270
+ * @return SCS version as a string.
271
+ */
272
+ const char *scs_version(void);
157
273
 
158
274
  #ifdef __cplusplus
159
275
  }
@@ -0,0 +1,34 @@
1
+ /*
2
+ * Definitions of primitive types used in SCS.
3
+ */
4
+
5
+ #ifndef SCS_TYPES_H_GUARD
6
+ #define SCS_TYPES_H_GUARD
7
+
8
+ #ifdef __cplusplus
9
+ extern "C" {
10
+ #endif
11
+
12
+ #ifdef DLONG
13
+ /*#ifdef _WIN64
14
+ #include <stdint.h>
15
+ typedef int64_t scs_int;
16
+ #else
17
+ typedef long scs_int;
18
+ #endif
19
+ */
20
+ typedef long long scs_int;
21
+ #else
22
+ typedef int scs_int;
23
+ #endif
24
+
25
+ #ifndef SFLOAT
26
+ typedef double scs_float;
27
+ #else
28
+ typedef float scs_float;
29
+ #endif
30
+
31
+ #ifdef __cplusplus
32
+ }
33
+ #endif
34
+ #endif
@@ -0,0 +1,83 @@
1
+ /*
2
+ * Define ScsWork and related internal-only structs (not part of external API).
3
+ */
4
+
5
+ #ifndef SCS_WORK_H_GUARD
6
+ #define SCS_WORK_H_GUARD
7
+
8
+ #ifdef __cplusplus
9
+ extern "C" {
10
+ #endif
11
+
12
+ /** Contains normalization variables. */
13
+ typedef struct {
14
+ scs_float *D, *E; /* for normalization */
15
+ scs_int m; /* Length of D */
16
+ scs_int n; /* Length of E */
17
+ scs_float primal_scale, dual_scale;
18
+ } ScsScaling;
19
+
20
+ /** Holds residual information. */
21
+ typedef struct {
22
+ scs_int last_iter;
23
+ scs_float xt_p_x; /* x' P x */
24
+ scs_float xt_p_x_tau; /* x'Px * tau^2 *not* divided out */
25
+ scs_float ctx;
26
+ scs_float ctx_tau; /* tau *not* divided out */
27
+ scs_float bty;
28
+ scs_float bty_tau; /* tau *not* divided out */
29
+ scs_float pobj; /* primal objective */
30
+ scs_float dobj; /* dual objective */
31
+ scs_float gap; /* pobj - dobj */
32
+ scs_float tau;
33
+ scs_float kap;
34
+ scs_float res_pri;
35
+ scs_float res_dual;
36
+ scs_float res_infeas;
37
+ scs_float res_unbdd_p;
38
+ scs_float res_unbdd_a;
39
+ /* tau NOT divided out */
40
+ scs_float *ax, *ax_s, *px, *aty, *ax_s_btau, *px_aty_ctau;
41
+ } ScsResiduals;
42
+
43
+ /** Workspace for SCS */
44
+ struct SCS_WORK {
45
+ /* x_prev = x from previous iteration */
46
+ scs_int time_limit_reached; /* set if the time-limit is reached */
47
+ scs_float *u, *u_t;
48
+ scs_float *v, *v_prev;
49
+ scs_float *rsk; /* rsk [ r; s; kappa ] */
50
+ scs_float *h; /* h = [c; b] */
51
+ scs_float *g; /* g = (I + M)^{-1} h */
52
+ scs_float *lin_sys_warm_start; /* linear system warm-start (indirect only) */
53
+ scs_float *diag_r; /* vector of R matrix diagonals (affects cone proj) */
54
+ AaWork *accel; /* struct for acceleration workspace */
55
+ scs_float *b_orig, *c_orig; /* original b and c vectors */
56
+ scs_float *b_normalized, *c_normalized; /* normalized b and c vectors */
57
+ scs_int m, n; /* A has m rows, n cols */
58
+ ScsMatrix *A; /* (possibly normalized) A matrix */
59
+ ScsMatrix *P; /* (possibly normalized) P matrix */
60
+ ScsLinSysWork *p; /* struct populated by linear system solver */
61
+ ScsScaling *scal; /* contains the re-scaling data */
62
+ ScsConeWork *cone_work; /* workspace for the cone projection step */
63
+ /* normalized and unnormalized residuals */
64
+ ScsResiduals *r_orig, *r_normalized;
65
+ /* track x,y,s as alg progresses, tau *not* divided out */
66
+ ScsSolution *xys_orig, *xys_normalized;
67
+ /* updating scale params workspace */
68
+ scs_float sum_log_scale_factor;
69
+ scs_int last_scale_update_iter, n_log_scale_factor, scale_updates;
70
+ /* aa norm stat */
71
+ scs_float aa_norm;
72
+ scs_int rejected_accel_steps, accepted_accel_steps;
73
+ scs_float setup_time; /* time taken for setup phase (milliseconds) */
74
+ scs_float scale; /* current scale parameter */
75
+ const ScsData *d;
76
+ const ScsCone *k;
77
+ const ScsSettings *stgs; /* contains solver settings specified by user */
78
+ };
79
+
80
+ #ifdef __cplusplus
81
+ }
82
+ #endif
83
+ #endif
@@ -5,10 +5,10 @@
5
5
  extern "C" {
6
6
  #endif
7
7
 
8
- #include <stdio.h>
9
- #include <stdlib.h>
10
8
  #include "cones.h"
11
9
  #include "scs.h"
10
+ #include <stdio.h>
11
+ #include <stdlib.h>
12
12
 
13
13
  /* timing code courtesy of A. Domahidi */
14
14
  #if (defined NOTIMER)
@@ -41,23 +41,11 @@ typedef struct SCS(timer) {
41
41
 
42
42
  #endif
43
43
 
44
- #if EXTRA_VERBOSE > 1
45
- extern SCS(timer) global_timer;
46
- #endif
47
-
48
44
  /* these all return milli-seconds */
49
45
  void SCS(tic)(SCS(timer) * t);
50
- scs_float SCS(toc)(SCS(timer) * t);
51
- scs_float SCS(str_toc)(char *str, SCS(timer) * t);
52
46
  scs_float SCS(tocq)(SCS(timer) * t);
53
-
54
- void SCS(print_cone_data)(const ScsCone *k);
55
- void SCS(print_data)(const ScsData *d);
56
- void SCS(print_work)(const ScsWork *w);
57
- void SCS(print_array)(const scs_float *arr, scs_int n, const char *name);
58
- void SCS(set_default_settings)(ScsData *d);
59
47
  void SCS(free_sol)(ScsSolution *sol);
60
- void SCS(free_data)(ScsData *d, ScsCone *k);
48
+ void SCS(free_data)(ScsData *d, ScsCone *k, ScsSettings *stgs);
61
49
 
62
50
  #ifdef __cplusplus
63
51
  }