scs 0.3.2 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +35 -6
  5. data/lib/scs/matrix.rb +72 -0
  6. data/lib/scs/solver.rb +19 -26
  7. data/lib/scs/version.rb +1 -1
  8. data/lib/scs.rb +1 -0
  9. data/vendor/scs/CITATION.cff +2 -2
  10. data/vendor/scs/CMakeLists.txt +285 -169
  11. data/vendor/scs/Makefile +43 -18
  12. data/vendor/scs/README.md +3 -1
  13. data/vendor/scs/include/cones.h +5 -3
  14. data/vendor/scs/include/glbopts.h +35 -17
  15. data/vendor/scs/include/linsys.h +8 -8
  16. data/vendor/scs/include/normalize.h +1 -0
  17. data/vendor/scs/include/rw.h +3 -3
  18. data/vendor/scs/include/scs.h +51 -24
  19. data/vendor/scs/include/scs_types.h +3 -1
  20. data/vendor/scs/include/scs_work.h +13 -15
  21. data/vendor/scs/include/util.h +4 -2
  22. data/vendor/scs/linsys/cpu/direct/private.c +32 -153
  23. data/vendor/scs/linsys/cpu/direct/private.h +6 -6
  24. data/vendor/scs/linsys/cpu/indirect/private.c +9 -22
  25. data/vendor/scs/linsys/cpu/indirect/private.h +4 -2
  26. data/vendor/scs/linsys/csparse.c +140 -12
  27. data/vendor/scs/linsys/csparse.h +10 -17
  28. data/vendor/scs/linsys/external/amd/LICENSE.txt +0 -897
  29. data/vendor/scs/linsys/external/amd/SuiteSparse_config.c +4 -2
  30. data/vendor/scs/linsys/external/amd/SuiteSparse_config.h +0 -5
  31. data/vendor/scs/linsys/gpu/gpu.c +4 -4
  32. data/vendor/scs/linsys/gpu/gpu.h +1 -1
  33. data/vendor/scs/linsys/gpu/indirect/private.c +15 -26
  34. data/vendor/scs/linsys/mkl/direct/private.c +182 -0
  35. data/vendor/scs/linsys/mkl/direct/private.h +38 -0
  36. data/vendor/scs/linsys/scs_matrix.c +49 -72
  37. data/vendor/scs/linsys/scs_matrix.h +4 -3
  38. data/vendor/scs/scs.mk +39 -30
  39. data/vendor/scs/src/aa.c +0 -4
  40. data/vendor/scs/src/cones.c +78 -184
  41. data/vendor/scs/src/exp_cone.c +399 -0
  42. data/vendor/scs/src/normalize.c +51 -0
  43. data/vendor/scs/src/rw.c +139 -76
  44. data/vendor/scs/src/scs.c +275 -202
  45. data/vendor/scs/src/util.c +36 -13
  46. data/vendor/scs/test/minunit.h +2 -1
  47. data/vendor/scs/test/problem_utils.h +5 -4
  48. data/vendor/scs/test/problems/degenerate.h +1 -0
  49. data/vendor/scs/test/problems/hs21_tiny_qp.h +2 -1
  50. data/vendor/scs/test/problems/hs21_tiny_qp_rw.h +13 -4
  51. data/vendor/scs/test/problems/infeasible_tiny_qp.h +1 -0
  52. data/vendor/scs/test/problems/max_ent +0 -0
  53. data/vendor/scs/test/problems/max_ent.h +8 -0
  54. data/vendor/scs/test/problems/qafiro_tiny_qp.h +2 -1
  55. data/vendor/scs/test/problems/random_prob.h +2 -39
  56. data/vendor/scs/test/problems/rob_gauss_cov_est.h +15 -3
  57. data/vendor/scs/test/problems/small_lp.h +4 -1
  58. data/vendor/scs/test/problems/small_qp.h +42 -7
  59. data/vendor/scs/test/problems/test_exp_cone.h +84 -0
  60. data/vendor/scs/test/problems/test_prob_from_data_file.h +57 -0
  61. data/vendor/scs/test/problems/test_validation.h +4 -1
  62. data/vendor/scs/test/problems/unbounded_tiny_qp.h +3 -3
  63. data/vendor/scs/test/random_socp_prob.c +3 -1
  64. data/vendor/scs/test/run_from_file.c +22 -4
  65. data/vendor/scs/test/run_tests.c +22 -9
  66. metadata +12 -4
data/vendor/scs/Makefile CHANGED
@@ -1,7 +1,7 @@
1
1
  # MAKEFILE for scs
2
2
  include scs.mk
3
3
 
4
- SCS_OBJECTS = src/util.o src/cones.o src/aa.o src/rw.o src/linalg.o src/ctrlc.o src/scs_version.o src/normalize.o
4
+ SCS_OBJECTS = src/util.o src/cones.o src/exp_cone.o src/aa.o src/rw.o src/linalg.o src/ctrlc.o src/scs_version.o src/normalize.o
5
5
  SCS_O = src/scs.o
6
6
  SCS_INDIR_O = src/scs_indir.o
7
7
 
