scs 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/README.md +34 -5
  4. data/lib/scs/matrix.rb +72 -0
  5. data/lib/scs/solver.rb +19 -26
  6. data/lib/scs/version.rb +1 -1
  7. data/lib/scs.rb +1 -0
  8. data/vendor/scs/CITATION.cff +1 -1
  9. data/vendor/scs/CMakeLists.txt +2 -2
  10. data/vendor/scs/README.md +3 -1
  11. data/vendor/scs/include/cones.h +5 -3
  12. data/vendor/scs/include/glbopts.h +4 -5
  13. data/vendor/scs/include/normalize.h +1 -0
  14. data/vendor/scs/include/rw.h +3 -3
  15. data/vendor/scs/include/scs.h +45 -22
  16. data/vendor/scs/include/scs_work.h +15 -18
  17. data/vendor/scs/include/util.h +3 -1
  18. data/vendor/scs/linsys/external/amd/LICENSE.txt +0 -897
  19. data/vendor/scs/linsys/external/amd/SuiteSparse_config.c +4 -2
  20. data/vendor/scs/linsys/external/amd/SuiteSparse_config.h +0 -5
  21. data/vendor/scs/linsys/scs_matrix.c +38 -67
  22. data/vendor/scs/linsys/scs_matrix.h +4 -3
  23. data/vendor/scs/scs.mk +0 -4
  24. data/vendor/scs/src/aa.c +0 -4
  25. data/vendor/scs/src/cones.c +63 -25
  26. data/vendor/scs/src/normalize.c +49 -0
  27. data/vendor/scs/src/rw.c +48 -40
  28. data/vendor/scs/src/scs.c +212 -170
  29. data/vendor/scs/src/util.c +26 -12
  30. data/vendor/scs/test/problem_utils.h +3 -3
  31. data/vendor/scs/test/problems/degenerate.h +1 -0
  32. data/vendor/scs/test/problems/hs21_tiny_qp.h +1 -0
  33. data/vendor/scs/test/problems/hs21_tiny_qp_rw.h +5 -1
  34. data/vendor/scs/test/problems/infeasible_tiny_qp.h +1 -0
  35. data/vendor/scs/test/problems/qafiro_tiny_qp.h +2 -1
  36. data/vendor/scs/test/problems/random_prob.h +5 -1
  37. data/vendor/scs/test/problems/rob_gauss_cov_est.h +8 -1
  38. data/vendor/scs/test/problems/small_lp.h +4 -1
  39. data/vendor/scs/test/problems/small_qp.h +42 -7
  40. data/vendor/scs/test/problems/test_validation.h +4 -1
  41. data/vendor/scs/test/problems/unbounded_tiny_qp.h +3 -3
  42. data/vendor/scs/test/random_socp_prob.c +3 -1
  43. data/vendor/scs/test/run_from_file.c +15 -3
  44. metadata +5 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db74c6ffd6696e799a18d2f5d02f5b753020a2535e539cdd26abac388f1ea046
4
- data.tar.gz: f7d5b3b98b58d812fb923193303b7f0bfcf7cb2972de2ae34a392fb9f4a5bd40
3
+ metadata.gz: 2afa78c52786f5325f64a76edb263b4d30dabab7b15a9415375ed57af861669c
4
+ data.tar.gz: ae105845b96b30fab4a24bdf3eb2c1f80db7b12d635716ac3c4acfdb17930783
5
5
  SHA512:
6
- metadata.gz: cf7a4948ba7a21865142a421da3e683904951faf7e602d429722cf05bdbae559dcc15484e6cb4afa6bf683ecf681757370bfa3fa7b01dab6620b300462eea703
7
- data.tar.gz: 493da1d4fbe2fdb7180fffad3599137500d437b082d788365bf828dd8845469b3bf0d63863ea467c013cc2f874c5b04ab935c7129d45b1c890278dda7ad21039
6
+ metadata.gz: b8bc74c496d1661b5f14e6da33c79987502d4c320c6789e4cd2d7a4bf118a8800978dc0cd0989f2f9d38978a9d27e14c37d47f8b6bb63ced36af97fee753f5e0
7
+ data.tar.gz: 5282b6cd3e7f7ed98423ef61eabb1275ce17bdb7b497fab9f7537c53cf7be154d3f1029a170c2c6562bb35780ebceca075e8ca12cd81af163bb7824bb2e91a27
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.4.0 (2022-07-06)
2
+
3
+ - Updated SCS to 3.2.0
4
+ - Added `Matrix` class
5
+ - Dropped support for Ruby < 2.7
6
+
1
7
  ## 0.3.2 (2022-01-17)
