scs 0.2.2 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/LICENSE.txt +18 -18
- data/README.md +19 -14
- data/lib/scs/ffi.rb +31 -20
- data/lib/scs/solver.rb +32 -9
- data/lib/scs/version.rb +1 -1
- data/vendor/scs/CITATION.cff +39 -0
- data/vendor/scs/CMakeLists.txt +320 -0
- data/vendor/scs/Makefile +32 -23
- data/vendor/scs/README.md +9 -218
- data/vendor/scs/include/aa.h +67 -23
- data/vendor/scs/include/cones.h +22 -19
- data/vendor/scs/include/glbopts.h +107 -79
- data/vendor/scs/include/linalg.h +3 -4
- data/vendor/scs/include/linsys.h +58 -44
- data/vendor/scs/include/normalize.h +6 -5
- data/vendor/scs/include/rw.h +8 -2
- data/vendor/scs/include/scs.h +257 -141
- data/vendor/scs/include/scs_types.h +34 -0
- data/vendor/scs/include/scs_work.h +83 -0
- data/vendor/scs/include/util.h +3 -15
- data/vendor/scs/linsys/cpu/direct/private.c +241 -232
- data/vendor/scs/linsys/cpu/direct/private.h +13 -7
- data/vendor/scs/linsys/cpu/indirect/private.c +194 -118
- data/vendor/scs/linsys/cpu/indirect/private.h +7 -4
- data/vendor/scs/linsys/csparse.c +87 -0
- data/vendor/scs/linsys/csparse.h +34 -0
- data/vendor/scs/linsys/external/amd/SuiteSparse_config.c +6 -6
- data/vendor/scs/linsys/external/amd/SuiteSparse_config.h +6 -1
- data/vendor/scs/linsys/external/amd/amd_internal.h +1 -1
- data/vendor/scs/linsys/external/amd/amd_order.c +5 -5
- data/vendor/scs/linsys/external/qdldl/changes +2 -0
- data/vendor/scs/linsys/external/qdldl/qdldl.c +29 -46
- data/vendor/scs/linsys/external/qdldl/qdldl.h +33 -41
- data/vendor/scs/linsys/external/qdldl/qdldl_types.h +11 -3
- data/vendor/scs/linsys/gpu/gpu.c +58 -21
- data/vendor/scs/linsys/gpu/gpu.h +70 -35
- data/vendor/scs/linsys/gpu/indirect/private.c +394 -157
- data/vendor/scs/linsys/gpu/indirect/private.h +27 -12
- data/vendor/scs/linsys/scs_matrix.c +478 -0
- data/vendor/scs/linsys/scs_matrix.h +70 -0
- data/vendor/scs/scs.mk +14 -10
- data/vendor/scs/src/aa.c +394 -110
- data/vendor/scs/src/cones.c +497 -359
- data/vendor/scs/src/ctrlc.c +15 -5
- data/vendor/scs/src/linalg.c +107 -26
- data/vendor/scs/src/normalize.c +30 -72
- data/vendor/scs/src/rw.c +202 -27
- data/vendor/scs/src/scs.c +769 -571
- data/vendor/scs/src/scs_version.c +11 -3
- data/vendor/scs/src/util.c +37 -106
- data/vendor/scs/test/minunit.h +22 -8
- data/vendor/scs/test/problem_utils.h +180 -25
- data/vendor/scs/test/problems/degenerate.h +130 -0
- data/vendor/scs/test/problems/hs21_tiny_qp.h +124 -0
- data/vendor/scs/test/problems/hs21_tiny_qp_rw.h +116 -0
- data/vendor/scs/test/problems/infeasible_tiny_qp.h +100 -0
- data/vendor/scs/test/problems/qafiro_tiny_qp.h +199 -0
- data/vendor/scs/test/problems/random_prob +0 -0
- data/vendor/scs/test/problems/random_prob.h +45 -0
- data/vendor/scs/test/problems/rob_gauss_cov_est.h +188 -31
- data/vendor/scs/test/problems/small_lp.h +14 -13
- data/vendor/scs/test/problems/small_qp.h +352 -0
- data/vendor/scs/test/problems/test_validation.h +43 -0
- data/vendor/scs/test/problems/unbounded_tiny_qp.h +82 -0
- data/vendor/scs/test/random_socp_prob.c +54 -53
- data/vendor/scs/test/rng.h +109 -0
- data/vendor/scs/test/run_from_file.c +20 -11
- data/vendor/scs/test/run_tests.c +35 -2
- metadata +29 -98
- data/vendor/scs/linsys/amatrix.c +0 -305
- data/vendor/scs/linsys/amatrix.h +0 -36
- data/vendor/scs/linsys/amatrix.o +0 -0
- data/vendor/scs/linsys/cpu/direct/private.o +0 -0
- data/vendor/scs/linsys/cpu/indirect/private.o +0 -0
- data/vendor/scs/linsys/external/amd/SuiteSparse_config.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_1.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_2.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_aat.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_control.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_defaults.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_dump.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_global.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_info.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_order.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_post_tree.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_postorder.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_preprocess.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_valid.o +0 -0
- data/vendor/scs/linsys/external/qdldl/qdldl.o +0 -0
- data/vendor/scs/src/aa.o +0 -0
- data/vendor/scs/src/cones.o +0 -0
- data/vendor/scs/src/ctrlc.o +0 -0
- data/vendor/scs/src/linalg.o +0 -0
- data/vendor/scs/src/normalize.o +0 -0
- data/vendor/scs/src/rw.o +0 -0
- data/vendor/scs/src/scs.o +0 -0
- data/vendor/scs/src/scs_version.o +0 -0
- data/vendor/scs/src/util.o +0 -0
- data/vendor/scs/test/data/small_random_socp +0 -0
- data/vendor/scs/test/problems/small_random_socp.h +0 -33
- data/vendor/scs/test/run_tests +0 -2
|
@@ -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_validation(void) {
|
|
8
|
+
scs_printf("Testing that SCS handles bad inputs correctly:\n");
|
|
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
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
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 =
|
|
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(
|
|
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->
|
|
93
|
-
k->l = (scs_int)floor(
|
|
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 =
|
|
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->
|
|
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->
|
|
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
|
-
|
|
148
|
+
gen_random_prob_data(nnz, col_nnz, d, k, opt_sol, seed);
|
|
149
|
+
scs_set_default_settings(stgs);
|
|
149
150
|
|
|
150
|
-
/*
|
|
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
|
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/* This program by D E Knuth is in the public domain and freely copyable
|
|
2
|
+
* AS LONG AS YOU MAKE ABSOLUTELY NO CHANGES!
|
|
3
|
+
* It is explained in Seminumerical Algorithms, 3rd edition, Section 3.6
|
|
4
|
+
* (or in the errata to the 2nd edition --- see
|
|
5
|
+
* http://www-cs-faculty.stanford.edu/~knuth/taocp.html
|
|
6
|
+
* in the changes to Volume 2 on pages 171 and following). */
|
|
7
|
+
|
|
8
|
+
/* N.B. The MODIFICATIONS introduced in the 9th printing (2002) are
|
|
9
|
+
included here; there's no backwards compatibility with the original. */
|
|
10
|
+
|
|
11
|
+
/* This version also adopts Brendan McKay's suggestion to
|
|
12
|
+
accommodate naive users who forget to call ran_start(seed). */
|
|
13
|
+
|
|
14
|
+
/* If you find any bugs, please report them immediately to
|
|
15
|
+
* taocp@cs.stanford.edu
|
|
16
|
+
* (and you will be rewarded if the bug is genuine). Thanks! */
|
|
17
|
+
|
|
18
|
+
/************ see the book for explanations and caveats! *******************/
|
|
19
|
+
/************ in particular, you need two's complement arithmetic **********/
|
|
20
|
+
|
|
21
|
+
#define KK 100 /* the long lag */
|
|
22
|
+
#define LL 37 /* the short lag */
|
|
23
|
+
#define MM (1L << 30) /* the modulus */
|
|
24
|
+
#define mod_diff(x, y) (((x) - (y)) & (MM - 1)) /* subtraction mod MM */
|
|
25
|
+
|
|
26
|
+
long ran_x[KK]; /* the generator state */
|
|
27
|
+
|
|
28
|
+
#ifdef __STDC__
|
|
29
|
+
void ran_array(long aa[], int n)
|
|
30
|
+
#else
|
|
31
|
+
void ran_array(aa, n) /* put n new random numbers in aa */
|
|
32
|
+
long *aa; /* destination */
|
|
33
|
+
int n; /* array length (must be at least KK) */
|
|
34
|
+
#endif
|
|
35
|
+
{
|
|
36
|
+
register int i, j;
|
|
37
|
+
for (j = 0; j < KK; j++)
|
|
38
|
+
aa[j] = ran_x[j];
|
|
39
|
+
for (; j < n; j++)
|
|
40
|
+
aa[j] = mod_diff(aa[j - KK], aa[j - LL]);
|
|
41
|
+
for (i = 0; i < LL; i++, j++)
|
|
42
|
+
ran_x[i] = mod_diff(aa[j - KK], aa[j - LL]);
|
|
43
|
+
for (; i < KK; i++, j++)
|
|
44
|
+
ran_x[i] = mod_diff(aa[j - KK], ran_x[i - LL]);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/* the following routines are from exercise 3.6--15 */
|
|
48
|
+
/* after calling ran_start, get new randoms by, e.g., "x=ran_arr_next()" */
|
|
49
|
+
|
|
50
|
+
#define QUALITY 1009 /* recommended quality level for high-res use */
|
|
51
|
+
long ran_arr_buf[QUALITY];
|
|
52
|
+
long ran_arr_dummy = -1, ran_arr_started = -1;
|
|
53
|
+
long *ran_arr_ptr = &ran_arr_dummy; /* the next random number, or -1 */
|
|
54
|
+
|
|
55
|
+
#define TT 70 /* guaranteed separation between streams */
|
|
56
|
+
#define is_odd(x) ((x)&1) /* units bit of x */
|
|
57
|
+
|
|
58
|
+
#ifdef __STDC__
|
|
59
|
+
void ran_start(long seed)
|
|
60
|
+
#else
|
|
61
|
+
void ran_start(seed) /* do this before using ran_array */
|
|
62
|
+
long seed; /* selector for different streams */
|
|
63
|
+
#endif
|
|
64
|
+
{
|
|
65
|
+
register int t, j;
|
|
66
|
+
long x[KK + KK - 1]; /* the preparation buffer */
|
|
67
|
+
register long ss = (seed + 2) & (MM - 2);
|
|
68
|
+
for (j = 0; j < KK; j++) {
|
|
69
|
+
x[j] = ss; /* bootstrap the buffer */
|
|
70
|
+
ss <<= 1;
|
|
71
|
+
if (ss >= MM)
|
|
72
|
+
ss -= MM - 2; /* cyclic shift 29 bits */
|
|
73
|
+
}
|
|
74
|
+
x[1]++; /* make x[1] (and only x[1]) odd */
|
|
75
|
+
for (ss = seed & (MM - 1), t = TT - 1; t;) {
|
|
76
|
+
for (j = KK - 1; j > 0; j--)
|
|
77
|
+
x[j + j] = x[j], x[j + j - 1] = 0; /* "square" */
|
|
78
|
+
for (j = KK + KK - 2; j >= KK; j--)
|
|
79
|
+
x[j - (KK - LL)] = mod_diff(x[j - (KK - LL)], x[j]),
|
|
80
|
+
x[j - KK] = mod_diff(x[j - KK], x[j]);
|
|
81
|
+
if (is_odd(ss)) { /* "multiply by z" */
|
|
82
|
+
for (j = KK; j > 0; j--)
|
|
83
|
+
x[j] = x[j - 1];
|
|
84
|
+
x[0] = x[KK]; /* shift the buffer cyclically */
|
|
85
|
+
x[LL] = mod_diff(x[LL], x[KK]);
|
|
86
|
+
}
|
|
87
|
+
if (ss)
|
|
88
|
+
ss >>= 1;
|
|
89
|
+
else
|
|
90
|
+
t--;
|
|
91
|
+
}
|
|
92
|
+
for (j = 0; j < LL; j++)
|
|
93
|
+
ran_x[j + KK - LL] = x[j];
|
|
94
|
+
for (; j < KK; j++)
|
|
95
|
+
ran_x[j - LL] = x[j];
|
|
96
|
+
for (j = 0; j < 10; j++)
|
|
97
|
+
ran_array(x, KK + KK - 1); /* warm things up */
|
|
98
|
+
ran_arr_ptr = &ran_arr_started;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
#define ran_arr_next() (*ran_arr_ptr >= 0 ? *ran_arr_ptr++ : ran_arr_cycle())
|
|
102
|
+
long ran_arr_cycle(void) {
|
|
103
|
+
if (ran_arr_ptr == &ran_arr_dummy)
|
|
104
|
+
ran_start(314159L); /* the user forgot to initialize */
|
|
105
|
+
ran_array(ran_arr_buf, QUALITY);
|
|
106
|
+
ran_arr_buf[KK] = -1;
|
|
107
|
+
ran_arr_ptr = ran_arr_buf + 1;
|
|
108
|
+
return ran_arr_buf[0];
|
|
109
|
+
}
|
|
@@ -12,16 +12,24 @@ scs_int override_setting(ScsSettings *s, char *param, char *val) {
|
|
|
12
12
|
s->rho_x = atof(val);
|
|
13
13
|
} else if (strcmp(param, "max_iters") == 0) {
|
|
14
14
|
s->max_iters = atoi(val);
|
|
15
|
-
} else if (strcmp(param, "
|
|
16
|
-
s->
|
|
15
|
+
} else if (strcmp(param, "eps_abs") == 0) {
|
|
16
|
+
s->eps_abs = atof(val);
|
|
17
|
+
} else if (strcmp(param, "eps_rel") == 0) {
|
|
18
|
+
s->eps_rel = atof(val);
|
|
19
|
+
} else if (strcmp(param, "eps_infeas") == 0) {
|
|
20
|
+
s->eps_infeas = atof(val);
|
|
17
21
|
} else if (strcmp(param, "alpha") == 0) {
|
|
18
22
|
s->alpha = atof(val);
|
|
19
|
-
} else if (strcmp(param, "cg_rate") == 0) {
|
|
20
|
-
s->cg_rate = atof(val);
|
|
21
23
|
} else if (strcmp(param, "verbose") == 0) {
|
|
22
24
|
s->verbose = atoi(val);
|
|
23
25
|
} else if (strcmp(param, "acceleration_lookback") == 0) {
|
|
24
26
|
s->acceleration_lookback = atoi(val);
|
|
27
|
+
} else if (strcmp(param, "acceleration_interval") == 0) {
|
|
28
|
+
s->acceleration_interval = atoi(val);
|
|
29
|
+
} else if (strcmp(param, "adaptive_scale") == 0) {
|
|
30
|
+
s->adaptive_scale = atoi(val);
|
|
31
|
+
} else if (strcmp(param, "log_csv_filename") == 0) {
|
|
32
|
+
s->log_csv_filename = val;
|
|
25
33
|
} else {
|
|
26
34
|
return -1;
|
|
27
35
|
}
|
|
@@ -36,6 +44,7 @@ int main(int argc, char **argv) {
|
|
|
36
44
|
scs_int read_status;
|
|
37
45
|
ScsData *d;
|
|
38
46
|
ScsCone *k;
|
|
47
|
+
ScsSettings *stgs;
|
|
39
48
|
ScsSolution *sol;
|
|
40
49
|
ScsInfo info = {0};
|
|
41
50
|
scs_int i;
|
|
@@ -44,7 +53,7 @@ int main(int argc, char **argv) {
|
|
|
44
53
|
return -1;
|
|
45
54
|
}
|
|
46
55
|
filename = argv[1];
|
|
47
|
-
read_status = SCS(read_data)(filename, &d, &k);
|
|
56
|
+
read_status = SCS(read_data)(filename, &d, &k, &stgs);
|
|
48
57
|
if (read_status < 0) {
|
|
49
58
|
scs_printf("Data read failure, exit.\n");
|
|
50
59
|
return -1;
|
|
@@ -52,18 +61,18 @@ int main(int argc, char **argv) {
|
|
|
52
61
|
for (i = 2; i < argc; i += 2) {
|
|
53
62
|
if (argc < i + 2) {
|
|
54
63
|
scs_printf("Incorrect number of arguments supplied\n.");
|
|
55
|
-
SCS(free_data)(d, k);
|
|
64
|
+
SCS(free_data)(d, k, stgs);
|
|
56
65
|
return -1;
|
|
57
66
|
}
|
|
58
|
-
if (override_setting(
|
|
67
|
+
if (override_setting(stgs, argv[i], argv[i + 1]) < 0) {
|
|
59
68
|
scs_printf("Unrecognized setting %s\n", argv[i]);
|
|
60
|
-
SCS(free_data)(d, k);
|
|
69
|
+
SCS(free_data)(d, k, stgs);
|
|
61
70
|
return -1;
|
|
62
71
|
}
|
|
63
72
|
}
|
|
64
|
-
sol = scs_calloc(1, sizeof(ScsSolution));
|
|
65
|
-
scs(d, k, sol, &info);
|
|
66
|
-
SCS(free_data)(d, k);
|
|
73
|
+
sol = (ScsSolution *)scs_calloc(1, sizeof(ScsSolution));
|
|
74
|
+
scs(d, k, stgs, sol, &info);
|
|
75
|
+
SCS(free_data)(d, k, stgs);
|
|
67
76
|
SCS(free_sol)(sol);
|
|
68
77
|
return 0;
|
|
69
78
|
}
|
data/vendor/scs/test/run_tests.c
CHANGED
|
@@ -6,16 +6,49 @@
|
|
|
6
6
|
#include "scs.h"
|
|
7
7
|
|
|
8
8
|
/* Include Tests */
|
|
9
|
+
#include "problems/degenerate.h"
|
|
10
|
+
#include "problems/hs21_tiny_qp.h"
|
|
11
|
+
#include "problems/hs21_tiny_qp_rw.h"
|
|
12
|
+
#include "problems/infeasible_tiny_qp.h"
|
|
13
|
+
#include "problems/qafiro_tiny_qp.h"
|
|
9
14
|
#include "problems/small_lp.h"
|
|
15
|
+
#include "problems/small_qp.h"
|
|
16
|
+
#include "problems/test_validation.h"
|
|
17
|
+
#include "problems/unbounded_tiny_qp.h"
|
|
18
|
+
|
|
19
|
+
#define _SKIP(problem) \
|
|
20
|
+
char *problem(void) { \
|
|
21
|
+
scs_printf("skipped\n"); \
|
|
22
|
+
return 0; \
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
#ifdef USE_LAPACK /* solve SDPs, requires blas / lapack */
|
|
10
26
|
#include "problems/rob_gauss_cov_est.h"
|
|
11
|
-
#
|
|
27
|
+
#else
|
|
28
|
+
_SKIP(rob_gauss_cov_est)
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
/* TODO: this reads a file written with 32bit ints */
|
|
32
|
+
#if defined(USE_LAPACK) && !defined(DLONG)
|
|
33
|
+
#include "problems/random_prob.h"
|
|
34
|
+
#else
|
|
35
|
+
_SKIP(random_prob)
|
|
36
|
+
#endif
|
|
12
37
|
|
|
13
38
|
int tests_run = 0;
|
|
14
39
|
|
|
15
40
|
static const char *all_tests(void) {
|
|
41
|
+
mu_run_test(test_validation);
|
|
42
|
+
mu_run_test(degenerate);
|
|
16
43
|
mu_run_test(small_lp);
|
|
44
|
+
mu_run_test(small_qp);
|
|
17
45
|
mu_run_test(rob_gauss_cov_est);
|
|
18
|
-
mu_run_test(
|
|
46
|
+
mu_run_test(hs21_tiny_qp);
|
|
47
|
+
mu_run_test(hs21_tiny_qp_rw);
|
|
48
|
+
mu_run_test(qafiro_tiny_qp);
|
|
49
|
+
mu_run_test(infeasible_tiny_qp);
|
|
50
|
+
mu_run_test(unbounded_tiny_qp);
|
|
51
|
+
mu_run_test(random_prob);
|
|
19
52
|
return 0;
|
|
20
53
|
}
|
|
21
54
|
|