blob: 9560d5ecbf4e26e77aabb315a78257adf560378f [file] [log] [blame]
Austin Schuh9049e202022-02-20 17:34:16 -08001#ifndef KKT_H
2# define KKT_H
3
4# ifdef __cplusplus
5extern "C" {
6# endif // ifdef __cplusplus
7
8# include "types.h"
9
10# ifndef EMBEDDED
11
12# include "cs.h"
13
14/**
15 * Form square symmetric KKT matrix of the form
16 *
17 * [P + param1 I, A';
18 * A -diag(param2)]
19 *
20 * NB: Only the upper triangular part is stuffed!
21 *
22 *
23 * If Pdiag_idx is not OSQP_NULL, it saves the index of the diagonal
24 * elements of P there and the number of diagonal elements in Pdiag_n.
25 *
26 * Similarly, if rhotoKKT is not null,
27 * it saves where the values of param2 go in the final KKT matrix
28 *
29 * NB: Pdiag_idx needs to be freed!
30 *
31 * @param P cost matrix (already just upper triangular part)
32 * @param A linear constraint matrix
33 * @param format CSC (0) or CSR (1)
34 * @param param1 regularization parameter
35 * @param param2 regularization parameter (vector)
36 * @param PtoKKT (modified) index mapping from elements of P to KKT matrix
37 * @param AtoKKT (modified) index mapping from elements of A to KKT matrix
38 * @param Pdiag_idx (modified) Address of the index of diagonal elements in P
39 * @param Pdiag_n (modified) Address to the number of diagonal elements in P
40 * @param param2toKKT (modified) index mapping from param2 to elements of
41 *KKT
42 * @return return status flag
43 */
44csc* form_KKT(const csc *P,
45 const csc *A,
46 c_int format,
47 c_float param1,
48 c_float *param2,
49 c_int *PtoKKT,
50 c_int *AtoKKT,
51 c_int **Pdiag_idx,
52 c_int *Pdiag_n,
53 c_int *param2toKKT);
54# endif // ifndef EMBEDDED
55
56
57# if EMBEDDED != 1
58
59/**
60 * Update KKT matrix using the elements of P
61 *
62 * @param KKT KKT matrix in CSC form (upper-triangular)
63 * @param P P matrix in CSC form (upper-triangular)
64 * @param PtoKKT Vector of pointers from P->x to KKT->x
65 * @param param1 Parameter added to the diagonal elements of P
66 * @param Pdiag_idx Index of diagonal elements in P->x
67 * @param Pdiag_n Number of diagonal elements of P
68 */
69void update_KKT_P(csc *KKT,
70 const csc *P,
71 const c_int *PtoKKT,
72 const c_float param1,
73 const c_int *Pdiag_idx,
74 const c_int Pdiag_n);
75
76
77/**
78 * Update KKT matrix using the elements of A
79 *
80 * @param KKT KKT matrix in CSC form (upper-triangular)
81 * @param A A matrix in CSC form (upper-triangular)
82 * @param AtoKKT Vector of pointers from A->x to KKT->x
83 */
84void update_KKT_A(csc *KKT,
85 const csc *A,
86 const c_int *AtoKKT);
87
88
89/**
90 * Update KKT matrix with new param2
91 *
92 * @param KKT KKT matrix
93 * @param param2 Parameter of the KKT matrix (vector)
94 * @param param2toKKT index where param2 enters in the KKT matrix
95 * @param m number of constraints
96 */
97void update_KKT_param2(csc *KKT,
98 const c_float *param2,
99 const c_int *param2toKKT,
100 const c_int m);
101
102# endif // EMBEDDED != 1
103
104
105# ifdef __cplusplus
106}
107# endif // ifdef __cplusplus
108
109#endif // ifndef KKT_H