scs 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +12 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +98 -0
  5. data/ext/scs/extconf.rb +29 -0
  6. data/lib/scs.rb +17 -0
  7. data/lib/scs/ffi.rb +117 -0
  8. data/lib/scs/solver.rb +173 -0
  9. data/lib/scs/version.rb +3 -0
  10. data/vendor/scs/LICENSE.txt +21 -0
  11. data/vendor/scs/Makefile +164 -0
  12. data/vendor/scs/README.md +222 -0
  13. data/vendor/scs/include/aa.h +56 -0
  14. data/vendor/scs/include/cones.h +46 -0
  15. data/vendor/scs/include/ctrlc.h +33 -0
  16. data/vendor/scs/include/glbopts.h +177 -0
  17. data/vendor/scs/include/linalg.h +26 -0
  18. data/vendor/scs/include/linsys.h +64 -0
  19. data/vendor/scs/include/normalize.h +18 -0
  20. data/vendor/scs/include/rw.h +17 -0
  21. data/vendor/scs/include/scs.h +161 -0
  22. data/vendor/scs/include/scs_blas.h +51 -0
  23. data/vendor/scs/include/util.h +65 -0
  24. data/vendor/scs/linsys/amatrix.c +305 -0
  25. data/vendor/scs/linsys/amatrix.h +36 -0
  26. data/vendor/scs/linsys/amatrix.o +0 -0
  27. data/vendor/scs/linsys/cpu/direct/private.c +366 -0
  28. data/vendor/scs/linsys/cpu/direct/private.h +26 -0
  29. data/vendor/scs/linsys/cpu/direct/private.o +0 -0
  30. data/vendor/scs/linsys/cpu/indirect/private.c +256 -0
  31. data/vendor/scs/linsys/cpu/indirect/private.h +31 -0
  32. data/vendor/scs/linsys/cpu/indirect/private.o +0 -0
  33. data/vendor/scs/linsys/external/amd/LICENSE.txt +934 -0
  34. data/vendor/scs/linsys/external/amd/SuiteSparse_config.c +469 -0
  35. data/vendor/scs/linsys/external/amd/SuiteSparse_config.h +254 -0
  36. data/vendor/scs/linsys/external/amd/SuiteSparse_config.o +0 -0
  37. data/vendor/scs/linsys/external/amd/amd.h +400 -0
  38. data/vendor/scs/linsys/external/amd/amd_1.c +180 -0
  39. data/vendor/scs/linsys/external/amd/amd_1.o +0 -0
  40. data/vendor/scs/linsys/external/amd/amd_2.c +1842 -0
  41. data/vendor/scs/linsys/external/amd/amd_2.o +0 -0
  42. data/vendor/scs/linsys/external/amd/amd_aat.c +184 -0
  43. data/vendor/scs/linsys/external/amd/amd_aat.o +0 -0
  44. data/vendor/scs/linsys/external/amd/amd_control.c +64 -0
  45. data/vendor/scs/linsys/external/amd/amd_control.o +0 -0
  46. data/vendor/scs/linsys/external/amd/amd_defaults.c +37 -0
  47. data/vendor/scs/linsys/external/amd/amd_defaults.o +0 -0
  48. data/vendor/scs/linsys/external/amd/amd_dump.c +179 -0
  49. data/vendor/scs/linsys/external/amd/amd_dump.o +0 -0
  50. data/vendor/scs/linsys/external/amd/amd_global.c +16 -0
  51. data/vendor/scs/linsys/external/amd/amd_global.o +0 -0
  52. data/vendor/scs/linsys/external/amd/amd_info.c +119 -0
  53. data/vendor/scs/linsys/external/amd/amd_info.o +0 -0
  54. data/vendor/scs/linsys/external/amd/amd_internal.h +304 -0
  55. data/vendor/scs/linsys/external/amd/amd_order.c +199 -0
  56. data/vendor/scs/linsys/external/amd/amd_order.o +0 -0
  57. data/vendor/scs/linsys/external/amd/amd_post_tree.c +120 -0
  58. data/vendor/scs/linsys/external/amd/amd_post_tree.o +0 -0
  59. data/vendor/scs/linsys/external/amd/amd_postorder.c +206 -0
  60. data/vendor/scs/linsys/external/amd/amd_postorder.o +0 -0
  61. data/vendor/scs/linsys/external/amd/amd_preprocess.c +118 -0
  62. data/vendor/scs/linsys/external/amd/amd_preprocess.o +0 -0
  63. data/vendor/scs/linsys/external/amd/amd_valid.c +92 -0
  64. data/vendor/scs/linsys/external/amd/amd_valid.o +0 -0
  65. data/vendor/scs/linsys/external/amd/changes +11 -0
  66. data/vendor/scs/linsys/external/qdldl/LICENSE +201 -0
  67. data/vendor/scs/linsys/external/qdldl/README.md +120 -0
  68. data/vendor/scs/linsys/external/qdldl/changes +4 -0
  69. data/vendor/scs/linsys/external/qdldl/qdldl.c +298 -0
  70. data/vendor/scs/linsys/external/qdldl/qdldl.h +177 -0
  71. data/vendor/scs/linsys/external/qdldl/qdldl.o +0 -0
  72. data/vendor/scs/linsys/external/qdldl/qdldl_types.h +21 -0
  73. data/vendor/scs/linsys/gpu/gpu.c +41 -0
  74. data/vendor/scs/linsys/gpu/gpu.h +85 -0
  75. data/vendor/scs/linsys/gpu/indirect/private.c +304 -0
  76. data/vendor/scs/linsys/gpu/indirect/private.h +36 -0
  77. data/vendor/scs/scs.mk +181 -0
  78. data/vendor/scs/src/aa.c +224 -0
  79. data/vendor/scs/src/aa.o +0 -0
  80. data/vendor/scs/src/cones.c +802 -0
  81. data/vendor/scs/src/cones.o +0 -0
  82. data/vendor/scs/src/ctrlc.c +77 -0
  83. data/vendor/scs/src/ctrlc.o +0 -0
  84. data/vendor/scs/src/linalg.c +84 -0
  85. data/vendor/scs/src/linalg.o +0 -0
  86. data/vendor/scs/src/normalize.c +93 -0
  87. data/vendor/scs/src/normalize.o +0 -0
  88. data/vendor/scs/src/rw.c +167 -0
  89. data/vendor/scs/src/rw.o +0 -0
  90. data/vendor/scs/src/scs.c +978 -0
  91. data/vendor/scs/src/scs.o +0 -0
  92. data/vendor/scs/src/scs_version.c +5 -0
  93. data/vendor/scs/src/scs_version.o +0 -0
  94. data/vendor/scs/src/util.c +196 -0
  95. data/vendor/scs/src/util.o +0 -0
  96. data/vendor/scs/test/data/small_random_socp +0 -0
  97. data/vendor/scs/test/minunit.h +13 -0
  98. data/vendor/scs/test/problem_utils.h +93 -0
  99. data/vendor/scs/test/problems/rob_gauss_cov_est.h +85 -0
  100. data/vendor/scs/test/problems/small_lp.h +50 -0
  101. data/vendor/scs/test/problems/small_random_socp.h +33 -0
  102. data/vendor/scs/test/random_socp_prob.c +171 -0
  103. data/vendor/scs/test/run_from_file.c +69 -0
  104. data/vendor/scs/test/run_tests +2 -0
  105. data/vendor/scs/test/run_tests.c +32 -0
  106. metadata +203 -0
