scs 0.2.2 → 0.3.2

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 (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
@@ -5,50 +5,94 @@
5
5
  extern "C" {
6
6
  #endif
7
7
 
8
+ #include "glbopts.h"
8
9
  #include <stdio.h>
9
10
  #include <stdlib.h>
10
11
  #include <string.h>
11
- #include "glbopts.h"
12
12
 
13
13
  typedef scs_float aa_float;
14
14
  typedef scs_int aa_int;
15
15
 
16
16
  typedef struct ACCEL_WORK AaWork;
17
17
 
18
- /* Initialize Anderson Acceleration, allocates memory.
18
+ /**
19
+ * Initialize Anderson Acceleration, allocates memory.
20
+ *
21
+ * @param dim the dimension of the variable for AA
22
+ * @param mem the memory (number of past iterations used) for AA
23
+ * @param type1 if True use type 1 AA, otherwise use type 2
24
+ * @param regularization type-I and type-II different, for type-I: 1e-8 works
25
+ * well, type-II: more stable can use 1e-12 often
26
+ * @param relaxation float in [0,2], mixing parameter (1.0 is vanilla)
27
+ * @param safeguard_factor factor that controls safeguarding checks
28
+ * larger is more aggressive but less stable
29
+ * @param max_weight_norm float, maximum norm of AA weights
30
+ * @param verbosity if greater than 0 prints out various info
31
+ *
32
+ * @return pointer to AA workspace
33
+ *
34
+ */
35
+ AaWork *aa_init(aa_int dim, aa_int mem, aa_int type1, aa_float regularization,
36
+ aa_float relaxation, aa_float safeguard_factor,
37
+ aa_float max_weight_norm, aa_int verbosity);
38
+ /**
39
+ * Apply Anderson Acceleration. The usage pattern should be as follows:
40
+ *
41
+ * - for i = 0 .. N:
42
+ * - if (i > 0): aa_apply(x, x_prev, a)
43
+ * - x_prev = x.copy()
44
+ * - x = F(x)
45
+ * - aa_safeguard(x, x_prev, a) // optional but helps stability
46
+ *
47
+ * Here F is the map we are trying to find the fixed point for. We put the AA
48
+ * before the map so that any properties of the map are maintained at the end.
49
+ * Eg if the map contains a projection onto a set then the output is guaranteed
50
+ * to be in the set.
51
+ *
19
52
  *
20
- * Args:
21
- * dim: the dimension of the variable for aa
22
- * aa_mem: the memory (number of past iterations used) for aa
23
- * type1: bool, if True use type 1 aa, otherwise use type 2
53
+ * @param f output of map at current iteration, overwritten with AA output
54
+ * @param x input to map at current iteration
55
+ * @param a workspace from aa_init
56
+ *
57
+ * @return (+ or -) norm of AA weights vector. If positive then update
58
+ * was accepted and f contains new point, if negative then update was
59
+ * rejected and f is unchanged
24
60
  *
25
- * Reurns:
26
- * Pointer to aa workspace
27
61
  */
28
- AaWork *aa_init(aa_int dim, aa_int aa_mem, aa_int type1);
62
+ aa_float aa_apply(aa_float *f, const aa_float *x, AaWork *a);
29
63
 
30
- /* Apply Anderson Acceleration.
64
+ /**
65
+ * Apply safeguarding.
66
+ *
67
+ * This step is optional but can improve stability.
68
+ *
69
+ * @param f_new output of map after AA step
70
+ * @param x_new AA output that is input to the map
71
+ * @param a workspace from aa_init
31
72
  *
32
- * Args:
33
- * f: output of map at current iteration, overwritten with aa output at end.
34
- * x: input to map at current iteration
35
- * a: aa workspace from aa_init
73
+ * @returns 0 if AA step is accepted otherwise -1, if AA step is rejected then
74
+ * this overwrites f_new and x_new with previous values
36
75
  *
37
- * Returns:
38
- * int, a value of 0 is success, <0 is failure at which point f is unchanged
39
76
  */
40
- aa_int aa_apply(aa_float *f, const aa_float *x, AaWork *a);
77
+ aa_int aa_safeguard(aa_float *f_new, aa_float *x_new, AaWork *a);
41
78
 
42
- /* Finish Anderson Acceleration, clears memory.
79
+ /**
80
+ * Finish Anderson Acceleration, clears memory.
81
+ *
82
+ * @param a AA workspace from aa_init
43
83
  *
44
- * Args:
45
- * a: aa workspace from aa_init.
46
84
  */
47
85
  void aa_finish(AaWork *a);
48
86
 
49
- #define MAX_AA_NRM (1e4)
50
-
51
- #define MIN(a, b) (((a) < (b)) ? (a) : (b))
87
+ /**
88
+ * Reset Anderson Acceleration.
89
+ *
90
+ * Resets AA as if at the first iteration, reuses original memory allocations.
91
+ *
92
+ * @param a AA workspace from aa_init
93
+ *
94
+ */
95
+ void aa_reset(AaWork *a);
52
96
 
53
97
  #ifdef __cplusplus
54
98
  }
@@ -8,37 +8,40 @@ extern "C" {
8
8
  #include "glbopts.h"
9
9
  #include "scs.h"
10
10
  #include "scs_blas.h"
11
+ #include "scs_work.h"
12
+ #include <string.h>
11
13
 
12
14
  /* private data to help cone projection step */
13
15
  struct SCS_CONE_WORK {
14
- scs_float total_cone_time;
16
+ /*
17
+ * cone_boundaries will contain array of indices of rows of A corresponding to
18
+ * cone boundaries, boundaries[0] is starting index for cones of size larger
19
+ * than 1
20
+ */
21
+ const ScsCone *k; /* original cone information */
22
+ scs_int *cone_boundaries;
23
+ scs_int cone_boundaries_len;
24
+ scs_int scaled_cones; /* boolean, whether the cones have been scaled */
25
+ scs_float *s; /* used for Moreau decomposition in projection */
26
+ scs_int m; /* total length of cone */
27
+ /* box cone quantities */
28
+ scs_float *bl, *bu, box_t_warm_start;
15
29
  #ifdef USE_LAPACK
16
30
  /* workspace for eigenvector decompositions: */
17
31
  scs_float *Xs, *Z, *e, *work;
18
- blas_int *iwork, lwork, liwork;
32
+ blas_int lwork;
19
33
  #endif
20
34
  };
21
35
 
22
- /*
23
- * boundaries will contain array of indices of rows of A corresponding to
24
- * cone boundaries, boundaries[0] is starting index for cones of size larger
25
- * than 1
26
- * returns length of boundaries array, boundaries malloc-ed here so should be
27
- * freed
28
- */
29
- scs_int SCS(get_cone_boundaries)(const ScsCone *k, scs_int **boundaries);
30
-
31
- ScsConeWork *SCS(init_cone)(const ScsCone *k);
36
+ ScsConeWork *SCS(init_cone)(const ScsCone *k, scs_int m);
32
37
  char *SCS(get_cone_header)(const ScsCone *k);
33
38
  scs_int SCS(validate_cones)(const ScsData *d, const ScsCone *k);
34
-
35
- /* pass in iter to control how accurate the cone projection
36
- with iteration, set iter < 0 for exact projection, warm_start contains guess
37
- of solution, can be SCS_NULL*/
38
- scs_int SCS(proj_dual_cone)(scs_float *x, const ScsCone *k, ScsConeWork *c,
39
- const scs_float *warm_start, scs_int iter);
39
+ scs_int SCS(proj_dual_cone)(scs_float *x, ScsConeWork *c, ScsScaling *scal,
40
+ scs_float *r_y);
40
41
  void SCS(finish_cone)(ScsConeWork *c);
41
- char *SCS(get_cone_summary)(const ScsInfo *info, ScsConeWork *c);
42
+ void SCS(set_r_y)(const ScsConeWork *c, scs_float scale, scs_float *r_y);
43
+ void SCS(enforce_cone_boundaries)(const ScsConeWork *c, scs_float *vec,
44
+ scs_float (*f)(const scs_float *, scs_int));
42
45
 
43
46
  #ifdef __cplusplus
44
47
  }
@@ -5,108 +5,93 @@
5
5
  extern "C" {
6
6
  #endif
7
7
 
8
+ #include "scs.h"
8
9
  #include <math.h>
9
10
 
10
11
  #ifndef SCS
11
- #define SCS(x) scs_##x
12
+ #define SCS(x) _scs_##x
12
13
  #endif
13
14
 
14
15
  /* SCS VERSION NUMBER ---------------------------------------------- */
15
- #define SCS_VERSION \
16
- ("2.1.2") /* string literals automatically null-terminated */
17
-
18
- /* SCS returns one of the following integers: */
19
- #define SCS_INFEASIBLE_INACCURATE (-7)
20
- #define SCS_UNBOUNDED_INACCURATE (-6)
21
- #define SCS_SIGINT (-5)
22
- #define SCS_FAILED (-4)
23
- #define SCS_INDETERMINATE (-3)
24
- #define SCS_INFEASIBLE (-2) /* primal infeasible, dual unbounded */
25
- #define SCS_UNBOUNDED (-1) /* primal unbounded, dual infeasible */
26
- #define SCS_UNFINISHED (0) /* never returned, used as placeholder */
27
- #define SCS_SOLVED (1)
28
- #define SCS_SOLVED_INACCURATE (2)
16
+ /* string literals automatically null-terminated */
17
+ #define SCS_VERSION ("3.1.1")
18
+
19
+ /* verbosity level */
20
+ #ifndef VERBOSITY
21
+ #define VERBOSITY (0)
22
+ #endif
29
23
 
30
24
  /* DEFAULT SOLVER PARAMETERS AND SETTINGS -------------------------- */
31
- #define MAX_ITERS (5000)
32
- #define EPS (1E-5)
25
+ #define MAX_ITERS (100000)
26
+ #define EPS_REL (1E-4)
27
+ #define EPS_ABS (1E-4)
28
+ #define EPS_INFEAS (1E-7)
33
29
  #define ALPHA (1.5)
34
- #define RHO_X (1E-3)
35
- #define SCALE (1.0)
36
- #define CG_RATE (2.0)
30
+ #define RHO_X (1E-6)
31
+ #define SCALE (0.1)
37
32
  #define VERBOSE (1)
38
33
  #define NORMALIZE (1)
39
34
  #define WARM_START (0)
40
35
  #define ACCELERATION_LOOKBACK (10)
36
+ #define ACCELERATION_INTERVAL (10)
37
+ #define ADAPTIVE_SCALE (1)
41
38
  #define WRITE_DATA_FILENAME (0)
39
+ #define LOG_CSV_FILENAME (0)
40
+ #define TIME_LIMIT_SECS (0.)
42
41
 
43
42
  /* redefine printfs and memory allocators as needed */
44
43
  #ifdef MATLAB_MEX_FILE
45
44
  #include "mex.h"
46
45
  #define scs_printf mexPrintf
47
- #define _scs_free mxFree
48
- #define _scs_malloc mxMalloc
49
- #define _scs_calloc mxCalloc
50
- #define _scs_realloc mxRealloc
46
+ #define scs_free mxFree
47
+ #define scs_malloc mxMalloc
48
+ #define scs_calloc mxCalloc
49
+ #define scs_realloc mxRealloc
51
50
  #elif defined PYTHON
52
51
  #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); \
52
+ #define scs_printf(...) \
53
+ { \
54
+ PyGILState_STATE gilstate = PyGILState_Ensure(); \
55
+ PySys_WriteStdout(__VA_ARGS__); \
56
+ PyGILState_Release(gilstate); \
59
57
  }
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))
58
+ #if PY_MAJOR_VERSION >= 3
59
+ #define scs_free PyMem_RawFree
60
+ #define scs_malloc PyMem_RawMalloc
61
+ #define scs_realloc PyMem_RawRealloc
62
+ #define scs_calloc PyMem_RawCalloc
63
+ /* only for SuiteSparse + python */
64
+ #define _scs_printf PySys_WriteStdout
65
+ #else
66
+ #define scs_free PyMem_Free
67
+ #define scs_malloc PyMem_Malloc
68
+ #define scs_realloc PyMem_Realloc
69
+ static inline void *scs_calloc(size_t count, size_t size) {
70
+ void *obj = PyMem_Malloc(count * size);
71
+ memset(obj, 0, count * size);
72
+ return obj;
73
+ }
74
+ #endif
75
+ #elif defined R_LANG
66
76
  #include <R_ext/Print.h> /* Rprintf etc */