@@ -19,7 +19,7 @@ TARGETS = $(OUT)/demo_socp_indirect $(OUT)/demo_socp_direct $(OUT)/run_from_file
19
19
  default: $(TARGETS) $(OUT)/libscsdir.a $(OUT)/libscsindir.a $(OUT)/libscsdir.$(SHARED) $(OUT)/libscsindir.$(SHARED)
20
20
  @echo "****************************************************************************************"
21
21
  @echo "Successfully compiled scs, copyright Brendan O'Donoghue 2012."
22
- @echo "To test, type '$(OUT)/demo_socp_direct' to solve a random SOCP."
22
+ @echo "To test, run 'make test' and then '$(OUT)/run_tests_direct'."
23
23
  @echo "**********************************************************************************"
24
24
  ifneq ($(USE_LAPACK), 0)
25
25
  @echo "Compiled with blas and lapack, can solve LPs, SOCPs, SDPs, ECPs, and PCPs"
@@ -41,6 +41,7 @@ $(SCS_INDIR_O): src/scs.c $(INC_FILES)
41
41
 
42
42
  src/util.o : src/util.c $(INC_FILES)
43
43
  src/cones.o : src/cones.c $(INC_FILES)
44
+ src/exp_cone.o : src/exp_cone.c $(INC_FILES)
44
45
  src/aa.o : src/aa.c $(INC_FILES)
45
46
  src/rw.o : src/rw.c $(INC_FILES)
46
47
  src/linalg.o: src/linalg.c $(INC_FILES)
@@ -49,6 +50,7 @@ src/scs_version.o: src/scs_version.c $(INC_FILES)
49
50
 
50
51
  $(DIRSRC)/private.o: $(DIRSRC)/private.c $(DIRSRC)/private.h
51
52
  $(INDIRSRC)/indirect/private.o: $(INDIRSRC)/private.c $(INDIRSRC)/private.h
53
+ $(MKLSRC)/private.o: $(MKLSRC)/private.c $(MKLSRC)/private.h
52
54
  $(LINSYS)/scs_matrix.o: $(LINSYS)/scs_matrix.c $(LINSYS)/scs_matrix.h
53
55
  $(LINSYS)/csparse.o: $(LINSYS)/csparse.c $(LINSYS)/csparse.h
54
56
 