@@ -0,0 +1,46 @@
1
+ #ifndef CONES_H_GUARD
2
+ #define CONES_H_GUARD
3
+
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif
7
+
8
+ #include "glbopts.h"
9
+ #include "scs.h"
10
+ #include "scs_blas.h"
11
+
12
+ /* private data to help cone projection step */
13
+ struct SCS_CONE_WORK {
14
+ scs_float total_cone_time;
15
+ #ifdef USE_LAPACK
16
+ /* workspace for eigenvector decompositions: */
17
+ scs_float *Xs, *Z, *e, *work;
18
+ blas_int *iwork, lwork, liwork;
19
+ #endif
20
+ };
21
+
22
+ /*
23
+ * boundaries will contain array of indices of rows of A corresponding to
24
+ * cone boundaries, boundaries[0] is starting index for cones of size larger
25
+ * than 1
26
+ * returns length of boundaries array, boundaries malloc-ed here so should be
27
+ * freed
28
+ */
29
+ scs_int SCS(get_cone_boundaries)(const ScsCone *k, scs_int **boundaries);
30
+
31
+ ScsConeWork *SCS(init_cone)(const ScsCone *k);
32
+ char *SCS(get_cone_header)(const ScsCone *k);
33
+ scs_int SCS(validate_cones)(const ScsData *d, const ScsCone *k);
34
+
35
+ /* pass in iter to control how accurate the cone projection
36
+ with iteration, set iter < 0 for exact projection, warm_start contains guess
37
+ of solution, can be SCS_NULL*/
38
+ scs_int SCS(proj_dual_cone)(scs_float *x, const ScsCone *k, ScsConeWork *c,
39
+ const scs_float *warm_start, scs_int iter);
40
+ void SCS(finish_cone)(ScsConeWork *c);
41
+ char *SCS(get_cone_summary)(const ScsInfo *info, ScsConeWork *c);
42
+
43
+ #ifdef __cplusplus
44
+ }
45
+ #endif
46
+ #endif
@@ -0,0 +1,33 @@
1
+ /*
2
+ * Interface for SCS signal handling.
3
+ */
4
+
5
+ #ifndef CTRLC_H_GUARD
6
+ #define CTRLC_H_GUARD
7
+
8
+ #ifdef __cplusplus
9
+ extern "C" {
10
+ #endif
11
+
12
+ #if CTRLC > 0
13
+
14
+ void scs_start_interrupt_listener(void);
15
+ void scs_end_interrupt_listener(void);
16
+ int scs_is_interrupted(void);
17
+
18
+ #else /* CTRLC = 0 */
19
+
20
+ /* Simply to suppress empty translation unit warnings. */
21
+ typedef int scs_make_iso_compilers_happy;
22
+
23
+ /* No signal handling. */
24
+ #define scs_start_interrupt_listener()
25
+ #define scs_end_interrupt_listener()
26
+ #define scs_is_interrupted() 0
27
+
28
+ #endif /* END IF CTRLC > 0 */
29
+
30
+ #ifdef __cplusplus
31
+ }
32
+ #endif
33
+ #endif
@@ -0,0 +1,177 @@
1
+ #ifndef GLB_H_GUARD
2
+ #define GLB_H_GUARD
3
+
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif
7
+
8
+ #include <math.h>
9
+
10
+ #ifndef SCS
11
+ #define SCS(x) scs_##x
12
+ #endif
13
+
14
+ /* SCS VERSION NUMBER ---------------------------------------------- */
15
+ #define SCS_VERSION \
16
+ ("2.1.2") /* string literals automatically null-terminated */
17
+
18
+ /* SCS returns one of the following integers: */
19
+ #define SCS_INFEASIBLE_INACCURATE (-7)
20
+ #define SCS_UNBOUNDED_INACCURATE (-6)
21
+ #define SCS_SIGINT (-5)
22
+ #define SCS_FAILED (-4)
23
+ #define SCS_INDETERMINATE (-3)
24
+ #define SCS_INFEASIBLE (-2) /* primal infeasible, dual unbounded */
25
+ #define SCS_UNBOUNDED (-1) /* primal unbounded, dual infeasible */
26
+ #define SCS_UNFINISHED (0) /* never returned, used as placeholder */
27
+ #define SCS_SOLVED (1)
28
+ #define SCS_SOLVED_INACCURATE (2)
29
+
30
+ /* DEFAULT SOLVER PARAMETERS AND SETTINGS -------------------------- */
31
+ #define MAX_ITERS (5000)
32
+ #define EPS (1E-5)
33
+ #define ALPHA (1.5)
34
+ #define RHO_X (1E-3)
35
+ #define SCALE (1.0)
36
+ #define CG_RATE (2.0)
37
+ #define VERBOSE (1)
38
+ #define NORMALIZE (1)
39
+ #define WARM_START (0)
40
+ #define ACCELERATION_LOOKBACK (10)
41
+ #define WRITE_DATA_FILENAME (0)
42
+
43
+ /* redefine printfs and memory allocators as needed */
44
+ #ifdef MATLAB_MEX_FILE
45
+ #include "mex.h"
46
+ #define scs_printf mexPrintf
47
+ #define _scs_free mxFree
48
+ #define _scs_malloc mxMalloc
49
+ #define _scs_calloc mxCalloc
50
+ #define _scs_realloc mxRealloc
51
+ #elif defined PYTHON
52
+ #include <Python.h>
53
+ #include <stdlib.h>
54
+ #define scs_printf(...) \
55
+ { \
56
+ PyGILState_STATE gilstate = PyGILState_Ensure(); \
57
+ PySys_WriteStdout(__VA_ARGS__); \
58
+ PyGILState_Release(gilstate); \
59
+ }
60
+ #define _scs_printf printf
61
+ #define _scs_free free
62
+ #define _scs_malloc malloc
63
+ #define _scs_calloc calloc
64
+ #define _scs_realloc realloc
65
+ #elif (defined(USING_R))
66
+ #include <R_ext/Print.h> /* Rprintf etc */
67
+ #include <stdio.h>
68
+ #include <stdlib.h>
69
+ #define scs_printf Rprintf
70
+ #define _scs_free free
71
+ #define _scs_malloc malloc
72
+ #define _scs_calloc calloc
73
+ #define _scs_realloc realloc
74
+ #else
75
+ #include <stdio.h>
76
+ #include <stdlib.h>
77
+ #define scs_printf printf
78
+ #define _scs_free free
79
+ #define _scs_malloc malloc
80
+ #define _scs_calloc calloc
81
+ #define _scs_realloc realloc
82
+ #endif
83
+
84
+ /* Only required for SuiteSparse compatibility: */
85
+ #ifndef _scs_printf
86
+ #define _scs_printf scs_printf
87
+ #endif
88
+
89
+ #define scs_free(x) \
90
+ _scs_free(x); \
91
+ x = SCS_NULL
92
+ #define scs_malloc(x) _scs_malloc(x)
93
+ #define scs_calloc(x, y) _scs_calloc(x, y)
94
+ #define scs_realloc(x, y) _scs_realloc(x, y)
95
+
96
+ #ifdef DLONG
97
+ #ifdef _WIN64
98
+ #include <stdint.h>
99
+ typedef int64_t scs_int;
100
+ /* typedef long scs_int; */
101
+ #else
102
+ typedef long scs_int;
103
+ #endif
104
+ #else
105
+ typedef int scs_int;
106
+ #endif
107
+
108
+ #ifndef SFLOAT
109
+ typedef double scs_float;
110
+ #ifndef NAN
111
+ #define NAN ((scs_float)0x7ff8000000000000)
112
+ #endif
113
+ #ifndef INFINITY
114
+ #define INFINITY NAN
115
+ #endif
116
+ #else
117
+ typedef float scs_float;
118
+ #ifndef NAN
119
+ #define NAN ((float)0x7fc00000)
120
+ #endif
121
+ #ifndef INFINITY
122
+ #define INFINITY NAN
123
+ #endif
124
+ #endif
125
+
126
+ #define SCS_NULL 0
127
+
128
+ #ifndef MAX
129
+ #define MAX(a, b) (((a) > (b)) ? (a) : (b))
130
+ #endif
131
+
132
+ #ifndef MIN
133
+ #define MIN(a, b) (((a) < (b)) ? (a) : (b))
134
+ #endif
135
+
136
+ #ifndef ABS
137
+ #define ABS(x) (((x) < 0) ? -(x) : (x))
138
+ #endif
139
+
140
+ #ifndef POWF
141
+ #ifdef SFLOAT
142
+ #define POWF powf
143
+ #else
144
+ #define POWF pow
145
+ #endif
146
+ #endif
147
+
148
+ #ifndef SQRTF
149
+ #ifdef SFLOAT
150
+ #define SQRTF sqrtf
151
+ #else
152
+ #define SQRTF sqrt
153
+ #endif
154
+ #endif
155
+
156
+ #define EPS_TOL (1E-18)
157
+ #define SAFEDIV_POS(X, Y) ((Y) < EPS_TOL ? ((X) / EPS_TOL) : (X) / (Y))
158
+
159
+ #if EXTRA_VERBOSE > 0
160
+ #define PRINT_INTERVAL (1)
161
+ #define CONVERGED_INTERVAL (1)
162
+ #else
163
+ /* print summary output every this num iterations */
164
+ #define PRINT_INTERVAL (100)
165
+ /* check for convergence every this num iterations */
166
+ #define CONVERGED_INTERVAL (20)
167
+ #endif
168
+
169
+ /* tolerance at which we declare problem indeterminate */
170
+ #define INDETERMINATE_TOL (1e-9)
171
+ /* maintain the iterates at this l2 norm (due to homogeneity) */
172
+ #define ITERATE_NORM (10.)
173
+
174
+ #ifdef __cplusplus
175
+ }
176
+ #endif
177
+ #endif
@@ -0,0 +1,26 @@
1
+ #ifndef LINALG_H_GUARD
2
+ #define LINALG_H_GUARD
3
+
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif
7
+
8
+ #include <math.h>
9
+ #include "scs.h"
10
+
11
+ void SCS(set_as_scaled_array)(scs_float *x, const scs_float *a,
12
+ const scs_float b, scs_int len);
13
+ void SCS(scale_array)(scs_float *a, const scs_float b, scs_int len);
14
+ scs_float SCS(dot)(const scs_float *x, const scs_float *y, scs_int len);
15
+ scs_float SCS(norm_sq)(const scs_float *v, scs_int len);
16
+ scs_float SCS(norm)(const scs_float *v, scs_int len);
17
+ scs_float SCS(norm_inf)(const scs_float *a, scs_int l);
18
+ void SCS(add_scaled_array)(scs_float *a, const scs_float *b, scs_int n,
19
+ const scs_float sc);
20
+ scs_float SCS(norm_diff)(const scs_float *a, const scs_float *b, scs_int l);
21
+ scs_float SCS(norm_inf_diff)(const scs_float *a, const scs_float *b, scs_int l);
22
+
23
+ #ifdef __cplusplus
24
+ }
25
+ #endif
26
+ #endif
@@ -0,0 +1,64 @@
1
+ #ifndef LINSYS_H_GUARD
2
+ #define LINSYS_H_GUARD
3
+
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif
7
+
8
+ #include "scs.h"
9
+
10
+ /* YOUR LINEAR SYSTEM SOLVER MUST IMPLEMENT THESE METHODS AND SCS_LIN_SYS_WORK
11
+ * STRUCT */
12
+
13
+ /* initialize ScsLinSysWork structure and perform any necessary preprocessing */
14
+ ScsLinSysWork *SCS(init_lin_sys_work)(const ScsMatrix *A,
15
+ const ScsSettings *stgs);
16
+ /* solves [d->RHO_X * I A' ; A -I] x = b for x, stores result in b, s contains
17
+ * warm-start, iter is current scs iteration count */
18
+ scs_int SCS(solve_lin_sys)(const ScsMatrix *A, const ScsSettings *stgs,
19
+ ScsLinSysWork *p, scs_float *b, const scs_float *s,
20
+ scs_int iter);
21
+ /* frees ScsLinSysWork structure and allocated memory in ScsLinSysWork */
22
+ void SCS(free_lin_sys_work)(ScsLinSysWork *p);
23
+
24
+ /* forms y += A'*x */
25
+ void SCS(accum_by_atrans)(const ScsMatrix *A, ScsLinSysWork *p,
26
+ const scs_float *x, scs_float *y);
27
+ /* forms y += A*x */
28
+ void SCS(accum_by_a)(const ScsMatrix *A, ScsLinSysWork *p, const scs_float *x,
29
+ scs_float *y);
30
+
31
+ /* returns negative num if input data is invalid */
32
+ scs_int SCS(validate_lin_sys)(const ScsMatrix *A);
33
+
34
+ /* returns string describing method, can return null, if not null free will be
35
+ * called on output */
36
+ char *SCS(get_lin_sys_method)(const ScsMatrix *A, const ScsSettings *stgs);
37
+ /* returns string containing summary information about linear system solves, can
38
+ * return null, if not null free will be called on output */
39
+ char *SCS(get_lin_sys_summary)(ScsLinSysWork *p, const ScsInfo *info);
40
+
41
+ /* Normalization routines, used if d->NORMALIZE is true */
42
+ /* normalizes A matrix, sets w->E and w->D diagonal scaling matrices, Anew =
43
+ * d->SCALE * (D^-1)*A*(E^-1) (different to paper which is D*A*E)
44
+ * D and E must be all positive entries, D must satisfy cone boundaries
45
+ * must set (w->mean_norm_row_a = mean of norms of rows of normalized A) THEN
46
+ * scale
47
+ * resulting A by d->SCALE */
48
+ void SCS(normalize_a)(ScsMatrix *A, const ScsSettings *stgs, const ScsCone *k,
49
+ ScsScaling *scal);
50
+ /* unnormalizes A matrix, unnormalizes by w->D and w->E and d->SCALE */
51
+ void SCS(un_normalize_a)(ScsMatrix *A, const ScsSettings *stgs,
52
+ const ScsScaling *scal);
53
+ /* to free the memory allocated in ScsMatrix */
54
+ void SCS(free_a_matrix)(ScsMatrix *A);
55
+
56
+ /* copies A (instead of in-place normalization), returns 0 for failure,
57
+ * allocates memory for dstp */
58
+ scs_int SCS(copy_a_matrix)(ScsMatrix **dstp, const ScsMatrix *src);
59
+
60
+ #ifdef __cplusplus
61
+ }
62
+ #endif
63
+
64
+ #endif
@@ -0,0 +1,18 @@
1
+ #ifndef NORMALIZE_H_GUARD
2
+ #define NORMALIZE_H_GUARD
3
+
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif
7
+
8
+ #include "scs.h"
9
+
10
+ void SCS(normalize_b_c)(ScsWork *w);
11
+ void SCS(calc_scaled_resids)(ScsWork *w, ScsResiduals *r);
12
+ void SCS(normalize_warm_start)(ScsWork *w);
13
+ void SCS(un_normalize_sol)(ScsWork *w, ScsSolution *sol);
14
+
15
+ #ifdef __cplusplus
16
+ }
17
+ #endif
18
+ #endif
@@ -0,0 +1,17 @@
1
+ #ifndef RW_H_GUARD
2
+ #define RW_H_GUARD
3
+
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif
7
+
8
+ #include "glbopts.h"
9
+ #include "scs.h"
10
+
11
+ void SCS(write_data)(const ScsData *d, const ScsCone *k);
12
+ scs_int SCS(read_data)(const char * filename, ScsData **d, ScsCone **k);
13
+
14
+ #ifdef __cplusplus
15
+ }
16
+ #endif
17
+ #endif
@@ -0,0 +1,161 @@
1
+ #ifndef SCS_H_GUARD
2
+ #define SCS_H_GUARD
3
+
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif
7
+
8
+ #include <string.h>
9
+ #include "glbopts.h"
10
+ #include "aa.h"
11
+
12
+ /* private data structs (that you define) containing any necessary data to solve
13
+ * linear system, etc. this defines the matrix A, only the linear system solver
14
+ * interacts with this struct */
15
+ typedef struct SCS_A_DATA_MATRIX ScsMatrix;
16
+ /* stores the necessary private workspace, only the linear system solver
17
+ * interacts with this struct */
18
+ typedef struct SCS_LIN_SYS_WORK ScsLinSysWork;
19
+
20
+ typedef struct SCS_PROBLEM_DATA ScsData;
21
+ typedef struct SCS_SETTINGS ScsSettings;
22
+ typedef struct SCS_SOL_VARS ScsSolution;
23
+ typedef struct SCS_INFO ScsInfo;
24
+ typedef struct SCS_SCALING ScsScaling;
25
+ typedef struct SCS_WORK ScsWork;
26
+ typedef struct SCS_RESIDUALS ScsResiduals;
27
+ typedef struct SCS_CONE ScsCone;
28
+ typedef struct SCS_ACCEL_WORK ScsAccelWork;
29
+ typedef struct SCS_CONE_WORK ScsConeWork;
30
+
31
+ /* struct containing problem data */
32
+ struct SCS_PROBLEM_DATA {
33
+ /* these cannot change for multiple runs for the same call to SCS(init) */
34
+ scs_int m, n; /* A has m rows, n cols */
35
+ ScsMatrix *A; /* A is supplied in data format specified by linsys solver */
36
+
37
+ /* these can change for multiple runs for the same call to SCS(init) */
38
+ scs_float *b, *c; /* dense arrays for b (size m), c (size n) */
39
+
40
+ ScsSettings *stgs; /* contains solver settings specified by user */
41
+ };
42
+
43
+ /* ScsSettings struct */
44
+ struct SCS_SETTINGS {
45
+ /* settings parameters: default suggested input */
46
+
47
+ /* these *cannot* change for multiple runs with the same call to SCS(init) */
48
+ scs_int normalize; /* boolean, heuristic data rescaling: 1 */
49
+ scs_float scale; /* if normalized, rescales by this factor: 5 */
50
+ scs_float rho_x; /* x equality constraint scaling: 1e-3 */
51
+
52
+ /* these can change for multiple runs with the same call to SCS(init) */
53
+ scs_int max_iters; /* maximum iterations to take: 2500 */
54
+ scs_float eps; /* convergence tolerance: 1e-3 */
55
+ scs_float alpha; /* relaxation parameter: 1.8 */
56
+ scs_float cg_rate; /* for indirect, tolerance goes down like
57
+ (1/iter)^cg_rate: 2 */
58
+ scs_int verbose; /* boolean, write out progress: 1 */
59
+ scs_int warm_start; /* boolean, warm start (put initial guess in ScsSolution
60
+ struct): 0 */
61
+ scs_int acceleration_lookback; /* memory for acceleration */
62
+ const char* write_data_filename; /* string, if set will dump data */
63
+ };
64
+
65
+ /* NB: rows of data matrix A must be specified in this exact order */
66
+ struct SCS_CONE {
67
+ scs_int f; /* number of linear equality constraints */
68
+ scs_int l; /* length of LP cone */
69
+ scs_int *q; /* array of second-order cone constraints */
70
+ scs_int qsize; /* length of SOC array */
71
+ scs_int *s; /* array of SD constraints */
72
+ scs_int ssize; /* length of SD array */
73
+ scs_int ep; /* number of primal exponential cone triples */
74
+ scs_int ed; /* number of dual exponential cone triples */
75
+ scs_float *p; /* array of power cone params, must be \in [-1, 1],
76
+ negative values are interpreted as specifying the
77
+ dual cone */
78
+ scs_int psize; /* number of (primal and dual) power cone triples */
79
+ };
80
+
81
+ /* contains primal-dual solution arrays */
82
+ struct SCS_SOL_VARS {
83
+ scs_float *x, *y, *s;
84
+ };
85
+
86
+ /* contains terminating information */
87
+ struct SCS_INFO {
88
+ scs_int iter; /* number of iterations taken */
89
+ char status[32]; /* status string, e.g. 'Solved' */
90
+ scs_int status_val; /* status as scs_int, defined in glbopts.h */
91
+ scs_float pobj; /* primal objective */
92
+ scs_float dobj; /* dual objective */
93
+ scs_float res_pri; /* primal equality residual */
94
+ scs_float res_dual; /* dual equality residual */
95
+ scs_float res_infeas; /* infeasibility cert residual */
96
+ scs_float res_unbdd; /* unbounded cert residual */
97
+ scs_float rel_gap; /* relative duality gap */
98
+ scs_float setup_time; /* time taken for setup phase (milliseconds) */
99
+ scs_float solve_time; /* time taken for solve phase (milliseconds) */
100
+ };
101
+
102
+ /* contains normalization variables */
103
+ struct SCS_SCALING {
104
+ scs_float *D, *E; /* for normalization */
105
+ scs_float mean_norm_row_a, mean_norm_col_a;
106
+ };
107
+
108
+ /*
109
+ * main library api's:
110
+ * SCS(init): allocates memory etc (e.g., factorize matrix [I A; A^T -I])
111
+ * SCS(solve): can be called many times with different b,c data per init call
112
+ * SCS(finish): cleans up the memory (one per init call)
113
+ */
114
+ ScsWork *SCS(init)(const ScsData *d, const ScsCone *k, ScsInfo *info);
115
+ scs_int SCS(solve)(ScsWork *w, const ScsData *d, const ScsCone *k,
116
+ ScsSolution *sol, ScsInfo *info);
117
+ void SCS(finish)(ScsWork *w);
118
+ /* scs calls SCS(init), SCS(solve), and SCS(finish) */
119
+ scs_int scs(const ScsData *d, const ScsCone *k, ScsSolution *sol,
120
+ ScsInfo *info);
121
+
122
+ const char *SCS(version)(void);
123
+ size_t SCS(sizeof_int)(void);
124
+ size_t SCS(sizeof_float)(void);
125
+
126
+ /* the following structs are not exposed to user */
127
+
128
+ /* workspace for SCS */
129
+ struct SCS_WORK {
130
+ /* x_prev = x from previous iteration */
131
+ scs_float *u, *u_best, *v, *v_best, *u_t, *u_prev, *v_prev;
132
+ scs_float *h, *g, *pr, *dr;
133
+ scs_float g_th, sc_b, sc_c, nm_b, nm_c, best_max_residual;
134
+ scs_float *b, *c; /* (possibly normalized) b and c vectors */
135
+ scs_int m, n; /* A has m rows, n cols */
136
+ ScsMatrix *A; /* (possibly normalized) A matrix */
137
+ ScsLinSysWork *p; /* struct populated by linear system solver */
138
+ ScsSettings *stgs; /* contains solver settings specified by user */
139
+ ScsScaling *scal; /* contains the re-scaling data */
140
+ ScsConeWork *cone_work; /* workspace for the cone projection step */
141
+ AaWork *accel; /* Struct for acceleration workspace */
142
+ };
143
+
144
+ /* to hold residual information (unnormalized) */
145
+ struct SCS_RESIDUALS {
146
+ scs_int last_iter;
147
+ scs_float res_dual;
148
+ scs_float res_pri;
149
+ scs_float res_infeas;
150
+ scs_float res_unbdd;
151
+ scs_float rel_gap;
152
+ scs_float ct_x_by_tau; /* not divided by tau */
153
+ scs_float bt_y_by_tau; /* not divided by tau */
154
+ scs_float tau;
155
+ scs_float kap;
156
+ };
157
+
158
+ #ifdef __cplusplus
159
+ }
160
+ #endif
161
+ #endif