scs 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
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
Binary file
@@ -22,9 +22,13 @@ void scs_start_interrupt_listener(void) {
22
22
  istate = (int)utSetInterruptEnabled(true);
23
23
  }
24
24
 
25
- void scs_end_interrupt_listener(void) { utSetInterruptEnabled((bool)istate); }
25
+ void scs_end_interrupt_listener(void) {
26
+ utSetInterruptEnabled((bool)istate);
27
+ }
26
28
 
27
- int scs_is_interrupted(void) { return (int)utIsInterruptPending(); }
29
+ int scs_is_interrupted(void) {
30
+ return (int)utIsInterruptPending();
31
+ }
28
32
 
29
33
  #elif (defined _WIN32 || _WIN64 || defined _WINDLL)
30
34
  #include <windows.h>
@@ -47,14 +51,18 @@ void scs_end_interrupt_listener(void) {
47
51
  SetConsoleCtrlHandler(scs_handle_ctrlc, FALSE);
48
52
  }
49
53
 
50
- int scs_is_interrupted(void) { return int_detected; }
54
+ int scs_is_interrupted(void) {
55
+ return int_detected;
56
+ }
51
57
 
52
58
  #else /* Unix */
53
59
 
54
60
  #include <signal.h>
55
61
  static int int_detected;
56
62
  struct sigaction oact;
57
- static void scs_handle_ctrlc(int dummy) { int_detected = dummy ? dummy : -1; }
63
+ static void scs_handle_ctrlc(int dummy) {
64
+ int_detected = dummy ? dummy : -1;
65
+ }
58
66
 
