quadprog.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef IGL_QUADPROG_H
  2. #define IGL_QUADPROG_H
  3. #include "igl_inline.h"
  4. #include <Eigen/Core>
  5. namespace igl
  6. {
  7. /// Solve a convex quadratic program. Optimized for small dense problems.
  8. /// Still works for Eigen::Dynamic (and then everything needs to be Dynamic).
  9. ///
  10. /// min_x ½ xᵀ H x + xᵀf
  11. /// subject to:
  12. /// lbi ≤ Ai x ≤ ubi
  13. /// lb ≤ x ≤ u
  14. ///
  15. /// @tparam Scalar (e.g., double)
  16. /// @tparam n #H or Eigen::Dynamic if not known at compile time
  17. /// @tparam ni #Ai or Eigen::Dynamic if not known at compile time
  18. /// @param[in] H #H by #H quadratic coefficients (only lower triangle used)
  19. /// @param[in] f #H linear coefficients
  20. /// @param[in] Ai #Ai by #H list of linear equality constraint coefficients
  21. /// @param[in] lbi #Ai list of linear equality lower bounds
  22. /// @param[in] ubi #Ai list of linear equality upper bounds
  23. /// @param[in] lb #H list of lower bounds
  24. /// @param[in] ub #H list of lower bounds
  25. /// @return #H-long solution x
  26. template <typename Scalar, int n, int ni>
  27. IGL_INLINE Eigen::Matrix<Scalar,n,1> quadprog(
  28. const Eigen::Matrix<Scalar,n,n> & H,
  29. const Eigen::Matrix<Scalar,n,1> & f,
  30. const Eigen::Matrix<Scalar,ni,n> & Ai,
  31. const Eigen::Matrix<Scalar,ni,1> & lbi,
  32. const Eigen::Matrix<Scalar,ni,1> & ubi,
  33. const Eigen::Matrix<Scalar,n,1> & lb,
  34. const Eigen::Matrix<Scalar,n,1> & ub);
  35. /// Solve a convex quadratic program. Optimized for small dense problems. All
  36. /// inequalities must be simple bounds.
  37. ///
  38. /// min_x ½ xᵀ H x + xᵀf
  39. /// subject to:
  40. /// A x = b
  41. /// lb ≤ x ≤ u
  42. ///
  43. /// @tparam Scalar (e.g., double)
  44. /// @tparam n #H or Eigen::Dynamic if not known at compile time
  45. /// @tparam m #A or Eigen::Dynamic if not known at compile time
  46. /// @param[in] H #H by #H quadratic coefficients (only lower triangle used)
  47. /// @param[in] f #H linear coefficients
  48. /// @param[in] A #A by #H list of linear equality constraint coefficients
  49. /// @param[in] b #A list of linear equality lower bounds
  50. /// @param[in] lb #H list of lower bounds
  51. /// @param[in] ub #H list of lower bounds
  52. /// @return #H-long solution x
  53. template <typename Scalar, int n, int m>
  54. IGL_INLINE Eigen::Matrix<Scalar,n,1> quadprog(
  55. const Eigen::Matrix<Scalar,n,n> & H,
  56. const Eigen::Matrix<Scalar,n,1> & f,
  57. const Eigen::Matrix<Scalar,m,n> & A,
  58. const Eigen::Matrix<Scalar,m,1> & b,
  59. const Eigen::Matrix<Scalar,n,1> & lb,
  60. const Eigen::Matrix<Scalar,n,1> & ub);
  61. /// Solve a convex quadratic program. Optimized for small dense problems. All
  62. /// constraints must be simple bounds.
  63. ///
  64. /// min_x ½ xᵀ H x + xᵀf
  65. /// subject to:
  66. /// lb ≤ x ≤ u
  67. ///
  68. /// @tparam Scalar (e.g., double)
  69. /// @tparam n #H or Eigen::Dynamic if not known at compile time
  70. /// @param[in] H #H by #H quadratic coefficients (only lower triangle used)
  71. /// @param[in] f #H linear coefficients
  72. /// @param[in] lb #H list of lower bounds
  73. /// @param[in] ub #H list of lower bounds
  74. /// @return #H-long solution x
  75. template <typename Scalar, int n>
  76. IGL_INLINE Eigen::Matrix<Scalar,n,1> quadprog(
  77. const Eigen::Matrix<Scalar,n,n> & H,
  78. const Eigen::Matrix<Scalar,n,1> & f,
  79. const Eigen::Matrix<Scalar,n,1> & lb,
  80. const Eigen::Matrix<Scalar,n,1> & ub);
  81. }
  82. #ifndef IGL_STATIC_LIBRARY
  83. # include "quadprog.cpp"
  84. #endif
  85. #endif