@@ -62,45 +64,68 @@ $(OUT)/libscsindir.a: $(SCS_INDIR_O) $(SCS_OBJECTS) $(INDIRSRC)/private.o $(LINS
62
64
  $(ARCHIVE) $@ $^
63
65
  - $(RANLIB) $@
64
66
 
67
+ $(OUT)/libscsmkl.a: $(SCS_O) $(SCS_OBJECTS) $(MKLSRC)/private.o $(LINSYS)/scs_matrix.o $(LINSYS)/csparse.o
68
+ mkdir -p $(OUT)
69
+ $(ARCHIVE) $@ $^
70
+ - $(RANLIB) $@
71
+
65
72
  $(OUT)/libscsdir.$(SHARED): $(SCS_O) $(SCS_OBJECTS) $(DIRSRC)/private.o $(AMD_OBJS) $(LDL_OBJS) $(LINSYS)/scs_matrix.o $(LINSYS)/csparse.o
66
73
  mkdir -p $(OUT)
67
- $(CC) $(CFLAGS) -shared -Wl,$(SONAME),$(@:$(OUT)/%=%) -o $@ $^ $(LDFLAGS)
74
+ $(CC) $(CFLAGS) -shared -Wl,$(SONAME),$(@:$(OUT)/%=%) -o $@ $^ $(LDFLAGS) $(BLASLDFLAGS)
68
75
 
69
76
  $(OUT)/libscsindir.$(SHARED): $(SCS_INDIR_O) $(SCS_OBJECTS) $(INDIRSRC)/private.o $(LINSYS)/scs_matrix.o $(LINSYS)/csparse.o
70
77
  mkdir -p $(OUT)
71
- $(CC) $(CFLAGS) -shared -Wl,$(SONAME),$(@:$(OUT)/%=%) -o $@ $^ $(LDFLAGS)
78
+ $(CC) $(CFLAGS) -shared -Wl,$(SONAME),$(@:$(OUT)/%=%) -o $@ $^ $(LDFLAGS) $(BLASLDFLAGS)
79
+
80
+ $(OUT)/libscsmkl.$(SHARED): $(SCS_O) $(SCS_OBJECTS) $(MKLSRC)/private.o $(LINSYS)/scs_matrix.o $(LINSYS)/csparse.o
81
+ mkdir -p $(OUT)
82
+ $(CC) $(CFLAGS) -shared -Wl,$(SONAME),$(@:$(OUT)/%=%) -o $@ $^ $(LDFLAGS) $(MKLFLAGS)
72
83
 
73
84
  $(OUT)/demo_socp_direct: test/random_socp_prob.c $(OUT)/libscsdir.a
74
- $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
85
+ $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(BLASLDFLAGS)
75
86
 
76
87
  $(OUT)/demo_socp_indirect: test/random_socp_prob.c $(OUT)/libscsindir.a
77
- $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
88
+ $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(BLASLDFLAGS)
89
+
90
+ $(OUT)/demo_socp_mkl: test/random_socp_prob.c $(OUT)/libscsmkl.a
91
+ $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(MKLFLAGS)
78
92
 
79
93
  $(OUT)/run_from_file_direct: test/run_from_file.c $(OUT)/libscsdir.a
80
- $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
94
+ $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(BLASLDFLAGS)
81
95
 
82
96
  $(OUT)/run_from_file_indirect: test/run_from_file.c $(OUT)/libscsindir.a
83
- $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
97
+ $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(BLASLDFLAGS)
84
98
 
85
99
  $(OUT)/run_from_file_gpu_indirect: test/run_from_file.c $(OUT)/libscsgpuindir.a
86
- $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(CULDFLAGS)
100
+ $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(BLASLDFLAGS) $(CULDFLAGS)
87
101
 
88
102
  # basic testing
89
103
  .PHONY: test
90
104
  test: $(OUT)/run_tests_indirect $(OUT)/run_tests_direct
91
105
  $(OUT)/run_tests_indirect: test/run_tests.c $(OUT)/libscsindir.a
92
- $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -Itest
106
+ $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(BLASLDFLAGS) -Itest
93
107
  $(OUT)/run_tests_direct: test/run_tests.c $(OUT)/libscsdir.a
94
- $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -Itest
108
+ $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(BLASLDFLAGS) -Itest
109
+ $(OUT)/run_tests_mkl: test/run_tests.c $(OUT)/libscsmkl.a
110
+ $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(MKLFLAGS) -Itest
111
+
95
112
 
96
113
  .PHONY: test_gpu
97
114
  test_gpu: $(OUT)/run_tests_gpu_indirect # $(OUT)/run_tests_gpu_direct
98
115
 
116
+ .PHONY: mkl
117
+ mkl: mklroot $(OUT)/libscsmkl.a $(OUT)/libscsmkl.$(SHARED) $(OUT)/run_tests_mkl $(OUT)/demo_socp_mkl
118
+ mklroot:
119
+ ifndef MKLROOT
120
+ $(error MKLROOT is undefined, set MKLROOT to the MKL install location)
121
+ endif
122
+
123
+
99
124
  $(OUT)/run_tests_gpu_indirect: test/run_tests.c $(OUT)/libscsgpuindir.a
100
- $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(CULDFLAGS) -Itest
125
+ $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(BLASLDFLAGS) $(CULDFLAGS) -Itest
101
126
 
102
127
  # $(OUT)/run_tests_gpu_direct: test/run_tests.c $(OUT)/libscsgpudir.a
103
- # $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(CULDFLAGS) -Itest
128
+ # $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(BLASLDFLAGS) $(CULDFLAGS) -Itest
104
129
 
105
130
  # REQUIRES GPU AND CUDA INSTALLED
106
131
  gpu: gpu_indirect # gpu_direct
@@ -119,7 +144,7 @@ $(GPUINDIR)/private.o: $(GPUINDIR)/private.c
119
144
 
120
145
  # $(OUT)/libscsgpudir.$(SHARED): $(SCS_O) $(SCS_OBJECTS) $(GPUDIR)/private.o $(AMD_OBJS) $(LINSYS)/scs_matrix.o $(LINSYS)/gpu/gpu.o
121
146
  # mkdir -p $(OUT)
122
- # $(CC) $(CFLAGS) -shared -Wl,$(SONAME),$(@:$(OUT)/%=%) -o $@ $^ $(LDFLAGS) $(CULDFLAGS)
147
+ # $(CC) $(CFLAGS) -shared -Wl,$(SONAME),$(@:$(OUT)/%=%) -o $@ $^ $(LDFLAGS) $(BLASLDFLAGS) $(CULDFLAGS)
123
148
 
124
149
  # $(OUT)/libscsgpudir.a: $(SCS_INDIR_O) $(SCS_OBJECTS) $(GPUDIR)/private.o $(AMD_OBJS) $(LINSYS)/scs_matrix.o $(LINSYS)/gpu/gpu.o
125
150
  # mkdir -p $(OUT)
@@ -128,7 +153,7 @@ $(GPUINDIR)/private.o: $(GPUINDIR)/private.c
128
153
 
129
154
  $(OUT)/libscsgpuindir.$(SHARED): $(SCS_O) $(SCS_OBJECTS) $(GPUINDIR)/private.o $(LINSYS)/scs_matrix.o $(LINSYS)/csparse.o $(LINSYS)/gpu/gpu.o
130
155
  mkdir -p $(OUT)
131
- $(CC) $(CFLAGS) -shared -Wl,$(SONAME),$(@:$(OUT)/%=%) -o $@ $^ $(LDFLAGS) $(CULDFLAGS)
156
+ $(CC) $(CFLAGS) -shared -Wl,$(SONAME),$(@:$(OUT)/%=%) -o $@ $^ $(LDFLAGS) $(BLASLDFLAGS) $(CULDFLAGS)
132
157
 
133
158
  $(OUT)/libscsgpuindir.a: $(SCS_INDIR_O) $(SCS_OBJECTS) $(GPUINDIR)/private.o $(LINSYS)/scs_matrix.o $(LINSYS)/csparse.o $(LINSYS)/gpu/gpu.o
134
159
  mkdir -p $(OUT)
@@ -136,14 +161,14 @@ $(OUT)/libscsgpuindir.a: $(SCS_INDIR_O) $(SCS_OBJECTS) $(GPUINDIR)/private.o $(L
136
161
  - $(RANLIB) $@
137
162
 
138
163
  # $(OUT)/demo_socp_gpu_direct: test/random_socp_prob.c $(OUT)/libscsgpudir.a
139
- # $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(CULDFLAGS)
164
+ # $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(BLASLDFLAGS) $(CULDFLAGS)
140
165
 
141
166
  $(OUT)/demo_socp_gpu_indirect: test/random_socp_prob.c $(OUT)/libscsgpuindir.a
142
- $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(CULDFLAGS)
167
+ $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(BLASLDFLAGS) $(CULDFLAGS)
143
168
 
144
169
  .PHONY: clean purge
145
170
  clean:
146
- @rm -rf $(TARGETS) $(SCS_O) $(SCS_INDIR_O) $(SCS_OBJECTS) $(AMD_OBJS) $(LDL_OBJS) $(LINSYS)/*.o $(DIRSRC)/*.o $(INDIRSRC)/*.o $(GPUDIR)/*.o $(GPUINDIR)/*.o $(LINSYS)/gpu/*.o
171
+ @rm -rf $(TARGETS) $(SCS_O) $(SCS_INDIR_O) $(SCS_OBJECTS) $(AMD_OBJS) $(LDL_OBJS) $(LINSYS)/*.o $(DIRSRC)/*.o $(INDIRSRC)/*.o $(MKLSRC)/*.o $(GPUDIR)/*.o $(GPUINDIR)/*.o $(LINSYS)/gpu/*.o
147
172
  @rm -rf $(OUT)/*.dSYM
148
173
  @rm -rf matlab/*.mex*
149
174
  @rm -rf .idea
data/vendor/scs/README.md CHANGED
@@ -8,6 +8,8 @@
8
8
 
9
9
 
10
10
  SCS (`splitting conic solver`) is a numerical optimization package for solving
11
- large-scale convex cone problems. The current version is `3.1.1`.
11
+ large-scale convex cone problems. The current version is `3.2.3`.
12
12
 
13
13
  The full documentation is available [here](https://www.cvxgrp.org/scs/).
14
+
15
+ If you wish to cite SCS please cite the papers listed [here](https://www.cvxgrp.org/scs/citing).
@@ -18,14 +18,14 @@ struct SCS_CONE_WORK {
18
18
  * cone boundaries, boundaries[0] is starting index for cones of size larger
19
19
  * than 1
20
20
  */
21
- const ScsCone *k; /* original cone information */
21
+ ScsCone *k; /* original cone information */
22
22
  scs_int *cone_boundaries;
23
23
  scs_int cone_boundaries_len;
24
24
  scs_int scaled_cones; /* boolean, whether the cones have been scaled */
25
25
  scs_float *s; /* used for Moreau decomposition in projection */
26
26
  scs_int m; /* total length of cone */
27
27
  /* box cone quantities */
28
- scs_float *bl, *bu, box_t_warm_start;
28
+ scs_float box_t_warm_start;
29
29
  #ifdef USE_LAPACK
30
30
  /* workspace for eigenvector decompositions: */
31
31
  scs_float *Xs, *Z, *e, *work;
@@ -33,7 +33,9 @@ struct SCS_CONE_WORK {
33
33
  #endif
34
34
  };
35
35
 
36
- ScsConeWork *SCS(init_cone)(const ScsCone *k, scs_int m);
36
+ void SCS(free_cone)(ScsCone *k);
37
+ void SCS(deep_copy_cone)(ScsCone *dest, const ScsCone *src);
38
+ ScsConeWork *SCS(init_cone)(ScsCone *k, scs_int m);
37
39
  char *SCS(get_cone_header)(const ScsCone *k);
38
40
  scs_int SCS(validate_cones)(const ScsData *d, const ScsCone *k);
39
41
  scs_int SCS(proj_dual_cone)(scs_float *x, ScsConeWork *c, ScsScaling *scal,
@@ -12,16 +12,17 @@ extern "C" {
12
12
  #define SCS(x) _scs_##x
13
13
  #endif
14
14
 
15
- /* SCS VERSION NUMBER ---------------------------------------------- */
15
+ /* SCS VERSION NUMBER ---------------------------------------------- */
16
16
  /* string literals automatically null-terminated */
17
- #define SCS_VERSION ("3.1.1")
17
+ #define SCS_VERSION ("3.2.3")
18
18
 
19
19
  /* verbosity level */
20
20
  #ifndef VERBOSITY
21
21
  #define VERBOSITY (0)
22
22
  #endif
23
23
 
24
- /* DEFAULT SOLVER PARAMETERS AND SETTINGS -------------------------- */
24
+ /* DEFAULT SOLVER PARAMETERS AND SETTINGS -------------------------- */
25
+ /* If you update any of these you must update the documentation manually */
25
26
  #define MAX_ITERS (100000)
26
27
  #define EPS_REL (1E-4)
27
28
  #define EPS_ABS (1E-4)
@@ -39,29 +40,50 @@ extern "C" {
39
40
  #define LOG_CSV_FILENAME (0)
40
41
  #define TIME_LIMIT_SECS (0.)
41
42
 
42
- /* redefine printfs and memory allocators as needed */
43
+ /* redefine printfs as needed */
44
+ #if NO_PRINTING > 0 /* Disable all printing */
45
+ #define scs_printf(...) /* No-op */
46
+ #else
43
47
  #ifdef MATLAB_MEX_FILE
44
48
  #include "mex.h"
45
49
  #define scs_printf mexPrintf
46
- #define scs_free mxFree
47
- #define scs_malloc mxMalloc
48
- #define scs_calloc mxCalloc
49
- #define scs_realloc mxRealloc
50
50
  #elif defined PYTHON
51
51
  #include <Python.h>
52
+ /* see:
53
+ * https://cython-users.narkive.com/jRjjs3sK/reacquire-gil-for-printing-in-wrapped-c-library
54
+ */
52
55
  #define scs_printf(...) \
53
56
  { \
54
57
  PyGILState_STATE gilstate = PyGILState_Ensure(); \
55
58
  PySys_WriteStdout(__VA_ARGS__); \
56
59
  PyGILState_Release(gilstate); \
57
60
  }
61
+ #elif defined R_LANG
62
+ #include <R_ext/Print.h> /* Rprintf etc */
63
+ #include <stdio.h>
64
+ #include <stdlib.h>
65
+ #define scs_printf Rprintf
66
+ #else
67
+ #include <stdio.h>
68
+ #include <stdlib.h>
69
+ #define scs_printf printf
70
+ #endif
71
+ #endif
72
+
73
+ /* redefine memory allocators as needed */
74
+ #ifdef MATLAB_MEX_FILE
75
+ #include "mex.h"
76
+ #define scs_free mxFree
77
+ #define scs_malloc mxMalloc
78
+ #define scs_calloc mxCalloc
79
+ #define scs_realloc mxRealloc
80
+ #elif defined PYTHON
81
+ #include <Python.h>
58
82
  #if PY_MAJOR_VERSION >= 3
59
83
  #define scs_free PyMem_RawFree
60
84
  #define scs_malloc PyMem_RawMalloc
61
85
  #define scs_realloc PyMem_RawRealloc
62
86
  #define scs_calloc PyMem_RawCalloc
63
- /* only for SuiteSparse + python */
64
- #define _scs_printf PySys_WriteStdout
65
87
  #else
66
88
  #define scs_free PyMem_Free
67
89
  #define scs_malloc PyMem_Malloc
@@ -73,10 +95,8 @@ static inline void *scs_calloc(size_t count, size_t size) {
73
95
  }
74
96
  #endif
75
97
  #elif defined R_LANG
76
- #include <R_ext/Print.h> /* Rprintf etc */
77
98
  #include <stdio.h>
78
99
  #include <stdlib.h>
79
- #define scs_printf Rprintf
80
100
  #define scs_free free
81
101
  #define scs_malloc malloc
82
102
  #define scs_calloc calloc
@@ -84,7 +104,6 @@ static inline void *scs_calloc(size_t count, size_t size) {
84
104
  #else
85
105
  #include <stdio.h>
86
106
  #include <stdlib.h>
87
- #define scs_printf printf
88
107
  #define scs_free free
89
108
  #define scs_malloc malloc
90
109
  #define scs_calloc calloc
@@ -107,8 +126,6 @@ static inline void *scs_calloc(size_t count, size_t size) {
107
126
  #endif
108
127
  #endif
109
128
 
110
- #define SCS_NULL 0
111
-
112
129
  #ifndef MAX
113
130
  #define MAX(a, b) (((a) > (b)) ? (a) : (b))
114
131
  #endif
@@ -145,8 +162,9 @@ static inline void *scs_calloc(size_t count, size_t size) {
145
162
  /* how many iterations between heuristic residual rescaling */
146
163
  #define RESCALING_MIN_ITERS (100)
147
164
 
148
- #define EPS_TOL (1E-18)
149
- #define SAFEDIV_POS(X, Y) ((Y) < EPS_TOL ? ((X) / EPS_TOL) : (X) / (Y))
165
+ #define _DIV_EPS_TOL (1E-18)
166
+ #define SAFEDIV_POS(X, Y) \
167
+ ((Y) < _DIV_EPS_TOL ? ((X) / _DIV_EPS_TOL) : (X) / (Y))
150
168
 
151
169
  #if VERBOSITY > 0
152
170
  #define PRINT_INTERVAL (1)
@@ -23,15 +23,15 @@ extern "C" {
23
23
  * @return Linear system solver workspace.
24
24
  *
25
25
  */
26
- ScsLinSysWork *SCS(init_lin_sys_work)(const ScsMatrix *A, const ScsMatrix *P,
27
- const scs_float *diag_r);
26
+ ScsLinSysWork *scs_init_lin_sys_work(const ScsMatrix *A, const ScsMatrix *P,
27
+ const scs_float *diag_r);
28
28
 
29
29
  /**
30
30
  * Frees `ScsLinSysWork` structure and associated allocated memory.
31
31
  *
32
32
  * @param w Linear system private workspace.
33
33
  */
34
- void SCS(free_lin_sys_work)(ScsLinSysWork *w);
34
+ void scs_free_lin_sys_work(ScsLinSysWork *w);
35
35
 
36
36
  /**
37
37
  * Solves the linear system as required by SCS at each iteration:
@@ -48,11 +48,11 @@ void SCS(free_lin_sys_work)(ScsLinSysWork *w);
48
48
  * @param b Right hand side, contains solution at the end.
49
49
  * @param s Contains warm-start (may be NULL).
50
50
  * @param tol Tolerance required for the system solve.
51
- * @return status < 0 indicates failure.
51
+ * @return status != 0 indicates failure.
52
52
  *
53
53
  */
54
- scs_int SCS(solve_lin_sys)(ScsLinSysWork *w, scs_float *b, const scs_float *s,
55
- scs_float tol);
54
+ scs_int scs_solve_lin_sys(ScsLinSysWork *w, scs_float *b, const scs_float *s,
55
+ scs_float tol);
56
56
  /**
57
57
  * Update the linsys workspace when `R` is changed. For example, a
58
58
  * direct method for solving the linear system might need to update the
@@ -62,14 +62,14 @@ scs_int SCS(solve_lin_sys)(ScsLinSysWork *w, scs_float *b, const scs_float *s,
62
62
  * @param new_diag_r Updated `diag_r`, diagonal entries of R.
63
63
  *
64
64
  */
65
- void SCS(update_lin_sys_diag_r)(ScsLinSysWork *w, const scs_float *new_diag_r);
65
+ void scs_update_lin_sys_diag_r(ScsLinSysWork *w, const scs_float *new_diag_r);
66
66
 
67
67
  /**
68
68
  * Name of the linear solver.
69
69
  *
70
70
  * @return name of method.
71
71
  */
72
- const char *SCS(get_lin_sys_method)(void);
72
+ const char *scs_get_lin_sys_method(void);
73
73
 
74
74
  #ifdef __cplusplus
75
75
  }
@@ -8,6 +8,7 @@ extern "C" {
8
8
  #include "glbopts.h"
9
9
  #include "scs_work.h"
10
10
 
11
+ void SCS(normalize_b_c)(ScsScaling *scal, scs_float *b, scs_float *c);
11
12
  void SCS(normalize_sol)(ScsScaling *scal, ScsSolution *sol);
12
13
  void SCS(un_normalize_sol)(ScsScaling *scal, ScsSolution *sol);
13
14
  void SCS(un_normalize_primal)(ScsScaling *scal, scs_float *r);
@@ -13,9 +13,9 @@ void SCS(write_data)(const ScsData *d, const ScsCone *k,
13
13
  const ScsSettings *stgs);
14
14
  scs_int SCS(read_data)(const char *filename, ScsData **d, ScsCone **k,
15
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);
16
+ void SCS(log_data_to_csv)(const ScsCone *k, const ScsSettings *stgs,
17
+ const ScsWork *w, scs_int iter,
18
+ SCS(timer) * solve_timer);
19
19
 
20
20
  #ifdef __cplusplus
21
21
  }
@@ -1,5 +1,9 @@
1
- /* This file contains the outward facing SCS API. */
2
- /* It includes all the input/output data structs and the API functions. */
1
+ /*
2
+ * Public header containing the outward facing SCS API. It includes all the
3
+ * input/output data structs and the API functions. Make sure this file and
4
+ * `scs_types.h` are somewhere appropriate and then use `#include "scs.h"` to
5
+ * access the SCS public API.
6
+ */
3
7
 
4
8
  #ifndef SCS_H_GUARD
5
9
  #define SCS_H_GUARD
@@ -11,6 +15,8 @@ extern "C" {
11
15
  /* Contains definitions of primitive types `scs_int` and `scs_float`. */
12
16
  #include "scs_types.h"
13
17
 
18
+ #define SCS_NULL 0 /* NULL type */
19
+
14
20
  /* The following abstract structs are implemented later. */
15
21
 
16
22
  /** Struct containing acceleration workspace. Implemented by acceleration. */
@@ -116,11 +122,11 @@ typedef struct {
116
122
  scs_float *bl;
117
123
  /** Total length of box cone (includes scale `t`). */
118
124
  scs_int bsize;
119
- /** Array of second-order cone constraints. */
125
+ /** Array of second-order cone constraints, `len(q) = qsize`. */
120
126
  scs_int *q;
121
127
  /** Length of second-order cone array `q`. */
122
128
  scs_int qsize;
123
- /** Array of semidefinite cone constraints. */
129
+ /** Array of semidefinite cone constraints, `len(s) = ssize`. */
124
130
  scs_int *s;
125
131
  /** Length of semidefinite constraints array `s`. */
126
132
  scs_int ssize;
@@ -129,7 +135,7 @@ typedef struct {
129
135
  /** Number of dual exponential cone triples. */
130
136
  scs_int ed;
131
137
  /** Array of power cone params, must be in `[-1, 1]`, negative values are
132
- * interpreted as specifying the dual cone. */
138
+ * interpreted as specifying the dual cone, `len(p) = psize ` */
133
139
  scs_float *p;
134
140
  /** Number of (primal and dual) power cone triples. */
135
141
  scs_int psize;
@@ -205,7 +211,9 @@ typedef struct {
205
211
  /**
206
212
  * Initialize SCS and allocate memory.
207
213
  *
208
- * All the inputs must be already allocated in memory before calling.
214
+ * All the inputs must be already allocated in memory before calling. After
215
+ * this function returns then the memory associated with `d`, `k`, and `stgs`
216
+ * can be freed as SCS maintains deep copies of these internally.
209
217
  *
210
218
  * It performs:
211
219
  * - data and settings validation
@@ -213,26 +221,45 @@ typedef struct {
213
221
  * - automatic parameters tuning (if enabled)
214
222
  * - setup linear system solver:
215
223
  * - direct solver: KKT matrix factorization is performed here
216
- * - indirect solver: KKT matrix preconditioning is performed here
217
- * - solve the linear system for the `r` vector in the paper.
224
+ * - indirect solver: KKT matrix preconditioning is performed here.
218
225
  *
219
226
  *
220
- * @param d Problem data.
221
- * @param k Cone data.
222
- * @param stgs SCS solver settings.
223
- * @return Solver work struct.
227
+ * @param d Problem data.
228
+ * @param k Cone data.
229
+ * @param stgs SCS solve settings.
230
+ * @return Solver workspace.
224
231
  */
225
232
  ScsWork *scs_init(const ScsData *d, const ScsCone *k, const ScsSettings *stgs);
226
233
 
234
+ /**
235
+ * Update the `b` vector, `c` vector, or both, before another solve call.
236
+ *
237
+ * After a solve we can reuse the SCS workspace in another solve if the only
238
+ * problem data that has changed are the `b` and `c` vectors.
239
+ *
240
+ * @param w SCS workspace from scs_init (modified in-place).
241
+ * @param b New `b` vector (can be `SCS_NULL` if unchanged).
242
+ * @param c New `c` vector (can be `SCS_NULL` if unchanged).
243
+ *
244
+ * @return 0 if update successful.
245
+ */
246
+ scs_int scs_update(ScsWork *w, scs_float *b, scs_float *c);
247
+
227
248
  /**
228
249
  * Solve quadratic cone program initialized by scs_init.
229
250
  *
230
- * @param w Workspace allocated by init.
231
- * @param sol Solver solution struct, will contain solution at termination.
232
- * @param info Solver info reporting.
251
+ * @param w Workspace allocated by scs_init.
252
+ * @param sol Solution will be stored here. If members `x`, `y`, `s`
253
+ * are NULL then SCS will allocate memory for them which
254
+ * must be freed by the caller.
255
+ * @param info Information about the solve will be stored here.
256
+ * @param warm_start Whether to use the entries of `sol` as warm-start for
257
+ * the solve.
258
+ *
233
259
  * @return Flag containing problem status (see \a glbopts.h).
234
260
  */
235
- scs_int scs_solve(ScsWork *w, ScsSolution *sol, ScsInfo *info);
261
+ scs_int scs_solve(ScsWork *w, ScsSolution *sol, ScsInfo *info,
262
+ scs_int warm_start);
236
263
 
237
264
  /**
238
265
  * Clean up allocated SCS workspace.
@@ -246,13 +273,13 @@ void scs_finish(ScsWork *w);
246
273
  *
247
274
  * All the inputs must already be allocated in memory before calling.
248
275
  *
249
- * @param d Problem data.
250
- * @param k Cone data.
251
- * @param stgs SCS solver settings.
252
- * @param sol Solution will be stored here. If members `x`, `y`, `s` are
253
- * NULL then SCS will allocate memory for them.
254
- * @param info Information about the solve will be stored here.
255
- * @return Flag that determines solve type (see \a glbopts.h).
276
+ * @param d Problem data.
277
+ * @param k Cone data.
278
+ * @param stgs SCS solver settings.
279
+ * @param sol Solution will be stored here. If members `x`, `y`, `s` are
280
+ * NULL then SCS will allocate memory for them.
281
+ * @param info Information about the solve will be stored here.
282
+ * @return Flag containing problem status (see \a glbopts.h).
256
283
  */
257
284
  scs_int scs(const ScsData *d, const ScsCone *k, const ScsSettings *stgs,
258
285
  ScsSolution *sol, ScsInfo *info);
@@ -260,7 +287,7 @@ scs_int scs(const ScsData *d, const ScsCone *k, const ScsSettings *stgs,
260
287
  /**
261
288
  * Helper function to set all settings to default values (see \a glbopts.h).
262
289
  *
263
- * @param stgs Settings struct that will be populated.
290
+ * @param stgs Settings struct that will be populated.
264
291
  */
265
292
  void scs_set_default_settings(ScsSettings *stgs);
266
293
 
@@ -1,5 +1,7 @@
1
1
  /*
2
- * Definitions of primitive types used in SCS.
2
+ * Pulic header including definitions of primitive types used in SCS.
3
+ * Make sure this file and `scs.h` are somewhere appropriate and then use
4
+ * `#include "scs.h"` to access the SCS public API.
3
5
  */
4
6
 
5
7
  #ifndef SCS_TYPES_H_GUARD
@@ -9,6 +9,8 @@
9
9
  extern "C" {
10
10
  #endif
11
11
 
12
+ #include "scs.h"
13
+
12
14
  /** Contains normalization variables. */
13
15
  typedef struct {
14
16
  scs_float *D, *E; /* for normalization */
@@ -40,10 +42,11 @@ typedef struct {
40
42
  scs_float *ax, *ax_s, *px, *aty, *ax_s_btau, *px_aty_ctau;
41
43
  } ScsResiduals;
42
44
 
43
- /** Workspace for SCS */
45
+ /** Workspace for SCS. */
44
46
  struct SCS_WORK {
45
47
  /* x_prev = x from previous iteration */
46
- scs_int time_limit_reached; /* set if the time-limit is reached */
48
+ scs_float setup_time; /* time taken for setup phase (milliseconds) */
49
+ scs_int time_limit_reached; /* boolean, if the time-limit is reached */
47
50
  scs_float *u, *u_t;
48
51
  scs_float *v, *v_prev;
49
52
  scs_float *rsk; /* rsk [ r; s; kappa ] */
@@ -51,12 +54,12 @@ struct SCS_WORK {
51
54
  scs_float *g; /* g = (I + M)^{-1} h */
52
55
  scs_float *lin_sys_warm_start; /* linear system warm-start (indirect only) */
53
56
  scs_float *diag_r; /* vector of R matrix diagonals (affects cone proj) */
54
- AaWork *accel; /* struct for acceleration workspace */
55
- scs_float *b_orig, *c_orig; /* original b and c vectors */
56
- scs_float *b_normalized, *c_normalized; /* normalized b and c vectors */
57
- scs_int m, n; /* A has m rows, n cols */
58
- ScsMatrix *A; /* (possibly normalized) A matrix */
59
- ScsMatrix *P; /* (possibly normalized) P matrix */
57
+ scs_float *b_orig, *c_orig; /* original unnormalized b and c vectors */
58
+ scs_float nm_b_orig, nm_c_orig; /* unnormalized NORM(b), NORM(c) */
59
+ AaWork *accel; /* struct for acceleration workspace */
60
+ ScsData *d; /* Problem data deep copy NORMALIZED */
61
+ ScsCone *k; /* Problem cone deep copy */
62
+ ScsSettings *stgs; /* contains solver settings specified by user */
60
63
  ScsLinSysWork *p; /* struct populated by linear system solver */
61
64
  ScsScaling *scal; /* contains the re-scaling data */
62
65
  ScsConeWork *cone_work; /* workspace for the cone projection step */
@@ -64,17 +67,12 @@ struct SCS_WORK {
64
67
  ScsResiduals *r_orig, *r_normalized;
65
68
  /* track x,y,s as alg progresses, tau *not* divided out */
66
69
  ScsSolution *xys_orig, *xys_normalized;
67
- /* updating scale params workspace */
70
+ /* Scale updating workspace */
68
71
  scs_float sum_log_scale_factor;
69
72
  scs_int last_scale_update_iter, n_log_scale_factor, scale_updates;
70
- /* aa norm stat */
73
+ /* AA stats */
71
74
  scs_float aa_norm;
72
75
  scs_int rejected_accel_steps, accepted_accel_steps;
73
- scs_float setup_time; /* time taken for setup phase (milliseconds) */
74
- scs_float scale; /* current scale parameter */
75
- const ScsData *d;
76
- const ScsCone *k;
77
- const ScsSettings *stgs; /* contains solver settings specified by user */
78
76
  };
79
77
 
80
78
  #ifdef __cplusplus
@@ -11,7 +11,7 @@ extern "C" {
11
11
  #include <stdlib.h>
12
12
 
13
13
  /* timing code courtesy of A. Domahidi */
14
- #if (defined NOTIMER)
14
+ #if (defined NO_TIMER)
15
15
  typedef void *SCS(timer);
16
16
  #elif (defined _WIN32 || defined _WIN64 || defined _WINDLL)
17
17
  /* Use Windows QueryPerformanceCounter for timing */
@@ -45,7 +45,9 @@ typedef struct SCS(timer) {
45
45
  void SCS(tic)(SCS(timer) * t);
46
46
  scs_float SCS(tocq)(SCS(timer) * t);
47
47
  void SCS(free_sol)(ScsSolution *sol);
48
- void SCS(free_data)(ScsData *d, ScsCone *k, ScsSettings *stgs);
48
+ void SCS(deep_copy_data)(ScsData *dest, const ScsData *src);
49
+ void SCS(deep_copy_stgs)(ScsSettings *dest, const ScsSettings *src);
50
+ void SCS(free_data)(ScsData *d);
49
51
 
50
52
  #ifdef __cplusplus
51
53
  }