kkt.h 3.2 KB

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