blob: 296aff82deacb824145027d1a5a2b671c48a1061 [file] [log] [blame]
Austin Schuh9049e202022-02-20 17:34:16 -08001#ifndef OSQP_H
2# define OSQP_H
3
4# ifdef __cplusplus
5extern "C" {
6# endif // ifdef __cplusplus
7
8/* Includes */
9# include "types.h"
10# include "util.h" // Needed for osqp_set_default_settings functions
11
12
13// Library to deal with sparse matrices enabled only if embedded not defined
14# ifndef EMBEDDED
15# include "cs.h"
16# endif // ifndef EMBEDDED
17
18/********************
19* Main Solver API *
20********************/
21
22/**
23 * @name Main solver API
24 * @{
25 */
26
27/**
28 * Set default settings from constants.h file
29 * assumes settings already allocated in memory
30 * @param settings settings structure
31 */
32void osqp_set_default_settings(OSQPSettings *settings);
33
34
35# ifndef EMBEDDED
36
37/**
38 * Initialize OSQP solver allocating memory.
39 *
40 * All the inputs must be already allocated in memory before calling.
41 *
42 * It performs:
43 * - data and settings validation
44 * - problem data scaling
45 * - automatic parameters tuning (if enabled)
46 * - setup linear system solver:
47 * - direct solver: KKT matrix factorization is performed here
48 * - indirect solver: KKT matrix preconditioning is performed here
49 *
50 * NB: This is the only function that allocates dynamic memory and is not used
51 *during code generation
52 *
53 * @param workp Solver workspace pointer
54 * @param data Problem data
55 * @param settings Solver settings
56 * @return Exitflag for errors (0 if no errors)
57 */
58c_int osqp_setup(OSQPWorkspace** workp, const OSQPData* data, const OSQPSettings* settings);
59
60# endif // #ifndef EMBEDDED
61
62/**
63 * Solve quadratic program
64 *
65 * The final solver information is stored in the \a work->info structure
66 *
67 * The solution is stored in the \a work->solution structure
68 *
69 * If the problem is primal infeasible, the certificate is stored
70 * in \a work->delta_y
71 *
72 * If the problem is dual infeasible, the certificate is stored in \a
73 * work->delta_x
74 *
75 * @param work Workspace allocated
76 * @return Exitflag for errors
77 */
78c_int osqp_solve(OSQPWorkspace *work);
79
80
81# ifndef EMBEDDED
82
83/**
84 * Cleanup workspace by deallocating memory
85 *
86 * This function is not used in code generation
87 * @param work Workspace
88 * @return Exitflag for errors
89 */
90c_int osqp_cleanup(OSQPWorkspace *work);
91
92# endif // ifndef EMBEDDED
93
94/** @} */
95
96
97/********************************************
98* Sublevel API *
99* *
100* Edit data without performing setup again *
101********************************************/
102
103/**
104 * @name Sublevel API
105 * @{
106 */
107
108/**
109 * Update linear cost in the problem
110 * @param work Workspace
111 * @param q_new New linear cost
112 * @return Exitflag for errors and warnings
113 */
114c_int osqp_update_lin_cost(OSQPWorkspace *work,
115 const c_float *q_new);
116
117
118/**
119 * Update lower and upper bounds in the problem constraints
120 * @param work Workspace
121 * @param l_new New lower bound
122 * @param u_new New upper bound
123 * @return Exitflag: 1 if new lower bound is not <= than new upper bound
124 */
125c_int osqp_update_bounds(OSQPWorkspace *work,
126 const c_float *l_new,
127 const c_float *u_new);
128
129
130/**
131 * Update lower bound in the problem constraints
132 * @param work Workspace
133 * @param l_new New lower bound
134 * @return Exitflag: 1 if new lower bound is not <= than upper bound
135 */
136c_int osqp_update_lower_bound(OSQPWorkspace *work,
137 const c_float *l_new);
138
139
140/**
141 * Update upper bound in the problem constraints
142 * @param work Workspace
143 * @param u_new New upper bound
144 * @return Exitflag: 1 if new upper bound is not >= than lower bound
145 */
146c_int osqp_update_upper_bound(OSQPWorkspace *work,
147 const c_float *u_new);
148
149
150/**
151 * Warm start primal and dual variables
152 * @param work Workspace structure
153 * @param x Primal variable
154 * @param y Dual variable
155 * @return Exitflag
156 */
157c_int osqp_warm_start(OSQPWorkspace *work,
158 const c_float *x,
159 const c_float *y);
160
161
162/**
163 * Warm start primal variable
164 * @param work Workspace structure
165 * @param x Primal variable
166 * @return Exitflag
167 */
168c_int osqp_warm_start_x(OSQPWorkspace *work,
169 const c_float *x);
170
171
172/**
173 * Warm start dual variable
174 * @param work Workspace structure
175 * @param y Dual variable
176 * @return Exitflag
177 */
178c_int osqp_warm_start_y(OSQPWorkspace *work,
179 const c_float *y);
180
181
182# if EMBEDDED != 1
183
184/**
185 * Update elements of matrix P (upper triangular)
186 * without changing sparsity structure.
187 *
188 *
189 * If Px_new_idx is OSQP_NULL, Px_new is assumed to be as long as P->x
190 * and the whole P->x is replaced.
191 *
192 * @param work Workspace structure
193 * @param Px_new Vector of new elements in P->x (upper triangular)
194 * @param Px_new_idx Index mapping new elements to positions in P->x
195 * @param P_new_n Number of new elements to be changed
196 * @return output flag: 0: OK
197 * 1: P_new_n > nnzP
198 * <0: error in the update
199 */
200c_int osqp_update_P(OSQPWorkspace *work,
201 const c_float *Px_new,
202 const c_int *Px_new_idx,
203 c_int P_new_n);
204
205
206/**
207 * Update elements of matrix A without changing sparsity structure.
208 *
209 *
210 * If Ax_new_idx is OSQP_NULL, Ax_new is assumed to be as long as A->x
211 * and the whole A->x is replaced.
212 *
213 * @param work Workspace structure
214 * @param Ax_new Vector of new elements in A->x
215 * @param Ax_new_idx Index mapping new elements to positions in A->x
216 * @param A_new_n Number of new elements to be changed
217 * @return output flag: 0: OK
218 * 1: A_new_n > nnzA
219 * <0: error in the update
220 */
221c_int osqp_update_A(OSQPWorkspace *work,
222 const c_float *Ax_new,
223 const c_int *Ax_new_idx,
224 c_int A_new_n);
225
226
227/**
228 * Update elements of matrix P (upper triangular) and elements of matrix A
229 * without changing sparsity structure.
230 *
231 *
232 * If Px_new_idx is OSQP_NULL, Px_new is assumed to be as long as P->x
233 * and the whole P->x is replaced.
234 *
235 * If Ax_new_idx is OSQP_NULL, Ax_new is assumed to be as long as A->x
236 * and the whole A->x is replaced.
237 *
238 * @param work Workspace structure
239 * @param Px_new Vector of new elements in P->x (upper triangular)
240 * @param Px_new_idx Index mapping new elements to positions in P->x
241 * @param P_new_n Number of new elements to be changed
242 * @param Ax_new Vector of new elements in A->x
243 * @param Ax_new_idx Index mapping new elements to positions in A->x
244 * @param A_new_n Number of new elements to be changed
245 * @return output flag: 0: OK
246 * 1: P_new_n > nnzP
247 * 2: A_new_n > nnzA
248 * <0: error in the update
249 */
250c_int osqp_update_P_A(OSQPWorkspace *work,
251 const c_float *Px_new,
252 const c_int *Px_new_idx,
253 c_int P_new_n,
254 const c_float *Ax_new,
255 const c_int *Ax_new_idx,
256 c_int A_new_n);
257
258/**
259 * Update rho. Limit it between RHO_MIN and RHO_MAX.
260 * @param work Workspace
261 * @param rho_new New rho setting
262 * @return Exitflag
263 */
264c_int osqp_update_rho(OSQPWorkspace *work,
265 c_float rho_new);
266
267# endif // if EMBEDDED != 1
268
269/** @} */
270
271
272/**
273 * @name Update settings
274 * @{
275 */
276
277
278/**
279 * Update max_iter setting
280 * @param work Workspace
281 * @param max_iter_new New max_iter setting
282 * @return Exitflag
283 */
284c_int osqp_update_max_iter(OSQPWorkspace *work,
285 c_int max_iter_new);
286
287
288/**
289 * Update absolute tolernace value
290 * @param work Workspace
291 * @param eps_abs_new New absolute tolerance value
292 * @return Exitflag
293 */
294c_int osqp_update_eps_abs(OSQPWorkspace *work,
295 c_float eps_abs_new);
296
297
298/**
299 * Update relative tolernace value
300 * @param work Workspace
301 * @param eps_rel_new New relative tolerance value
302 * @return Exitflag
303 */
304c_int osqp_update_eps_rel(OSQPWorkspace *work,
305 c_float eps_rel_new);
306
307
308/**
309 * Update primal infeasibility tolerance
310 * @param work Workspace
311 * @param eps_prim_inf_new New primal infeasibility tolerance
312 * @return Exitflag
313 */
314c_int osqp_update_eps_prim_inf(OSQPWorkspace *work,
315 c_float eps_prim_inf_new);
316
317
318/**
319 * Update dual infeasibility tolerance
320 * @param work Workspace
321 * @param eps_dual_inf_new New dual infeasibility tolerance
322 * @return Exitflag
323 */
324c_int osqp_update_eps_dual_inf(OSQPWorkspace *work,
325 c_float eps_dual_inf_new);
326
327
328/**
329 * Update relaxation parameter alpha
330 * @param work Workspace
331 * @param alpha_new New relaxation parameter value
332 * @return Exitflag
333 */
334c_int osqp_update_alpha(OSQPWorkspace *work,
335 c_float alpha_new);
336
337
338/**
339 * Update warm_start setting
340 * @param work Workspace
341 * @param warm_start_new New warm_start setting
342 * @return Exitflag
343 */
344c_int osqp_update_warm_start(OSQPWorkspace *work,
345 c_int warm_start_new);
346
347
348/**
349 * Update scaled_termination setting
350 * @param work Workspace
351 * @param scaled_termination_new New scaled_termination setting
352 * @return Exitflag
353 */
354c_int osqp_update_scaled_termination(OSQPWorkspace *work,
355 c_int scaled_termination_new);
356
357/**
358 * Update check_termination setting
359 * @param work Workspace
360 * @param check_termination_new New check_termination setting
361 * @return Exitflag
362 */
363c_int osqp_update_check_termination(OSQPWorkspace *work,
364 c_int check_termination_new);
365
366
367# ifndef EMBEDDED
368
369/**
370 * Update regularization parameter in polish
371 * @param work Workspace
372 * @param delta_new New regularization parameter
373 * @return Exitflag
374 */
375c_int osqp_update_delta(OSQPWorkspace *work,
376 c_float delta_new);
377
378
379/**
380 * Update polish setting
381 * @param work Workspace
382 * @param polish_new New polish setting
383 * @return Exitflag
384 */
385c_int osqp_update_polish(OSQPWorkspace *work,
386 c_int polish_new);
387
388
389/**
390 * Update number of iterative refinement steps in polish
391 * @param work Workspace
392 * @param polish_refine_iter_new New iterative reginement steps
393 * @return Exitflag
394 */
395c_int osqp_update_polish_refine_iter(OSQPWorkspace *work,
396 c_int polish_refine_iter_new);
397
398
399/**
400 * Update verbose setting
401 * @param work Workspace
402 * @param verbose_new New verbose setting
403 * @return Exitflag
404 */
405c_int osqp_update_verbose(OSQPWorkspace *work,
406 c_int verbose_new);
407
408
409# endif // #ifndef EMBEDDED
410
411# ifdef PROFILING
412
413/**
414 * Update time_limit setting
415 * @param work Workspace
416 * @param time_limit_new New time_limit setting
417 * @return Exitflag
418 */
419c_int osqp_update_time_limit(OSQPWorkspace *work,
420 c_float time_limit_new);
421# endif // ifdef PROFILING
422
423/** @} */
424
425
426# ifdef __cplusplus
427}
428# endif // ifdef __cplusplus
429
430#endif // ifndef OSQP_H