cone.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. /* cone module */
  20. #ifndef __CONE_H__
  21. #define __CONE_H__
  22. #include "glblopts.h"
  23. #include "expcone.h"
  24. #define CONEMODE (0) /* 0: expand to sparse cones (ECOS standard) */
  25. /* 1: dense cones (slow for big cones) */
  26. /* 2: dense of fixed size */
  27. /* LP CONE ------------------------------------------------------------- */
  28. typedef struct lpcone{
  29. idxint p; /* dimension of cone */
  30. pfloat* w; /* scalings */
  31. pfloat* v; /* = w^2 - saves p multiplications */
  32. idxint* kkt_idx; /* indices of KKT matrix to which scalings w^2 map */
  33. } lpcone;
  34. /* SECOND-ORDER CONE --------------------------------------------------- */
  35. /* (all KKT indices are in compressed column format pointing into Kpr) */
  36. typedef struct socone{
  37. idxint p; /* dimension of cone */
  38. pfloat* skbar; /* temporary variables to work with */
  39. pfloat* zkbar; /* temporary variables to work with */
  40. pfloat a; /* = wbar(1) */
  41. pfloat d1; /* first element of D */
  42. pfloat w; /* = q'*q */
  43. pfloat eta; /* eta = (sres / zres)^(1/4) */
  44. pfloat eta_square; /* eta^2 = (sres / zres)^(1/2) */
  45. pfloat* q; /* = wbar(2:end) */
  46. #if CONEMODE == 0
  47. idxint* Didx; /* indices for D */
  48. pfloat u0; /* eta */
  49. pfloat u1; /* u = [u0; u1*q] */
  50. pfloat v1; /* v = [0; v1*q] */
  51. #endif
  52. #if CONEMODE > 0
  53. idxint* colstart; /* colstart[n] gives index in KKT matrix where
  54. the nth column of this scaling matrix in (3,3)
  55. block starts */
  56. pfloat c; /* = 1 + a + w/(1+a) */
  57. pfloat d; /* = 1 + 2/(1+a) + w/(1+a)^2 */
  58. #endif
  59. } socone;
  60. /* GENERAL STRUCTURE FOR A CONE ---------------------------------------- */
  61. typedef struct cone{
  62. lpcone* lpc; /* LP cone */
  63. socone* soc; /* Second-Order cone */
  64. idxint nsoc; /* number of second-order cones */
  65. #ifdef EXPCONE
  66. expcone* expc; /* array of exponential cones*/
  67. idxint nexc; /* number of exponential cones*/
  68. idxint fexv; /* Index of first slack variable
  69. * corresponding to an exponential cone */
  70. #endif
  71. } cone;
  72. /* ERROR CODES --------------------------------------------------------- */
  73. #define INSIDE_CONE (0)
  74. #define OUTSIDE_CONE (1)
  75. /* METHODS ------------------------------------------------------------- */
  76. /**
  77. * Scales a conic variable such that it lies strictly in the cone.
  78. * If it is already in the cone, r is simply copied to s.
  79. * Otherwise s = r + (1+alpha)*e where alpha is the biggest residual.
  80. */
  81. void bring2cone(cone* C, pfloat* r, pfloat* s);
  82. #ifdef EXPCONE
  83. /* When there are exponential variables in the definition of the problem
  84. * the initialization strategy changes to using the central ray for all
  85. * cones.
  86. */
  87. void unitInitialization(cone* C, pfloat* s, pfloat* z, pfloat scaling);
  88. #endif
  89. /**
  90. * Update scalings.
  91. * Returns OUTSIDE_CONE as soon as any multiplier or slack leaves the cone,
  92. * as this indicates severe problems.
  93. * When compiled with EXPCONE it calculates the value of muH(z_e) with
  94. * z_e the dual slacks for the exponential cone
  95. * and stores the Hessian in the cone structure.
  96. */
  97. #ifdef EXPCONE
  98. idxint updateScalings(cone* C, pfloat* s, pfloat* z, pfloat* lambda, pfloat mu);
  99. #else
  100. idxint updateScalings(cone* C, pfloat* s, pfloat* z, pfloat* lambda);
  101. #endif
  102. #ifdef EXPCONE
  103. pfloat evalSymmetricBarrierValue(pfloat* siter, pfloat *ziter, pfloat tauIter, pfloat kapIter, cone* C, pfloat D);
  104. #endif
  105. /**
  106. * Fast multiplication by scaling matrix.
  107. * Returns lambda = W*z
  108. */
  109. void scale(pfloat* z, cone* C, pfloat* lambda);
  110. /**
  111. * Fast multiplication with V := W^2.
  112. * Computes y += W^2*x;
  113. */
  114. void scale2add(pfloat *x, pfloat* y, cone* C);
  115. /**
  116. * Fast left-division by scaling matrix.
  117. * Returns z = W\lambda
  118. */
  119. void unscale(pfloat* lambda, cone* C, pfloat* z);
  120. /**
  121. * Conic product, implements the "o" operator, w = u o v
  122. * and returns e'*w (where e is the conic 1-vector)
  123. */
  124. pfloat conicProduct(pfloat* u, pfloat* v, cone* C, pfloat* w);
  125. /**
  126. * Conic division, implements the "\" operator, w = u \ v
  127. */
  128. void conicDivision(pfloat* u, pfloat* v, cone* C, pfloat* w);
  129. /*
  130. * Returns details on second order cone
  131. * Purpose: cleaner code
  132. */
  133. void getSOCDetails(socone *soc, idxint *conesize, pfloat* eta_square, pfloat* d1, pfloat* u0, pfloat* u1, pfloat* v1, pfloat **q);
  134. /*
  135. * Returns dx, dy and dz from the expanded and permuted version of
  136. * a search direction vector.
  137. */
  138. void unstretch(idxint n, idxint p, cone *C, idxint *Pinv, pfloat *Px, pfloat *dx, pfloat *dy, pfloat *dz);
  139. #endif