kkt_inverse.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #ifndef IGL_KKT_INVERSE_H
  9. #define IGL_KKT_INVERSE_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Dense>
  12. //// debug
  13. //#include <matlabinterface.h>
  14. //Engine *g_pEngine;
  15. namespace igl
  16. {
  17. /// Constructs the inverse of the KKT matrix of a convex, linear equality
  18. /// constrained quadratic minimization problem.
  19. ///
  20. /// Systems of the form:
  21. ///
  22. /// ╱ A Aeqᵀ ╲ ╱ x ╲ = ╱ b ╲
  23. /// ╲ Aeq 0 ╱ ╲ λ ╱ ╲ beq ╱
  24. /// ╲_____.______╱╲__.__╱ ╲___.___╱
  25. /// M z c
  26. ///
  27. /// Arise, for example, when solve convex, linear equality constrained
  28. /// quadratic minimization problems:
  29. ///
  30. /// min ½ xᵀ A x - xᵀb subject to Aeq x = beq
  31. ///
  32. /// This function constructs a matrix S such that x = S c solves the system
  33. /// above. That is:
  34. ///
  35. /// S = [In 0] M⁻¹
  36. ///
  37. /// so that
  38. ///
  39. /// x = S c
  40. ///
  41. /// @tparam T should be a eigen matrix primitive type like float or double
  42. /// @param[in] A n by n matrix of quadratic coefficients
  43. /// @param[in] B n by 1 column of linear coefficients
  44. /// @param[in] Aeq m by n list of linear equality constraint coefficients
  45. /// @param[in] Beq m by 1 list of linear equality constraint constant values
  46. /// @param[in] use_lu_decomposition use lu rather than SVD
  47. /// @param[out] S n by (n + m) "solve" matrix, such that S*[B', Beq'] is a solution
  48. /// @return true on success, false on error
  49. template <typename T>
  50. IGL_INLINE void kkt_inverse(
  51. const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>& A,
  52. const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>& Aeq,
  53. const bool use_lu_decomposition,
  54. Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>& S);
  55. }
  56. #ifndef IGL_STATIC_LIBRARY
  57. # include "kkt_inverse.cpp"
  58. #endif
  59. #endif