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
@@ -71,7 +71,32 @@ scs_float SCS(tocq)(SCS(timer) * t) {
71
71
 
72
72
  #endif
73
73
 
74
- void SCS(free_data)(ScsData *d, ScsCone *k, ScsSettings *stgs) {
74
+ void SCS(deep_copy_data)(ScsData *dest, const ScsData *src) {
75
+ dest->n = src->n;
76
+ dest->m = src->m;
77
+ SCS(copy_matrix)(&(dest->A), src->A);
78
+ SCS(copy_matrix)(&(dest->P), src->P);
79
+ dest->b = (scs_float *)scs_calloc(dest->m, sizeof(scs_float));
80
+ memcpy(dest->b, src->b, dest->m * sizeof(scs_float));
81
+ dest->c = (scs_float *)scs_calloc(dest->n, sizeof(scs_float));
82
+ memcpy(dest->c, src->c, dest->n * sizeof(scs_float));
83
+ }
84
+
85
+ void SCS(deep_copy_stgs)(ScsSettings *dest, const ScsSettings *src) {
86
+ memcpy(dest, src, sizeof(ScsSettings));
87
+ if (src->write_data_filename) {
88
+ dest->write_data_filename = strdup(src->write_data_filename);
89
+ } else {
90
+ dest->write_data_filename = SCS_NULL;
91
+ }
92
+ if (src->log_csv_filename) {
93
+ dest->log_csv_filename = strdup(src->log_csv_filename);
94
+ } else {
95
+ dest->log_csv_filename = SCS_NULL;
96
+ }
97
+ }
98
+
99
+ void SCS(free_data)(ScsData *d) {
75
100
  if (d) {
76
101
  scs_free(d->b);
77
102
  scs_free(d->c);
@@ -83,17 +108,6 @@ void SCS(free_data)(ScsData *d, ScsCone *k, ScsSettings *stgs) {
83
108
  }
84
109
  scs_free(d);
85
110
  }
86
- if (k) {
87
- scs_free(k->bu);
88
- scs_free(k->bl);
89
- scs_free(k->q);
90
- scs_free(k->s);
91
- scs_free(k->p);
92
- scs_free(k);
93
- }
94
- if (stgs) {
95
- scs_free(stgs);
96
- }
97
111
  }
98
112
 
99
113
  void SCS(free_sol)(ScsSolution *sol) {
@@ -205,10 +205,10 @@ const char *verify_solution_correct(ScsData *d, ScsCone *k, ScsSettings *stgs,
205
205
  /**************** ASSERTS *****************/
206
206
  if (status == SCS_SOLVED) {
207
207
  mu_assert_less("Primal residual ERROR", ABS(res_pri - info->res_pri),
208
- 1e-11);
208
+ 1e-10);
209
209
  mu_assert_less("Dual residual ERROR", ABS(res_dual - info->res_dual),
210
- 1e-11);
211
- mu_assert_less("Gap ERROR", ABS(gap - info->gap), 1e-8 * (1 + ABS(gap)));
210
+ 1e-10);
211
+ mu_assert_less("Gap ERROR", ABS(gap - info->gap), 1e-7 * (1 + ABS(gap)));
212
212
  mu_assert_less("Primal obj ERROR", ABS(pobj - info->pobj),
213
213
  1e-9 * (1 + ABS(pobj)));
214
214
  mu_assert_less("Dual obj ERROR", ABS(dobj - info->dobj),
@@ -1,6 +1,7 @@
1
1
  #include "glbopts.h"
2
2
  #include "linalg.h"
3
3
  #include "minunit.h"
4
+ #include "problem_utils.h"
4
5
  #include "scs.h"
5
6
  #include "scs_matrix.h"
6
7
  #include "util.h"
@@ -1,6 +1,7 @@
1
1
  #include "glbopts.h"
2
2
  #include "linalg.h"
3
3
  #include "minunit.h"
4
+ #include "problem_utils.h"
4
5
  #include "scs.h"
5
6
  #include "scs_matrix.h"
6
7
  #include "util.h"
@@ -1,6 +1,7 @@
1
1
  #include "glbopts.h"
2
2
  #include "linalg.h"
3
3
  #include "minunit.h"
4
+ #include "problem_utils.h"
4
5
  #include "rw.h"
5
6
  #include "scs.h"
6
7
  #include "scs_matrix.h"
@@ -110,7 +111,10 @@ static const char *hs21_tiny_qp_rw(void) {
110
111
  mu_assert("hs21_tiny_qp: SCS failed to produce outputflag SCS_SOLVED",
111
112
  success);
112
113
 
114
+ SCS(free_data)(d);
115
+ SCS(free_cone)(k);
113
116
  SCS(free_sol)(sol);
114
- SCS(free_data)(d, k, stgs);
117
+ scs_free(stgs);
118
+
115
119
  return fail;
116
120
  }
@@ -1,6 +1,7 @@
1
1
  #include "glbopts.h"
2
2
  #include "linalg.h"
3
3
  #include "minunit.h"
4
+ #include "problem_utils.h"
4
5
  #include "scs.h"
5
6
  #include "scs_matrix.h"
6
7
  #include "util.h"
@@ -1,6 +1,7 @@
1
1
  #include "glbopts.h"
2
2
  #include "linalg.h"
3
3
  #include "minunit.h"
4
+ #include "problem_utils.h"
4
5
  #include "scs.h"
5
6
  #include "scs_matrix.h"
6
7
  #include "util.h"
@@ -141,7 +142,7 @@ static const char *qafiro_tiny_qp(void) {
141
142
  stgs->warm_start = 1;
142
143
  exitflag = scs(d, k, stgs, sol, &info);
143
144
  /* 25 iters should be enough if warm-started */
144
- mu_assert("qafiro_tiny_qp: warm-start failure", info.iter <= 50);
145
+ mu_assert("qafiro_tiny_qp: warm-start failure", info.iter <= 100);
145
146
  success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
146
147
 
147
148
  mu_assert("qafiro_tiny_qp: SCS failed to produce outputflag SCS_SOLVED",
@@ -1,6 +1,7 @@
1
1
  #include "glbopts.h"
2
2
  #include "minunit.h"
3
3
  #include "problem_utils.h"
4
+ #include "rw.h"
4
5
  #include "scs.h"
5
6
  #include "util.h"
6
7
 
@@ -39,7 +40,10 @@ static const char *random_prob(void) {
39
40
 
40
41
  mu_assert("random_prob: SCS failed to produce SCS_SOLVED", success);
41
42
  fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
42
- SCS(free_data)(d, k, stgs);
43
+ SCS(free_data)(d);
44
+ SCS(free_cone)(k);
43
45
  SCS(free_sol)(sol);
46
+ scs_free(stgs);
47
+
44
48
  return fail;
45
49
  }
@@ -1,6 +1,8 @@
1
1
  #include "glbopts.h"
2
2
  #include "linalg.h"
3
3
  #include "minunit.h"
4
+ #include "problem_utils.h"
5
+ #include "rw.h"
4
6
  #include "scs.h"
5
7
  #include "scs_matrix.h"
6
8
  #include "util.h"
@@ -173,6 +175,8 @@ static const char *rob_gauss_cov_est(void) {
173
175
  mu_assert("rob_gauss_cov_est: SCS failed to produce outputflag SCS_SOLVED",
174
176
  success);
175
177
  fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
178
+ if (fail)
179
+ return fail;
176
180
 
177
181
  /* test warm-starting */
178
182
  stgs->warm_start = 1;
@@ -236,7 +240,10 @@ static const char *rob_gauss_cov_est(void) {
236
240
  mu_assert("rob_gauss_cov_est_rw: SCS failed to produce outputflag SCS_SOLVED",
237
241
  success);
238
242
 
243
+ SCS(free_data)(d);
244
+ SCS(free_cone)(k);
239
245
  SCS(free_sol)(sol);
240
- SCS(free_data)(d, k, stgs);
246
+ scs_free(stgs);
247
+
241
248
  return fail;
242
249
  }
@@ -44,8 +44,11 @@ static const char *small_lp(void) {
44
44
 
45
45
  mu_assert("small_lp: SCS failed to produce outputflag SCS_SOLVED", success);
46
46
  fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
47
- SCS(free_data)(d, k, stgs);
47
+ SCS(free_data)(d);
48
+ SCS(free_cone)(k);
48
49
  SCS(free_sol)(sol);
49
50
  SCS(free_sol)(opt_sol);
51
+ scs_free(stgs);
52
+
50
53
  return fail;
51
54
  }
@@ -251,7 +251,7 @@ scs_float u[] = {
251
251
  96.00000, 96.00000, 96.00000, 96.00000, 96.00000, 96.00000,
252
252
  96.00000, 96.00000, 96.00000, 96.00000, 96.00000, 96.00000,
253
253
  96.00000, 96.00000, 96.00000, 96.00000};
254
- scs_float q[] = {0.00000, 0.00000, -35.02643, 0.00000, 0.00000,
254
+ scs_float c[] = {0.00000, 0.00000, -35.02643, 0.00000, 0.00000,
255
255
  -3.56718, 0.00000, -17.41907, 0.00000, 0.00000,
256
256
  -17.64691, 0.00000, 0.00000, 0.00000, 0.00000,
257
257
  0.00000, 0.00000, 0.00000, 0.00000, 0.00000,
@@ -298,7 +298,7 @@ static const char *small_qp(void) {
298
298
  d->n = n;
299
299
  d->b = (scs_float *)scs_calloc(m + 1, sizeof(scs_float));
300
300
  d->b[0] = 1; /* t var in box cone */
301
- d->c = q;
301
+ d->c = c;
302
302
 
303
303
  d->A = (ScsMatrix *)scs_calloc(1, sizeof(ScsMatrix));
304
304
  d->A->m = m + 1; /* t var in box cone */
@@ -332,11 +332,48 @@ static const char *small_qp(void) {
332
332
  stgs->eps_rel = 1e-6;
333
333
  stgs->eps_infeas = 1e-10;
334
334
 
335
- exitflag = scs(d, k, stgs, sol, &info);
335
+ ScsWork *w = scs_init(d, k, stgs);
336
+ exitflag = scs_solve(w, sol, &info, 0);
336
337
  success = exitflag == SCS_SOLVED;
337
338
 
338
339
  mu_assert("small_qp: SCS failed to produce outputflag SCS_SOLVED", success);
339
340
  fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
341
+ if (fail)
342
+ return fail;
343
+
344
+ /* test updating c */
345
+ d->c[0] = 1.0; /* set to new value */
346
+ scs_update(w, SCS_NULL, d->c);
347
+ exitflag = scs_solve(w, sol, &info, 1);
348
+ success = exitflag == SCS_SOLVED;
349
+
350
+ mu_assert("small_qp: SCS failed to produce outputflag SCS_SOLVED", success);
351
+ fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
352
+ if (fail)
353
+ return fail;
354
+
355
+ /* test updating b */
356
+ d->b[0] = 4.0; /* set to new value */
357
+ scs_update(w, d->b, SCS_NULL);
358
+ exitflag = scs_solve(w, sol, &info, 1);
359
+ success = exitflag == SCS_SOLVED;
360
+
361
+ mu_assert("small_qp: SCS failed to produce outputflag SCS_SOLVED", success);
362
+ fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
363
+ if (fail)
364
+ return fail;
365
+
366
+ /* revert back to original data */
367
+ d->c[0] = 0.0; /* revert to original value */
368
+ d->b[0] = 1.0; /* revert to original value */
369
+ scs_update(w, d->b, d->c);
370
+ exitflag = scs_solve(w, sol, &info, 1);
371
+ success = exitflag == SCS_SOLVED;
372
+
373
+ mu_assert("small_qp: SCS failed to produce outputflag SCS_SOLVED", success);
374
+ fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
375
+
376
+ scs_finish(w);
340
377
 
341
378
  scs_free(d->A);
342
379
  scs_free(d->P);
@@ -344,9 +381,7 @@ static const char *small_qp(void) {
344
381
  scs_free(k);
345
382
  scs_free(d);
346
383
  scs_free(stgs);
347
- scs_free(sol->x);
348
- scs_free(sol->y);
349
- scs_free(sol->s);
350
- scs_free(sol);
384
+ SCS(free_sol)(sol);
385
+
351
386
  return fail;
352
387
  }
@@ -36,8 +36,11 @@ static const char *test_validation(void) {
36
36
 
37
37
  mu_assert("test_fails: SCS failed to produce outputflag SCS_FAILED",
38
38
  exitflag == SCS_FAILED);
39
- SCS(free_data)(d, k, stgs);
39
+ SCS(free_data)(d);
40
+ SCS(free_cone)(k);
40
41
  SCS(free_sol)(sol);
41
42
  SCS(free_sol)(opt_sol);
43
+ scs_free(stgs);
44
+
42
45
  return 0;
43
46
  }
@@ -1,6 +1,7 @@
1
1
  #include "glbopts.h"
2
2
  #include "linalg.h"
3
3
  #include "minunit.h"
4
+ #include "problem_utils.h"
4
5
  #include "scs.h"
5
6
  #include "scs_matrix.h"
6
7
  #include "util.h"
@@ -73,10 +74,9 @@ static const char *unbounded_tiny_qp(void) {
73
74
  fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
74
75
 
75
76
  SCS(free_sol)(sol);
76
- scs_free(d->A);
77
- scs_free(d->P);
78
- scs_free(k);
77
+ SCS(free_cone)(k);
79
78
  scs_free(stgs);
79
+ scs_free(d->A);
80
80
  scs_free(d);
81
81
  return fail;
82
82
  }
@@ -164,9 +164,11 @@ int main(int argc, char **argv) {
164
164
  scs_printf("scs dua obj = %4f\n", -SCS(dot)(d->b, sol->y, d->m));
165
165
  }
166
166
 
167
- SCS(free_data)(d, k, stgs);
167
+ SCS(free_data)(d);
168
+ SCS(free_cone)(k);
168
169
  SCS(free_sol)(sol);
169
170
  SCS(free_sol)(opt_sol);
171
+ scs_free(stgs);
170
172
 
171
173
  return 0;
172
174
  }
@@ -61,18 +61,30 @@ int main(int argc, char **argv) {
61
61
  for (i = 2; i < argc; i += 2) {
62
62
  if (argc < i + 2) {
63
63
  scs_printf("Incorrect number of arguments supplied\n.");
64
- SCS(free_data)(d, k, stgs);
64
+
65
+ SCS(free_data)(d);
66
+ SCS(free_cone)(k);
67
+ scs_free(stgs);
68
+
65
69
  return -1;
66
70
  }
67
71
  if (override_setting(stgs, argv[i], argv[i + 1]) < 0) {
68
72
  scs_printf("Unrecognized setting %s\n", argv[i]);
69
- SCS(free_data)(d, k, stgs);
73
+
74
+ SCS(free_data)(d);
75
+ SCS(free_cone)(k);
76
+ scs_free(stgs);
77
+
70
78
  return -1;
71
79
  }
72
80
  }
73
81
  sol = (ScsSolution *)scs_calloc(1, sizeof(ScsSolution));
74
82
  scs(d, k, stgs, sol, &info);
75
- SCS(free_data)(d, k, stgs);
83
+
84
+ SCS(free_data)(d);
85
+ SCS(free_cone)(k);
76
86
  SCS(free_sol)(sol);
87
+ scs_free(stgs);
88
+
77
89
  return 0;
78
90
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-17 00:00:00.000000000 Z
11
+ date: 2022-07-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: andrew@ankane.org
@@ -23,6 +23,7 @@ files:
23
23
  - ext/scs/extconf.rb
24
24
  - lib/scs.rb
25
25
  - lib/scs/ffi.rb
26
+ - lib/scs/matrix.rb
26
27
  - lib/scs/solver.rb
27
28
  - lib/scs/version.rb
28
29
  - vendor/scs/CITATION.cff
@@ -120,14 +121,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
121
  requirements:
121
122
  - - ">="
122
123
  - !ruby/object:Gem::Version
123
- version: '2.4'
124
+ version: '2.7'
124
125
  required_rubygems_version: !ruby/object:Gem::Requirement
125
126
  requirements:
126
127
  - - ">="
127
128
  - !ruby/object:Gem::Version
128
129
  version: '0'
129
130
  requirements: []
130
- rubygems_version: 3.3.3
131
+ rubygems_version: 3.3.7
131
132
  signing_key:
132
133
  specification_version: 4
133
134
  summary: SCS - the splitting conic solver - for Ruby