67
77
  #include <stdio.h>
68
78
  #include <stdlib.h>
69
79
  #define scs_printf Rprintf
70
- #define _scs_free free
71
- #define _scs_malloc malloc
72
- #define _scs_calloc calloc
73
- #define _scs_realloc realloc
80
+ #define scs_free free
81
+ #define scs_malloc malloc
82
+ #define scs_calloc calloc
83
+ #define scs_realloc realloc
74
84
  #else
75
85
  #include <stdio.h>
76
86
  #include <stdlib.h>
77
87
  #define scs_printf printf
78
- #define _scs_free free
79
- #define _scs_malloc malloc
80
- #define _scs_calloc calloc
81
- #define _scs_realloc realloc
82
- #endif
83
-
84
- /* Only required for SuiteSparse compatibility: */
85
- #ifndef _scs_printf
86
- #define _scs_printf scs_printf
87
- #endif
88
-
89
- #define scs_free(x) \
90
- _scs_free(x); \
91
- x = SCS_NULL
92
- #define scs_malloc(x) _scs_malloc(x)
93
- #define scs_calloc(x, y) _scs_calloc(x, y)
94
- #define scs_realloc(x, y) _scs_realloc(x, y)
95
-
96
- #ifdef DLONG
97
- #ifdef _WIN64
98
- #include <stdint.h>
99
- typedef int64_t scs_int;
100
- /* typedef long scs_int; */
101
- #else
102
- typedef long scs_int;
103
- #endif
104
- #else
105
- typedef int scs_int;
88
+ #define scs_free free
89
+ #define scs_malloc malloc
90
+ #define scs_calloc calloc
91
+ #define scs_realloc realloc
106
92
  #endif
