scs 0.2.1 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/LICENSE.txt +18 -18
  4. data/README.md +12 -7
  5. data/lib/scs/ffi.rb +30 -13
  6. data/lib/scs/solver.rb +32 -14
  7. data/lib/scs/version.rb +1 -1
  8. data/vendor/scs/CITATION.cff +39 -0
  9. data/vendor/scs/CMakeLists.txt +272 -0
  10. data/vendor/scs/Makefile +24 -15
  11. data/vendor/scs/README.md +8 -216
  12. data/vendor/scs/include/aa.h +67 -23
  13. data/vendor/scs/include/cones.h +17 -17
  14. data/vendor/scs/include/glbopts.h +98 -32
  15. data/vendor/scs/include/linalg.h +2 -4
  16. data/vendor/scs/include/linsys.h +58 -44
  17. data/vendor/scs/include/normalize.h +3 -3
  18. data/vendor/scs/include/rw.h +8 -2
  19. data/vendor/scs/include/scs.h +293 -133
  20. data/vendor/scs/include/util.h +3 -15
  21. data/vendor/scs/linsys/cpu/direct/private.c +220 -224
  22. data/vendor/scs/linsys/cpu/direct/private.h +13 -7
  23. data/vendor/scs/linsys/cpu/indirect/private.c +177 -110
  24. data/vendor/scs/linsys/cpu/indirect/private.h +8 -4
  25. data/vendor/scs/linsys/csparse.c +87 -0
  26. data/vendor/scs/linsys/csparse.h +34 -0
  27. data/vendor/scs/linsys/external/amd/SuiteSparse_config.c +1 -1
  28. data/vendor/scs/linsys/external/amd/amd_internal.h +1 -1
  29. data/vendor/scs/linsys/external/qdldl/changes +2 -0
  30. data/vendor/scs/linsys/external/qdldl/qdldl.c +29 -46
  31. data/vendor/scs/linsys/external/qdldl/qdldl.h +33 -41
  32. data/vendor/scs/linsys/external/qdldl/qdldl_types.h +11 -3
  33. data/vendor/scs/linsys/gpu/gpu.c +58 -21
  34. data/vendor/scs/linsys/gpu/gpu.h +66 -28
  35. data/vendor/scs/linsys/gpu/indirect/private.c +368 -154
  36. data/vendor/scs/linsys/gpu/indirect/private.h +26 -12
  37. data/vendor/scs/linsys/scs_matrix.c +498 -0
  38. data/vendor/scs/linsys/scs_matrix.h +70 -0
  39. data/vendor/scs/scs.mk +13 -9
  40. data/vendor/scs/src/aa.c +384 -109
  41. data/vendor/scs/src/cones.c +440 -353
  42. data/vendor/scs/src/ctrlc.c +15 -5
  43. data/vendor/scs/src/linalg.c +84 -28
  44. data/vendor/scs/src/normalize.c +22 -64
  45. data/vendor/scs/src/rw.c +161 -22
  46. data/vendor/scs/src/scs.c +768 -561
  47. data/vendor/scs/src/scs_version.c +9 -3
  48. data/vendor/scs/src/util.c +37 -106
  49. data/vendor/scs/test/minunit.h +17 -8
  50. data/vendor/scs/test/problem_utils.h +176 -14
  51. data/vendor/scs/test/problems/degenerate.h +130 -0
  52. data/vendor/scs/test/problems/hs21_tiny_qp.h +124 -0
  53. data/vendor/scs/test/problems/hs21_tiny_qp_rw.h +116 -0
  54. data/vendor/scs/test/problems/infeasible_tiny_qp.h +100 -0
  55. data/vendor/scs/test/problems/qafiro_tiny_qp.h +199 -0
  56. data/vendor/scs/test/problems/random_prob +0 -0
  57. data/vendor/scs/test/problems/random_prob.h +45 -0
  58. data/vendor/scs/test/problems/rob_gauss_cov_est.h +188 -31
  59. data/vendor/scs/test/problems/small_lp.h +13 -14
  60. data/vendor/scs/test/problems/test_fails.h +43 -0
  61. data/vendor/scs/test/problems/unbounded_tiny_qp.h +82 -0
  62. data/vendor/scs/test/random_socp_prob.c +54 -53
  63. data/vendor/scs/test/rng.h +109 -0
  64. data/vendor/scs/test/run_from_file.c +19 -10
  65. data/vendor/scs/test/run_tests.c +27 -3
  66. metadata +25 -97
  67. data/vendor/scs/linsys/amatrix.c +0 -305
  68. data/vendor/scs/linsys/amatrix.h +0 -36
  69. data/vendor/scs/linsys/amatrix.o +0 -0
  70. data/vendor/scs/linsys/cpu/direct/private.o +0 -0
  71. data/vendor/scs/linsys/cpu/indirect/private.o +0 -0
  72. data/vendor/scs/linsys/external/amd/SuiteSparse_config.o +0 -0
  73. data/vendor/scs/linsys/external/amd/amd_1.o +0 -0
  74. data/vendor/scs/linsys/external/amd/amd_2.o +0 -0
  75. data/vendor/scs/linsys/external/amd/amd_aat.o +0 -0
  76. data/vendor/scs/linsys/external/amd/amd_control.o +0 -0
  77. data/vendor/scs/linsys/external/amd/amd_defaults.o +0 -0
  78. data/vendor/scs/linsys/external/amd/amd_dump.o +0 -0
  79. data/vendor/scs/linsys/external/amd/amd_global.o +0 -0
  80. data/vendor/scs/linsys/external/amd/amd_info.o +0 -0
  81. data/vendor/scs/linsys/external/amd/amd_order.o +0 -0
  82. data/vendor/scs/linsys/external/amd/amd_post_tree.o +0 -0
  83. data/vendor/scs/linsys/external/amd/amd_postorder.o +0 -0
  84. data/vendor/scs/linsys/external/amd/amd_preprocess.o +0 -0
  85. data/vendor/scs/linsys/external/amd/amd_valid.o +0 -0
  86. data/vendor/scs/linsys/external/qdldl/qdldl.o +0 -0
  87. data/vendor/scs/src/aa.o +0 -0
  88. data/vendor/scs/src/cones.o +0 -0
  89. data/vendor/scs/src/ctrlc.o +0 -0
  90. data/vendor/scs/src/linalg.o +0 -0
  91. data/vendor/scs/src/normalize.o +0 -0
  92. data/vendor/scs/src/rw.o +0 -0
  93. data/vendor/scs/src/scs.o +0 -0
  94. data/vendor/scs/src/scs_version.o +0 -0
  95. data/vendor/scs/src/util.o +0 -0
  96. data/vendor/scs/test/data/small_random_socp +0 -0
  97. data/vendor/scs/test/problems/small_random_socp.h +0 -33
  98. data/vendor/scs/test/run_tests +0 -2
