1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
/*
* ECOS - Embedded Conic Solver.
* Copyright (C) 2012-2015 A. Domahidi [domahidi@embotech.com],
* Automatic Control Lab, ETH Zurich & embotech GmbH, Zurich, Switzerland.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __ECOS_H__
#define __ECOS_H__
#include "glblopts.h"
#include "spla.h"
#include "cone.h"
#include "kkt.h"
#if PROFILING > 0
#include "timer.h"
#endif
#if CTRLC > 0
#include "ctrlc.h"
#endif
/* ECOS VERSION NUMBER - FORMAT: X.Y.Z --------------------------------- */
#define ECOS_VERSION ("2.0.4")
/* DEFAULT SOLVER PARAMETERS AND SETTINGS STRUCT ----------------------- */
#define MAXIT (100) /* maximum number of iterations */
#define FEASTOL (1E-8) /* primal/dual infeasibility tolerance */
#define ABSTOL (1E-8) /* absolute tolerance on duality gap */
#define RELTOL (1E-8) /* relative tolerance on duality gap */
#define FTOL_INACC (1E-4) /* inaccurate solution feasibility tol. */
#define ATOL_INACC (5E-5) /* inaccurate solution absolute tol. */
#define RTOL_INACC (5E-5) /* inaccurate solution relative tol. */
#define GAMMA (0.99) /* scaling the final step length */
#define STATICREG (1) /* static regularization: 0:off, 1:on */
#define DELTASTAT (7E-8) /* regularization parameter */
#define DELTA (2E-7) /* dyn. regularization parameter */
#define EPS (1E-13) /* dyn. regularization threshold (do not 0!) */
#define VERBOSE (1) /* bool for verbosity; PRINTLEVEL < 3 */
#define NITREF (9) /* number of iterative refinement steps */
#define IRERRFACT (6) /* factor by which IR should reduce err */
#define LINSYSACC (1E-14) /* rel. accuracy of search direction */
#define SIGMAMIN (1E-4) /* always do some centering */
#define SIGMAMAX (1.0) /* never fully center */
#define STEPMIN (1E-6) /* smallest step that we do take */
#define STEPMAX (0.999) /* largest step allowed, also in affine dir. */
#define SAFEGUARD (500) /* Maximum increase in PRES before
ECOS_NUMERICS is thrown. */
/*Ecos exponential cone default settings*/
#ifdef EXPCONE
#define MAX_BK (90) /*Maximum backtracking steps*/
#define BK_SCALE (0.8) /*Backtracking constant*/
#define MIN_DISTANCE (0.1) /* dont let sqrt(r), sqrt(-u) or sqrt(v)
become smaller than
MIN_DISTANCE*mu*/
#define CENTRALITY (1) /*Centrality requirement*/
#endif
/* EQUILIBRATION METHOD ------------------------------------------------ */
#define EQUILIBRATE (1) /* use equlibration of data matrices? >0: yes */
#define EQUIL_ITERS (3) /* number of equilibration iterations */
#define RUIZ_EQUIL /* define algorithm to use - if both are ... */
/*#define ALTERNATING_EQUIL*/ /* ... commented out no equlibration is used */
/* EXITCODES ----------------------------------------------------------- */
#define ECOS_OPTIMAL (0) /* Problem solved to optimality */
#define ECOS_PINF (1) /* Found certificate of primal infeasibility */
#define ECOS_DINF (2) /* Found certificate of dual infeasibility */
#define ECOS_INACC_OFFSET (10) /* Offset exitflag at inaccurate results */
#define ECOS_MAXIT (-1) /* Maximum number of iterations reached */
#define ECOS_NUMERICS (-2) /* Search direction unreliable */
#define ECOS_OUTCONE (-3) /* s or z got outside the cone, numerics? */
#define ECOS_SIGINT (-4) /* solver interrupted by a signal/ctrl-c */
#define ECOS_FATAL (-7) /* Unknown problem in solver */
#ifdef __cplusplus
extern "C" {
#endif
/* SETTINGS STRUCT ----------------------------------------------------- */
typedef struct settings{
pfloat gamma; /* scaling the final step length */
pfloat delta; /* regularization parameter */
pfloat eps; /* regularization threshold */
pfloat feastol; /* primal/dual infeasibility tolerance */
pfloat abstol; /* absolute tolerance on duality gap */
pfloat reltol; /* relative tolerance on duality gap */
pfloat feastol_inacc; /* primal/dual infeasibility relaxed tolerance */
pfloat abstol_inacc; /* absolute relaxed tolerance on duality gap */
pfloat reltol_inacc; /* relative relaxed tolerance on duality gap */
idxint nitref; /* number of iterative refinement steps */
idxint maxit; /* maximum number of iterations */
idxint verbose; /* verbosity bool for PRINTLEVEL < 3 */
#ifdef EXPCONE /*Exponential cone settings*/
idxint max_bk_iter; /* Maximum backtracking iterations */
pfloat bk_scale; /* Backtracking scaling */
pfloat centrality; /* Centrality bound, ignored when centrality vars = 0*/
#endif
} settings;
/* INFO STRUCT --------------------------------------------------------- */
typedef struct stats{
pfloat pcost;
pfloat dcost;
pfloat pres;
pfloat dres;
pfloat pinf;
pfloat dinf;
pfloat pinfres;
pfloat dinfres;
pfloat gap;
pfloat relgap;
pfloat sigma;
pfloat mu;
pfloat step;
pfloat step_aff;
pfloat kapovert;
idxint iter;
idxint nitref1;
idxint nitref2;
idxint nitref3;
#if PROFILING > 0
pfloat tsetup;
pfloat tsolve;
#endif
#if PROFILING > 1
pfloat tfactor;
pfloat tkktsolve;
pfloat torder;
pfloat tkktcreate;
pfloat ttranspose;
pfloat tperm;
pfloat tfactor_t1;
pfloat tfactor_t2;
#endif
#ifdef EXPCONE
/* Counters for backtracking, each of these counts
* one condition that can fail and cause a backtrack
*/
idxint pob; /* Potential decreases */
idxint cb; /* Centrality violations */
idxint cob; /* The s'z of one cone is too small w.r.t. mu */
idxint pb; /* Primal infeasibility */
idxint db; /* Dual infeasibility */
idxint affBack; /* Total affine backtracking steps */
idxint cmbBack; /* Total combined backtracking steps */
pfloat centrality; /*Centrality at the end of the backtracking*/
#endif
} stats;
/* ALL DATA NEEDED BY SOLVER ------------------------------------------- */
typedef struct pwork{
/* dimensions */
idxint n; /* number of primal variables x */
idxint m; /* number of conically constrained variables s */
idxint p; /* number of equality constraints */
idxint D; /* degree of the cone */
/* variables */
pfloat* x; /* primal variables */
pfloat* y; /* multipliers for equality constaints */
pfloat* z; /* multipliers for conic inequalities */
pfloat* s; /* slacks for conic inequalities */
pfloat* lambda; /* scaled variable */
pfloat kap; /* kappa (homogeneous embedding) */
pfloat tau; /* tau (homogeneous embedding) */
/* best iterate seen so far */
/* variables */
pfloat* best_x; /* primal variables */
pfloat* best_y; /* multipliers for equality constaints */
pfloat* best_z; /* multipliers for conic inequalities */
pfloat* best_s; /* slacks for conic inequalities */
pfloat best_kap; /* kappa (homogeneous embedding) */
pfloat best_tau; /* tau (homogeneous embedding) */
pfloat best_cx;
pfloat best_by;
pfloat best_hz;
stats* best_info; /* info of best iterate */
/* temporary stuff holding search direction etc. */
pfloat* dsaff;
pfloat* dzaff;
pfloat* W_times_dzaff;
pfloat* dsaff_by_W;
pfloat* saff;
pfloat* zaff;
/* cone */
cone* C;
/* problem data */
spmat* A; spmat* G; pfloat* c; pfloat* b; pfloat* h;
/* indices that map entries of A and G to the KKT matrix */
idxint *AtoK; idxint *GtoK;
#if defined EQUILIBRATE && EQUILIBRATE > 0
/* equilibration vector */
pfloat *xequil;
pfloat *Aequil;
pfloat *Gequil;
#endif
/* scalings of problem data */
pfloat resx0; pfloat resy0; pfloat resz0;
/* residuals */
pfloat *rx; pfloat *ry; pfloat *rz; pfloat rt;
pfloat hresx; pfloat hresy; pfloat hresz;
/* norm iterates */
pfloat nx,ny,nz,ns;
/* temporary storage */
pfloat cx; pfloat by; pfloat hz; pfloat sz;
/* KKT System */
kkt* KKT;
/* info struct */
stats* info;
/* settings struct */
settings* stgs;
} pwork;
/* SOME USEFUL MACROS -------------------------------------------------- */
#define MAX(X,Y) ((X) < (Y) ? (Y) : (X)) /* maximum of 2 expressions */
/* safe division x/y where y is assumed to be positive! */
#define SAFEDIV_POS(X,Y) ( (Y) < EPS ? ((X)/EPS) : (X)/(Y) )
/* METHODS */
/* set up work space */
/* could be done by codegen */
pwork* ECOS_setup(idxint n, idxint m, idxint p, idxint l, idxint ncones, idxint* q, idxint nex,
pfloat* Gpr, idxint* Gjc, idxint* Gir,
pfloat* Apr, idxint* Ajc, idxint* Air,
pfloat* c, pfloat* h, pfloat* b);
#ifdef EXPCONE
pfloat expConeLineSearch(pwork* w, pfloat dtau, pfloat dkappa, idxint affine);
#endif
/* solve */
idxint ECOS_solve(pwork* w);
/**
* Cleanup: free memory (not used for embedded solvers, only standalone)
*
* Use the second argument to give the number of variables to NOT free.
* This is useful if you want to use the result of the optimization without
* copying over the arrays. One use case is the MEX interface, where we
* do not want to free x,y,s,z (depending on the number of LHS).
*/
void ECOS_cleanup(pwork* w, idxint keepvars);
/**
* Version: returns the current version number
* Use a character array of length 7 to obtain the version number
* in the format
* x.y.zzz
* where x is the major, y the minor and zzz the build number
*/
const char* ECOS_ver(void);
/* ------------------- EXPERT LEVEL INTERFACES ---------------------- */
/*
* Updates one element of the RHS vector h of inequalities
* After the call, w->h[idx] = value (but equilibrated)
*/
void ecos_updateDataEntry_h(pwork* w, idxint idx, pfloat value);
/*
* Updates one element of the OBJ vector c of inequalities
* After the call, w->c[idx] = value (but equilibrated)
*/
void ecos_updateDataEntry_c(pwork* w, idxint idx, pfloat value);
/*
* Updates numerical data for G, A, c, h, and b,
* and re-equilibrates.
* Then updates the corresponding KKT entries.
*/
void ECOS_updateData(pwork *w, pfloat *Gpr, pfloat *Apr,
pfloat* c, pfloat* h, pfloat* b);
#ifdef __cplusplus
}
#endif
#endif
|