107
93
 
108
94
  #ifndef SFLOAT
109
- typedef double scs_float;
110
95
  #ifndef NAN
111
96
  #define NAN ((scs_float)0x7ff8000000000000)
112
97
  #endif
@@ -114,7 +99,6 @@ typedef double scs_float;
114
99
  #define INFINITY NAN
115
100
  #endif
116
101
  #else
117
- typedef float scs_float;
118
102
  #ifndef NAN
119
103
  #define NAN ((float)0x7fc00000)
120
104
  #endif
@@ -153,23 +137,67 @@ typedef float scs_float;
153
137
  #endif
154
138
  #endif
155
139
 
140
+ /* Force SCS to treat the problem as (non-homogeneous) feasible for this many */
141
+ /* iters. This acts like a warm-start that biases towards feasibility, which */
142
+ /* is the most common use-case */
143
+ #define FEASIBLE_ITERS (1)
144
+
145
+ /* how many iterations between heuristic residual rescaling */
146
+ #define RESCALING_MIN_ITERS (100)
147
+
156
148
  #define EPS_TOL (1E-18)
157
149
  #define SAFEDIV_POS(X, Y) ((Y) < EPS_TOL ? ((X) / EPS_TOL) : (X) / (Y))
158
150
 
159
- #if EXTRA_VERBOSE > 0
151
+ #if VERBOSITY > 0
160
152
  #define PRINT_INTERVAL (1)