@@ -12,8 +12,8 @@ extern "C" {
12
12
  #endif
13
13
 
14
14
  /* SCS VERSION NUMBER ---------------------------------------------- */
15
- #define SCS_VERSION \
16
- ("2.1.2") /* string literals automatically null-terminated */
15
+ #define SCS_VERSION \
16
+ ("3.0.0") /* string literals automatically null-terminated */
17
17
 
18
18
  /* SCS returns one of the following integers: */
19
19
  #define SCS_INFEASIBLE_INACCURATE (-7)
@@ -27,18 +27,28 @@ extern "C" {
27
27
  #define SCS_SOLVED (1)
28
28
  #define SCS_SOLVED_INACCURATE (2)
29
29
 
30
+ /* verbosity level */
31
+ #ifndef VERBOSITY
32
+ #define VERBOSITY (0)
33
+ #endif
34
+
30
35
  /* DEFAULT SOLVER PARAMETERS AND SETTINGS -------------------------- */
31
- #define MAX_ITERS (5000)
32
- #define EPS (1E-5)
36
+ #define MAX_ITERS (100000)
37
+ #define EPS_REL (1E-4)
38
+ #define EPS_ABS (1E-4)
39
+ #define EPS_INFEAS (1E-7)
33
40
  #define ALPHA (1.5)
34
- #define RHO_X (1E-3)
35
- #define SCALE (1.0)
36
- #define CG_RATE (2.0)
41
+ #define RHO_X (1E-6)
42
+ #define SCALE (0.1)
37
43
  #define VERBOSE (1)
38
44
  #define NORMALIZE (1)
39
45
  #define WARM_START (0)
40
46
  #define ACCELERATION_LOOKBACK (10)
47
+ #define ACCELERATION_INTERVAL (10)
48
+ #define ADAPTIVE_SCALE (1)
41
49
  #define WRITE_DATA_FILENAME (0)
50
+ #define LOG_CSV_FILENAME (0)
51
+ #define TIME_LIMIT_SECS (0.)
42
52
 
43
53
  /* redefine printfs and memory allocators as needed */
44
54
  #ifdef MATLAB_MEX_FILE
@@ -50,19 +60,30 @@ extern "C" {
50
60
  #define _scs_realloc mxRealloc
51
61
  #elif defined PYTHON
52
62
  #include <Python.h>
53
- #include <stdlib.h>
54
- #define scs_printf(...) \
55
- { \
56
- PyGILState_STATE gilstate = PyGILState_Ensure(); \
57
- PySys_WriteStdout(__VA_ARGS__); \
58
- PyGILState_Release(gilstate); \
63
+ #define scs_printf(...) \
64
+ { \
65
+ PyGILState_STATE gilstate = PyGILState_Ensure(); \
66
+ PySys_WriteStdout(__VA_ARGS__); \
67
+ PyGILState_Release(gilstate); \
59
68
  }
60
- #define _scs_printf printf
61
- #define _scs_free free
62
- #define _scs_malloc malloc
63
- #define _scs_calloc calloc
64
- #define _scs_realloc realloc
65
- #elif (defined(USING_R))
69
+ /* only for SuiteSparse */
70
+ #define _scs_printf PySys_WriteStdout
71
+ #if PY_MAJOR_VERSION >= 3
72
+ #define _scs_free PyMem_RawFree
73
+ #define _scs_malloc PyMem_RawMalloc
74
+ #define _scs_realloc PyMem_RawRealloc
75
+ #define _scs_calloc PyMem_RawCalloc
76
+ #else
77
+ #define _scs_free PyMem_Free
78
+ #define _scs_malloc PyMem_Malloc
79
+ #define _scs_realloc PyMem_Realloc
80
+ static inline void *_scs_calloc(size_t count, size_t size) {
81
+ void *obj = PyMem_Malloc(count * size);
82
+ memset(obj, 0, count * size);
83
+ return obj;
84
+ }
85
+ #endif
86
+ #elif defined R_LANG
66
87
  #include <R_ext/Print.h> /* Rprintf etc */
67
88
  #include <stdio.h>
68
89
  #include <stdlib.h>
@@ -86,21 +107,22 @@ extern "C" {
86
107
  #define _scs_printf scs_printf
87
108
  #endif
88
109
 
89
- #define scs_free(x) \
90
- _scs_free(x); \
110
+ #define scs_free(x) \
111
+ _scs_free(x); \
91
112
  x = SCS_NULL
92
113
  #define scs_malloc(x) _scs_malloc(x)
93
114
  #define scs_calloc(x, y) _scs_calloc(x, y)
94
115
  #define scs_realloc(x, y) _scs_realloc(x, y)
95
116
 
96
117
  #ifdef DLONG
97
- #ifdef _WIN64
118
+ /*#ifdef _WIN64
98
119
  #include <stdint.h>
99
120
  typedef int64_t scs_int;
100
- /* typedef long scs_int; */
101
121
  #else
102
122
  typedef long scs_int;
103
123
  #endif
124
+ */
125
+ typedef long long scs_int;
104
126
  #else
105
127
  typedef int scs_int;
106
128
  #endif
@@ -153,23 +175,67 @@ typedef float scs_float;
153
175
  #endif
154
176
  #endif
155
177
 
178
+ /* Force SCS to treat the problem as (non-homogeneous) feasible for this many */
179
+ /* iters. This acts like a warm-start that biases towards feasibility, which */
180
+ /* is the most common use-case */
181
+ #define FEASIBLE_ITERS (1)
182
+
183
+ /* how many iterations between heuristic residual rescaling */
184
+ #define RESCALING_MIN_ITERS (100)
185
+
156
186
  #define EPS_TOL (1E-18)
157
187
  #define SAFEDIV_POS(X, Y) ((Y) < EPS_TOL ? ((X) / EPS_TOL) : (X) / (Y))
158
188
 
159
- #if EXTRA_VERBOSE > 0
189
+ #if VERBOSITY > 0
160
190
  #define PRINT_INTERVAL (1)
161
191
  #define CONVERGED_INTERVAL (1)
162
192
  #else
193
+
163
194
  /* print summary output every this num iterations */
164
- #define PRINT_INTERVAL (100)
195
+ #define PRINT_INTERVAL (250)
165
196
  /* check for convergence every this num iterations */
166
- #define CONVERGED_INTERVAL (20)
167
- #endif
168
-
169
- /* tolerance at which we declare problem indeterminate */
170
- #define INDETERMINATE_TOL (1e-9)
171
- /* maintain the iterates at this l2 norm (due to homogeneity) */
172
- #define ITERATE_NORM (10.)
197
+ #define CONVERGED_INTERVAL (25)
198
+ #endif
199
+
200
+ /* maintain the iterates at L2 norm = ITERATE_NORM * sqrt(n+m+1) */
201
+ #define ITERATE_NORM (1.)
202
+
203
+ /* Which norm to use for termination checking etc */
204
+ /* #define NORM SCS(norm_2) */
205
+ #define NORM SCS(norm_inf)
206
+
207
+ /* Factor which is scales tau in the linear system update */
208
+ /* Larger factors prevent tau from moving as much */
209
+ #define TAU_FACTOR (10.)
210
+
211
+ /* Anderson acceleration parameters: */
212
+ #define AA_RELAXATION (1.0)
213
+ #define AA_REGULARIZATION_TYPE_1 (1e-6)
214
+ #define AA_REGULARIZATION_TYPE_2 (1e-10)
215
+ /* Safeguarding norm factor at which we reject AA steps */
216
+ #define AA_SAFEGUARD_FACTOR (1.)
217
+ /* Max allowable AA weight norm */
218
+ #define AA_MAX_WEIGHT_NORM (1e10)
219
+
220
+ /* (Dual) Scale updating parameters */
221
+ #define MAX_SCALE_VALUE (1e6)
222
+ #define MIN_SCALE_VALUE (1e-6)
223
+ #define SCALE_NORM NORM /* what norm to use when computing the scale factor */
224
+
225
+ /* CG == Conjugate gradient */
226
+ /* Linear system tolerances, only used with indirect */
227
+ #define CG_BEST_TOL (1e-12)
228
+ /* This scales the current residuals to get the tolerance we solve the
229
+ * linear system to at each iteration. Lower factors require more CG steps
230
+ * but give better accuracy */
231
+ #define CG_TOL_FACTOR (0.2)
232
+
233
+ /* norm to use when deciding CG convergence */
234
+ #ifndef CG_NORM
235
+ #define CG_NORM SCS(norm_inf)
236
+ #endif
237
+ /* cg tol ~ O(1/k^(CG_RATE)) */
238
+ #define CG_RATE (1.5)
173
239
 
174
240
  #ifdef __cplusplus
175
241
  }
@@ -5,15 +5,13 @@
5
5
  extern "C" {
6
6
  #endif
7
7
 
8
- #include <math.h>
9
8
  #include "scs.h"
9
+ #include <math.h>
10
10
 
11
- void SCS(set_as_scaled_array)(scs_float *x, const scs_float *a,
12
- const scs_float b, scs_int len);
13
11
  void SCS(scale_array)(scs_float *a, const scs_float b, scs_int len);
14
12
  scs_float SCS(dot)(const scs_float *x, const scs_float *y, scs_int len);
15
13
  scs_float SCS(norm_sq)(const scs_float *v, scs_int len);
16
- scs_float SCS(norm)(const scs_float *v, scs_int len);
14
+ scs_float SCS(norm_2)(const scs_float *v, scs_int len);
17
15
  scs_float SCS(norm_inf)(const scs_float *a, scs_int l);
18
16
  void SCS(add_scaled_array)(scs_float *a, const scs_float *b, scs_int n,
19
17
  const scs_float sc);
@@ -7,55 +7,69 @@ extern "C" {
7
7
 
8
8
  #include "scs.h"
9
9
 
10
- /* YOUR LINEAR SYSTEM SOLVER MUST IMPLEMENT THESE METHODS AND SCS_LIN_SYS_WORK
11
- * STRUCT */
10
+ /* This is the API that any new linear system solver must implement */
12
11
 
13
- /* initialize ScsLinSysWork structure and perform any necessary preprocessing */
14
- ScsLinSysWork *SCS(init_lin_sys_work)(const ScsMatrix *A,
15
- const ScsSettings *stgs);
16
- /* solves [d->RHO_X * I A' ; A -I] x = b for x, stores result in b, s contains
17
- * warm-start, iter is current scs iteration count */
18
- scs_int SCS(solve_lin_sys)(const ScsMatrix *A, const ScsSettings *stgs,
19
- ScsLinSysWork *p, scs_float *b, const scs_float *s,
20
- scs_int iter);
21
- /* frees ScsLinSysWork structure and allocated memory in ScsLinSysWork */
22
- void SCS(free_lin_sys_work)(ScsLinSysWork *p);
12
+ /* Struct containing linear system workspace. Implemented by linear solver. */
13
+ /* This typedef is in scs.h */
14
+ /* typedef struct SCS_LIN_SYS_WORK ScsLinSysWork; */
23
15
 
24
- /* forms y += A'*x */
25
- void SCS(accum_by_atrans)(const ScsMatrix *A, ScsLinSysWork *p,
26
- const scs_float *x, scs_float *y);
27
- /* forms y += A*x */
28
- void SCS(accum_by_a)(const ScsMatrix *A, ScsLinSysWork *p, const scs_float *x,
29
- scs_float *y);
16
+ /**
17
+ * Initialize `ScsLinSysWork` structure and perform any necessary preprocessing.
18
+ *
19
+ * @param A A data matrix.
20
+ * @param P P data matrix.
21
+ * @param rho_y_vec `rho_y > 0` diagonal entries.
22
+ * @param rho_x `rho_x > 0` float.
23
+ * @return Linear system solver workspace.
24
+ *
25
+ */
26
+ ScsLinSysWork *SCS(init_lin_sys_work)(const ScsMatrix *A, const ScsMatrix *P,
27
+ scs_float *rho_y_vec, scs_float rho_x);
30
28
 
31
- /* returns negative num if input data is invalid */
32
- scs_int SCS(validate_lin_sys)(const ScsMatrix *A);
29
+ /**
30
+ * Frees `ScsLinSysWork` structure and associated allocated memory.
31
+ *
32
+ * @param w Linear system private workspace.
33
+ */
34
+ void SCS(free_lin_sys_work)(ScsLinSysWork *w);
33
35
 
34
- /* returns string describing method, can return null, if not null free will be
35
- * called on output */
36
- char *SCS(get_lin_sys_method)(const ScsMatrix *A, const ScsSettings *stgs);
37
- /* returns string containing summary information about linear system solves, can
38
- * return null, if not null free will be called on output */
39
- char *SCS(get_lin_sys_summary)(ScsLinSysWork *p, const ScsInfo *info);
36
+ /**
37
+ * Solves the linear system required by SCS at each iteration:
38
+ * \f[
39
+ * \begin{bmatrix}
40
+ * (\rho_x I + P) & A^\top \\
41
+ * A & -\mathrm{diag}(\rho_y) \\
42
+ * \end{bmatrix} x = b
43
+ * \f]
44
+ *
45
+ * for `x`. Overwrites `b` with result.
46
+ *
47
+ * @param w Linear system private workspace.
48
+ * @param b Right hand side, contains solution at the end.
49
+ * @param s Contains warm-start (may be NULL).
50
+ * @param tol Tolerance required for the system solve.
51
+ * @return status < 0 indicates failure.
52
+ *
53
+ */
54
+ scs_int SCS(solve_lin_sys)(ScsLinSysWork *w, scs_float *b, const scs_float *s,
55
+ scs_float tol);
56
+ /**
57
+ * Update the linsys workspace when `rho_y_vec` is changed. For example, a
58
+ * direct method for solving the linear system might need to update the
59
+ * factorization of the matrix.
60
+ *
61
+ * @param w Linear system private workspace.
62
+ * @param rho_y_vec `rho_y` diagonal entries.
63
+ *
64
+ */
65
+ void SCS(update_lin_sys_rho_y_vec)(ScsLinSysWork *w, scs_float *rho_y_vec);
40
66
 
41
- /* Normalization routines, used if d->NORMALIZE is true */
42
- /* normalizes A matrix, sets w->E and w->D diagonal scaling matrices, Anew =
43
- * d->SCALE * (D^-1)*A*(E^-1) (different to paper which is D*A*E)
44
- * D and E must be all positive entries, D must satisfy cone boundaries
45
- * must set (w->mean_norm_row_a = mean of norms of rows of normalized A) THEN
46
- * scale
47
- * resulting A by d->SCALE */
48
- void SCS(normalize_a)(ScsMatrix *A, const ScsSettings *stgs, const ScsCone *k,
49
- ScsScaling *scal);
50
- /* unnormalizes A matrix, unnormalizes by w->D and w->E and d->SCALE */
51
- void SCS(un_normalize_a)(ScsMatrix *A, const ScsSettings *stgs,
52
- const ScsScaling *scal);
53
- /* to free the memory allocated in ScsMatrix */
54
- void SCS(free_a_matrix)(ScsMatrix *A);
55
-
56
- /* copies A (instead of in-place normalization), returns 0 for failure,
57
- * allocates memory for dstp */
58
- scs_int SCS(copy_a_matrix)(ScsMatrix **dstp, const ScsMatrix *src);
67
+ /**
68
+ * Name of the linear solver.
69
+ *
70
+ * @return name of method.
71
+ */
72
+ const char *SCS(get_lin_sys_method)(void);
59
73
 
60
74
  #ifdef __cplusplus
61
75
  }
@@ -7,10 +7,10 @@ extern "C" {
7
7
 
8
8
  #include "scs.h"
9
9
 
10
- void SCS(normalize_b_c)(ScsWork *w);
11
- void SCS(calc_scaled_resids)(ScsWork *w, ScsResiduals *r);
12
- void SCS(normalize_warm_start)(ScsWork *w);
10
+ void SCS(normalize_sol)(ScsWork *w, ScsSolution *sol);
13
11
  void SCS(un_normalize_sol)(ScsWork *w, ScsSolution *sol);
12
+ void SCS(un_normalize_primal)(ScsWork *w, scs_float *r);
13
+ void SCS(un_normalize_dual)(ScsWork *w, scs_float *r);
14
14
 
15
15
  #ifdef __cplusplus
16
16
  }
@@ -7,9 +7,15 @@ extern "C" {
7
7
 
8
8
  #include "glbopts.h"
9
9
  #include "scs.h"
10
+ #include "util.h"
10
11
 
11
- void SCS(write_data)(const ScsData *d, const ScsCone *k);
12
- scs_int SCS(read_data)(const char * filename, ScsData **d, ScsCone **k);
12
+ void SCS(write_data)(const ScsData *d, const ScsCone *k,
13
+ const ScsSettings *stgs);
14
+ scs_int SCS(read_data)(const char *filename, ScsData **d, ScsCone **k,
15
+ ScsSettings **stgs);
16
+ void SCS(log_data_to_csv)(const ScsData *d, const ScsCone *k,
17
+ const ScsSettings *stgs, const ScsWork *w,
18
+ scs_int iter, SCS(timer) * solve_timer);
13
19
 
14
20
  #ifdef __cplusplus
15
21
  }