scs 0.3.0 → 0.4.0

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 (92) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -0
  3. data/README.md +42 -13
  4. data/lib/scs/ffi.rb +1 -7
  5. data/lib/scs/matrix.rb +72 -0
  6. data/lib/scs/solver.rb +19 -26
  7. data/lib/scs/version.rb +1 -1
  8. data/lib/scs.rb +1 -0
  9. data/vendor/scs/CITATION.cff +1 -1
  10. data/vendor/scs/CMakeLists.txt +55 -7
  11. data/vendor/scs/Makefile +9 -9
  12. data/vendor/scs/README.md +4 -1
  13. data/vendor/scs/include/aa.h +1 -1
  14. data/vendor/scs/include/cones.h +17 -12
  15. data/vendor/scs/include/glbopts.h +27 -66
  16. data/vendor/scs/include/linalg.h +2 -1
  17. data/vendor/scs/include/linsys.h +13 -13
  18. data/vendor/scs/include/normalize.h +7 -5
  19. data/vendor/scs/include/rw.h +3 -3
  20. data/vendor/scs/include/scs.h +85 -106
  21. data/vendor/scs/include/scs_types.h +34 -0
  22. data/vendor/scs/include/scs_work.h +80 -0
  23. data/vendor/scs/include/util.h +3 -1
  24. data/vendor/scs/linsys/cpu/direct/private.c +86 -73
  25. data/vendor/scs/linsys/cpu/direct/private.h +2 -2
  26. data/vendor/scs/linsys/cpu/indirect/private.c +42 -33
  27. data/vendor/scs/linsys/cpu/indirect/private.h +1 -2
  28. data/vendor/scs/linsys/csparse.c +3 -3
  29. data/vendor/scs/linsys/external/amd/LICENSE.txt +0 -897
  30. data/vendor/scs/linsys/external/amd/SuiteSparse_config.c +9 -7
  31. data/vendor/scs/linsys/external/amd/SuiteSparse_config.h +1 -1
  32. data/vendor/scs/linsys/external/amd/amd_order.c +5 -5
  33. data/vendor/scs/linsys/gpu/gpu.h +8 -11
  34. data/vendor/scs/linsys/gpu/indirect/private.c +72 -49
  35. data/vendor/scs/linsys/gpu/indirect/private.h +14 -13
  36. data/vendor/scs/linsys/scs_matrix.c +55 -104
  37. data/vendor/scs/linsys/scs_matrix.h +5 -4
  38. data/vendor/scs/scs.mk +1 -5
  39. data/vendor/scs/src/aa.c +13 -8
  40. data/vendor/scs/src/cones.c +197 -108
  41. data/vendor/scs/src/linalg.c +25 -0
  42. data/vendor/scs/src/normalize.c +75 -26
  43. data/vendor/scs/src/rw.c +74 -30
  44. data/vendor/scs/src/scs.c +300 -264
  45. data/vendor/scs/src/scs_version.c +8 -6
  46. data/vendor/scs/src/util.c +27 -13
  47. data/vendor/scs/test/minunit.h +6 -1
  48. data/vendor/scs/test/problem_utils.h +28 -35
  49. data/vendor/scs/test/problems/degenerate.h +2 -1
  50. data/vendor/scs/test/problems/hs21_tiny_qp.h +2 -1
  51. data/vendor/scs/test/problems/hs21_tiny_qp_rw.h +6 -2
  52. data/vendor/scs/test/problems/infeasible_tiny_qp.h +2 -1
  53. data/vendor/scs/test/problems/qafiro_tiny_qp.h +5 -4
  54. data/vendor/scs/test/problems/random_prob.h +6 -2
  55. data/vendor/scs/test/problems/rob_gauss_cov_est.h +9 -2
  56. data/vendor/scs/test/problems/small_lp.h +7 -2
  57. data/vendor/scs/test/problems/small_qp.h +387 -0
  58. data/vendor/scs/test/problems/{test_fails.h → test_validation.h} +7 -4
  59. data/vendor/scs/test/problems/unbounded_tiny_qp.h +4 -4
  60. data/vendor/scs/test/random_socp_prob.c +4 -2
  61. data/vendor/scs/test/run_from_file.c +16 -4
  62. data/vendor/scs/test/run_tests.c +23 -14
  63. metadata +10 -35
  64. data/vendor/scs/linsys/cpu/direct/private.o +0 -0
  65. data/vendor/scs/linsys/cpu/indirect/private.o +0 -0
  66. data/vendor/scs/linsys/csparse.o +0 -0
  67. data/vendor/scs/linsys/external/amd/SuiteSparse_config.o +0 -0
  68. data/vendor/scs/linsys/external/amd/amd_1.o +0 -0
  69. data/vendor/scs/linsys/external/amd/amd_2.o +0 -0
  70. data/vendor/scs/linsys/external/amd/amd_aat.o +0 -0
  71. data/vendor/scs/linsys/external/amd/amd_control.o +0 -0
  72. data/vendor/scs/linsys/external/amd/amd_defaults.o +0 -0
  73. data/vendor/scs/linsys/external/amd/amd_dump.o +0 -0
  74. data/vendor/scs/linsys/external/amd/amd_global.o +0 -0
  75. data/vendor/scs/linsys/external/amd/amd_info.o +0 -0
  76. data/vendor/scs/linsys/external/amd/amd_order.o +0 -0
  77. data/vendor/scs/linsys/external/amd/amd_post_tree.o +0 -0
  78. data/vendor/scs/linsys/external/amd/amd_postorder.o +0 -0
  79. data/vendor/scs/linsys/external/amd/amd_preprocess.o +0 -0
  80. data/vendor/scs/linsys/external/amd/amd_valid.o +0 -0
  81. data/vendor/scs/linsys/external/qdldl/qdldl.o +0 -0
  82. data/vendor/scs/linsys/scs_matrix.o +0 -0
  83. data/vendor/scs/src/aa.o +0 -0
  84. data/vendor/scs/src/cones.o +0 -0
  85. data/vendor/scs/src/ctrlc.o +0 -0
  86. data/vendor/scs/src/linalg.o +0 -0
  87. data/vendor/scs/src/normalize.o +0 -0
  88. data/vendor/scs/src/rw.o +0 -0
  89. data/vendor/scs/src/scs.o +0 -0
  90. data/vendor/scs/src/scs_indir.o +0 -0
  91. data/vendor/scs/src/scs_version.o +0 -0
  92. data/vendor/scs/src/util.o +0 -0
