scs 0.2.3 → 0.3.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 (100) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/README.md +11 -6
  4. data/lib/scs/ffi.rb +30 -13
  5. data/lib/scs/solver.rb +32 -9
  6. data/lib/scs/version.rb +1 -1
  7. data/vendor/scs/CITATION.cff +39 -0
  8. data/vendor/scs/CMakeLists.txt +7 -8
  9. data/vendor/scs/Makefile +24 -15
  10. data/vendor/scs/README.md +5 -263
  11. data/vendor/scs/include/aa.h +67 -23
  12. data/vendor/scs/include/cones.h +17 -17
  13. data/vendor/scs/include/glbopts.h +98 -32
  14. data/vendor/scs/include/linalg.h +2 -4
  15. data/vendor/scs/include/linsys.h +58 -44
  16. data/vendor/scs/include/normalize.h +3 -3
  17. data/vendor/scs/include/rw.h +8 -2
  18. data/vendor/scs/include/scs.h +293 -133
  19. data/vendor/scs/include/util.h +3 -15
  20. data/vendor/scs/linsys/cpu/direct/private.c +220 -224
  21. data/vendor/scs/linsys/cpu/direct/private.h +13 -7
  22. data/vendor/scs/linsys/cpu/direct/private.o +0 -0
  23. data/vendor/scs/linsys/cpu/indirect/private.c +177 -110
  24. data/vendor/scs/linsys/cpu/indirect/private.h +8 -4
  25. data/vendor/scs/linsys/cpu/indirect/private.o +0 -0
  26. data/vendor/scs/linsys/csparse.c +87 -0
  27. data/vendor/scs/linsys/csparse.h +34 -0
  28. data/vendor/scs/linsys/csparse.o +0 -0
  29. data/vendor/scs/linsys/external/amd/SuiteSparse_config.c +1 -1
  30. data/vendor/scs/linsys/external/amd/SuiteSparse_config.o +0 -0
  31. data/vendor/scs/linsys/external/amd/amd_1.o +0 -0
  32. data/vendor/scs/linsys/external/amd/amd_2.o +0 -0
  33. data/vendor/scs/linsys/external/amd/amd_aat.o +0 -0
  34. data/vendor/scs/linsys/external/amd/amd_control.o +0 -0
  35. data/vendor/scs/linsys/external/amd/amd_defaults.o +0 -0
  36. data/vendor/scs/linsys/external/amd/amd_dump.o +0 -0
  37. data/vendor/scs/linsys/external/amd/amd_global.o +0 -0
  38. data/vendor/scs/linsys/external/amd/amd_info.o +0 -0
  39. data/vendor/scs/linsys/external/amd/amd_internal.h +1 -1
  40. data/vendor/scs/linsys/external/amd/amd_order.o +0 -0
  41. data/vendor/scs/linsys/external/amd/amd_post_tree.o +0 -0
  42. data/vendor/scs/linsys/external/amd/amd_postorder.o +0 -0
  43. data/vendor/scs/linsys/external/amd/amd_preprocess.o +0 -0
  44. data/vendor/scs/linsys/external/amd/amd_valid.o +0 -0
  45. data/vendor/scs/linsys/external/qdldl/changes +2 -0
  46. data/vendor/scs/linsys/external/qdldl/qdldl.c +29 -46
  47. data/vendor/scs/linsys/external/qdldl/qdldl.h +33 -41
  48. data/vendor/scs/linsys/external/qdldl/qdldl.o +0 -0
  49. data/vendor/scs/linsys/external/qdldl/qdldl_types.h +11 -3
  50. data/vendor/scs/linsys/gpu/gpu.c +31 -33
  51. data/vendor/scs/linsys/gpu/gpu.h +48 -31
  52. data/vendor/scs/linsys/gpu/indirect/private.c +338 -232
  53. data/vendor/scs/linsys/gpu/indirect/private.h +23 -14
  54. data/vendor/scs/linsys/scs_matrix.c +498 -0
  55. data/vendor/scs/linsys/scs_matrix.h +70 -0
  56. data/vendor/scs/linsys/scs_matrix.o +0 -0
  57. data/vendor/scs/scs.mk +13 -9
  58. data/vendor/scs/src/aa.c +384 -109
  59. data/vendor/scs/src/aa.o +0 -0
  60. data/vendor/scs/src/cones.c +440 -353
  61. data/vendor/scs/src/cones.o +0 -0
  62. data/vendor/scs/src/ctrlc.c +15 -5
  63. data/vendor/scs/src/ctrlc.o +0 -0
  64. data/vendor/scs/src/linalg.c +84 -28
  65. data/vendor/scs/src/linalg.o +0 -0
  66. data/vendor/scs/src/normalize.c +22 -64
  67. data/vendor/scs/src/normalize.o +0 -0
  68. data/vendor/scs/src/rw.c +160 -21
  69. data/vendor/scs/src/rw.o +0 -0
  70. data/vendor/scs/src/scs.c +767 -563
  71. data/vendor/scs/src/scs.o +0 -0
  72. data/vendor/scs/src/scs_indir.o +0 -0
  73. data/vendor/scs/src/scs_version.c +9 -3
  74. data/vendor/scs/src/scs_version.o +0 -0
  75. data/vendor/scs/src/util.c +37 -106
  76. data/vendor/scs/src/util.o +0 -0
  77. data/vendor/scs/test/minunit.h +17 -8
  78. data/vendor/scs/test/problem_utils.h +176 -14
  79. data/vendor/scs/test/problems/degenerate.h +130 -0
  80. data/vendor/scs/test/problems/hs21_tiny_qp.h +124 -0
  81. data/vendor/scs/test/problems/hs21_tiny_qp_rw.h +116 -0
  82. data/vendor/scs/test/problems/infeasible_tiny_qp.h +100 -0
  83. data/vendor/scs/test/problems/qafiro_tiny_qp.h +199 -0
  84. data/vendor/scs/test/problems/random_prob +0 -0
  85. data/vendor/scs/test/problems/random_prob.h +45 -0
  86. data/vendor/scs/test/problems/rob_gauss_cov_est.h +188 -31
  87. data/vendor/scs/test/problems/small_lp.h +13 -14
  88. data/vendor/scs/test/problems/test_fails.h +43 -0
  89. data/vendor/scs/test/problems/unbounded_tiny_qp.h +82 -0
  90. data/vendor/scs/test/random_socp_prob.c +54 -53
  91. data/vendor/scs/test/rng.h +109 -0
  92. data/vendor/scs/test/run_from_file.c +19 -10
  93. data/vendor/scs/test/run_tests.c +27 -3
  94. metadata +20 -8
  95. data/vendor/scs/linsys/amatrix.c +0 -305
  96. data/vendor/scs/linsys/amatrix.h +0 -36
  97. data/vendor/scs/linsys/amatrix.o +0 -0
  98. data/vendor/scs/test/data/small_random_socp +0 -0
  99. data/vendor/scs/test/problems/small_random_socp.h +0 -33
  100. data/vendor/scs/test/run_tests +0 -2
