kkt.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * ECOS - Embedded Conic Solver.
  3. * Copyright (C) 2012-2015 A. Domahidi [domahidi@embotech.com],
  4. * Automatic Control Lab, ETH Zurich & embotech GmbH, Zurich, Switzerland.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /* The KKT module.
  20. * Handles all computation related to KKT matrix:
  21. * - updating the matrix
  22. * - its factorization
  23. * - solving for search directions
  24. * - etc.
  25. */
  26. #ifndef __KKT_H__
  27. #define __KKT_H__
  28. #include "glblopts.h"
  29. #include "spla.h"
  30. #include "cone.h"
  31. typedef struct kkt{
  32. spmat* PKPt; /* Permuted KKT matrix, upper part only */
  33. spmat* L; /* LDL factor L */
  34. pfloat* D; /* diagonal matrix D */
  35. pfloat* work1; /* workspace needed for factorization */
  36. pfloat* work2; /* workspace needed for factorization */
  37. pfloat* work3; /* workspace needed for factorization */
  38. pfloat* work4; /* workspace needed for factorization */
  39. pfloat* work5; /* workspace needed for factorization */
  40. pfloat* work6; /* workspace needed for factorization */
  41. pfloat* RHS1; /* Right hand side 1 */
  42. pfloat* RHS2; /* Right hand side 2 */
  43. pfloat* dx1; /* search direction of size n */
  44. pfloat* dx2; /* search direction of size n */
  45. pfloat* dy1; /* search direction of size p */
  46. pfloat* dy2; /* search direction of size p */
  47. pfloat* dz1; /* search direction of size m */
  48. pfloat* dz2; /* search direction of size m */
  49. idxint* P; /* permutation */
  50. idxint* Pinv; /* reverse permutation */
  51. idxint* PK; /* permutation of row indices of KKT matrix */
  52. idxint* Parent; /* Elimination tree of factorization */
  53. idxint* Sign; /* Permuted sign vector for regularization */
  54. idxint* Pattern; /* idxint workspace needed for factorization */
  55. idxint* Flag; /* idxint workspace needed for factorization */
  56. idxint* Lnz; /* idxint workspace needed for factorization */
  57. pfloat delta; /* size of regularization */
  58. } kkt;
  59. /* Return codes */
  60. #define KKT_PROBLEM (0)
  61. #define KKT_OK (1)
  62. /* METHODS */
  63. /**
  64. * Factorization of KKT matrix. Just a convenient wrapper for the LDL call.
  65. * The second argument delta determindes the threshold of dynamic regularization,
  66. * while the last argument is the regularization parameter if it becomes active.
  67. *
  68. * If detailed profiling is turned on, the function returns the accumulated times
  69. * for sparsity pattern computation in t1 and for numerical solve in t2.
  70. */
  71. #if PROFILING > 1
  72. idxint kkt_factor(kkt* KKT, pfloat eps, pfloat delta, pfloat *t1, pfloat *t2);
  73. #else
  74. idxint kkt_factor(kkt* KKT, pfloat eps, pfloat delta);
  75. #endif
  76. /**
  77. * Solves the permuted KKT system and returns the unpermuted search directions.
  78. *
  79. * On entry, the factorization of the permuted KKT matrix, PKPt,
  80. * is assumed to be up to date (call kkt_factor beforehand to achieve this).
  81. * The right hand side, Pb, is assumed to be already permuted.
  82. *
  83. * On exit, the resulting search directions are written into dx, dy and dz,
  84. * where these variables are permuted back to the original ordering.
  85. *
  86. * KKT->nitref iterative refinement steps are applied to solve the linear system.
  87. *
  88. * Returns the number of iterative refinement steps really taken.
  89. */
  90. idxint kkt_solve(kkt* KKT,
  91. spmat* A, spmat* G,
  92. pfloat* Pb,
  93. pfloat* dx, pfloat* dy, pfloat* dz,
  94. idxint n, idxint p, idxint m,
  95. cone* C,
  96. idxint isinit,
  97. idxint nitref);
  98. /**
  99. * Updates the permuted KKT matrix by copying in the new scalings.
  100. */
  101. void kkt_update(spmat* PKP, idxint* P, cone *C);
  102. /**
  103. * Initializes the (3,3) block of the KKT matrix to produce the matrix
  104. *
  105. * [0 A' G']
  106. * K = [A 0 0 ]
  107. * [G 0 -I ]
  108. *
  109. * It is assumed that the A,G have been already copied in appropriately,
  110. * and that enough memory has been allocated (this is done in preproc.c module).
  111. *
  112. * Note that the function works on the permuted KKT matrix.
  113. */
  114. void kkt_init(spmat* PKP, idxint* P, cone *C);
  115. #endif