@@ -5,27 +5,16 @@
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
- ("3.0.0") /* 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.2.0")
29
18
 
30
19
  /* verbosity level */
31
20
  #ifndef VERBOSITY
@@ -54,30 +43,31 @@ extern "C" {
54
43
  #ifdef MATLAB_MEX_FILE
55
44
  #include "mex.h"
56
45
  #define scs_printf mexPrintf
57
- #define _scs_free mxFree
58
- #define _scs_malloc mxMalloc
59
- #define _scs_calloc mxCalloc
60
- #define _scs_realloc mxRealloc
46
+ #define scs_free mxFree
47
+ #define scs_malloc mxMalloc
48
+ #define scs_calloc mxCalloc
49
+ #define scs_realloc mxRealloc
61
50
  #elif defined PYTHON
62
51
  #include <Python.h>
52
+ /* see:
53
+ * https://cython-users.narkive.com/jRjjs3sK/reacquire-gil-for-printing-in-wrapped-c-library
54
+ */
63
55
  #define scs_printf(...) \
64
56
  { \
65
57
  PyGILState_STATE gilstate = PyGILState_Ensure(); \
66
58
  PySys_WriteStdout(__VA_ARGS__); \
67
59
  PyGILState_Release(gilstate); \
68
60
  }
69
- /* only for SuiteSparse */
70
- #define _scs_printf PySys_WriteStdout
71
61
  #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
62
+ #define scs_free PyMem_RawFree
63
+ #define scs_malloc PyMem_RawMalloc
64
+ #define scs_realloc PyMem_RawRealloc
65
+ #define scs_calloc PyMem_RawCalloc
76
66
  #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) {
67
+ #define scs_free PyMem_Free
68
+ #define scs_malloc PyMem_Malloc
69
+ #define scs_realloc PyMem_Realloc
70
+ static inline void *scs_calloc(size_t count, size_t size) {
81
71
  void *obj = PyMem_Malloc(count * size);
82
72
  memset(obj, 0, count * size);
83
73
  return obj;
@@ -88,47 +78,21 @@ static inline void *_scs_calloc(size_t count, size_t size) {
88
78
  #include <stdio.h>
89
79
  #include <stdlib.h>
90
80
  #define scs_printf Rprintf
91
- #define _scs_free free
92
- #define _scs_malloc malloc
93
- #define _scs_calloc calloc
94
- #define _scs_realloc realloc
81
+ #define scs_free free
82
+ #define scs_malloc malloc
83
+ #define scs_calloc calloc
84
+ #define scs_realloc realloc
95
85
  #else
96
86
  #include <stdio.h>
97
87
  #include <stdlib.h>
98
88
  #define scs_printf printf
99
- #define _scs_free free
100
- #define _scs_malloc malloc
101
- #define _scs_calloc calloc
102
- #define _scs_realloc realloc
103
- #endif
104
-
105
- /* Only required for SuiteSparse compatibility: */
106
- #ifndef _scs_printf
107
- #define _scs_printf scs_printf
108
- #endif
109
-
110
- #define scs_free(x) \
111
- _scs_free(x); \
112
- x = SCS_NULL
113
- #define scs_malloc(x) _scs_malloc(x)
114
- #define scs_calloc(x, y) _scs_calloc(x, y)
115
- #define scs_realloc(x, y) _scs_realloc(x, y)
116
-
117
- #ifdef DLONG
118
- /*#ifdef _WIN64
119
- #include <stdint.h>
120
- typedef int64_t scs_int;
121
- #else
122
- typedef long scs_int;
123
- #endif
124
- */
125
- typedef long long scs_int;
126
- #else
127
- typedef int scs_int;
89
+ #define scs_free free
90
+ #define scs_malloc malloc
91
+ #define scs_calloc calloc
92
+ #define scs_realloc realloc
128
93
  #endif
129
94
 
130
95
  #ifndef SFLOAT
131
- typedef double scs_float;
132
96
  #ifndef NAN
133
97
  #define NAN ((scs_float)0x7ff8000000000000)
134
98
  #endif
@@ -136,7 +100,6 @@ typedef double scs_float;
136
100
  #define INFINITY NAN
137
101
  #endif
138
102
  #else
139
- typedef float scs_float;
140
103
  #ifndef NAN
141
104
  #define NAN ((float)0x7fc00000)
142
105
  #endif
@@ -145,8 +108,6 @@ typedef float scs_float;
145
108
  #endif
146
109
  #endif
147
110
 
148
- #define SCS_NULL 0
149
-
150
111
  #ifndef MAX
151
112
  #define MAX(a, b) (((a) > (b)) ? (a) : (b))
152
113
  #endif
@@ -5,7 +5,7 @@
5
5
  extern "C" {
6
6
  #endif
7
7
 
8
- #include "scs.h"
8
+ #include "glbopts.h"
9
9
  #include <math.h>
10
10
 
11
11
  void SCS(scale_array)(scs_float *a, const scs_float b, scs_int len);
@@ -17,6 +17,7 @@ void SCS(add_scaled_array)(scs_float *a, const scs_float *b, scs_int n,
17
17
  const scs_float sc);
18
18
  scs_float SCS(norm_diff)(const scs_float *a, const scs_float *b, scs_int l);
19
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);
20
21
 
21
22
  #ifdef __cplusplus
22
23
  }
@@ -5,6 +5,7 @@
5
5
  extern "C" {
6
6
  #endif
7
7
 
8
+ #include "glbopts.h"
8
9
  #include "scs.h"
9
10
 
10
11
  /* This is the API that any new linear system solver must implement */
@@ -16,15 +17,14 @@ extern "C" {
16
17
  /**
17
18
  * Initialize `ScsLinSysWork` structure and perform any necessary preprocessing.
18
19
  *
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.
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
23
  * @return Linear system solver workspace.
24
24
  *
25
25
  */
26
26
  ScsLinSysWork *SCS(init_lin_sys_work)(const ScsMatrix *A, const ScsMatrix *P,
27
- scs_float *rho_y_vec, scs_float rho_x);
27
+ const scs_float *diag_r);
28
28
 
29
29
  /**
30
30
  * Frees `ScsLinSysWork` structure and associated allocated memory.
@@ -34,15 +34,15 @@ ScsLinSysWork *SCS(init_lin_sys_work)(const ScsMatrix *A, const ScsMatrix *P,
34
34
  void SCS(free_lin_sys_work)(ScsLinSysWork *w);
35
35
 
36
36
  /**
37
- * Solves the linear system required by SCS at each iteration:
37
+ * Solves the linear system as required by SCS at each iteration:
38
38
  * \f[
39
39
  * \begin{bmatrix}
40
- * (\rho_x I + P) & A^\top \\
41
- * A & -\mathrm{diag}(\rho_y) \\
40
+ * (R_x + P) & A^\top \\
41
+ * A & -R_y \\
42
42
  * \end{bmatrix} x = b
43
43
  * \f]
44
44
  *
45
- * for `x`. Overwrites `b` with result.
45
+ * for `x`, where `diag(R_x, R_y) = R`. Overwrites `b` with result.
46
46
  *
47
47
  * @param w Linear system private workspace.
48
48
  * @param b Right hand side, contains solution at the end.
@@ -54,15 +54,15 @@ void SCS(free_lin_sys_work)(ScsLinSysWork *w);
54
54
  scs_int SCS(solve_lin_sys)(ScsLinSysWork *w, scs_float *b, const scs_float *s,
55
55
  scs_float tol);
56
56
  /**
57
- * Update the linsys workspace when `rho_y_vec` is changed. For example, a
57
+ * Update the linsys workspace when `R` is changed. For example, a
58
58
  * direct method for solving the linear system might need to update the
59
59
  * factorization of the matrix.
60
60
  *
61
- * @param w Linear system private workspace.
62
- * @param rho_y_vec `rho_y` diagonal entries.
61
+ * @param w Linear system private workspace.
62
+ * @param new_diag_r Updated `diag_r`, diagonal entries of R.
63
63
  *
64
64
  */
65
- void SCS(update_lin_sys_rho_y_vec)(ScsLinSysWork *w, scs_float *rho_y_vec);
65
+ void SCS(update_lin_sys_diag_r)(ScsLinSysWork *w, const scs_float *new_diag_r);
66
66
 
67
67
  /**
68
68
  * Name of the linear solver.
@@ -5,12 +5,14 @@
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_sol)(ScsWork *w, ScsSolution *sol);
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);
11
+ void SCS(normalize_b_c)(ScsScaling *scal, scs_float *b, scs_float *c);
12
+ void SCS(normalize_sol)(ScsScaling *scal, ScsSolution *sol);
13
+ void SCS(un_normalize_sol)(ScsScaling *scal, ScsSolution *sol);
14
+ void SCS(un_normalize_primal)(ScsScaling *scal, scs_float *r);
15
+ void SCS(un_normalize_dual)(ScsScaling *scal, scs_float *r);
14
16
 
15
17
  #ifdef __cplusplus
16
18
  }
@@ -13,9 +13,9 @@ void SCS(write_data)(const ScsData *d, const ScsCone *k,
13
13
  const ScsSettings *stgs);
14
14
  scs_int SCS(read_data)(const char *filename, ScsData **d, ScsCone **k,
15
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);
16
+ void SCS(log_data_to_csv)(const ScsCone *k, const ScsSettings *stgs,
17
+ const ScsWork *w, scs_int iter,
18
+ SCS(timer) * solve_timer);
19
19
 
20
20
  #ifdef __cplusplus
21
21
  }
@@ -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,20 +8,36 @@
5
8
  extern "C" {
6
9
  #endif
7
10
 
8
- #include <string.h>
11
+ /* Contains definitions of primitive types `scs_int` and `scs_float`. */
12
+ #include "scs_types.h"
13
+
14
+ #define SCS_NULL 0 /* NULL type */
9
15
 
10
- #include "aa.h"
11
- #include "glbopts.h"
16
+ /* The following abstract structs are implemented later. */
12
17
 
13
18
  /** Struct containing acceleration workspace. Implemented by acceleration. */
14
- typedef struct SCS_ACCEL_WORK ScsAccelWork;
19
+ typedef struct ACCEL_WORK AaWork;
15
20
  /** Struct containing cone projection workspace. Implemented by cones. */
16
21
  typedef struct SCS_CONE_WORK ScsConeWork;
17
22
  /** Struct containing linear system workspace. Implemented by linear solver. */
18
23
  typedef struct SCS_LIN_SYS_WORK ScsLinSysWork;
24
+ /** Struct containing SCS workspace. Implemented in `scs_work.h`. */
25
+ typedef struct SCS_WORK ScsWork;
19
26
 
20
- /** This defines the data matrices which should be supplied in column compressed
21
- * format with zero based indexing.
27
+ /* SCS returns one of the following integer exit flags: */
28
+ #define SCS_INFEASIBLE_INACCURATE (-7)
29
+ #define SCS_UNBOUNDED_INACCURATE (-6)
30
+ #define SCS_SIGINT (-5)
31
+ #define SCS_FAILED (-4)
32
+ #define SCS_INDETERMINATE (-3)
33
+ #define SCS_INFEASIBLE (-2) /* primal infeasible, dual unbounded */
34
+ #define SCS_UNBOUNDED (-1) /* primal unbounded, dual infeasible */
35
+ #define SCS_UNFINISHED (0) /* never returned, used as placeholder */
36
+ #define SCS_SOLVED (1)
37
+ #define SCS_SOLVED_INACCURATE (2)
38
+
39
+ /** This defines the data matrices which should be supplied in compressed
40
+ * sparse column format with zero based indexing.
22
41
  */
23
42
  typedef struct {
24
43
  /** Matrix values, size: number of non-zeros. */
@@ -99,11 +118,11 @@ typedef struct {
99
118
  scs_float *bl;
100
119
  /** Total length of box cone (includes scale `t`). */
101
120
  scs_int bsize;
102
- /** Array of second-order cone constraints. */
121
+ /** Array of second-order cone constraints, `len(q) = qsize`. */
103
122
  scs_int *q;
104
123
  /** Length of second-order cone array `q`. */
105
124
  scs_int qsize;
106
- /** Array of semidefinite cone constraints. */
125
+ /** Array of semidefinite cone constraints, `len(s) = ssize`. */
107
126
  scs_int *s;
108
127
  /** Length of semidefinite constraints array `s`. */
109
128
  scs_int ssize;
@@ -112,7 +131,7 @@ typedef struct {
112
131
  /** Number of dual exponential cone triples. */
113
132
  scs_int ed;
114
133
  /** Array of power cone params, must be in `[-1, 1]`, negative values are
115
- * interpreted as specifying the dual cone. */
134
+ * interpreted as specifying the dual cone, `len(p) = psize ` */
116
135
  scs_float *p;
117
136
  /** Number of (primal and dual) power cone triples. */
118
137
  scs_int psize;
@@ -120,7 +139,10 @@ typedef struct {
120
139
 
121
140
  /** Contains primal-dual solution arrays or a certificate of infeasibility.
122
141
  * Check the exit flag to determine whether this contains a solution or a
123
- * certificate. */
142
+ * certificate. If when passed into SCS the members `x`, `y`, `s` are
143
+ * NULL then SCS will allocate memory for them which should be managed
144
+ * by the user to prevent memory leaks.
145
+ */
124
146
  typedef struct {
125
147
  /** Primal variable. */
126
148
  scs_float *x;
@@ -136,6 +158,8 @@ typedef struct {
136
158
  scs_int iter;
137
159
  /** Status string, e.g. 'solved'. */
138
160
  char status[128];
161
+ /** Linear system solver used. */
162
+ char lin_sys_solver[128];
139
163
  /** Status as scs_int, defined in glbopts.h. */
140
164
  scs_int status_val;
141
165
  /** Number of updates to scale. */
@@ -176,84 +200,16 @@ typedef struct {
176
200
  scs_float accel_time;
177
201
  } ScsInfo;
178
202
 
179
- /* the following structs are not exposed to user */
180
-
181
- /** Contains normalization variables. */
182
- typedef struct {
183
- scs_float *D, *E; /* for normalization */
184
- scs_float primal_scale, dual_scale;
185
- } ScsScaling;
186
-
187
- /** Holds residual information. */
188
- typedef struct {
189
- scs_int last_iter;
190
- scs_float xt_p_x; /* x' P x */
191
- scs_float xt_p_x_tau; /* x'Px * tau^2 *not* divided out */
192
- scs_float ctx;
193
- scs_float ctx_tau; /* tau *not* divided out */
194
- scs_float bty;
195
- scs_float bty_tau; /* tau *not* divided out */
196
- scs_float pobj; /* primal objective */
197
- scs_float dobj; /* dual objective */
198
- scs_float gap; /* pobj - dobj */
199
- scs_float tau;
200
- scs_float kap;
201
- scs_float res_pri;
202
- scs_float res_dual;
203
- scs_float res_infeas;
204
- scs_float res_unbdd_p;
205
- scs_float res_unbdd_a;
206
- /* tau NOT divided out */
207
- scs_float *ax, *ax_s, *px, *aty, *ax_s_btau, *px_aty_ctau;
208
- } ScsResiduals;
209
-
210
- /** Workspace for SCS */
211
- typedef struct {
212
- /* x_prev = x from previous iteration */
213
- scs_int time_limit_reached; /* set if the time-limit is reached */
214
- scs_float *u, *u_t;
215
- scs_float *v, *v_prev;
216
- scs_float *rsk; /* rsk [ r; s; kappa ] */
217
- scs_float *h; /* h = [c; b] */
218
- scs_float *g; /* g = (I + M)^{-1} h */
219
- scs_float *lin_sys_warm_start; /* linear system warm-start (indirect only) */
220
- scs_float *rho_y_vec; /* vector of rho y parameters (affects cone project) */
221
- AaWork *accel; /* struct for acceleration workspace */
222
- scs_float *b_orig, *c_orig; /* original b and c vectors */
223
- scs_float *b_normalized, *c_normalized; /* normalized b and c vectors */
224
- scs_int m, n; /* A has m rows, n cols */
225
- ScsMatrix *A; /* (possibly normalized) A matrix */
226
- ScsMatrix *P; /* (possibly normalized) P matrix */
227
- ScsLinSysWork *p; /* struct populated by linear system solver */
228
- ScsScaling *scal; /* contains the re-scaling data */
229
- ScsConeWork *cone_work; /* workspace for the cone projection step */
230
- scs_int *cone_boundaries; /* array with boundaries of cones */
231
- scs_int cone_boundaries_len; /* total length of cones */
232
- /* normalized and unnormalized residuals */
233
- ScsResiduals *r_orig, *r_normalized;
234
- /* track x,y,s as alg progresses, tau *not* divided out */
235
- ScsSolution *xys_orig, *xys_normalized;
236
- /* updating scale params workspace */
237
- scs_float sum_log_scale_factor;
238
- scs_int last_scale_update_iter, n_log_scale_factor, scale_updates;
239
- /* aa norm stat */
240
- scs_float aa_norm;
241
- scs_int rejected_accel_steps, accepted_accel_steps;
242
- scs_float setup_time; /* time taken for setup phase (milliseconds) */
243
- scs_float scale; /* current scale parameter */
244
- const ScsData *d;
245
- const ScsCone *k;
246
- const ScsSettings *stgs; /* contains solver settings specified by user */
247
- } ScsWork;
248
-
249
203
  /*
250
- * main library API
204
+ * Main library API.
251
205
  */
252
206
 
253
207
  /**
254
208
  * Initialize SCS and allocate memory.
255
209
  *
256
- * All the inputs must be already allocated in memory before calling.
210
+ * All the inputs must be already allocated in memory before calling. After
211
+ * this function returns then the memory associated with `d`, `k`, and `stgs`
212
+ * can be freed as SCS maintains deep copies of these internally.
257
213
  *
258
214
  * It performs:
259
215
  * - data and settings validation
@@ -261,45 +217,65 @@ typedef struct {
261
217
  * - automatic parameters tuning (if enabled)
262
218
  * - setup linear system solver:
263
219
  * - direct solver: KKT matrix factorization is performed here
264
- * - indirect solver: KKT matrix preconditioning is performed here
265
- * - solve the linear system for the `r` vector in the paper.
220
+ * - indirect solver: KKT matrix preconditioning is performed here.
266
221
  *
267
222
  *
268
- * @param d Problem data.
269
- * @param k Cone data.
270
- * @param stgs SCS solver settings.
271
- * @return Solver work struct.
223
+ * @param d Problem data.
224
+ * @param k Cone data.
225
+ * @param stgs SCS solve settings.
226
+ * @return Solver workspace.
272
227
  */
273
- ScsWork *SCS(init)(const ScsData *d, const ScsCone *k, const ScsSettings *stgs);
228
+ ScsWork *scs_init(const ScsData *d, const ScsCone *k, const ScsSettings *stgs);
274
229
 
275
230
  /**
276
- * Solve quadratic cone program initialized by SCS(init).
231
+ * Update the `b` vector, `c` vector, or both, before another solve call.
232
+ *
233
+ * After a solve we can reuse the SCS workspace in another solve if the only
234
+ * problem data that has changed are the `b` and `c` vectors.
235
+ *
236
+ * @param w SCS workspace from scs_init (modified in-place).
237
+ * @param b New `b` vector (can be `SCS_NULL` if unchanged).
238
+ * @param c New `c` vector (can be `SCS_NULL` if unchanged).
239
+ *
240
+ * @return 0 if update successful.
241
+ */
242
+ scs_int scs_update(ScsWork *w, scs_float *b, scs_float *c);
243
+
244
+ /**
245
+ * Solve quadratic cone program initialized by scs_init.
246
+ *
247
+ * @param w Workspace allocated by scs_init.
248
+ * @param sol Solution will be stored here. If members `x`, `y`, `s`
249
+ * are NULL then SCS will allocate memory for them which
250
+ * must be freed by the caller.
251
+ * @param info Information about the solve will be stored here.
252
+ * @param warm_start Whether to use the entries of `sol` as warm-start for
253
+ * the solve.
277
254
  *
278
- * @param w Workspace allocated by init.
279
- * @param sol Solver solution struct, will contain solution at termination.
280
- * @param info Solver info reporting.
281
255
  * @return Flag containing problem status (see \a glbopts.h).
282
256
  */
283
- scs_int SCS(solve)(ScsWork *w, ScsSolution *sol, ScsInfo *info);
257
+ scs_int scs_solve(ScsWork *w, ScsSolution *sol, ScsInfo *info,
258
+ scs_int warm_start);
284
259
 
285
260
  /**
286
261
  * Clean up allocated SCS workspace.
287
262
  *
288
263
  * @param w Workspace allocated by init, will be deallocated.
289
264
  */
290
- void SCS(finish)(ScsWork *w);
265
+ void scs_finish(ScsWork *w);
291
266
 
292
267
  /**
293
268
  * Solve quadratic cone program defined by data in d and cone k.
294
269
  *
295
270
  * All the inputs must already be allocated in memory before calling.
296
271
  *
297
- * @param d Problem data.
298
- * @param k Cone data.
299
- * @param stgs SCS solver settings.
300
- * @param sol Solution will be stored here.
301
- * @param info Information about the solve will be stored here.
302
- * @return Flag that determines solve type (see \a glbopts.h).
272
+ * @param d Problem data.
273
+ * @param k Cone data.
274
+ * @param stgs SCS solver settings.
275
+ * @param sol Solution will be stored here. If members `x`, `y`, `s` are
276
+ * NULL then SCS will allocate memory for them.
277
+ * @param info Information about the solve will be stored here.
278
+ * @return Flag containing problem status (see \a glbopts.h).
303
279
  */
304
280
  scs_int scs(const ScsData *d, const ScsCone *k, const ScsSettings *stgs,
305
281
  ScsSolution *sol, ScsInfo *info);
@@ -307,13 +283,16 @@ scs_int scs(const ScsData *d, const ScsCone *k, const ScsSettings *stgs,
307
283
  /**
308
284
  * Helper function to set all settings to default values (see \a glbopts.h).
309
285
  *
310
- * @param stgs Settings struct that will be populated.
286
+ * @param stgs Settings struct that will be populated.
311
287
  */
312
- void SCS(set_default_settings)(ScsSettings *stgs);
288
+ void scs_set_default_settings(ScsSettings *stgs);
313
289
 
314
- const char *SCS(version)(void);
315
- size_t SCS(sizeof_int)(void);
316
- size_t SCS(sizeof_float)(void);
290
+ /**
291
+ * Helper function simply returns the current version of SCS as a string.
292
+ *
293
+ * @return SCS version as a string.
294
+ */
295
+ const char *scs_version(void);
317
296
 
318
297
  #ifdef __cplusplus
319
298
  }
@@ -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,80 @@
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
+ #include "scs.h"
13
+
14
+ /** Contains normalization variables. */
15
+ typedef struct {
16
+ scs_float *D, *E; /* for normalization */
17
+ scs_int m; /* Length of D */
18
+ scs_int n; /* Length of E */
19
+ scs_float primal_scale, dual_scale;
20
+ } ScsScaling;
21
+
22
+ /** Holds residual information. */
23
+ typedef struct {
24
+ scs_int last_iter;
25
+ scs_float xt_p_x; /* x' P x */
26
+ scs_float xt_p_x_tau; /* x'Px * tau^2 *not* divided out */
27
+ scs_float ctx;
28
+ scs_float ctx_tau; /* tau *not* divided out */
29
+ scs_float bty;
30
+ scs_float bty_tau; /* tau *not* divided out */
31
+ scs_float pobj; /* primal objective */
32
+ scs_float dobj; /* dual objective */
33
+ scs_float gap; /* pobj - dobj */
34
+ scs_float tau;
35
+ scs_float kap;
36
+ scs_float res_pri;
37
+ scs_float res_dual;
38
+ scs_float res_infeas;
39
+ scs_float res_unbdd_p;
40
+ scs_float res_unbdd_a;
41
+ /* tau NOT divided out */
42
+ scs_float *ax, *ax_s, *px, *aty, *ax_s_btau, *px_aty_ctau;
43
+ } ScsResiduals;
44
+
45
+ /** Workspace for SCS. */
46
+ struct SCS_WORK {
47
+ /* x_prev = x from previous iteration */
48
+ scs_float setup_time; /* time taken for setup phase (milliseconds) */
49
+ scs_int time_limit_reached; /* boolean, if the time-limit is reached */
50
+ scs_float *u, *u_t;
51
+ scs_float *v, *v_prev;
52
+ scs_float *rsk; /* rsk [ r; s; kappa ] */
53
+ scs_float *h; /* h = [c; b] */
54
+ scs_float *g; /* g = (I + M)^{-1} h */
55
+ scs_float *lin_sys_warm_start; /* linear system warm-start (indirect only) */
56
+ scs_float *diag_r; /* vector of R matrix diagonals (affects cone proj) */
57
+ scs_float *b_orig, *c_orig; /* original unnormalized b and c vectors */
58
+ AaWork *accel; /* struct for acceleration workspace */
59
+ ScsData *d; /* Problem data deep copy NORMALIZED */
60
+ ScsCone *k; /* Problem cone deep copy */
61
+ ScsSettings *stgs; /* contains solver settings specified by user */
62
+ ScsLinSysWork *p; /* struct populated by linear system solver */
63
+ ScsScaling *scal; /* contains the re-scaling data */
64
+ ScsConeWork *cone_work; /* workspace for the cone projection step */
65
+ /* normalized and unnormalized residuals */
66
+ ScsResiduals *r_orig, *r_normalized;
67
+ /* track x,y,s as alg progresses, tau *not* divided out */
68
+ ScsSolution *xys_orig, *xys_normalized;
69
+ /* Scale updating workspace */
70
+ scs_float sum_log_scale_factor;
71
+ scs_int last_scale_update_iter, n_log_scale_factor, scale_updates;
72
+ /* AA stats */
73
+ scs_float aa_norm;
74
+ scs_int rejected_accel_steps, accepted_accel_steps;
75
+ };
76
+
77
+ #ifdef __cplusplus
78
+ }
79
+ #endif
80
+ #endif
@@ -45,7 +45,9 @@ typedef struct SCS(timer) {
45
45
  void SCS(tic)(SCS(timer) * t);
46
46
  scs_float SCS(tocq)(SCS(timer) * t);
47
47
  void SCS(free_sol)(ScsSolution *sol);
48
- void SCS(free_data)(ScsData *d, ScsCone *k, ScsSettings *stgs);
48
+ void SCS(deep_copy_data)(ScsData *dest, const ScsData *src);
49
+ void SCS(deep_copy_stgs)(ScsSettings *dest, const ScsSettings *src);
50
+ void SCS(free_data)(ScsData *d);
49
51
 
50
52
  #ifdef __cplusplus
51
53
  }