scs/
lib.rs

1#[allow(non_camel_case_types)]
2pub type scs_int = ::std::os::raw::c_int;
3
4#[repr(C)]
5#[derive(Debug, Copy, Clone)]
6pub struct ScsMatrix {
7    pub x: *mut f64, // column compressed format
8    pub i: *mut scs_int,   // row index
9    pub p: *mut scs_int,   // column pointer
10    pub m: scs_int,        // rows
11    pub n: scs_int,        // cols
12}
13
14// TODO: what to do here?
15#[repr(C)]
16#[derive(Debug, Copy, Clone)]
17pub struct AaWork {
18    _unused: [u8; 0],
19}
20
21extern "C" {
22    pub fn aa_init(dim: scs_int, aa_mem: scs_int, type1: scs_int) -> *mut AaWork;
23    pub fn aa_apply(f: *mut f64, x: *const f64, a: *mut AaWork) -> scs_int;
24    pub fn aa_finish(a: *mut AaWork);
25}
26
27#[repr(C)]
28#[derive(Debug, Copy, Clone)]
29pub struct ScsLinSysWork {
30    _unused: [u8; 0],
31}
32
33#[repr(C)]
34#[derive(Debug, Copy, Clone)]
35pub struct ScsAccelWork {
36    _unused: [u8; 0],
37}
38
39#[repr(C)]
40#[derive(Debug, Copy, Clone)]
41pub struct ScsConeWork {
42    _unused: [u8; 0],
43}
44
45#[repr(C)]
46#[derive(Debug, Copy, Clone)]
47#[allow(non_snake_case)]
48pub struct ScsData {
49    pub m: scs_int,
50    pub n: scs_int,
51    pub A: *mut ScsMatrix,
52    pub b: *mut f64,
53    pub c: *mut f64,
54    pub stgs: *mut ScsSettings,
55}
56
57#[repr(C)]
58#[derive(Debug, Copy, Clone)]
59pub struct ScsSettings {
60    pub normalize: scs_int,
61    pub scale: f64,
62    pub rho_x: f64,
63    pub max_iters: scs_int,
64    pub eps: f64,
65    pub alpha: f64,
66    pub cg_rate: f64,
67    pub verbose: scs_int,
68    pub warm_start: scs_int,
69    pub acceleration_lookback: scs_int,
70    pub write_data_filename: *const ::std::os::raw::c_char,
71}
72
73#[repr(C)]
74#[derive(Debug, Copy, Clone)]
75pub struct ScsCone {
76    pub f: scs_int,
77    pub l: scs_int,
78    pub q: *mut scs_int,
79    pub qsize: scs_int,
80    pub s: *mut scs_int,
81    pub ssize: scs_int,
82    pub ep: scs_int,
83    pub ed: scs_int,
84    pub p: *mut f64,
85    pub psize: scs_int,
86}
87
88#[repr(C)]
89#[derive(Debug, Copy, Clone)]
90pub struct ScsSolution {
91    pub x: *mut f64,
92    pub y: *mut f64,
93    pub s: *mut f64,
94}
95
96#[repr(C)]
97#[derive(Default, Debug, Copy, Clone)]
98pub struct ScsInfo {
99    pub iter: scs_int,
100    pub status: [::std::os::raw::c_char; 32usize],
101    pub status_val: scs_int,
102    pub pobj: f64,
103    pub dobj: f64,
104    pub res_pri: f64,
105    pub res_dual: f64,
106    pub res_infeas: f64,
107    pub res_unbdd: f64,
108    pub rel_gap: f64,
109    pub setup_time: f64,
110    pub solve_time: f64,
111}
112
113#[repr(C)]
114#[derive(Debug, Copy, Clone)]
115#[allow(non_snake_case)]
116pub struct ScsScaling {
117    pub D: *mut f64,
118    pub E: *mut f64,
119    pub mean_norm_row_a: f64,
120    pub mean_norm_col_a: f64,
121}
122
123extern "C" {
124    ///This initializes the ScsWork struct containing the workspace that scs will
125    /// use, and performs the necessary preprocessing (e.g. matrix factorization).
126    ///All inputs `d`, `k`, and `info` must be memory allocated before calling.
127    pub fn scs_init(d: *const ScsData, k: *const ScsCone, info: *mut ScsInfo) -> *mut ScsWork;
128
129    ///This solves the problem as defined by ScsData `d` and ScsCone `k` using the
130    ///workspace in `w`. The solution is returned in `sol` and information about
131    ///the solve is returned in `info` (outputs must have memory allocated before
132    ///calling).  None of the inputs can be NULL. You can call `scs_solve` many
133    ///times for one call to `scs_init`, so long as the matrix `A` does not change
134    ///(vectors `b` and `c` can change).
135    pub fn scs_solve(
136        w: *mut ScsWork,
137        d: *const ScsData,
138        k: *const ScsCone,
139        sol: *mut ScsSolution,
140        info: *mut ScsInfo,
141    ) -> scs_int;
142
143    ///Called after all solves completed to free allocated memory and other
144    ///cleanup.
145    pub fn scs_finish(w: *mut ScsWork);
146
147    ///Convenience method that simply calls all the above routines in order, for
148    ///cases where the workspace does not need to be reused. All inputs must have
149    ///memory allocated before this call.
150    pub fn scs(
151        d: *const ScsData,
152        k: *const ScsCone,
153        sol: *mut ScsSolution,
154        info: *mut ScsInfo,
155    ) -> scs_int;
156
157    /// Get the SCS version.
158    pub fn scs_version() -> *const ::std::os::raw::c_char;
159}
160
161#[repr(C)]
162#[derive(Debug, Copy, Clone)]
163#[allow(non_snake_case)]
164pub struct ScsWork {
165    pub u: *mut f64,
166    pub v: *mut f64,
167    pub u_t: *mut f64,
168    pub u_prev: *mut f64,
169    pub v_prev: *mut f64,
170    pub h: *mut f64,
171    pub g: *mut f64,
172    pub pr: *mut f64,
173    pub dr: *mut f64,
174    pub g_th: f64,
175    pub sc_b: f64,
176    pub sc_c: f64,
177    pub nm_b: f64,
178    pub nm_c: f64,
179    pub b: *mut f64,
180    pub c: *mut f64,
181    pub m: scs_int,
182    pub n: scs_int,
183    pub A: *mut ScsMatrix,
184    pub p: *mut ScsLinSysWork,
185    pub stgs: *mut ScsSettings,
186    pub scal: *mut ScsScaling,
187    pub cone_work: *mut ScsConeWork,
188    pub accel: *mut AaWork,
189}
190
191#[repr(C)]
192#[derive(Debug, Copy, Clone)]
193pub struct ScsResiduals {
194    pub last_iter: scs_int,
195    pub res_dual: f64,
196    pub res_pri: f64,
197    pub res_infeas: f64,
198    pub res_unbdd: f64,
199    pub rel_gap: f64,
200    pub ct_x_by_tau: f64,
201    pub bt_y_by_tau: f64,
202    pub tau: f64,
203    pub kap: f64,
204}