scs 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +84 -0
- data/ext/scs/Rakefile +11 -0
- data/lib/scs/ffi.rb +117 -0
- data/lib/scs/solver.rb +178 -0
- data/lib/scs/version.rb +3 -0
- data/lib/scs.rb +17 -0
- data/vendor/scs/LICENSE.txt +21 -0
- data/vendor/scs/Makefile +164 -0
- data/vendor/scs/README.md +220 -0
- data/vendor/scs/include/aa.h +56 -0
- data/vendor/scs/include/cones.h +46 -0
- data/vendor/scs/include/ctrlc.h +33 -0
- data/vendor/scs/include/glbopts.h +177 -0
- data/vendor/scs/include/linalg.h +26 -0
- data/vendor/scs/include/linsys.h +64 -0
- data/vendor/scs/include/normalize.h +18 -0
- data/vendor/scs/include/rw.h +17 -0
- data/vendor/scs/include/scs.h +161 -0
- data/vendor/scs/include/scs_blas.h +51 -0
- data/vendor/scs/include/util.h +65 -0
- data/vendor/scs/linsys/amatrix.c +305 -0
- data/vendor/scs/linsys/amatrix.h +36 -0
- data/vendor/scs/linsys/amatrix.o +0 -0
- data/vendor/scs/linsys/cpu/direct/private.c +366 -0
- data/vendor/scs/linsys/cpu/direct/private.h +26 -0
- data/vendor/scs/linsys/cpu/direct/private.o +0 -0
- data/vendor/scs/linsys/cpu/indirect/private.c +256 -0
- data/vendor/scs/linsys/cpu/indirect/private.h +31 -0
- data/vendor/scs/linsys/cpu/indirect/private.o +0 -0
- data/vendor/scs/linsys/external/amd/LICENSE.txt +934 -0
- data/vendor/scs/linsys/external/amd/SuiteSparse_config.c +469 -0
- data/vendor/scs/linsys/external/amd/SuiteSparse_config.h +254 -0
- data/vendor/scs/linsys/external/amd/SuiteSparse_config.o +0 -0
- data/vendor/scs/linsys/external/amd/amd.h +400 -0
- data/vendor/scs/linsys/external/amd/amd_1.c +180 -0
- data/vendor/scs/linsys/external/amd/amd_1.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_2.c +1842 -0
- data/vendor/scs/linsys/external/amd/amd_2.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_aat.c +184 -0
- data/vendor/scs/linsys/external/amd/amd_aat.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_control.c +64 -0
- data/vendor/scs/linsys/external/amd/amd_control.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_defaults.c +37 -0
- data/vendor/scs/linsys/external/amd/amd_defaults.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_dump.c +179 -0
- data/vendor/scs/linsys/external/amd/amd_dump.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_global.c +16 -0
- data/vendor/scs/linsys/external/amd/amd_global.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_info.c +119 -0
- data/vendor/scs/linsys/external/amd/amd_info.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_internal.h +304 -0
- data/vendor/scs/linsys/external/amd/amd_order.c +199 -0
- data/vendor/scs/linsys/external/amd/amd_order.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_post_tree.c +120 -0
- data/vendor/scs/linsys/external/amd/amd_post_tree.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_postorder.c +206 -0
- data/vendor/scs/linsys/external/amd/amd_postorder.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_preprocess.c +118 -0
- data/vendor/scs/linsys/external/amd/amd_preprocess.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_valid.c +92 -0
- data/vendor/scs/linsys/external/amd/amd_valid.o +0 -0
- data/vendor/scs/linsys/external/amd/changes +11 -0
- data/vendor/scs/linsys/external/qdldl/LICENSE +201 -0
- data/vendor/scs/linsys/external/qdldl/README.md +120 -0
- data/vendor/scs/linsys/external/qdldl/changes +4 -0
- data/vendor/scs/linsys/external/qdldl/qdldl.c +298 -0
- data/vendor/scs/linsys/external/qdldl/qdldl.h +177 -0
- data/vendor/scs/linsys/external/qdldl/qdldl.o +0 -0
- data/vendor/scs/linsys/external/qdldl/qdldl_types.h +21 -0
- data/vendor/scs/linsys/gpu/gpu.c +41 -0
- data/vendor/scs/linsys/gpu/gpu.h +85 -0
- data/vendor/scs/linsys/gpu/indirect/private.c +304 -0
- data/vendor/scs/linsys/gpu/indirect/private.h +36 -0
- data/vendor/scs/scs.mk +181 -0
- data/vendor/scs/src/aa.c +224 -0
- data/vendor/scs/src/aa.o +0 -0
- data/vendor/scs/src/cones.c +802 -0
- data/vendor/scs/src/cones.o +0 -0
- data/vendor/scs/src/ctrlc.c +77 -0
- data/vendor/scs/src/ctrlc.o +0 -0
- data/vendor/scs/src/linalg.c +84 -0
- data/vendor/scs/src/linalg.o +0 -0
- data/vendor/scs/src/normalize.c +93 -0
- data/vendor/scs/src/normalize.o +0 -0
- data/vendor/scs/src/rw.c +167 -0
- data/vendor/scs/src/rw.o +0 -0
- data/vendor/scs/src/scs.c +975 -0
- data/vendor/scs/src/scs.o +0 -0
- data/vendor/scs/src/scs_version.c +5 -0
- data/vendor/scs/src/scs_version.o +0 -0
- data/vendor/scs/src/util.c +196 -0
- data/vendor/scs/src/util.o +0 -0
- data/vendor/scs/test/data/small_random_socp +0 -0
- data/vendor/scs/test/minunit.h +13 -0
- data/vendor/scs/test/problem_utils.h +93 -0
- data/vendor/scs/test/problems/rob_gauss_cov_est.h +85 -0
- data/vendor/scs/test/problems/small_lp.h +50 -0
- data/vendor/scs/test/problems/small_random_socp.h +33 -0
- data/vendor/scs/test/random_socp_prob.c +171 -0
- data/vendor/scs/test/run_from_file.c +69 -0
- data/vendor/scs/test/run_tests +2 -0
- data/vendor/scs/test/run_tests.c +32 -0
- metadata +203 -0
@@ -0,0 +1,220 @@
|
|
1
|
+
SCS
|
2
|
+
====
|
3
|
+
|
4
|
+
[![Build Status](https://travis-ci.org/cvxgrp/scs.svg?branch=master)](https://travis-ci.org/cvxgrp/scs)
|
5
|
+
[![Build status](https://ci.appveyor.com/api/projects/status/4542u6kom5293qpm/branch/master?svg=true)](https://ci.appveyor.com/project/bodono/scs/branch/master)
|
6
|
+
|
7
|
+
SCS (`splitting conic solver`) is a numerical optimization package for solving
|
8
|
+
large-scale convex cone problems, based on our paper [Conic Optimization via
|
9
|
+
Operator Splitting and Homogeneous Self-Dual
|
10
|
+
Embedding](http://www.stanford.edu/~boyd/papers/scs.html). It is written in C
|
11
|
+
and can be used in other C, C++,
|
12
|
+
[Python](https://github.com/bodono/scs-python),
|
13
|
+
[Matlab](https://github.com/bodono/scs-matlab),
|
14
|
+
[R](https://github.com/bodono/scs-r),
|
15
|
+
[Julia](https://github.com/JuliaOpt/SCS.jl), programs via the linked
|
16
|
+
interfaces. It can also be called as a solver from convex optimization
|
17
|
+
toolboxes [CVX](http://cvxr.com/cvx/) (3.0 or later),
|
18
|
+
[CVXPY](https://github.com/cvxgrp/cvxpy),
|
19
|
+
[Convex.jl](https://github.com/JuliaOpt/Convex.jl), and
|
20
|
+
[Yalmip](https://github.com/johanlofberg/YALMIP).
|
21
|
+
|
22
|
+
The current version is `2.1.2`. If you wish to cite SCS, please use the
|
23
|
+
following:
|
24
|
+
```
|
25
|
+
@article{ocpb:16,
|
26
|
+
author = {B. O'Donoghue and E. Chu and N. Parikh and S. Boyd},
|
27
|
+
title = {Conic Optimization via Operator Splitting and Homogeneous Self-Dual Embedding},
|
28
|
+
journal = {Journal of Optimization Theory and Applications},
|
29
|
+
month = {June},
|
30
|
+
year = {2016},
|
31
|
+
volume = {169},
|
32
|
+
number = {3},
|
33
|
+
pages = {1042-1068},
|
34
|
+
url = {http://stanford.edu/~boyd/papers/scs.html},
|
35
|
+
}
|
36
|
+
@misc{scs,
|
37
|
+
author = {B. O'Donoghue and E. Chu and N. Parikh and S. Boyd},
|
38
|
+
title = {{SCS}: Splitting Conic Solver, version 2.1.2},
|
39
|
+
howpublished = {\url{https://github.com/cvxgrp/scs}},
|
40
|
+
month = nov,
|
41
|
+
year = 2019
|
42
|
+
}
|
43
|
+
```
|
44
|
+
|
45
|
+
----
|
46
|
+
SCS numerically solves convex cone programs using the alternating direction
|
47
|
+
method of multipliers
|
48
|
+
([ADMM](http://web.stanford.edu/~boyd/papers/admm_distr_stats.html)). It
|
49
|
+
returns solutions to both the primal and dual problems if the problem is
|
50
|
+
feasible, or a certificate of infeasibility otherwise. It solves the following
|
51
|
+
primal cone problem:
|
52
|
+
|
53
|
+
```
|
54
|
+
minimize c'x
|
55
|
+
subject to Ax + s = b
|
56
|
+
s in K
|
57
|
+
```
|
58
|
+
over variables `x` and `s`, where `A`, `b` and `c` are user-supplied data and
|
59
|
+
`K` is a user-defined convex cone. The dual problem is given by
|
60
|
+
```
|
61
|
+
maximize -b'y
|
62
|
+
subject to -A'y == c
|
63
|
+
y in K^*
|
64
|
+
```
|
65
|
+
over variable `y`, where `K^*` denotes the dual cone to `K`.
|
66
|
+
|
67
|
+
The cone `K` can be any Cartesian product of the following primitive cones:
|
68
|
+
+ zero cone `{x | x = 0 }` (dual to the free cone `{x | x in R}`)
|
69
|
+
+ positive orthant `{x | x >= 0}`
|
70
|
+
+ second-order cone `{(t,x) | ||x||_2 <= t}`
|
71
|
+
+ positive semidefinite cone `{ X | min(eig(X)) >= 0, X = X^T }`
|
72
|
+
+ exponential cone `{(x,y,z) | y e^(x/y) <= z, y>0 }`
|
73
|
+
+ dual exponential cone `{(u,v,w) | −u e^(v/u) <= e w, u<0}`
|
74
|
+
+ power cone `{(x,y,z) | x^a * y^(1-a) >= |z|, x>=0, y>=0}`
|
75
|
+
+ dual power cone `{(u,v,w) | (u/a)^a * (v/(1-a))^(1-a) >= |w|, u>=0, v>=0}`
|
76
|
+
|
77
|
+
The rows of the data matrix `A` correspond to the cones in `K`. **The rows of
|
78
|
+
`A` must be in the order of the cones given above, i.e., first come the rows
|
79
|
+
that correspond to the zero/free cones, then those that correspond to the
|
80
|
+
positive orthants, then SOCs, etc.** For a `k` dimensional semidefinite cone
|
81
|
+
when interpreting the rows of the data matrix `A` SCS assumes that the `k x k`
|
82
|
+
matrix variable has been vectorized by scaling the off-diagonal entries by
|
83
|
+
`sqrt(2)` and stacking the **lower triangular elements column-wise** to create a
|
84
|
+
vector of length `k(k+1)/2`. See the section on semidefinite programming below.
|
85
|
+
|
86
|
+
At termination SCS returns solution `(x*, s*, y*)` if the problem is feasible,
|
87
|
+
or a certificate of infeasibility otherwise. See
|
88
|
+
[here](http://web.stanford.edu/~boyd/cvxbook/) for more details about
|
89
|
+
cone programming and certificates of infeasibility.
|
90
|
+
|
91
|
+
**Anderson Acceleration**
|
92
|
+
|
93
|
+
By default SCS uses Anderson acceleration (AA) to speed up convergence. The
|
94
|
+
number of iterates that SCS uses in the AA calculation can be controlled by the
|
95
|
+
parameter `acceleration_lookback` in the settings struct. It defaults to 10. AA
|
96
|
+
is available as a standalone package [here](https://github.com/cvxgrp/aa). More
|
97
|
+
details are available in our paper on AA
|
98
|
+
[here](https://stanford.edu/~boyd/papers/nonexp_global_aa1.html).
|
99
|
+
|
100
|
+
**Semidefinite Programming**
|
101
|
+
|
102
|
+
SCS assumes that the matrix variables and the input data corresponding to
|
103
|
+
semidefinite cones have been vectorized by **scaling the off-diagonal entries by
|
104
|
+
`sqrt(2)`** and stacking the lower triangular elements **column-wise**. For a `k
|
105
|
+
x k` matrix variable (or data matrix) this operation would create a vector of
|
106
|
+
length `k(k+1)/2`. Scaling by `sqrt(2)` is required to preserve the
|
107
|
+
inner-product.
|
108
|
+
|
109
|
+
**To recover the matrix solution this operation must be inverted on the
|
110
|
+
components of the vector returned by SCS corresponding to semidefinite cones**.
|
111
|
+
That is, the off-diagonal entries must be scaled by `1/sqrt(2)` and the upper
|
112
|
+
triangular entries are filled in by copying the values of lower triangular
|
113
|
+
entries.
|
114
|
+
|
115
|
+
More explicitly, we want to express
|
116
|
+
`Tr(C X)` as `vec(C)'*vec(X)`, where the `vec` operation takes the `k x k` matrix
|
117
|
+
```
|
118
|
+
X = [ X11 X12 ... X1k
|
119
|
+
X21 X22 ... X2k
|
120
|
+
...
|
121
|
+
Xk1 Xk2 ... Xkk ]
|
122
|
+
```
|
123
|
+
and produces a vector consisting of
|
124
|
+
```
|
125
|
+
vec(X) = (X11, sqrt(2)*X21, ..., sqrt(2)*Xk1, X22, sqrt(2)*X32, ..., Xkk).
|
126
|
+
```
|
127
|
+
|
128
|
+
**Linear equation solvers**
|
129
|
+
|
130
|
+
Each iteration of SCS requires the solution of a set of linear equations. This
|
131
|
+
package includes two implementations for solving linear equations: a direct
|
132
|
+
solver which uses a cached LDL factorization and an indirect solver based on
|
133
|
+
conjugate gradients. The indirect solver can be run on either the cpu or
|
134
|
+
gpu.
|
135
|
+
|
136
|
+
The direct solver uses external numerical linear algebra packages:
|
137
|
+
* [QDLDL](https://github.com/oxfordcontrol/qdldl)
|
138
|
+
* [AMD](http://www.cise.ufl.edu/research/sparse/).
|
139
|
+
|
140
|
+
### Using SCS in C
|
141
|
+
Typing `make` at the command line will compile the code and create SCS libraries
|
142
|
+
in the `out` folder. To run the tests execute:
|
143
|
+
```sh
|
144
|
+
make
|
145
|
+
make test
|
146
|
+
test/run_tests
|
147
|
+
```
|
148
|
+
|
149
|
+
If `make` completes successfully, it will produce two static library files,
|
150
|
+
`libscsdir.a`, `libscsindir.a`, and two dynamic library files `libscsdir.ext`,
|
151
|
+
`libscsindir.ext` (where `.ext` extension is platform dependent) in the same
|
152
|
+
folder. It will also produce two demo binaries in the `out` folder named
|
153
|
+
`demo_socp_direct`, and `demo_socp_indirect`. If you have a GPU and have CUDA
|
154
|
+
installed, you can also execture `make gpu` to compile SCS to run on the GPU
|
155
|
+
which will create additional libraries and demo binaries in the `out` folder
|
156
|
+
corresponding to the gpu version. Note that the GPU version requires 32 bit
|
157
|
+
ints, which can be enforced by compiling with `DLONG=0`.
|
158
|
+
|
159
|
+
To use the libraries in your own source code, compile your code with the linker
|
160
|
+
option `-L(PATH_TO_SCS_LIBS)` and `-lscsdir` or `-lscsindir` (as needed). The
|
161
|
+
API and required data structures are defined in the file `include/scs.h`. The
|
162
|
+
four main API functions are:
|
163
|
+
|
164
|
+
* `ScsWork * scs_init(const ScsData * d, const ScsCone * k, ScsInfo * info);`
|
165
|
+
|
166
|
+
This initializes the ScsWork struct containing the workspace that scs will
|
167
|
+
use, and performs the necessary preprocessing (e.g. matrix factorization).
|
168
|
+
All inputs `d`, `k`, and `info` must be memory allocated before calling.
|
169
|
+
|
170
|
+
* `scs_int scs_solve(ScsWork * w, const ScsData * d, const ScsCone * k, ScsSolution * sol, ScsInfo * info);`
|
171
|
+
|
172
|
+
This solves the problem as defined by ScsData `d` and ScsCone `k` using the
|
173
|
+
workspace in `w`. The solution is returned in `sol` and information about
|
174
|
+
the solve is returned in `info` (outputs must have memory allocated before
|
175
|
+
calling). None of the inputs can be NULL. You can call `scs_solve` many
|
176
|
+
times for one call to `scs_init`, so long as the matrix `A` does not change
|
177
|
+
(vectors `b` and `c` can change).
|
178
|
+
|
179
|
+
* `void scs_finish(ScsWork * w);`
|
180
|
+
|
181
|
+
Called after all solves completed to free allocated memory and other
|
182
|
+
cleanup.
|
183
|
+
|
184
|
+
* `scs_int scs(const ScsData * d, const ScsCone * k, ScsSolution * sol, ScsInfo * info);`
|
185
|
+
|
186
|
+
Convenience method that simply calls all the above routines in order, for
|
187
|
+
cases where the workspace does not need to be reused. All inputs must have
|
188
|
+
memory allocated before this call.
|
189
|
+
|
190
|
+
The data matrix `A` is specified in column-compressed format and the vectors `b`
|
191
|
+
and `c` are specified as dense arrays. The solutions `x` (primal), `s` (slack),
|
192
|
+
and `y` (dual) are returned as dense arrays. Cones are specified as the struct
|
193
|
+
defined in `include/scs.h`, the rows of `A` must correspond to the cones in the
|
194
|
+
exact order as specified by the cone struct (i.e. put linear cones before
|
195
|
+
second-order cones etc.).
|
196
|
+
|
197
|
+
**Warm-start**
|
198
|
+
|
199
|
+
You can warm-start SCS (supply a guess of the solution) by setting `warm_start`
|
200
|
+
in the ScsData struct to `1` and supplying the warm-starts in the ScsSolution
|
201
|
+
struct (`x`,`y`, and `s`). All inputs must be warm-started if any one is. These
|
202
|
+
are used to initialize the iterates in `scs_solve`.
|
203
|
+
|
204
|
+
**Re-using matrix factorization**
|
205
|
+
|
206
|
+
If using the direct version you can factorize the matrix once and solve many
|
207
|
+
times. Simply call `scs_init` once, and use `scs_solve` many times with the same
|
208
|
+
workspace, changing the input data `b` and `c` (and optionally warm-starts) for
|
209
|
+
each iteration.
|
210
|
+
|
211
|
+
**Using your own linear system solver**
|
212
|
+
|
213
|
+
To use your own linear system solver simply implement all the methods and the
|
214
|
+
two structs in `include/linsys.h` and plug it in.
|
215
|
+
|
216
|
+
**BLAS / LAPACK install error**
|
217
|
+
|
218
|
+
If you get an error like `cannot find -lblas` or `cannot find -llapack`, then
|
219
|
+
you need to install blas and lapack and / or update your environment variables
|
220
|
+
to point to the install locations.
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#ifndef AA_H_GUARD
|
2
|
+
#define AA_H_GUARD
|
3
|
+
|
4
|
+
#ifdef __cplusplus
|
5
|
+
extern "C" {
|
6
|
+
#endif
|
7
|
+
|
8
|
+
#include <stdio.h>
|
9
|
+
#include <stdlib.h>
|
10
|
+
#include <string.h>
|
11
|
+
#include "glbopts.h"
|
12
|
+
|
13
|
+
typedef scs_float aa_float;
|
14
|
+
typedef scs_int aa_int;
|
15
|
+
|
16
|
+
typedef struct ACCEL_WORK AaWork;
|
17
|
+
|
18
|
+
/* Initialize Anderson Acceleration, allocates memory.
|
19
|
+
*
|
20
|
+
* Args:
|
21
|
+
* dim: the dimension of the variable for aa
|
22
|
+
* aa_mem: the memory (number of past iterations used) for aa
|
23
|
+
* type1: bool, if True use type 1 aa, otherwise use type 2
|
24
|
+
*
|
25
|
+
* Reurns:
|
26
|
+
* Pointer to aa workspace
|
27
|
+
*/
|
28
|
+
AaWork *aa_init(aa_int dim, aa_int aa_mem, aa_int type1);
|
29
|
+
|
30
|
+
/* Apply Anderson Acceleration.
|
31
|
+
*
|
32
|
+
* Args:
|
33
|
+
* f: output of map at current iteration, overwritten with aa output at end.
|
34
|
+
* x: input to map at current iteration
|
35
|
+
* a: aa workspace from aa_init
|
36
|
+
*
|
37
|
+
* Returns:
|
38
|
+
* int, a value of 0 is success, <0 is failure at which point f is unchanged
|
39
|
+
*/
|
40
|
+
aa_int aa_apply(aa_float *f, const aa_float *x, AaWork *a);
|
41
|
+
|
42
|
+
/* Finish Anderson Acceleration, clears memory.
|
43
|
+
*
|
44
|
+
* Args:
|
45
|
+
* a: aa workspace from aa_init.
|
46
|
+
*/
|
47
|
+
void aa_finish(AaWork *a);
|
48
|
+
|
49
|
+
#define MAX_AA_NRM (1e4)
|
50
|
+
|
51
|
+
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
52
|
+
|
53
|
+
#ifdef __cplusplus
|
54
|
+
}
|
55
|
+
#endif
|
56
|
+
#endif
|
@@ -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
|