2
8
 
3
9
  - Updated SCS to 3.1.1
data/README.md CHANGED
@@ -18,11 +18,16 @@ If installation fails, you may need to install [dependencies](#dependencies).
18
18
 
19
19
  ## Getting Started
20
20
 
21
- Prep the problem
21
+ Prep the problem, like [this one](https://www.cvxgrp.org/scs/examples/python/basic_qp.html)
22
22
 
23
23
  ```ruby
24
- data = {a: [[1], [-1]], b: [1, 0], c: [-1]}
25
- cone = {q: [], l: 2}
24
+ data = {
25
+ p: SCS::Matrix.from_dense([[3, -1], [-1, 2]]),
26
+ a: SCS::Matrix.from_dense([[-1, 1], [1, 0], [0, 1]]),
27
+ b: [-1, 0.3, -0.5],
28
+ c: [-1, -1]
29
+ }
30
+ cone = {z: 1, l: 2}
26
31
  ```
27
32
 
28
33
  And solve it
@@ -32,12 +37,36 @@ solver = SCS::Solver.new
32
37
  solver.solve(data, cone)
33
38
  ```
34
39
 
40
+ ## Data
41
+
42
+ Matrices can be a sparse matrix
43
+
44
+ ```ruby
45
+ a = SCS::Matrix.new(3, 2)
46
+ a[0, 0] = 1
47
+ a[1, 0] = 2
48
+ # or
49
+ SCS::Matrix.from_dense([[1, 0], [2, 0], [0, 0]])
50
+ ```
51
+
52
+ Arrays can be Ruby arrays
53
+
54
+ ```ruby
55
+ [1, 2, 3]
56
+ ```
57
+
58
+ Or Numo arrays
59
+
60
+ ```ruby
61
+ Numo::NArray.cast([1, 2, 3])
62
+ ```
63
+
35
64
  ## Settings
36
65
 
37
66
  Default values shown
38
67
 
39
68
  ```ruby
40
- solver.solve(data, cone, {
69
+ solver.solve(data, cone,
41
70
  normalize: true, # heuristic data rescaling
42
71
  scale: 0.1, # if normalized, rescales by this factor
43
72
  adaptive_scale: true, # heuristically adapt dual scale through the solve
@@ -54,7 +83,7 @@ solver.solve(data, cone, {
54
83
  acceleration_interval: 10, # iterations to run Anderson acceleration
55
84
  write_data_filename: nil, # filename to write data if set
56
85
  log_csv_filename: nil # write csv logs of various quantities
57
- })
86
+ )
58
87
  ```
59
88
 
60
89
  ## Direct vs Indirect
data/lib/scs/matrix.rb ADDED
@@ -0,0 +1,72 @@
1
+ module SCS
2
+ class Matrix
3
+ attr_reader :m, :n
4
+
5
+ def initialize(m, n)
6
+ @m = m
7
+ @n = n
8
+ @data = {}
9
+ end
10
+
11
+ def []=(row_index, column_index, value)
12
+ raise IndexError, "row index out of bounds" if row_index < 0 || row_index >= @m
13
+ raise IndexError, "column index out of bounds" if column_index < 0 || column_index >= @n
14
+ # dictionary of keys, optimized for converting to CSC
15
+ # TODO try COO for performance
16
+ if value == 0
17
+ (@data[column_index] ||= {}).delete(row_index)
18
+ else
19
+ (@data[column_index] ||= {})[row_index] = value
20
+ end
21
+ end
22
+
23
+ def to_csc
24
+ cx = []
25
+ ci = []
26
+ cp = []
27
+
28
+ # CSC format
29
+ # https://www.gormanalysis.com/blog/sparse-matrix-storage-formats/
30
+ cp << 0
31
+ n.times do |j|
32
+ (@data[j] || {}).sort_by { |k, v| k }.each do |k, v|
33
+ cx << v
34
+ ci << k
35
+ end
36
+ # cumulative column values
37
+ cp << cx.size
38
+ end
39
+
40
+ {
41
+ start: cp,
42
+ index: ci,
43
+ value: cx
44
+ }
45
+ end
46
+
47
+ # private, for tests
48
+ def nnz
49
+ @data.sum { |_, v| v.count }
50
+ end
51
+
52
+ def initialize_copy(other)
53
+ super
54
+ @data = @data.transform_values(&:dup)
55
+ end
56
+
57
+ def self.from_dense(data)
58
+ data = data.to_a
59
+ m = data.size
60
+ n = m > 0 ? data.first.size : 0
61
+
62
+ mtx = Matrix.new(m, n)
63
+ data.each_with_index do |row, i|
64
+ raise ArgumentError, "row has different number of columns" if row.size != n
65
+ row.each_with_index do |v, j|
66
+ mtx[i, j] = v if v != 0
67
+ end
68
+ end
69
+ mtx
70
+ end
71
+ end
72
+ end
data/lib/scs/solver.rb CHANGED
@@ -73,42 +73,35 @@ module SCS
73
73
  char_ptr[0, idx].map(&:chr).join
74
74
  end
75
75
 
76
- # TODO add support sparse matrices
77
76
  def csc_matrix(mtx, upper: false)
78
- mtx = mtx.to_a
79
-
80
- m, n = shape(mtx)
81
-
82
- cx = []
83
- ci = []
84
- cp = []
85
-
86
- # CSC format
87
- # https://www.gormanalysis.com/blog/sparse-matrix-storage-formats/
88
- cp << 0
89
- n.times do |j|
90
- mtx.each_with_index do |row, i|
91
- if row[j] != 0 && (!upper || i <= j)
92
- cx << row[j]
93
- ci << i
77
+ mtx = Matrix.from_dense(mtx) unless mtx.is_a?(Matrix)
78
+
79
+ if upper
80
+ # TODO improve performance
81
+ mtx = mtx.dup
82
+ mtx.m.times do |i|
83
+ mtx.n.times do |j|
84
+ mtx[i, j] = 0 if i > j
94
85
  end
95
86
  end
96
- # cumulative column values
97
- cp << cx.size
98
87
  end
99
88
 
89
+ csc = mtx.to_csc
90
+
100
91
  # construct matrix
101
92
  matrix = ffi::Matrix.malloc
102
- matrix.x = float_array(cx)
103
- matrix.i = int_array(ci)
104
- matrix.p = int_array(cp)
105
- matrix.m = m
106
- matrix.n = n
93
+ matrix.x = float_array(csc[:value])
94
+ matrix.i = int_array(csc[:index])
95
+ matrix.p = int_array(csc[:start])
96
+ matrix.m = mtx.m
97
+ matrix.n = mtx.n
107
98
  matrix
108
99
  end
109
100
 
110
101
  def shape(a)
111
- if defined?(Matrix) && a.is_a?(Matrix)
102
+ if a.is_a?(Matrix)
103
+ [a.m, a.n]
104
+ elsif defined?(::Matrix) && a.is_a?(::Matrix)
112
105
  [a.row_count, a.column_count]
113
106
  elsif defined?(Numo::NArray) && a.is_a?(Numo::NArray)
114
107
  a.shape
@@ -126,7 +119,7 @@ module SCS
126
119
 
127
120
  if data[:p]
128
121
  raise ArgumentError, "Bad p shape" if shape(data[:p]) != [n, n]
129
- cdata.p = csc_matrix(data[:p])
122
+ cdata.p = csc_matrix(data[:p], upper: true)
130
123
  end
131
124
 
132
125
  raise ArgumentError, "Bad b size" if data[:b].to_a.size != m
data/lib/scs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module SCS
2
- VERSION = "0.3.2"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/scs.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  require "fiddle/import"
3
3
 
4
4
  # modules
5
+ require "scs/matrix"
5
6
  require "scs/solver"
6
7
  require "scs/version"
7
8
 
@@ -10,7 +10,7 @@ authors:
10
10
  - family-names: "Boyd"
11
11
  given-names: "Stephen"
12
12
  title: "SCS: Spltting Conic Solver"
13
- version: 3.1.1
13
+ version: 3.2.0
14
14
  date-released: 2021
15
15
  url: "https://github.com/cvxgrp/scs"
16
16
 
@@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.5)
5
5
 
6
6
  project(scs
7
7
  LANGUAGES C
8
- VERSION 3.1.1)
8
+ VERSION 3.2.0)
9
9
 
10
10
  # Defines the CMAKE_INSTALL_LIBDIR, CMAKE_INSTALL_BINDIR and many other useful macros.
11
11
  # See https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html
@@ -110,7 +110,7 @@ option(DLONG "Use long integers (64bit) for indexing" OFF)
110
110
  message(STATUS "Long integers (64bit) are ${DLONG}")
111
111
 
112
112
 
113
- set(COMPILER_OPTS "-DUSE_LAPACK -DCOPYAMATRIX -DCTRLC")
113
+ set(COMPILER_OPTS "-DUSE_LAPACK -DCTRLC")
114
114
 
115
115
  # Primitive types
116
116
  if(SFLOAT)
data/vendor/scs/README.md CHANGED
@@ -8,6 +8,8 @@
8
8
 
9
9
 
10
10
  SCS (`splitting conic solver`) is a numerical optimization package for solving
11
- large-scale convex cone problems. The current version is `3.1.1`.
11
+ large-scale convex cone problems. The current version is `3.2.0`.
12
12
 
13
13
  The full documentation is available [here](https://www.cvxgrp.org/scs/).
14
+
15
+ If you wish to cite SCS please cite the papers listed [here](https://www.cvxgrp.org/scs/citing).
@@ -18,14 +18,14 @@ struct SCS_CONE_WORK {
18
18
  * cone boundaries, boundaries[0] is starting index for cones of size larger
19
19
  * than 1
20
20
  */
21
- const ScsCone *k; /* original cone information */
21
+ ScsCone *k; /* original cone information */
22
22
  scs_int *cone_boundaries;
23
23
  scs_int cone_boundaries_len;
24
24
  scs_int scaled_cones; /* boolean, whether the cones have been scaled */
25
25
  scs_float *s; /* used for Moreau decomposition in projection */
26
26
  scs_int m; /* total length of cone */
27
27
  /* box cone quantities */
28
- scs_float *bl, *bu, box_t_warm_start;
28
+ scs_float box_t_warm_start;
29
29
  #ifdef USE_LAPACK
30
30
  /* workspace for eigenvector decompositions: */
31
31
  scs_float *Xs, *Z, *e, *work;
@@ -33,7 +33,9 @@ struct SCS_CONE_WORK {
33
33
  #endif
34
34
  };
35
35
 
36
- ScsConeWork *SCS(init_cone)(const ScsCone *k, scs_int m);
36
+ void SCS(free_cone)(ScsCone *k);
37
+ void SCS(deep_copy_cone)(ScsCone *dest, const ScsCone *src);
38
+ ScsConeWork *SCS(init_cone)(ScsCone *k, scs_int m);
37
39
  char *SCS(get_cone_header)(const ScsCone *k);
38
40
  scs_int SCS(validate_cones)(const ScsData *d, const ScsCone *k);
39
41
  scs_int SCS(proj_dual_cone)(scs_float *x, ScsConeWork *c, ScsScaling *scal,
@@ -14,7 +14,7 @@ extern "C" {
14
14
 
15
15
  /* SCS VERSION NUMBER ---------------------------------------------- */
16
16
  /* string literals automatically null-terminated */
17
- #define SCS_VERSION ("3.1.1")
17
+ #define SCS_VERSION ("3.2.0")
18
18
 
19
19
  /* verbosity level */
20
20
  #ifndef VERBOSITY
@@ -49,6 +49,9 @@ extern "C" {
49
49
  #define scs_realloc mxRealloc
50
50
  #elif defined PYTHON
51
51
  #include <Python.h>
52
+ /* see:
53
+ * https://cython-users.narkive.com/jRjjs3sK/reacquire-gil-for-printing-in-wrapped-c-library
54
+ */
52
55
  #define scs_printf(...) \
53
56
  { \
54
57
  PyGILState_STATE gilstate = PyGILState_Ensure(); \
@@ -60,8 +63,6 @@ extern "C" {
60
63
  #define scs_malloc PyMem_RawMalloc
61
64
  #define scs_realloc PyMem_RawRealloc
62
65
  #define scs_calloc PyMem_RawCalloc
63
- /* only for SuiteSparse + python */
64
- #define _scs_printf PySys_WriteStdout
65
66
  #else
66
67
  #define scs_free PyMem_Free
67
68
  #define scs_malloc PyMem_Malloc
@@ -107,8 +108,6 @@ static inline void *scs_calloc(size_t count, size_t size) {
107
108
  #endif
108
109
  #endif
109
110
 
110
- #define SCS_NULL 0
111
-
112
111
  #ifndef MAX
113
112
  #define MAX(a, b) (((a) > (b)) ? (a) : (b))
114
113
  #endif
@@ -8,6 +8,7 @@ extern "C" {
8
8
  #include "glbopts.h"
9
9
  #include "scs_work.h"
10
10
 
11
+ void SCS(normalize_b_c)(ScsScaling *scal, scs_float *b, scs_float *c);
11
12
  void SCS(normalize_sol)(ScsScaling *scal, ScsSolution *sol);
12
13
  void SCS(un_normalize_sol)(ScsScaling *scal, ScsSolution *sol);
13
14
  void SCS(un_normalize_primal)(ScsScaling *scal, scs_float *r);
@@ -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
  }
@@ -11,6 +11,8 @@ extern "C" {
11
11
  /* Contains definitions of primitive types `scs_int` and `scs_float`. */
12
12
  #include "scs_types.h"
13
13
 
14
+ #define SCS_NULL 0 /* NULL type */
15
+
14
16
  /* The following abstract structs are implemented later. */
15
17
 
16
18
  /** Struct containing acceleration workspace. Implemented by acceleration. */
@@ -116,11 +118,11 @@ typedef struct {
116
118
  scs_float *bl;
117
119
  /** Total length of box cone (includes scale `t`). */
118
120
  scs_int bsize;
119
- /** Array of second-order cone constraints. */
121
+ /** Array of second-order cone constraints, `len(q) = qsize`. */
120
122
  scs_int *q;
121
123
  /** Length of second-order cone array `q`. */
122
124
  scs_int qsize;
123
- /** Array of semidefinite cone constraints. */
125
+ /** Array of semidefinite cone constraints, `len(s) = ssize`. */
124
126
  scs_int *s;
125
127
  /** Length of semidefinite constraints array `s`. */
126
128
  scs_int ssize;
@@ -129,7 +131,7 @@ typedef struct {
129
131
  /** Number of dual exponential cone triples. */
130
132
  scs_int ed;
131
133
  /** Array of power cone params, must be in `[-1, 1]`, negative values are
132
- * interpreted as specifying the dual cone. */
134
+ * interpreted as specifying the dual cone, `len(p) = psize ` */
133
135
  scs_float *p;
134
136
  /** Number of (primal and dual) power cone triples. */
135
137
  scs_int psize;
@@ -205,7 +207,9 @@ typedef struct {
205
207
  /**
206
208
  * Initialize SCS and allocate memory.
207
209
  *
208
- * 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.
209
213
  *
210
214
  * It performs:
211
215
  * - data and settings validation
@@ -213,26 +217,45 @@ typedef struct {
213
217
  * - automatic parameters tuning (if enabled)
214
218
  * - setup linear system solver:
215
219
  * - 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.
220
+ * - indirect solver: KKT matrix preconditioning is performed here.
218
221
  *
219
222
  *
220
- * @param d Problem data.
221
- * @param k Cone data.
222
- * @param stgs SCS solver settings.
223
- * @return Solver work struct.
223
+ * @param d Problem data.
224
+ * @param k Cone data.
225
+ * @param stgs SCS solve settings.
226
+ * @return Solver workspace.
224
227
  */
225
228
  ScsWork *scs_init(const ScsData *d, const ScsCone *k, const ScsSettings *stgs);
226
229
 
230
+ /**
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
+
227
244
  /**
228
245
  * Solve quadratic cone program initialized by scs_init.
229
246
  *
230
- * @param w Workspace allocated by init.
231
- * @param sol Solver solution struct, will contain solution at termination.
232
- * @param info Solver info reporting.
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.
254
+ *
233
255
  * @return Flag containing problem status (see \a glbopts.h).
234
256
  */
235
- 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);
236
259
 
237
260
  /**
238
261
  * Clean up allocated SCS workspace.
@@ -246,13 +269,13 @@ void scs_finish(ScsWork *w);
246
269
  *
247
270
  * All the inputs must already be allocated in memory before calling.
248
271
  *
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).
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).
256
279
  */
257
280
  scs_int scs(const ScsData *d, const ScsCone *k, const ScsSettings *stgs,
258
281
  ScsSolution *sol, ScsInfo *info);
@@ -260,7 +283,7 @@ scs_int scs(const ScsData *d, const ScsCone *k, const ScsSettings *stgs,
260
283
  /**
261
284
  * Helper function to set all settings to default values (see \a glbopts.h).
262
285
  *
263
- * @param stgs Settings struct that will be populated.
286
+ * @param stgs Settings struct that will be populated.
264
287
  */
265
288
  void scs_set_default_settings(ScsSettings *stgs);
266
289
 
@@ -9,6 +9,8 @@
9
9
  extern "C" {
10
10
  #endif
11
11
 
12
+ #include "scs.h"
13
+
12
14
  /** Contains normalization variables. */
13
15
  typedef struct {
14
16
  scs_float *D, *E; /* for normalization */
@@ -40,10 +42,11 @@ typedef struct {
40
42
  scs_float *ax, *ax_s, *px, *aty, *ax_s_btau, *px_aty_ctau;
41
43
  } ScsResiduals;
42
44
 
43
- /** Workspace for SCS */
45
+ /** Workspace for SCS. */
44
46
  struct SCS_WORK {
45
47
  /* x_prev = x from previous iteration */
46
- scs_int time_limit_reached; /* set if the time-limit is reached */
48
+ scs_float setup_time; /* time taken for setup phase (milliseconds) */
49
+ scs_int time_limit_reached; /* boolean, if the time-limit is reached */
47
50
  scs_float *u, *u_t;
48
51
  scs_float *v, *v_prev;
49
52
  scs_float *rsk; /* rsk [ r; s; kappa ] */
@@ -51,30 +54,24 @@ struct SCS_WORK {
51
54
  scs_float *g; /* g = (I + M)^{-1} h */
52
55
  scs_float *lin_sys_warm_start; /* linear system warm-start (indirect only) */
53
56
  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 */
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 */
63
65
  /* normalized and unnormalized residuals */
64
66
  ScsResiduals *r_orig, *r_normalized;
65
67
  /* track x,y,s as alg progresses, tau *not* divided out */
66
68
  ScsSolution *xys_orig, *xys_normalized;
67
- /* updating scale params workspace */
69
+ /* Scale updating workspace */
68
70
  scs_float sum_log_scale_factor;
69
71
  scs_int last_scale_update_iter, n_log_scale_factor, scale_updates;
70
- /* aa norm stat */
72
+ /* AA stats */
71
73
  scs_float aa_norm;
72
74
  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
75
  };
79
76
 
80
77
  #ifdef __cplusplus
@@ -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
  }