@@ -1,47 +1,141 @@
1
- #include "amatrix.h"
2
1
  #include "glbopts.h"
3
2
  #include "linalg.h"
4
3
  #include "minunit.h"
5
4
  #include "scs.h"
5
+ #include "scs_matrix.h"
6
6
  #include "util.h"
7
7
 
8
- static scs_float Ax[] = {-1.0, -0.25035003149, -0.214684983694, -0.0013696512491, -1.0, -1.0, 0.0941450010301, -0.0929840802212, 0.0143905024814, -1.0, -1.41421356237, -1.0, 0.0941450010301, -0.0929840802212, 0.0143905024814, 1.0, -1.0, -0.0354035554388, -0.0402731435884, -0.151196563215, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.41421356237, 1.0, -1.41421356237, 1.0, -1.41421356237, 1.0, -1.0, 1.0, -1.41421356237, 1.0, -1.41421356237, 1.0, -1.0, 1.0, 1.0, -1.41421356237, 1.0, -1.0, -1.0, -1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0};
9
- static scs_int Ai[] = {11, 15, 16, 17, 36, 12, 15, 16, 17, 18, 37, 13, 15, 16, 17, 18, 14, 15, 16, 17, 38, 15, 19, 16, 20, 17, 21, 19, 20, 21, 25, 19, 20, 21, 19, 22, 20, 23, 21, 24, 3, 26, 4, 5, 27, 7, 28, 9, 29, 6, 30, 8, 31, 10, 32, 11, 33, 12, 13, 34, 14, 35, 1, 7, 0, 8, 9, 2, 10, 1, 3, 41, 2, 6, 44, 25, 39, 25, 42};
10
- static scs_int Ap[] = {0, 5, 11, 16, 21, 23, 25, 27, 31, 34, 36, 38, 40, 42, 45, 47, 49, 51, 53, 55, 57, 60, 62, 64, 66, 67, 69, 72, 75, 77, 79};
11
- static scs_float b[] = {-0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, 1.0, -0.0, -0.0, 1.0, -0.0};
12
- static scs_float c[] ={0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
13
-
14
- static scs_int m = 45;
15
- static scs_int n = 30;
16
-
17
- static scs_int f = 19;
18
- static scs_int l = 7;
19
- static scs_int *q = SCS_NULL;
20
- static scs_int qsize = 0;
21
- static scs_int s[] = {4, 2};
22
- static scs_int ssize = 2;
23
- static scs_int ep = 2;
24
- static scs_int ed = 0;
25
- static scs_float *p = SCS_NULL;
26
- static scs_int psize = 0;
27
-
28
- static scs_float opt = -4.8912;
29
-
30
8
  static const char *rob_gauss_cov_est(void) {
31
9
  ScsCone *k = (ScsCone *)scs_calloc(1, sizeof(ScsCone));
32
10
  ScsData *d = (ScsData *)scs_calloc(1, sizeof(ScsData));
11
+ ScsSettings *stgs = (ScsSettings *)scs_calloc(1, sizeof(ScsSettings));
33
12
  ScsSolution *sol = (ScsSolution *)scs_calloc(1, sizeof(ScsSolution));
34
13
  ScsInfo info = {0};
35
14
  scs_int exitflag;
36
15
  scs_float perr, derr;
37
16
  scs_int success;
17
+ const char *fail;
18
+
19
+ /* data */
20
+ scs_float Ax[] = {-1.0,
21
+ -0.25035003149,
22
+ -0.214684983694,
23
+ -0.0013696512491,
24
+ -1.0,
25
+ -1.0,
26
+ 0.0941450010301,
27
+ -0.0929840802212,
28
+ 0.0143905024814,
29
+ -1.0,
30
+ -1.41421356237,
31
+ -1.0,
32
+ 0.0941450010301,
33
+ -0.0929840802212,
34
+ 0.0143905024814,
35
+ 1.0,
36
+ -1.0,
37
+ -0.0354035554388,
38
+ -0.0402731435884,
39
+ -0.151196563215,
40
+ -1.0,
41
+ 1.0,
42
+ 1.0,
43
+ 1.0,
44
+ 1.0,
45
+ 1.0,
46
+ 1.0,
47
+ 1.0,
48
+ 1.0,
49
+ 1.0,
50
+ -1.0,
51
+ -1.0,
52
+ -1.0,
53
+ -1.0,
54
+ -1.0,
55
+ -1.0,
56
+ -1.0,
57
+ -1.0,
58
+ -1.0,
59
+ -1.0,
60
+ 1.0,
61
+ -1.0,
62
+ 1.0,
63
+ 1.0,
64
+ -1.41421356237,
65
+ 1.0,
66
+ -1.41421356237,
67
+ 1.0,
68
+ -1.41421356237,
69
+ 1.0,
70
+ -1.0,
71
+ 1.0,
72
+ -1.41421356237,
73
+ 1.0,
74
+ -1.41421356237,
75
+ 1.0,
76
+ -1.0,
77
+ 1.0,
78
+ 1.0,
79
+ -1.41421356237,
80
+ 1.0,
81
+ -1.0,
82
+ -1.0,
83
+ -1.0,
84
+ 1.0,
85
+ -1.0,
86
+ -1.0,
87
+ -1.0,
88
+ -1.0,
89
+ 1.0,
90
+ -1.0,
91
+ -1.0,
92
+ 1.0,
93
+ -1.0,
94
+ -1.0,
95
+ -1.0,
96
+ -1.0,
97
+ -1.0,
98
+ -1.0};
99
+ scs_int Ai[] = {11, 15, 16, 17, 36, 12, 15, 16, 17, 18, 37, 13, 15, 16,
100
+ 17, 18, 14, 15, 16, 17, 38, 15, 19, 16, 20, 17, 21, 19,
101
+ 20, 21, 25, 19, 20, 21, 19, 22, 20, 23, 21, 24, 3, 26,
102
+ 4, 5, 27, 7, 28, 9, 29, 6, 30, 8, 31, 10, 32, 11,
103
+ 33, 12, 13, 34, 14, 35, 1, 7, 0, 8, 9, 2, 10, 1,
104
+ 3, 41, 2, 6, 44, 25, 39, 25, 42};
105
+ scs_int Ap[] = {0, 5, 11, 16, 21, 23, 25, 27, 31, 34, 36,
106
+ 38, 40, 42, 45, 47, 49, 51, 53, 55, 57, 60,
107
+ 62, 64, 66, 67, 69, 72, 75, 77, 79};
108
+ scs_float b[] = {-0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0,
109
+ -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0,
110
+ -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0,
111
+ -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0,
112
+ -0.0, -0.0, -0.0, -0.0, 1.0, -0.0, -0.0, 1.0, -0.0};
113
+ scs_float c[] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 1.0,
114
+ 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
115
+ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
116
+
117
+ scs_int m = 45;
118
+ scs_int n = 30;
119
+
120
+ scs_int z = 19;
121
+ scs_int l = 7;
122
+ scs_int *q = SCS_NULL;
123
+ scs_int qsize = 0;
124
+ scs_int s[] = {4, 2};
125
+ scs_int ssize = 2;
126
+ scs_int ep = 2;
127
+ scs_int ed = 0;
128
+ scs_float *p = SCS_NULL;
129
+ scs_int psize = 0;
130
+
131
+ scs_float opt = -4.8912;
132
+ /* end data */
38
133
 
39
134
  d->m = m;
40
135
  d->n = n;
41
136
  d->b = b;
42
137
  d->c = c;
43
138
 
44
- d->stgs = (ScsSettings *)scs_calloc(1, sizeof(ScsSettings));
45
139
  d->A = (ScsMatrix *)scs_calloc(1, sizeof(ScsMatrix));
46
140
 
47
141
  d->A->m = m;
@@ -50,7 +144,7 @@ static const char *rob_gauss_cov_est(void) {
50
144
  d->A->i = Ai;
51
145
  d->A->p = Ap;
52
146
 
53
- k->f = f;
147
+ k->z = z;
54
148
  k->l = l;
55
149
  k->q = q;
56
150
  k->qsize = qsize;
@@ -61,9 +155,12 @@ static const char *rob_gauss_cov_est(void) {
61
155
  k->p = p;
62
156
  k->psize = psize;
63
157
 
64
- SCS(set_default_settings)(d);
158
+ SCS(set_default_settings)(stgs);
159
+ stgs->eps_abs = 1e-6;
160
+ stgs->eps_rel = 1e-6;
161
+ stgs->eps_infeas = 1e-9;
65
162
 
66
- exitflag = scs(d, k, sol, &info);
163
+ exitflag = scs(d, k, stgs, sol, &info);
67
164
 
68
165
  perr = SCS(dot)(d->c, sol->x, d->n) - opt;
69
166
  derr = -SCS(dot)(d->b, sol->y, d->m) - opt;
@@ -73,13 +170,73 @@ static const char *rob_gauss_cov_est(void) {
73
170
 
74
171
  success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
75
172
 
76
- SCS(free_sol)(sol);
173
+ mu_assert("rob_gauss_cov_est: SCS failed to produce outputflag SCS_SOLVED",
174
+ success);
175
+ fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
176
+
177
+ /* test warm-starting */
178
+ stgs->warm_start = 1;
179
+ exitflag = scs(d, k, stgs, sol, &info);
180
+ /* 100 iters should be enough if warm-started */
181
+ mu_assert("rob_gauss_cov_est: warm-start failure", info.iter <= 100);
182
+ success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
183
+
184
+ mu_assert("rob_gauss_cov_est: SCS failed to produce outputflag SCS_SOLVED",
185
+ success);
186
+
187
+ /* test read / write */
188
+ stgs->write_data_filename = "rob_gauss_cov_est";
189
+ stgs->max_iters = 1;
190
+
191
+ exitflag = scs(d, k, stgs, sol, &info);
192
+
193
+ /* kill data */
77
194
  scs_free(d->A);
78
195
  scs_free(k);
79
- scs_free(d->stgs);
196
+ scs_free(stgs);
80
197
  scs_free(d);
81
198
 
82
- mu_assert("rob_gauss_cov_est: SCS failed to produce outputflag SCS_SOLVED",
199
+ SCS(read_data)("rob_gauss_cov_est", &d, &k, &stgs);
200
+ stgs->max_iters = 1000;
201
+ /* solve with read data */
202
+ exitflag = scs(d, k, stgs, sol, &info);
203
+
204
+ perr = info.pobj - opt;
205
+ derr = info.dobj - opt;
206
+
207
+ scs_printf("primal obj error %4e\n", perr);
208
+ scs_printf("dual obj error %4e\n", derr);
209
+
210
+ success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
211
+
212
+ mu_assert("rob_gauss_cov_est_rw: SCS failed to produce outputflag SCS_SOLVED",
83
213
  success);
84
- return 0;
214
+ fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
215
+
216
+ /* test other settings */
217
+ stgs->warm_start = 0;
218
+ stgs->normalize = 0;
219
+ stgs->adaptive_scale = 0;
220
+ stgs->acceleration_lookback = 10;
221
+ stgs->acceleration_interval = 10;
222
+ stgs->write_data_filename = SCS_NULL;
223
+ stgs->max_iters = 1000;
224
+ stgs->log_csv_filename = "rob_gauss_cov_est.csv";
225
+
226
+ exitflag = scs(d, k, stgs, sol, &info);
227
+
228
+ perr = info.pobj - opt;
229
+ derr = info.dobj - opt;
230
+
231
+ scs_printf("primal obj error %4e\n", perr);
232
+ scs_printf("dual obj error %4e\n", derr);
233
+
234
+ success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
235
+
236
+ mu_assert("rob_gauss_cov_est_rw: SCS failed to produce outputflag SCS_SOLVED",
237
+ success);
238
+
239
+ SCS(free_sol)(sol);
240
+ SCS(free_data)(d, k, stgs);
241
+ return fail;
85
242
  }
@@ -7,6 +7,7 @@
7
7
  static const char *small_lp(void) {
8
8
  ScsCone *k = (ScsCone *)scs_calloc(1, sizeof(ScsCone));
9
9
  ScsData *d = (ScsData *)scs_calloc(1, sizeof(ScsData));
10
+ ScsSettings *stgs = (ScsSettings *)scs_calloc(1, sizeof(ScsSettings));
10
11
  ScsSolution *sol = (ScsSolution *)scs_calloc(1, sizeof(ScsSolution));
11
12
  ScsSolution *opt_sol = (ScsSolution *)scs_calloc(1, sizeof(ScsSolution));
12
13
  ScsInfo info = {0};
@@ -19,22 +20,19 @@ static const char *small_lp(void) {
19
20
  scs_int exitflag;
20
21
  scs_float perr, derr;
21
22
  scs_int success;
23
+ const char *fail;
22
24
 
23
- d->stgs = (ScsSettings *)scs_calloc(1, sizeof(ScsSettings));
24
- k->f = (scs_int)floor(m * p_f);
25
- k->l = m - k->f;
26
-
27
- srand(seed);
25
+ k->z = (scs_int)floor(m * p_f);
26
+ k->l = m - k->z;
28
27
 
29
28
  d->m = m;
30
29
  d->n = n;
31
- gen_random_prob_data(nnz, col_nnz, d, k, opt_sol);
32
- SCS(set_default_settings)(d);
33
-
34
- /* this test fails with the default choice of 10 */
35
- d->stgs->acceleration_lookback = 20;
30
+ gen_random_prob_data(nnz, col_nnz, d, k, opt_sol, seed);
31
+ SCS(set_default_settings)(stgs);
32
+ stgs->eps_abs = 1e-5;
33
+ stgs->eps_rel = 1e-5;
36
34
 
37
- exitflag = scs(d, k, sol, &info);
35
+ exitflag = scs(d, k, stgs, sol, &info);
38
36
  perr = SCS(dot)(d->c, sol->x, d->n) - SCS(dot)(d->c, opt_sol->x, d->n);
39
37
  derr = -SCS(dot)(d->b, sol->y, d->m) + SCS(dot)(d->b, opt_sol->y, d->m);
40
38
  scs_printf("primal obj error %4e\n", perr);
@@ -42,9 +40,10 @@ static const char *small_lp(void) {
42
40
 
43
41
  success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
44
42
 
45
- SCS(free_data)(d, k);
43
+ mu_assert("small_lp: SCS failed to produce outputflag SCS_SOLVED", success);
44
+ fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
45
+ SCS(free_data)(d, k, stgs);
46
46
  SCS(free_sol)(sol);
47
47
  SCS(free_sol)(opt_sol);
48
- mu_assert("small_lp: SCS failed to produce outputflag SCS_SOLVED", success);
49
- return 0;
48
+ return fail;
50
49
  }
@@ -0,0 +1,43 @@
1
+ #include "glbopts.h"
2
+ #include "minunit.h"
3
+ #include "problem_utils.h"
4
+ #include "scs.h"
5
+ #include "util.h"
6
+
7
+ static const char *test_fails(void) {
8
+ scs_printf("Testing that SCS handles bad inputs correctly:");
9
+
10
+ ScsCone *k = (ScsCone *)scs_calloc(1, sizeof(ScsCone));
11
+ ScsData *d = (ScsData *)scs_calloc(1, sizeof(ScsData));
12
+ ScsSettings *stgs = (ScsSettings *)scs_calloc(1, sizeof(ScsSettings));
13
+ ScsSolution *sol = (ScsSolution *)scs_calloc(1, sizeof(ScsSolution));
14
+ ScsSolution *opt_sol = (ScsSolution *)scs_calloc(1, sizeof(ScsSolution));
15
+ ScsInfo info = {0};
16
+ scs_float p_f = 0.1;
17
+ int seed = 1234;
18
+ scs_int n = 1;
19
+ scs_int m = 3;
20
+ scs_int col_nnz = (scs_int)ceil(sqrt(n));
21
+ scs_int nnz = n * col_nnz;
22
+ scs_int exitflag;
23
+
24
+ k->z = (scs_int)floor(m * p_f);
25
+ k->l = m - k->z;
26
+
27
+ d->m = m;
28
+ d->n = n;
29
+ gen_random_prob_data(nnz, col_nnz, d, k, opt_sol, seed);
30
+ SCS(set_default_settings)(stgs);
31
+
32
+ /* TODO test more failure modes */
33
+ stgs->eps_abs = -1;
34
+
35
+ exitflag = scs(d, k, stgs, sol, &info);
36
+
37
+ mu_assert("test_fails: SCS failed to produce outputflag SCS_FAILED",
38
+ exitflag == SCS_FAILED);
39
+ SCS(free_data)(d, k, stgs);
40
+ SCS(free_sol)(sol);
41
+ SCS(free_sol)(opt_sol);
42
+ return 0;
43
+ }
@@ -0,0 +1,82 @@
1
+ #include "glbopts.h"
2
+ #include "linalg.h"
3
+ #include "minunit.h"
4
+ #include "scs.h"
5
+ #include "scs_matrix.h"
6
+ #include "util.h"
7
+
8
+ static const char *unbounded_tiny_qp(void) {
9
+ ScsCone *k = (ScsCone *)scs_calloc(1, sizeof(ScsCone));
10
+ ScsData *d = (ScsData *)scs_calloc(1, sizeof(ScsData));
11
+ ScsSettings *stgs = (ScsSettings *)scs_calloc(1, sizeof(ScsSettings));
12
+ ScsSolution *sol = (ScsSolution *)scs_calloc(1, sizeof(ScsSolution));
13
+ ScsInfo info = {0};
14
+ scs_int exitflag;
15
+ const char *fail;
16
+
17
+ /* data */
18
+ scs_float Ax[] = {
19
+ -0.04101197, 1.68314201, 0.5543439, -0.96712378, 0.19370457,
20
+ -1.15055711, 1.13315795, -1.05910693, 1.24512977, -0.70999048,
21
+ -0.89976326, -0.41373294, -0.73848186, 0.08663554, -0.1681749,
22
+ -0.42711619, -0.90501247, -0.490446, -0.67124734, 1.67772257,
23
+ 0.39924394, 0.16330292, 0.55609205, -1.22088238, -0.25891675,
24
+ -3.07159984, -1.84102417, 1.5621635, -1.13771529, 0.56067264,
25
+ -0.0854747, 0.31024722, -0.07437118, -0.20711534, -0.35241366,
26
+ -0.98965142, -1.91488894, 1.01591507, 0.45387459, 1.43709968,
27
+ -0.0482982, -0.32447, -0.91433399, 0.49750765, 0.09150015,
28
+ 0.69164184, 0.51064936, -1.35009809, -1.35403213, 1.51897627};
29
+ scs_int Ai[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6,
30
+ 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3,
31
+ 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
32
+ scs_int Ap[] = {0, 10, 20, 30, 40, 50};
33
+
34
+ scs_float b[] = {1.4672744, 0.36190605, -0.5548082, -0.35039932,
35
+ -1.12765224, 0.51012137, -0.24927975, -1.45270362,
36
+ -1.94080389, -0.0189713};
37
+ scs_float c[] = {0.17547329, -0.11983635, -0.11791039, 0.12099476,
38
+ 0.61931906};
39
+
40
+ scs_int m = 10;
41
+ scs_int n = 5;
42
+
43
+ scs_int l = m;
44
+
45
+ /* end data */
46
+
47
+ d->m = m;
48
+ d->n = n;
49
+ d->b = b;
50
+ d->c = c;
51
+
52
+ d->A = (ScsMatrix *)scs_calloc(1, sizeof(ScsMatrix));
53
+
54
+ d->A->m = m;
55
+ d->A->n = n;
56
+
57
+ d->A->x = Ax;
58
+ d->A->i = Ai;
59
+ d->A->p = Ap;
60
+
61
+ k->l = l;
62
+
63
+ SCS(set_default_settings)(stgs);
64
+ stgs->eps_abs = 1e-6;
65
+ stgs->eps_rel = 1e-6;
66
+ stgs->eps_infeas = 1e-7;
67
+
68
+ exitflag = scs(d, k, stgs, sol, &info);
69
+
70
+ mu_assert("unbounded_tiny_qp: SCS failed to produce outputflag SCS_UNBOUNDED",
71
+ exitflag == SCS_UNBOUNDED);
72
+
73
+ fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
74
+
75
+ SCS(free_sol)(sol);
76
+ scs_free(d->A);
77
+ scs_free(d->P);
78
+ scs_free(k);
79
+ scs_free(stgs);
80
+ scs_free(d);
81
+ return fail;
82
+ }
@@ -1,7 +1,7 @@
1
- #include <time.h> /* to seed random */
2
- #include "amatrix.h"
3
1
  #include "problem_utils.h"
4
2
  #include "scs.h"
3
+ #include "scs_matrix.h"
4
+ #include <time.h> /* to seed random */
5
5
 
6
6
  /*
7
7
  create data for problem:
@@ -11,7 +11,7 @@
11
11
 
12
12
  where K is a product of zero, linear, and second-order cones. A is a sparse
13
13
  matrix in
14
- CSC format. A is 3n by n with about sqrt(n) nonzeros per column.
14
+ CSC format. A is factor * n by n with about sqrt(n) nonzeros per column.
15
15
 
16
16
  Construct data in such a way that the problem is primal and dual
17
17
  feasible and thus bounded.
@@ -21,9 +21,11 @@ int main(int argc, char **argv) {
21
21
  scs_int n, m, col_nnz, nnz, i, q_total, q_num_rows, max_q;
22
22
  ScsCone *k;
23
23
  ScsData *d;
24
+ ScsSettings *stgs;
24
25
  ScsSolution *sol, *opt_sol;
25
26
  ScsInfo info = {0};
26
27
  scs_float p_f, p_l;
28
+ scs_int factor = 4;
27
29
  int seed = 0;
28
30
 
29
31
  /* default parameters */
@@ -32,68 +34,64 @@ int main(int argc, char **argv) {
32
34
  seed = time(SCS_NULL);
33
35
 
34
36
  switch (argc) {
35
- case 5:
36
- seed = atoi(argv[4]);
37
- /* no break */
38
- case 4:
39
- p_f = atof(argv[2]);
40
- p_l = atof(argv[3]);
41
- /* no break */
42
- case 2:
43
- n = atoi(argv[1]);
44
- break;
45
- default:
46
- scs_printf(
47
- "usage:\t%s n p_f p_l s\n"
48
- "\tcreates an SOCP with n variables where p_f fraction of "
49
- "rows correspond\n"
50
- "\tto equality constraints, p_l fraction of rows correspond "
51
- "to LP constraints,\n"
52
- "\tand the remaining percentage of rows are involved in "
53
- "second-order\n"
54
- "\tcone constraints. the random number generator is seeded "
55
- "with s.\n"
56
- "\tnote that p_f + p_l should be less than or equal to 1, "
57
- "and that\n"
58
- "\tp_f should be less than .33, since that corresponds to "
59
- "as many equality\n"
60
- "\tconstraints as variables.\n",
61
- argv[0]);
62
- scs_printf(
63
- "\nusage:\t%s n p_f p_l\n"
64
- "\tdefaults the seed to the system time\n",
65
- argv[0]);
66
- scs_printf(
67
- "\nusage:\t%s n\n"
68
- "\tdefaults to using p_f = 0.1 and p_l = 0.3\n",
69
- argv[0]);
70
- return 0;
37
+ case 5:
38
+ seed = atoi(argv[4]);
39
+ /* no break */
40
+ case 4:
41
+ p_f = atof(argv[2]);
42
+ p_l = atof(argv[3]);
43
+ /* no break */
44
+ case 2:
45
+ n = atoi(argv[1]);
46
+ break;
47
+ default:
48
+ scs_printf("usage:\t%s n p_f p_l s\n"
49
+ "\tcreates an SOCP with n variables where p_f fraction of "
50
+ "rows correspond\n"
51
+ "\tto equality constraints, p_l fraction of rows correspond "
52
+ "to LP constraints,\n"
53
+ "\tand the remaining percentage of rows are involved in "
54
+ "second-order\n"
55
+ "\tcone constraints. the random number generator is seeded "
56
+ "with s.\n"
57
+ "\tnote that p_f + p_l should be less than or equal to 1, "
58
+ "and that\n"
59
+ "\tp_f should be less than .33, since that corresponds to "
60
+ "as many equality\n"
61
+ "\tconstraints as variables.\n",
62
+ argv[0]);
63
+ scs_printf("\nusage:\t%s n p_f p_l\n"
64
+ "\tdefaults the seed to the system time\n",
65
+ argv[0]);
66
+ scs_printf("\nusage:\t%s n\n"
67
+ "\tdefaults to using p_f = 0.1 and p_l = 0.3\n",
68
+ argv[0]);
69
+ return 0;
71
70
  }
72
- srand(seed);
73
71
  scs_printf("seed : %i\n", seed);
74
72
 
75
73
  k = (ScsCone *)scs_calloc(1, sizeof(ScsCone));
76
74
  d = (ScsData *)scs_calloc(1, sizeof(ScsData));
77
- d->stgs = (ScsSettings *)scs_calloc(1, sizeof(ScsSettings));
75
+ stgs = (ScsSettings *)scs_calloc(1, sizeof(ScsSettings));
78
76
  sol = (ScsSolution *)scs_calloc(1, sizeof(ScsSolution));
79
77
  opt_sol = (ScsSolution *)scs_calloc(1, sizeof(ScsSolution));
80
78
 
81
- m = 3 * n;
79
+ m = factor * n;
82
80
  col_nnz = (int)ceil(sqrt(n));
83
81
  nnz = n * col_nnz;
84
82
 
85
- max_q = (scs_int)ceil(3 * n / log(3 * n));
83
+ max_q = (scs_int)ceil(factor * n / log(factor * n));
86
84
 
87
85
  if (p_f + p_l > 1.0) {
88
86
  printf("error: p_f + p_l > 1.0!\n");
89
87
  return 1;
90
88
  }
91
89
 
92
- k->f = (scs_int)floor(3 * n * p_f);
93
- k->l = (scs_int)floor(3 * n * p_l);
90
+ k->z = (scs_int)floor(factor * n * p_f);
91
+ k->l = (scs_int)floor(factor * n * p_l);
94
92
 
95
93
  k->qsize = 0;
96
- q_num_rows = 3 * n - k->f - k->l;
94
+ q_num_rows = factor * n - k->z - k->l;
97
95
  k->q = (scs_int *)scs_malloc(q_num_rows * sizeof(scs_int));
98
96
 
99
97
  while (q_num_rows > max_q) {
@@ -117,6 +115,9 @@ int main(int argc, char **argv) {
117
115
  k->ssize = 0;
118
116
  k->ep = 0;
119
117
  k->ed = 0;
118
+ k->bsize = 0;
119
+ k->bu = SCS_NULL;
120
+ k->bl = SCS_NULL;
120
121
 
121
122
  scs_printf("\nA is %ld by %ld, with %ld nonzeros per column.\n", (long)m,
122
123
  (long)n, (long)col_nnz);
@@ -130,7 +131,7 @@ int main(int argc, char **argv) {
130
131
  ((scs_float)n * sizeof(scs_int)) / POWF(2, 30));
131
132
 
132
133
  printf("ScsCone information:\n");
133
- printf("Zero cone rows: %ld\n", (long)k->f);
134
+ printf("Zero cone rows: %ld\n", (long)k->z);
134
135
  printf("LP cone rows: %ld\n", (long)k->l);
135
136
  printf("Number of second-order cones: %ld, covering %ld rows, with sizes\n[",
136
137
  (long)k->qsize, (long)q_total);
@@ -139,20 +140,20 @@ int main(int argc, char **argv) {
139
140
  }
140
141
  printf("]\n");
141
142
  printf("Number of rows covered is %ld out of %ld.\n\n",
142
- (long)(q_total + k->f + k->l), (long)m);
143
+ (long)(q_total + k->z + k->l), (long)m);
143
144
 
144
145
  /* set up SCS structures */
145
146
  d->m = m;
146
147
  d->n = n;
147
- gen_random_prob_data(nnz, col_nnz, d, k, opt_sol);
148
- SCS(set_default_settings)(d);
148
+ gen_random_prob_data(nnz, col_nnz, d, k, opt_sol, seed);
149
+ SCS(set_default_settings)(stgs);
149
150
 
150
- /* d->stgs->write_data_filename = "random_socp_prob"; */
151
+ /* stgs->write_data_filename = "random_socp_prob"; */
151
152
 
152
153
  scs_printf("true pri opt = %4f\n", SCS(dot)(d->c, opt_sol->x, d->n));
153
154
  scs_printf("true dua opt = %4f\n", -SCS(dot)(d->b, opt_sol->y, d->m));
154
155
  /* solve! */
155
- scs(d, k, sol, &info);
156
+ scs(d, k, stgs, sol, &info);
156
157
  scs_printf("true pri opt = %4f\n", SCS(dot)(d->c, opt_sol->x, d->n));
157
158
  scs_printf("true dua opt = %4f\n", -SCS(dot)(d->b, opt_sol->y, d->m));
158
159
 
@@ -163,7 +164,7 @@ int main(int argc, char **argv) {
163
164
  scs_printf("scs dua obj = %4f\n", -SCS(dot)(d->b, sol->y, d->m));
164
165
  }
165
166
 
166
- SCS(free_data)(d, k);
167
+ SCS(free_data)(d, k, stgs);
167
168
  SCS(free_sol)(sol);
168
169
  SCS(free_sol)(opt_sol);
169
170