59
67
  void scs_start_interrupt_listener(void) {
60
68
  struct sigaction act;
@@ -70,7 +78,9 @@ void scs_end_interrupt_listener(void) {
70
78
  sigaction(SIGINT, &oact, &act);
71
79
  }
72
80
 
73
- int scs_is_interrupted(void) { return int_detected; }
81
+ int scs_is_interrupted(void) {
82
+ return int_detected;
83
+ }
74
84
 
75
85
  #endif /* END IF MATLAB_MEX_FILE / WIN32 */
76
86
 
Binary file
@@ -1,17 +1,40 @@
1
1
  #include "linalg.h"
2
+ #include "scs_blas.h"
2
3
  #include <math.h>
3
4
 
4
- /* x = b*a */
5
- void SCS(set_as_scaled_array)(scs_float *x, const scs_float *a,
6
- const scs_float b, scs_int len) {
5
+ /* these routines do not have BLAS implementations (that I can find at least) */
6
+
7
+ scs_float SCS(norm_diff)(const scs_float *a, const scs_float *b, scs_int len) {
8
+ scs_float nm_diff = 0.0, tmp;
9
+ scs_int i;
10
+ for (i = 0; i < len; ++i) {
11
+ tmp = (a[i] - b[i]);
12
+ nm_diff += tmp * tmp;
13
+ }
14
+ return SQRTF(nm_diff);
15
+ }
16
+
17
+ scs_float SCS(norm_inf_diff)(const scs_float *a, const scs_float *b,
18
+ scs_int len) {
19
+ scs_float tmp, max = 0.0;
7
20
  scs_int i;
8
- for (i = 0; i < len; ++i) x[i] = b * a[i];
21
+ for (i = 0; i < len; ++i) {
22
+ tmp = ABS(a[i] - b[i]);
23
+ if (tmp > max) {
24
+ max = tmp;
25
+ }
26
+ }
27
+ return max;
9
28
  }
10
29
 
30
+ #ifndef USE_LAPACK
31
+ /* Self-rolled basic linear algebra routines */
32
+
11
33
  /* a *= b */
12
34
  void SCS(scale_array)(scs_float *a, const scs_float b, scs_int len) {
13
35
  scs_int i;
14
- for (i = 0; i < len; ++i) a[i] *= b;
36
+ for (i = 0; i < len; ++i)
37
+ a[i] *= b;
15
38
  }
16
39
 
17
40
  /* x'*y */
@@ -35,14 +58,14 @@ scs_float SCS(norm_sq)(const scs_float *v, scs_int len) {
35
58
  }
36
59
 
37
60
  /* ||v||_2 */
38
- scs_float SCS(norm)(const scs_float *v, scs_int len) {
61
+ scs_float SCS(norm_2)(const scs_float *v, scs_int len) {
39
62
  return SQRTF(SCS(norm_sq)(v, len));
40
63
  }
41
64
 
42
- scs_float SCS(norm_inf)(const scs_float *a, scs_int l) {
65
+ scs_float SCS(norm_inf)(const scs_float *a, scs_int len) {
43
66
  scs_float tmp, max = 0.0;
44
67
  scs_int i;
45
- for (i = 0; i < l; ++i) {
68
+ for (i = 0; i < len; ++i) {
46
69
  tmp = ABS(a[i]);
47
70
  if (tmp > max) {
48
71
  max = tmp;
@@ -51,7 +74,7 @@ scs_float SCS(norm_inf)(const scs_float *a, scs_int l) {
51
74
  return max;
52
75
  }
53
76
 
54
- /* saxpy a += sc*b */
77
+ /* axpy a += sc*b */
55
78
  void SCS(add_scaled_array)(scs_float *a, const scs_float *b, scs_int n,
56
79
  const scs_float sc) {
57
80
  scs_int i;
@@ -60,25 +83,58 @@ void SCS(add_scaled_array)(scs_float *a, const scs_float *b, scs_int n,
60
83
  }
61
84
  }
62
85
 
63
- scs_float SCS(norm_diff)(const scs_float *a, const scs_float *b, scs_int l) {
64
- scs_float nm_diff = 0.0, tmp;
65
- scs_int i;
66
- for (i = 0; i < l; ++i) {
67
- tmp = (a[i] - b[i]);
68
- nm_diff += tmp * tmp;
69
- }
70
- return SQRTF(nm_diff);
86
+ #else
87
+ /* If we have BLAS / LAPACK we may as well use them */
88
+
89
+ scs_float BLAS(nrm2)(blas_int *n, const scs_float *x, blas_int *incx);
90
+ scs_float BLAS(dot)(const blas_int *n, const scs_float *x, const blas_int *incx,
91
+ const scs_float *y, const blas_int *incy);
92
+ scs_float BLAS(lange)(const char *norm, const blas_int *m, const blas_int *n,
93
+ const scs_float *a, blas_int *lda, scs_float *work);
94
+ void BLAS(axpy)(blas_int *n, const scs_float *a, const scs_float *x,
95
+ blas_int *incx, scs_float *y, blas_int *incy);
96
+ void BLAS(scal)(const blas_int *n, const scs_float *sa, scs_float *sx,
97
+ const blas_int *incx);
98
+
99
+ /* a *= b */
100
+ void SCS(scale_array)(scs_float *a, const scs_float b, scs_int len) {
101
+ blas_int bone = 1;
102
+ blas_int blen = (blas_int)len;
103
+ BLAS(scal)(&blen, &b, a, &bone);
71
104
  }
72
105
 
73
- scs_float SCS(norm_inf_diff)(const scs_float *a, const scs_float *b,
74
- scs_int l) {
75
- scs_float tmp, max = 0.0;
76
- scs_int i;
77
- for (i = 0; i < l; ++i) {
78
- tmp = ABS(a[i] - b[i]);
79
- if (tmp > max) {
80
- max = tmp;
81
- }
82
- }
83
- return max;
106
+ /* x'*y */
107
+ scs_float SCS(dot)(const scs_float *x, const scs_float *y, scs_int len) {
108
+ blas_int bone = 1;
109
+ blas_int blen = (blas_int)len;
110
+ return BLAS(dot)(&blen, x, &bone, y, &bone);
84
111
  }
112
+
113
+ /* ||v||_2^2 */
114
+ scs_float SCS(norm_sq)(const scs_float *v, scs_int len) {
115
+ scs_float nrm = SCS(norm_2)(v, len);
116
+ return nrm * nrm;
117
+ }
118
+
119
+ /* ||v||_2 */
120
+ scs_float SCS(norm_2)(const scs_float *v, scs_int len) {
121
+ blas_int bone = 1;
122
+ blas_int blen = (blas_int)len;
123
+ return BLAS(nrm2)(&blen, v, &bone);
124
+ }
125
+
126
+ scs_float SCS(norm_inf)(const scs_float *a, scs_int len) {
127
+ blas_int bone = 1;
128
+ blas_int blen = (blas_int)len;
129
+ return BLAS(lange)("Max", &blen, &bone, a, &bone, SCS_NULL);
130
+ }
131
+
132
+ /* axpy a += sc*b */
133
+ void SCS(add_scaled_array)(scs_float *a, const scs_float *b, scs_int len,
134
+ const scs_float sc) {
135
+ blas_int bone = 1;
136
+ blas_int blen = (blas_int)len;
137
+ BLAS(axpy)(&blen, &sc, b, &bone, a, &bone);
138
+ }
139
+
140
+ #endif
Binary file
@@ -1,93 +1,51 @@
1
1
  #include "normalize.h"
2
+
2
3
  #include "linalg.h"
3
4
  #include "scs.h"
4
5
 
5
- #define MIN_SCALE (1e-6)
6
-
7
- void SCS(normalize_b_c)(ScsWork *w) {
6
+ /* needed for normalizing the warm-start */
7
+ void SCS(normalize_sol)(ScsWork *w, ScsSolution *sol) {
8
8
  scs_int i;
9
- scs_float nm, *D = w->scal->D, *E = w->scal->E, *b = w->b, *c = w->c;
10
- /* scale b */
11
- for (i = 0; i < w->m; ++i) {
12
- b[i] /= D[i];
13
- }
14
- nm = SCS(norm)(b, w->m);
15
- w->sc_b = w->scal->mean_norm_col_a / MAX(nm, MIN_SCALE);
16
- /* scale c */
17
- for (i = 0; i < w->n; ++i) {
18
- c[i] /= E[i];
19
- }
20
- nm = SCS(norm)(c, w->n);
21
- w->sc_c = w->scal->mean_norm_row_a / MAX(nm, MIN_SCALE);
22
- SCS(scale_array)(b, w->sc_b * w->stgs->scale, w->m);
23
- SCS(scale_array)(c, w->sc_c * w->stgs->scale, w->n);
24
- }
25
-
26
- void SCS(calc_scaled_resids)(ScsWork *w, ScsResiduals *r) {
27
9
  scs_float *D = w->scal->D;
28
10
  scs_float *E = w->scal->E;
29
- scs_float *u = w->u;
30
- scs_float *u_t = w->u_t;
31
- scs_float *u_prev = w->u_prev;
32
- scs_float tmp;
33
- scs_int i, n = w->n, m = w->m;
34
-
35
- r->res_pri = 0;
36
- for (i = 0; i < n; ++i) {
37
- tmp = (u[i] - u_t[i]) / (E[i] * w->sc_b);
38
- r->res_pri += tmp * tmp;
39
- }
40
- for (i = 0; i < m; ++i) {
41
- tmp = (u[i + n] - u_t[i + n]) / (D[i] * w->sc_c);
42
- r->res_pri += tmp * tmp;
11
+ for (i = 0; i < w->n; ++i) {
12
+ sol->x[i] /= (E[i] / w->scal->dual_scale);
43
13
  }
44
- tmp = u[n + m] - u_t[n + m];
45
- r->res_pri += tmp * tmp;
46
- r->res_pri = sqrt(r->res_pri);
47
-
48
- r->res_dual = 0;
49
- for (i = 0; i < n; ++i) {
50
- tmp = (u[i] - u_prev[i]) * E[i] / w->sc_b;
51
- r->res_dual += tmp * tmp;
14
+ for (i = 0; i < w->m; ++i) {
15
+ sol->y[i] /= (D[i] / w->scal->primal_scale);
52
16
  }
53
- for (i = 0; i < m; ++i) {
54
- tmp = (u[i + n] - u_prev[i + n]) * D[i] / w->sc_c;
55
- r->res_dual += tmp * tmp;
17
+ for (i = 0; i < w->m; ++i) {
18
+ sol->s[i] *= (D[i] * w->scal->dual_scale);
56
19
  }
57
- tmp = u[n + m] - u_t[n + m];
58
- r->res_dual += tmp * tmp;
59
- r->res_dual = sqrt(r->res_dual);
60
20
  }
61
21
 
62
- void SCS(normalize_warm_start)(ScsWork *w) {
22
+ void SCS(un_normalize_sol)(ScsWork *w, ScsSolution *sol) {
63
23
  scs_int i;
64
24
  scs_float *D = w->scal->D;
65
25
  scs_float *E = w->scal->E;
66
- scs_float *x = w->u;
67
- scs_float *y = &(w->u[w->n]);
68
- scs_float *s = &(w->v[w->n]);
69
26
  for (i = 0; i < w->n; ++i) {
70
- x[i] *= (E[i] * w->sc_b);
27
+ sol->x[i] *= (E[i] / w->scal->dual_scale);
71
28
  }
72
29
  for (i = 0; i < w->m; ++i) {
73
- y[i] *= (D[i] * w->sc_c);
30
+ sol->y[i] *= (D[i] / w->scal->primal_scale);
74
31
  }
75
32
  for (i = 0; i < w->m; ++i) {
76
- s[i] /= (D[i] / (w->sc_b * w->stgs->scale));
33
+ sol->s[i] /= (D[i] * w->scal->dual_scale);
77
34
  }
78
35
  }
79
36
 
80
- void SCS(un_normalize_sol)(ScsWork *w, ScsSolution *sol) {
37
+ void SCS(un_normalize_primal)(ScsWork *w, scs_float *r) {
81
38
  scs_int i;
82
39
  scs_float *D = w->scal->D;
83
- scs_float *E = w->scal->E;
84
- for (i = 0; i < w->n; ++i) {
85
- sol->x[i] /= (E[i] * w->sc_b);
86
- }
87
40
  for (i = 0; i < w->m; ++i) {
88
- sol->y[i] /= (D[i] * w->sc_c);
41
+ r[i] /= (D[i] * w->scal->dual_scale);
89
42
  }
90
- for (i = 0; i < w->m; ++i) {
91
- sol->s[i] *= D[i] / (w->sc_b * w->stgs->scale);
43
+ }
44
+
45
+ void SCS(un_normalize_dual)(ScsWork *w, scs_float *r) {
46
+ scs_int i;
47
+ scs_float *E = w->scal->E;
48
+ for (i = 0; i < w->n; ++i) {
49
+ r[i] /= (E[i] * w->scal->primal_scale);
92
50
  }
93
51
  }
Binary file
data/vendor/scs/src/rw.c CHANGED
@@ -4,16 +4,20 @@
4
4
  #include <stdio.h>
5
5
  #include <stdlib.h>
6
6
 
7
- #include "amatrix.h"
7
+ #include "linalg.h"
8
8
  #include "scs.h"
9
+ #include "scs_matrix.h"
9
10
  #include "util.h"
10
11
 
11
12
  /* writes/reads problem data to/from filename */
12
13
  /* This is a VERY naive implementation, doesn't care about portability etc */
13
14
 
14
15
  static void write_scs_cone(const ScsCone *k, FILE *fout) {
15
- fwrite(&(k->f), sizeof(scs_int), 1, fout);
16
+ fwrite(&(k->z), sizeof(scs_int), 1, fout);
16
17
  fwrite(&(k->l), sizeof(scs_int), 1, fout);
18
+ fwrite(&(k->bsize), sizeof(scs_int), 1, fout);
19
+ fwrite(k->bl, sizeof(scs_float), MAX(k->bsize - 1, 0), fout);
20
+ fwrite(k->bu, sizeof(scs_float), MAX(k->bsize - 1, 0), fout);
17
21
  fwrite(&(k->qsize), sizeof(scs_int), 1, fout);
18
22
  fwrite(k->q, sizeof(scs_int), k->qsize, fout);
19
23
  fwrite(&(k->ssize), sizeof(scs_int), 1, fout);
@@ -26,8 +30,13 @@ static void write_scs_cone(const ScsCone *k, FILE *fout) {
26
30
 
27
31
  static ScsCone *read_scs_cone(FILE *fin) {
28
32
  ScsCone *k = (ScsCone *)scs_calloc(1, sizeof(ScsCone));
29
- fread(&(k->f), sizeof(scs_int), 1, fin);
33
+ fread(&(k->z), sizeof(scs_int), 1, fin);
30
34
  fread(&(k->l), sizeof(scs_int), 1, fin);
35
+ fread(&(k->bsize), sizeof(scs_int), 1, fin);
36
+ k->bl = scs_calloc(MAX(k->bsize - 1, 0), sizeof(scs_float));
37
+ k->bu = scs_calloc(MAX(k->bsize - 1, 0), sizeof(scs_float));
38
+ fread(k->bl, sizeof(scs_float), MAX(k->bsize - 1, 0), fin);
39
+ fread(k->bu, sizeof(scs_float), MAX(k->bsize - 1, 0), fin);
31
40
  fread(&(k->qsize), sizeof(scs_int), 1, fin);
32
41
  k->q = scs_calloc(k->qsize, sizeof(scs_int));
33
42
  fread(k->q, sizeof(scs_int), k->qsize, fin);
@@ -49,13 +58,17 @@ static void write_scs_stgs(const ScsSettings *s, FILE *fout) {
49
58
  fwrite(&(s->scale), sizeof(scs_float), 1, fout);
50
59
  fwrite(&(s->rho_x), sizeof(scs_float), 1, fout);
51
60
  fwrite(&(s->max_iters), sizeof(scs_int), 1, fout);
52
- fwrite(&(s->eps), sizeof(scs_float), 1, fout);
61
+ fwrite(&(s->eps_abs), sizeof(scs_float), 1, fout);
62
+ fwrite(&(s->eps_rel), sizeof(scs_float), 1, fout);
63
+ fwrite(&(s->eps_infeas), sizeof(scs_float), 1, fout);
53
64
  fwrite(&(s->alpha), sizeof(scs_float), 1, fout);
54
- fwrite(&(s->cg_rate), sizeof(scs_float), 1, fout);
55
65
  fwrite(&(s->verbose), sizeof(scs_int), 1, fout);
56
66
  fwrite(&warm_start, sizeof(scs_int), 1, fout);
57
67
  fwrite(&(s->acceleration_lookback), sizeof(scs_int), 1, fout);
68
+ fwrite(&(s->acceleration_interval), sizeof(scs_int), 1, fout);
69
+ fwrite(&(s->adaptive_scale), sizeof(scs_int), 1, fout);
58
70
  /* Do not write the write_data_filename */
71
+ /* Do not write the log_csv_filename */
59
72
  }
60
73
 
61
74
  static ScsSettings *read_scs_stgs(FILE *fin) {
@@ -64,12 +77,15 @@ static ScsSettings *read_scs_stgs(FILE *fin) {
64
77
  fread(&(s->scale), sizeof(scs_float), 1, fin);
65
78
  fread(&(s->rho_x), sizeof(scs_float), 1, fin);
66
79
  fread(&(s->max_iters), sizeof(scs_int), 1, fin);
67
- fread(&(s->eps), sizeof(scs_float), 1, fin);
80
+ fread(&(s->eps_abs), sizeof(scs_float), 1, fin);
81
+ fread(&(s->eps_rel), sizeof(scs_float), 1, fin);
82
+ fread(&(s->eps_infeas), sizeof(scs_float), 1, fin);
68
83
  fread(&(s->alpha), sizeof(scs_float), 1, fin);
69
- fread(&(s->cg_rate), sizeof(scs_float), 1, fin);
70
84
  fread(&(s->verbose), sizeof(scs_int), 1, fin);
71
85
  fread(&(s->warm_start), sizeof(scs_int), 1, fin);
72
86
  fread(&(s->acceleration_lookback), sizeof(scs_int), 1, fin);
87
+ fread(&(s->acceleration_interval), sizeof(scs_int), 1, fin);
88
+ fread(&(s->adaptive_scale), sizeof(scs_int), 1, fin);
73
89
  return s;
74
90
  }
75
91
 
@@ -98,15 +114,21 @@ static ScsMatrix *read_amatrix(FILE *fin) {
98
114
  }
99
115
 
100
116
  static void write_scs_data(const ScsData *d, FILE *fout) {
117
+ scs_int has_p = d->P ? 1 : 0;
101
118
  fwrite(&(d->m), sizeof(scs_int), 1, fout);
102
119
  fwrite(&(d->n), sizeof(scs_int), 1, fout);
103
120
  fwrite(d->b, sizeof(scs_float), d->m, fout);
104
121
  fwrite(d->c, sizeof(scs_float), d->n, fout);
105
- write_scs_stgs(d->stgs, fout);
106
122
  write_amatrix(d->A, fout);
123
+ /* write has P bit */
124
+ fwrite(&has_p, sizeof(scs_int), 1, fout);
125
+ if (d->P) {
126
+ write_amatrix(d->P, fout);
127
+ }
107
128
  }
108
129
 
109
130
  static ScsData *read_scs_data(FILE *fin) {
131
+ scs_int has_p = 0;
110
132
  ScsData *d = (ScsData *)scs_calloc(1, sizeof(ScsData));
111
133
  fread(&(d->m), sizeof(scs_int), 1, fin);
112
134
  fread(&(d->n), sizeof(scs_int), 1, fin);
@@ -114,26 +136,37 @@ static ScsData *read_scs_data(FILE *fin) {
114
136
  d->c = scs_calloc(d->n, sizeof(scs_float));
115
137
  fread(d->b, sizeof(scs_float), d->m, fin);
116
138
  fread(d->c, sizeof(scs_float), d->n, fin);
117
- d->stgs = read_scs_stgs(fin);
118
139
  d->A = read_amatrix(fin);
140
+ /* If has_p bit is not set or this hits end of file then has_p = 0 */
141
+ has_p &= fread(&has_p, sizeof(scs_int), 1, fin);
142
+ d->P = has_p ? read_amatrix(fin) : SCS_NULL;
119
143
  return d;
120
144
  }
121
145
 
122
- void SCS(write_data)(const ScsData *d, const ScsCone *k) {
123
- FILE *fout = fopen(d->stgs->write_data_filename, "wb");
124
- uint32_t scs_int_sz = (uint32_t)sizeof(scs_int);
125
- uint32_t scs_float_sz = (uint32_t)sizeof(scs_float);
126
- scs_printf("writing data to %s\n", d->stgs->write_data_filename);
146
+ void SCS(write_data)(const ScsData *d, const ScsCone *k,
147
+ const ScsSettings *stgs) {
148
+ FILE *fout = fopen(stgs->write_data_filename, "wb");
149
+ uint32_t scs_int_sz = (uint32_t)SCS(sizeof_int)();
150
+ uint32_t scs_float_sz = (uint32_t)SCS(sizeof_float)();
151
+ const char *scs_version = SCS_VERSION;
152
+ uint32_t scs_version_sz = (uint32_t)strlen(scs_version);
153
+ scs_printf("writing data to %s\n", stgs->write_data_filename);
127
154
  fwrite(&(scs_int_sz), sizeof(uint32_t), 1, fout);
128
155
  fwrite(&(scs_float_sz), sizeof(uint32_t), 1, fout);
156
+ fwrite(&(scs_version_sz), sizeof(uint32_t), 1, fout);
157
+ fwrite(scs_version, 1, scs_version_sz, fout);
129
158
  write_scs_cone(k, fout);
130
159
  write_scs_data(d, fout);
160
+ write_scs_stgs(stgs, fout);
131
161
  fclose(fout);
132
162
  }
133
163
 
134
- scs_int SCS(read_data)(const char *filename, ScsData **d, ScsCone **k) {
164
+ scs_int SCS(read_data)(const char *filename, ScsData **d, ScsCone **k,
165
+ ScsSettings **stgs) {
135
166
  uint32_t file_int_sz;
136
167
  uint32_t file_float_sz;
168
+ uint32_t file_version_sz;
169
+ char file_version[16];
137
170
  FILE *fin = fopen(filename, "rb");
138
171
  if (!fin) {
139
172
  scs_printf("Error reading file %s\n", filename);
@@ -142,26 +175,132 @@ scs_int SCS(read_data)(const char *filename, ScsData **d, ScsCone **k) {
142
175
  scs_printf("Reading data from %s\n", filename);
143
176
  fread(&(file_int_sz), sizeof(uint32_t), 1, fin);
144
177
  fread(&(file_float_sz), sizeof(uint32_t), 1, fin);
145
-
146
178
  if (file_int_sz != (uint32_t)sizeof(scs_int)) {
147
179
  scs_printf(
148
- "Error, sizeof(file int) is %lu, but scs expects sizeof(int) "
149
- "%lu, scs should be recompiled with correct flags.\n",
180
+ "Error, sizeof(file int) is %lu, but scs expects sizeof(int) %lu, "
181
+ "scs should be recompiled with correct flags.\n",
150
182
  (unsigned long)file_int_sz, (unsigned long)sizeof(scs_int));
151
183
  fclose(fin);
152
184
  return -1;
153
185
  }
154
186
  if (file_float_sz != (uint32_t)sizeof(scs_float)) {
155
187
  scs_printf(
156
- "Error, sizeof(file float) is %lu, but scs expects "
157
- "sizeof(float) %lu, scs should be recompiled with the correct flags.\n",
188
+ "Error, sizeof(file float) is %lu, but scs expects sizeof(float) %lu, "
189
+ "scs should be recompiled with the correct flags.\n",
158
190
  (unsigned long)file_float_sz, (unsigned long)sizeof(scs_float));
159
191
  fclose(fin);
160
192
  return -1;
161
193
  }
162
-
194
+ fread(&(file_version_sz), sizeof(uint32_t), 1, fin);
195
+ fread(file_version, 1, file_version_sz, fin);
196
+ file_version[file_version_sz] = '\0';
197
+ if (strcmp(file_version, SCS_VERSION) != 0) {
198
+ scs_printf("************************************************************\n"
199
+ "Warning: SCS file version %s, this is SCS version %s.\n"
200
+ "The file reading / writing logic might have changed.\n"
201
+ "************************************************************\n",
202
+ file_version, SCS_VERSION);
203
+ }
163
204
  *k = read_scs_cone(fin);
164
205
  *d = read_scs_data(fin);
206
+ *stgs = read_scs_stgs(fin);
165
207
  fclose(fin);
166
208
  return 0;
167
209
  }
210
+
211
+ void SCS(log_data_to_csv)(const ScsData *d, const ScsCone *k,
212
+ const ScsSettings *stgs, const ScsWork *w,
213
+ scs_int iter, SCS(timer) * solve_timer) {
214
+ ScsResiduals *r = w->r_orig;
215
+ ScsResiduals *r_n = w->r_normalized;
216
+ /* if iter 0 open to write, else open to append */
217
+ FILE *fout = fopen(stgs->log_csv_filename, iter == 0 ? "w" : "a");
218
+ if (!fout) {
219
+ scs_printf("Error: Could not open %s for writing\n",
220
+ stgs->log_csv_filename);
221
+ return;
222
+ }
223
+ scs_int l = w->m + w->n + 1;
224
+ if (iter == 0) {
225
+ /* need to end in comma so that csv parsing is correct */
226
+ fprintf(fout, "iter,"
227
+ "res_pri,"
228
+ "res_dual,"
229
+ "gap,"
230
+ "ax_s_btau_nrm_inf,"
231
+ "px_aty_ctau_nrm_inf,"
232
+ "ax_s_btau_nrm_2,"
233
+ "px_aty_ctau_nrm_2,"
234
+ "res_infeas,"
235
+ "res_unbdd_a,"
236
+ "res_unbdd_p,"
237
+ "pobj,"
238
+ "dobj,"
239
+ "tau,"
240
+ "kap,"
241
+ "res_pri_normalized,"
242
+ "res_dual_normalized,"
243
+ "gap_normalized,"
244
+ "ax_s_btau_nrm_inf_normalized,"
245
+ "px_aty_ctau_nrm_inf_normalized,"
246
+ "ax_s_btau_nrm_2_normalized,"
247
+ "px_aty_ctau_nrm_2_normalized,"
248
+ "res_infeas_normalized,"
249
+ "res_unbdd_a_normalized,"
250
+ "res_unbdd_p_normalized,"
251
+ "pobj_normalized,"
252
+ "dobj_normalized,"
253
+ "tau_normalized,"
254
+ "kap_normalized,"
255
+ "scale,"
256
+ "diff_u_ut_nrm_2,"
257
+ "diff_v_v_prev_nrm_2,"
258
+ "diff_u_ut_nrm_inf,"
259
+ "diff_v_v_prev_nrm_inf,"
260
+ "aa_norm,"
261
+ "accepted_accel_steps,"
262
+ "rejected_accel_steps,"
263
+ "time,"
264
+ "\n");
265
+ }
266
+ fprintf(fout, "%li,", (long)iter);
267
+ fprintf(fout, "%.16e,", r->res_pri);
268
+ fprintf(fout, "%.16e,", r->res_dual);
269
+ fprintf(fout, "%.16e,", r->gap);
270
+ fprintf(fout, "%.16e,", SCS(norm_inf)(r->ax_s_btau, w->m));
271
+ fprintf(fout, "%.16e,", SCS(norm_inf)(r->px_aty_ctau, w->n));
272
+ fprintf(fout, "%.16e,", SCS(norm_2)(r->ax_s_btau, w->m));
273
+ fprintf(fout, "%.16e,", SCS(norm_2)(r->px_aty_ctau, w->n));
274
+ fprintf(fout, "%.16e,", r->res_infeas);
275
+ fprintf(fout, "%.16e,", r->res_unbdd_a);
276
+ fprintf(fout, "%.16e,", r->res_unbdd_p);
277
+ fprintf(fout, "%.16e,", r->pobj);
278
+ fprintf(fout, "%.16e,", r->dobj);
279
+ fprintf(fout, "%.16e,", r->tau);
280
+ fprintf(fout, "%.16e,", r->kap);
281
+ fprintf(fout, "%.16e,", r_n->res_pri);
282
+ fprintf(fout, "%.16e,", r_n->res_dual);
283
+ fprintf(fout, "%.16e,", r_n->gap);
284
+ fprintf(fout, "%.16e,", SCS(norm_inf)(r_n->ax_s_btau, w->m));
285
+ fprintf(fout, "%.16e,", SCS(norm_inf)(r_n->px_aty_ctau, w->n));
286
+ fprintf(fout, "%.16e,", SCS(norm_2)(r_n->ax_s_btau, w->m));
287
+ fprintf(fout, "%.16e,", SCS(norm_2)(r_n->px_aty_ctau, w->n));
288
+ fprintf(fout, "%.16e,", r_n->res_infeas);
289
+ fprintf(fout, "%.16e,", r_n->res_unbdd_a);
290
+ fprintf(fout, "%.16e,", r_n->res_unbdd_p);
291
+ fprintf(fout, "%.16e,", r_n->pobj);
292
+ fprintf(fout, "%.16e,", r_n->dobj);
293
+ fprintf(fout, "%.16e,", r_n->tau);
294
+ fprintf(fout, "%.16e,", r_n->kap);
295
+ fprintf(fout, "%.16e,", w->scale);
296
+ fprintf(fout, "%.16e,", SCS(norm_diff)(w->u, w->u_t, l));
297
+ fprintf(fout, "%.16e,", SCS(norm_diff)(w->v, w->v_prev, l));
298
+ fprintf(fout, "%.16e,", SCS(norm_inf_diff)(w->u, w->u_t, l));
299
+ fprintf(fout, "%.16e,", SCS(norm_inf_diff)(w->v, w->v_prev, l));
300
+ fprintf(fout, "%.16e,", w->aa_norm);
301
+ fprintf(fout, "%li,", (long)w->accepted_accel_steps);
302
+ fprintf(fout, "%li,", (long)w->rejected_accel_steps);
303
+ fprintf(fout, "%.16e,", SCS(tocq)(solve_timer) / 1e3);
304
+ fprintf(fout, "\n");
305
+ fclose(fout);
306
+ }
data/vendor/scs/src/rw.o CHANGED
Binary file