scs 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +11 -6
- data/lib/scs/ffi.rb +30 -13
- 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 +7 -8
- data/vendor/scs/Makefile +24 -15
- data/vendor/scs/README.md +5 -263
- data/vendor/scs/include/aa.h +67 -23
- data/vendor/scs/include/cones.h +17 -17
- data/vendor/scs/include/glbopts.h +98 -32
- data/vendor/scs/include/linalg.h +2 -4
- data/vendor/scs/include/linsys.h +58 -44
- data/vendor/scs/include/normalize.h +3 -3
- data/vendor/scs/include/rw.h +8 -2
- data/vendor/scs/include/scs.h +293 -133
- data/vendor/scs/include/util.h +3 -15
- data/vendor/scs/linsys/cpu/direct/private.c +220 -224
- data/vendor/scs/linsys/cpu/direct/private.h +13 -7
- data/vendor/scs/linsys/cpu/direct/private.o +0 -0
- data/vendor/scs/linsys/cpu/indirect/private.c +177 -110
- data/vendor/scs/linsys/cpu/indirect/private.h +8 -4
- data/vendor/scs/linsys/cpu/indirect/private.o +0 -0
- data/vendor/scs/linsys/csparse.c +87 -0
- data/vendor/scs/linsys/csparse.h +34 -0
- data/vendor/scs/linsys/csparse.o +0 -0
- data/vendor/scs/linsys/external/amd/SuiteSparse_config.c +1 -1
- 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_internal.h +1 -1
- 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/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.o +0 -0
- data/vendor/scs/linsys/external/qdldl/qdldl_types.h +11 -3
- data/vendor/scs/linsys/gpu/gpu.c +31 -33
- data/vendor/scs/linsys/gpu/gpu.h +48 -31
- data/vendor/scs/linsys/gpu/indirect/private.c +338 -232
- data/vendor/scs/linsys/gpu/indirect/private.h +23 -14
- data/vendor/scs/linsys/scs_matrix.c +498 -0
- data/vendor/scs/linsys/scs_matrix.h +70 -0
- data/vendor/scs/linsys/scs_matrix.o +0 -0
- data/vendor/scs/scs.mk +13 -9
- data/vendor/scs/src/aa.c +384 -109
- data/vendor/scs/src/aa.o +0 -0
- data/vendor/scs/src/cones.c +440 -353
- data/vendor/scs/src/cones.o +0 -0
- data/vendor/scs/src/ctrlc.c +15 -5
- data/vendor/scs/src/ctrlc.o +0 -0
- data/vendor/scs/src/linalg.c +84 -28
- data/vendor/scs/src/linalg.o +0 -0
- data/vendor/scs/src/normalize.c +22 -64
- data/vendor/scs/src/normalize.o +0 -0
- data/vendor/scs/src/rw.c +160 -21
- data/vendor/scs/src/rw.o +0 -0
- data/vendor/scs/src/scs.c +767 -563
- data/vendor/scs/src/scs.o +0 -0
- data/vendor/scs/src/scs_indir.o +0 -0
- data/vendor/scs/src/scs_version.c +9 -3
- data/vendor/scs/src/scs_version.o +0 -0
- data/vendor/scs/src/util.c +37 -106
- data/vendor/scs/src/util.o +0 -0
- data/vendor/scs/test/minunit.h +17 -8
- data/vendor/scs/test/problem_utils.h +176 -14
- 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 +13 -14
- data/vendor/scs/test/problems/test_fails.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 +19 -10
- data/vendor/scs/test/run_tests.c +27 -3
- metadata +20 -8
- 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/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
data/vendor/scs/include/linsys.h
CHANGED
@@ -7,55 +7,69 @@ extern "C" {
|
|
7
7
|
|
8
8
|
#include "scs.h"
|
9
9
|
|
10
|
-
/*
|
11
|
-
* STRUCT */
|
10
|
+
/* This is the API that any new linear system solver must implement */
|
12
11
|
|
13
|
-
/*
|
14
|
-
|
15
|
-
|
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);
|
12
|
+
/* Struct containing linear system workspace. Implemented by linear solver. */
|
13
|
+
/* This typedef is in scs.h */
|
14
|
+
/* typedef struct SCS_LIN_SYS_WORK ScsLinSysWork; */
|
23
15
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
16
|
+
/**
|
17
|
+
* Initialize `ScsLinSysWork` structure and perform any necessary preprocessing.
|
18
|
+
*
|
19
|
+
* @param A A data matrix.
|
20
|
+
* @param P P data matrix.
|
21
|
+
* @param rho_y_vec `rho_y > 0` diagonal entries.
|
22
|
+
* @param rho_x `rho_x > 0` float.
|
23
|
+
* @return Linear system solver workspace.
|
24
|
+
*
|
25
|
+
*/
|
26
|
+
ScsLinSysWork *SCS(init_lin_sys_work)(const ScsMatrix *A, const ScsMatrix *P,
|
27
|
+
scs_float *rho_y_vec, scs_float rho_x);
|
30
28
|
|
31
|
-
|
32
|
-
|
29
|
+
/**
|
30
|
+
* Frees `ScsLinSysWork` structure and associated allocated memory.
|
31
|
+
*
|
32
|
+
* @param w Linear system private workspace.
|
33
|
+
*/
|
34
|
+
void SCS(free_lin_sys_work)(ScsLinSysWork *w);
|
33
35
|
|
34
|
-
|
35
|
-
*
|
36
|
-
|
37
|
-
|
38
|
-
*
|
39
|
-
|
36
|
+
/**
|
37
|
+
* Solves the linear system required by SCS at each iteration:
|
38
|
+
* \f[
|
39
|
+
* \begin{bmatrix}
|
40
|
+
* (\rho_x I + P) & A^\top \\
|
41
|
+
* A & -\mathrm{diag}(\rho_y) \\
|
42
|
+
* \end{bmatrix} x = b
|
43
|
+
* \f]
|
44
|
+
*
|
45
|
+
* for `x`. Overwrites `b` with result.
|
46
|
+
*
|
47
|
+
* @param w Linear system private workspace.
|
48
|
+
* @param b Right hand side, contains solution at the end.
|
49
|
+
* @param s Contains warm-start (may be NULL).
|
50
|
+
* @param tol Tolerance required for the system solve.
|
51
|
+
* @return status < 0 indicates failure.
|
52
|
+
*
|
53
|
+
*/
|
54
|
+
scs_int SCS(solve_lin_sys)(ScsLinSysWork *w, scs_float *b, const scs_float *s,
|
55
|
+
scs_float tol);
|
56
|
+
/**
|
57
|
+
* Update the linsys workspace when `rho_y_vec` is changed. For example, a
|
58
|
+
* direct method for solving the linear system might need to update the
|
59
|
+
* factorization of the matrix.
|
60
|
+
*
|
61
|
+
* @param w Linear system private workspace.
|
62
|
+
* @param rho_y_vec `rho_y` diagonal entries.
|
63
|
+
*
|
64
|
+
*/
|
65
|
+
void SCS(update_lin_sys_rho_y_vec)(ScsLinSysWork *w, scs_float *rho_y_vec);
|
40
66
|
|
41
|
-
|
42
|
-
|
43
|
-
*
|
44
|
-
*
|
45
|
-
|
46
|
-
*
|
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);
|
67
|
+
/**
|
68
|
+
* Name of the linear solver.
|
69
|
+
*
|
70
|
+
* @return name of method.
|
71
|
+
*/
|
72
|
+
const char *SCS(get_lin_sys_method)(void);
|
59
73
|
|
60
74
|
#ifdef __cplusplus
|
61
75
|
}
|
@@ -7,10 +7,10 @@ extern "C" {
|
|
7
7
|
|
8
8
|
#include "scs.h"
|
9
9
|
|
10
|
-
void SCS(
|
11
|
-
void SCS(calc_scaled_resids)(ScsWork *w, ScsResiduals *r);
|
12
|
-
void SCS(normalize_warm_start)(ScsWork *w);
|
10
|
+
void SCS(normalize_sol)(ScsWork *w, ScsSolution *sol);
|
13
11
|
void SCS(un_normalize_sol)(ScsWork *w, ScsSolution *sol);
|
12
|
+
void SCS(un_normalize_primal)(ScsWork *w, scs_float *r);
|
13
|
+
void SCS(un_normalize_dual)(ScsWork *w, scs_float *r);
|
14
14
|
|
15
15
|
#ifdef __cplusplus
|
16
16
|
}
|
data/vendor/scs/include/rw.h
CHANGED
@@ -7,9 +7,15 @@ extern "C" {
|
|
7
7
|
|
8
8
|
#include "glbopts.h"
|
9
9
|
#include "scs.h"
|
10
|
+
#include "util.h"
|
10
11
|
|
11
|
-
void SCS(write_data)(const ScsData *d, const ScsCone *k
|
12
|
-
|
12
|
+
void SCS(write_data)(const ScsData *d, const ScsCone *k,
|
13
|
+
const ScsSettings *stgs);
|
14
|
+
scs_int SCS(read_data)(const char *filename, ScsData **d, ScsCone **k,
|
15
|
+
ScsSettings **stgs);
|
16
|
+
void SCS(log_data_to_csv)(const ScsData *d, const ScsCone *k,
|
17
|
+
const ScsSettings *stgs, const ScsWork *w,
|
18
|
+
scs_int iter, SCS(timer) * solve_timer);
|
13
19
|
|
14
20
|
#ifdef __cplusplus
|
15
21
|
}
|
data/vendor/scs/include/scs.h
CHANGED
@@ -6,155 +6,315 @@ extern "C" {
|
|
6
6
|
#endif
|
7
7
|
|
8
8
|
#include <string.h>
|
9
|
-
#include "glbopts.h"
|
10
|
-
#include "aa.h"
|
11
9
|
|
12
|
-
|
13
|
-
|
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;
|
10
|
+
#include "aa.h"
|
11
|
+
#include "glbopts.h"
|
19
12
|
|
20
|
-
|
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;
|
13
|
+
/** Struct containing acceleration workspace. Implemented by acceleration. */
|
28
14
|
typedef struct SCS_ACCEL_WORK ScsAccelWork;
|
15
|
+
/** Struct containing cone projection workspace. Implemented by cones. */
|
29
16
|
typedef struct SCS_CONE_WORK ScsConeWork;
|
17
|
+
/** Struct containing linear system workspace. Implemented by linear solver. */
|
18
|
+
typedef struct SCS_LIN_SYS_WORK ScsLinSysWork;
|
30
19
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
scs_float
|
57
|
-
|
58
|
-
scs_int
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
scs_int
|
71
|
-
|
72
|
-
scs_int
|
73
|
-
|
74
|
-
scs_int
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
scs_int
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
scs_float
|
97
|
-
|
98
|
-
scs_float
|
99
|
-
|
100
|
-
|
20
|
+
/** This defines the data matrices which should be supplied in column compressed
|
21
|
+
* format with zero based indexing.
|
22
|
+
*/
|
23
|
+
typedef struct {
|
24
|
+
/** Matrix values, size: number of non-zeros. */
|
25
|
+
scs_float *x;
|
26
|
+
/** Matrix row indices, size: number of non-zeros. */
|
27
|
+
scs_int *i;
|
28
|
+
/** Matrix column pointers, size: `n+1`. */
|
29
|
+
scs_int *p;
|
30
|
+
/** Number of rows. */
|
31
|
+
scs_int m;
|
32
|
+
/** Number of columns. */
|
33
|
+
scs_int n;
|
34
|
+
} ScsMatrix;
|
35
|
+
|
36
|
+
/** Struct containing all settings. */
|
37
|
+
typedef struct {
|
38
|
+
/** Whether to heuristically rescale the data before solve. */
|
39
|
+
scs_int normalize;
|
40
|
+
/** Initial dual scaling factor (may be updated if adaptive_scale is on). */
|
41
|
+
scs_float scale;
|
42
|
+
/** Whether to adaptively update `scale`. */
|
43
|
+
scs_int adaptive_scale;
|
44
|
+
/** Primal constraint scaling factor. */
|
45
|
+
scs_float rho_x;
|
46
|
+
/** Maximum iterations to take. */
|
47
|
+
scs_int max_iters;
|
48
|
+
/** Absolute convergence tolerance. */
|
49
|
+
scs_float eps_abs;
|
50
|
+
/** Relative convergence tolerance. */
|
51
|
+
scs_float eps_rel;
|
52
|
+
/** Infeasible convergence tolerance. */
|
53
|
+
scs_float eps_infeas;
|
54
|
+
/** Douglas-Rachford relaxation parameter. */
|
55
|
+
scs_float alpha;
|
56
|
+
/** Time limit in secs (can be fractional). */
|
57
|
+
scs_float time_limit_secs;
|
58
|
+
/** Whether to log progress to stdout. */
|
59
|
+
scs_int verbose;
|
60
|
+
/** Whether to use warm start (put initial guess in ScsSolution struct). */
|
61
|
+
scs_int warm_start;
|
62
|
+
/** Memory for acceleration. */
|
63
|
+
scs_int acceleration_lookback;
|
64
|
+
/** Interval to apply acceleration. */
|
65
|
+
scs_int acceleration_interval;
|
66
|
+
/** String, if set will dump raw prob data to this file. */
|
67
|
+
const char *write_data_filename;
|
68
|
+
/** String, if set will log data to this csv file (makes SCS very slow). */
|
69
|
+
const char *log_csv_filename;
|
70
|
+
} ScsSettings;
|
71
|
+
|
72
|
+
/** Struct containing problem data. */
|
73
|
+
typedef struct {
|
74
|
+
/** A has `m` rows. */
|
75
|
+
scs_int m;
|
76
|
+
/** A has `n` cols, P has `n` cols and `n` rows. */
|
77
|
+
scs_int n;
|
78
|
+
/** A is supplied in CSC format (size `m` x `n`). */
|
79
|
+
ScsMatrix *A;
|
80
|
+
/** P is supplied in CSC format (size `n` x `n`), must be symmetric positive
|
81
|
+
* semidefinite. Only pass in the upper triangular entries. If `P = 0` then
|
82
|
+
* set `P = SCS_NULL`. */
|
83
|
+
ScsMatrix *P;
|
84
|
+
/** Dense array for b (size `m`). */
|
85
|
+
scs_float *b;
|
86
|
+
/** Dense array for c (size `n`). */
|
87
|
+
scs_float *c;
|
88
|
+
} ScsData;
|
89
|
+
|
90
|
+
/** Cone data. Rows of data matrix `A` must be specified in this exact order. */
|
91
|
+
typedef struct {
|
92
|
+
/** Number of linear equality constraints (primal zero, dual free). */
|
93
|
+
scs_int z;
|
94
|
+
/** Number of positive orthant cones. */
|
95
|
+
scs_int l;
|
96
|
+
/** Upper box values, `len(bu) = len(bl) = max(bsize-1, 0)`. */
|
97
|
+
scs_float *bu;
|
98
|
+
/** Lower box values, `len(bu) = len(bl) = max(bsize-1, 0)`. */
|
99
|
+
scs_float *bl;
|
100
|
+
/** Total length of box cone (includes scale `t`). */
|
101
|
+
scs_int bsize;
|
102
|
+
/** Array of second-order cone constraints. */
|
103
|
+
scs_int *q;
|
104
|
+
/** Length of second-order cone array `q`. */
|
105
|
+
scs_int qsize;
|
106
|
+
/** Array of semidefinite cone constraints. */
|
107
|
+
scs_int *s;
|
108
|
+
/** Length of semidefinite constraints array `s`. */
|
109
|
+
scs_int ssize;
|
110
|
+
/** Number of primal exponential cone triples. */
|
111
|
+
scs_int ep;
|
112
|
+
/** Number of dual exponential cone triples. */
|
113
|
+
scs_int ed;
|
114
|
+
/** Array of power cone params, must be in `[-1, 1]`, negative values are
|
115
|
+
* interpreted as specifying the dual cone. */
|
116
|
+
scs_float *p;
|
117
|
+
/** Number of (primal and dual) power cone triples. */
|
118
|
+
scs_int psize;
|
119
|
+
} ScsCone;
|
120
|
+
|
121
|
+
/** Contains primal-dual solution arrays or a certificate of infeasibility.
|
122
|
+
* Check the exit flag to determine whether this contains a solution or a
|
123
|
+
* certificate. */
|
124
|
+
typedef struct {
|
125
|
+
/** Primal variable. */
|
126
|
+
scs_float *x;
|
127
|
+
/** Dual variable. */
|
128
|
+
scs_float *y;
|
129
|
+
/** Slack variable. */
|
130
|
+
scs_float *s;
|
131
|
+
} ScsSolution;
|
101
132
|
|
102
|
-
|
103
|
-
struct
|
133
|
+
/** Contains information about the solve run at termination. */
|
134
|
+
typedef struct {
|
135
|
+
/** Number of iterations taken. */
|
136
|
+
scs_int iter;
|
137
|
+
/** Status string, e.g. 'solved'. */
|
138
|
+
char status[128];
|
139
|
+
/** Status as scs_int, defined in glbopts.h. */
|
140
|
+
scs_int status_val;
|
141
|
+
/** Number of updates to scale. */
|
142
|
+
scs_int scale_updates;
|
143
|
+
/** Primal objective. */
|
144
|
+
scs_float pobj;
|
145
|
+
/** Dual objective. */
|
146
|
+
scs_float dobj;
|
147
|
+
/** Primal equality residual. */
|
148
|
+
scs_float res_pri;
|
149
|
+
/** Dual equality residual. */
|
150
|
+
scs_float res_dual;
|
151
|
+
/** Duality gap. */
|
152
|
+
scs_float gap;
|
153
|
+
/** Infeasibility cert residual. */
|
154
|
+
scs_float res_infeas;
|
155
|
+
/** Unbounded cert residual. */
|
156
|
+
scs_float res_unbdd_a;
|
157
|
+
/** Unbounded cert residual. */
|
158
|
+
scs_float res_unbdd_p;
|
159
|
+
/** Time taken for setup phase (milliseconds). */
|
160
|
+
scs_float setup_time;
|
161
|
+
/** Time taken for solve phase (milliseconds). */
|
162
|
+
scs_float solve_time;
|
163
|
+
/** Final scale parameter. */
|
164
|
+
scs_float scale;
|
165
|
+
/** Complementary slackness. */
|
166
|
+
scs_float comp_slack;
|
167
|
+
/** Number of rejected AA steps. */
|
168
|
+
scs_int rejected_accel_steps;
|
169
|
+
/** Number of accepted AA steps. */
|
170
|
+
scs_int accepted_accel_steps;
|
171
|
+
/** Total time (milliseconds) spent in the linear system solver. */
|
172
|
+
scs_float lin_sys_time;
|
173
|
+
/** Total time (milliseconds) spent in the cone projection. */
|
174
|
+
scs_float cone_time;
|
175
|
+
/** Total time (milliseconds) spent in the acceleration routine. */
|
176
|
+
scs_float accel_time;
|
177
|
+
} ScsInfo;
|
178
|
+
|
179
|
+
/* the following structs are not exposed to user */
|
180
|
+
|
181
|
+
/** Contains normalization variables. */
|
182
|
+
typedef struct {
|
104
183
|
scs_float *D, *E; /* for normalization */
|
105
|
-
scs_float
|
106
|
-
};
|
184
|
+
scs_float primal_scale, dual_scale;
|
185
|
+
} ScsScaling;
|
186
|
+
|
187
|
+
/** Holds residual information. */
|
188
|
+
typedef struct {
|
189
|
+
scs_int last_iter;
|
190
|
+
scs_float xt_p_x; /* x' P x */
|
191
|
+
scs_float xt_p_x_tau; /* x'Px * tau^2 *not* divided out */
|
192
|
+
scs_float ctx;
|
193
|
+
scs_float ctx_tau; /* tau *not* divided out */
|
194
|
+
scs_float bty;
|
195
|
+
scs_float bty_tau; /* tau *not* divided out */
|
196
|
+
scs_float pobj; /* primal objective */
|
197
|
+
scs_float dobj; /* dual objective */
|
198
|
+
scs_float gap; /* pobj - dobj */
|
199
|
+
scs_float tau;
|
200
|
+
scs_float kap;
|
201
|
+
scs_float res_pri;
|
202
|
+
scs_float res_dual;
|
203
|
+
scs_float res_infeas;
|
204
|
+
scs_float res_unbdd_p;
|
205
|
+
scs_float res_unbdd_a;
|
206
|
+
/* tau NOT divided out */
|
207
|
+
scs_float *ax, *ax_s, *px, *aty, *ax_s_btau, *px_aty_ctau;
|
208
|
+
} ScsResiduals;
|
209
|
+
|
210
|
+
/** Workspace for SCS */
|
211
|
+
typedef struct {
|
212
|
+
/* x_prev = x from previous iteration */
|
213
|
+
scs_int time_limit_reached; /* set if the time-limit is reached */
|
214
|
+
scs_float *u, *u_t;
|
215
|
+
scs_float *v, *v_prev;
|
216
|
+
scs_float *rsk; /* rsk [ r; s; kappa ] */
|
217
|
+
scs_float *h; /* h = [c; b] */
|
218
|
+
scs_float *g; /* g = (I + M)^{-1} h */
|
219
|
+
scs_float *lin_sys_warm_start; /* linear system warm-start (indirect only) */
|
220
|
+
scs_float *rho_y_vec; /* vector of rho y parameters (affects cone project) */
|
221
|
+
AaWork *accel; /* struct for acceleration workspace */
|
222
|
+
scs_float *b_orig, *c_orig; /* original b and c vectors */
|
223
|
+
scs_float *b_normalized, *c_normalized; /* normalized b and c vectors */
|
224
|
+
scs_int m, n; /* A has m rows, n cols */
|
225
|
+
ScsMatrix *A; /* (possibly normalized) A matrix */
|
226
|
+
ScsMatrix *P; /* (possibly normalized) P matrix */
|
227
|
+
ScsLinSysWork *p; /* struct populated by linear system solver */
|
228
|
+
ScsScaling *scal; /* contains the re-scaling data */
|
229
|
+
ScsConeWork *cone_work; /* workspace for the cone projection step */
|
230
|
+
scs_int *cone_boundaries; /* array with boundaries of cones */
|
231
|
+
scs_int cone_boundaries_len; /* total length of cones */
|
232
|
+
/* normalized and unnormalized residuals */
|
233
|
+
ScsResiduals *r_orig, *r_normalized;
|
234
|
+
/* track x,y,s as alg progresses, tau *not* divided out */
|
235
|
+
ScsSolution *xys_orig, *xys_normalized;
|
236
|
+
/* updating scale params workspace */
|
237
|
+
scs_float sum_log_scale_factor;
|
238
|
+
scs_int last_scale_update_iter, n_log_scale_factor, scale_updates;
|
239
|
+
/* aa norm stat */
|
240
|
+
scs_float aa_norm;
|
241
|
+
scs_int rejected_accel_steps, accepted_accel_steps;
|
242
|
+
scs_float setup_time; /* time taken for setup phase (milliseconds) */
|
243
|
+
scs_float scale; /* current scale parameter */
|
244
|
+
const ScsData *d;
|
245
|
+
const ScsCone *k;
|
246
|
+
const ScsSettings *stgs; /* contains solver settings specified by user */
|
247
|
+
} ScsWork;
|
107
248
|
|
108
249
|
/*
|
109
|
-
* main library
|
110
|
-
|
111
|
-
|
112
|
-
|
250
|
+
* main library API
|
251
|
+
*/
|
252
|
+
|
253
|
+
/**
|
254
|
+
* Initialize SCS and allocate memory.
|
255
|
+
*
|
256
|
+
* All the inputs must be already allocated in memory before calling.
|
257
|
+
*
|
258
|
+
* It performs:
|
259
|
+
* - data and settings validation
|
260
|
+
* - problem data scaling
|
261
|
+
* - automatic parameters tuning (if enabled)
|
262
|
+
* - setup linear system solver:
|
263
|
+
* - direct solver: KKT matrix factorization is performed here
|
264
|
+
* - indirect solver: KKT matrix preconditioning is performed here
|
265
|
+
* - solve the linear system for the `r` vector in the paper.
|
266
|
+
*
|
267
|
+
*
|
268
|
+
* @param d Problem data.
|
269
|
+
* @param k Cone data.
|
270
|
+
* @param stgs SCS solver settings.
|
271
|
+
* @return Solver work struct.
|
272
|
+
*/
|
273
|
+
ScsWork *SCS(init)(const ScsData *d, const ScsCone *k, const ScsSettings *stgs);
|
274
|
+
|
275
|
+
/**
|
276
|
+
* Solve quadratic cone program initialized by SCS(init).
|
277
|
+
*
|
278
|
+
* @param w Workspace allocated by init.
|
279
|
+
* @param sol Solver solution struct, will contain solution at termination.
|
280
|
+
* @param info Solver info reporting.
|
281
|
+
* @return Flag containing problem status (see \a glbopts.h).
|
282
|
+
*/
|
283
|
+
scs_int SCS(solve)(ScsWork *w, ScsSolution *sol, ScsInfo *info);
|
284
|
+
|
285
|
+
/**
|
286
|
+
* Clean up allocated SCS workspace.
|
287
|
+
*
|
288
|
+
* @param w Workspace allocated by init, will be deallocated.
|
113
289
|
*/
|
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
290
|
void SCS(finish)(ScsWork *w);
|
118
|
-
|
119
|
-
|
120
|
-
|
291
|
+
|
292
|
+
/**
|
293
|
+
* Solve quadratic cone program defined by data in d and cone k.
|
294
|
+
*
|
295
|
+
* All the inputs must already be allocated in memory before calling.
|
296
|
+
*
|
297
|
+
* @param d Problem data.
|
298
|
+
* @param k Cone data.
|
299
|
+
* @param stgs SCS solver settings.
|
300
|
+
* @param sol Solution will be stored here.
|
301
|
+
* @param info Information about the solve will be stored here.
|
302
|
+
* @return Flag that determines solve type (see \a glbopts.h).
|
303
|
+
*/
|
304
|
+
scs_int scs(const ScsData *d, const ScsCone *k, const ScsSettings *stgs,
|
305
|
+
ScsSolution *sol, ScsInfo *info);
|
306
|
+
|
307
|
+
/**
|
308
|
+
* Helper function to set all settings to default values (see \a glbopts.h).
|
309
|
+
*
|
310
|
+
* @param stgs Settings struct that will be populated.
|
311
|
+
*/
|
312
|
+
void SCS(set_default_settings)(ScsSettings *stgs);
|
121
313
|
|
122
314
|
const char *SCS(version)(void);
|
123
315
|
size_t SCS(sizeof_int)(void);
|
124
316
|
size_t SCS(sizeof_float)(void);
|
125
317
|
|
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
318
|
#ifdef __cplusplus
|
159
319
|
}
|
160
320
|
#endif
|
data/vendor/scs/include/util.h
CHANGED
@@ -5,10 +5,10 @@
|
|
5
5
|
extern "C" {
|
6
6
|
#endif
|
7
7
|
|
8
|
-
#include <stdio.h>
|
9
|
-
#include <stdlib.h>
|
10
8
|
#include "cones.h"
|
11
9
|
#include "scs.h"
|
10
|
+
#include <stdio.h>
|
11
|
+
#include <stdlib.h>
|
12
12
|
|
13
13
|
/* timing code courtesy of A. Domahidi */
|
14
14
|
#if (defined NOTIMER)
|
@@ -41,23 +41,11 @@ typedef struct SCS(timer) {
|
|
41
41
|
|
42
42
|
#endif
|
43
43
|
|
44
|
-
#if EXTRA_VERBOSE > 1
|
45
|
-
extern SCS(timer) global_timer;
|
46
|
-
#endif
|
47
|
-
|
48
44
|
/* these all return milli-seconds */
|
49
45
|
void SCS(tic)(SCS(timer) * t);
|
50
|
-
scs_float SCS(toc)(SCS(timer) * t);
|
51
|
-
scs_float SCS(str_toc)(char *str, SCS(timer) * t);
|
52
46
|
scs_float SCS(tocq)(SCS(timer) * t);
|
53
|
-
|
54
|
-
void SCS(print_cone_data)(const ScsCone *k);
|
55
|
-
void SCS(print_data)(const ScsData *d);
|
56
|
-
void SCS(print_work)(const ScsWork *w);
|
57
|
-
void SCS(print_array)(const scs_float *arr, scs_int n, const char *name);
|
58
|
-
void SCS(set_default_settings)(ScsData *d);
|
59
47
|
void SCS(free_sol)(ScsSolution *sol);
|
60
|
-
void SCS(free_data)(ScsData *d, ScsCone *k);
|
48
|
+
void SCS(free_data)(ScsData *d, ScsCone *k, ScsSettings *stgs);
|
61
49
|
|
62
50
|
#ifdef __cplusplus
|
63
51
|
}
|