161
153
  #define CONVERGED_INTERVAL (1)
162
154
  #else
155
+
163
156
  /* print summary output every this num iterations */
164
- #define PRINT_INTERVAL (100)
157
+ #define PRINT_INTERVAL (250)
165
158
  /* 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.)
159
+ #define CONVERGED_INTERVAL (25)
160
+ #endif
161
+
162
+ /* maintain the iterates at L2 norm = ITERATE_NORM * sqrt(n+m+1) */
163
+ #define ITERATE_NORM (1.)
164
+
165
+ /* Which norm to use for termination checking etc */
166
+ /* #define NORM SCS(norm_2) */
167
+ #define NORM SCS(norm_inf)
168
+
169
+ /* Factor which is scales tau in the linear system update */
170
+ /* Larger factors prevent tau from moving as much */
171
+ #define TAU_FACTOR (10.)
172
+
173
+ /* Anderson acceleration parameters: */
174
+ #define AA_RELAXATION (1.0)
175
+ #define AA_REGULARIZATION_TYPE_1 (1e-6)
176
+ #define AA_REGULARIZATION_TYPE_2 (1e-10)
177
+ /* Safeguarding norm factor at which we reject AA steps */
178
+ #define AA_SAFEGUARD_FACTOR (1.)
179
+ /* Max allowable AA weight norm */
180
+ #define AA_MAX_WEIGHT_NORM (1e10)
181
+
182
+ /* (Dual) Scale updating parameters */
183
+ #define MAX_SCALE_VALUE (1e6)
184
+ #define MIN_SCALE_VALUE (1e-6)
185
+ #define SCALE_NORM NORM /* what norm to use when computing the scale factor */
186
+
187
+ /* CG == Conjugate gradient */
188
+ /* Linear system tolerances, only used with indirect */
189
+ #define CG_BEST_TOL (1e-12)
190
+ /* This scales the current residuals to get the tolerance we solve the
191
+ * linear system to at each iteration. Lower factors require more CG steps
192
+ * but give better accuracy */
193
+ #define CG_TOL_FACTOR (0.2)
194
+
195
+ /* norm to use when deciding CG convergence */
196
+ #ifndef CG_NORM
197
+ #define CG_NORM SCS(norm_inf)
198
+ #endif
199
+ /* cg tol ~ O(1/k^(CG_RATE)) */
200
+ #define CG_RATE (1.5)
173
201
 
174
202
  #ifdef __cplusplus
175
203
  }
@@ -5,20 +5,19 @@
5
5
  extern "C" {
6
6
  #endif
7
7
 
8
+ #include "glbopts.h"
8
9
  #include <math.h>
9
- #include "scs.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);
20
18
  scs_float SCS(norm_diff)(const scs_float *a, const scs_float *b, scs_int l);
21
19
  scs_float SCS(norm_inf_diff)(const scs_float *a, const scs_float *b, scs_int l);
20
+ scs_float SCS(mean)(const scs_float *x, scs_int l);
22
21
 
23
22
  #ifdef __cplusplus
24
23
  }
@@ -5,57 +5,71 @@
5
5
  extern "C" {
6
6
  #endif
7
7
 
8
+ #include "glbopts.h"
8
9
  #include "scs.h"
9
10
 
10
- /* YOUR LINEAR SYSTEM SOLVER MUST IMPLEMENT THESE METHODS AND SCS_LIN_SYS_WORK
11
- * STRUCT */
11
+ /* This is the API that any new linear system solver must implement */
12
12
 
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);
13
+ /* Struct containing linear system workspace. Implemented by linear solver. */
14
+ /* This typedef is in scs.h */
15
+ /* typedef struct SCS_LIN_SYS_WORK ScsLinSysWork; */
23
16
 
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);
17
+ /**
18
+ * Initialize `ScsLinSysWork` structure and perform any necessary preprocessing.
19
+ *
20
+ * @param A `A` data matrix, `m x n`.
21
+ * @param P `P` data matrix, `n x n`.
22
+ * @param diag_r `R > 0` diagonal entries of length `m + n`.
23
+ * @return Linear system solver workspace.
24
+ *
25
+ */
26
+ ScsLinSysWork *SCS(init_lin_sys_work)(const ScsMatrix *A, const ScsMatrix *P,
27
+ const scs_float *diag_r);
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 as required by SCS at each iteration:
38
+ * \f[
39
+ * \begin{bmatrix}
40
+ * (R_x + P) & A^\top \\
41
+ * A & -R_y \\
42
+ * \end{bmatrix} x = b
43
+ * \f]
44
+ *
45
+ * for `x`, where `diag(R_x, R_y) = R`. 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 `R` 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 new_diag_r Updated `diag_r`, diagonal entries of R.
63
+ *
64
+ */
65
+ void SCS(update_lin_sys_diag_r)(ScsLinSysWork *w, const scs_float *new_diag_r);
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
  }
@@ -5,12 +5,13 @@
5
5
  extern "C" {
6
6
  #endif
7
7
 
8
- #include "scs.h"
8
+ #include "glbopts.h"
9
+ #include "scs_work.h"
9
10
 
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);
13
- void SCS(un_normalize_sol)(ScsWork *w, ScsSolution *sol);
11
+ void SCS(normalize_sol)(ScsScaling *scal, ScsSolution *sol);
12
+ void SCS(un_normalize_sol)(ScsScaling *scal, ScsSolution *sol);
13
+ void SCS(un_normalize_primal)(ScsScaling *scal, scs_float *r);
14
+ void SCS(un_normalize_dual)(ScsScaling *scal, scs_float *r);
14
15
 
15
16
  #ifdef __cplusplus
16
17
  }
@@ -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
  }