active_set.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #ifndef IGL_ACTIVE_SET_H
  2. #define IGL_ACTIVE_SET_H
  3. #include "igl_inline.h"
  4. #include "SolverStatus.h"
  5. #include <Eigen/Core>
  6. #include <Eigen/Sparse>
  7. namespace igl
  8. {
  9. struct active_set_params;
  10. // Known Bugs: rows of [Aeq;Aieq] **must** be linearly independent. Should be
  11. // using QR decomposition otherwise:
  12. // http://www.okstate.edu/sas/v8/sashtml/ormp/chap5/sect32.htm
  13. //
  14. // ACTIVE_SET Minimize quadratic energy Z'*A*Z + Z'*B + C with constraints
  15. // that Z(known) = Y, optionally also subject to the constraints Aeq*Z = Beq,
  16. // and further optionally subject to the linear inequality constraints that
  17. // Aieq*Z <= Bieq and constant inequality constraints lx <= x <= ux
  18. //
  19. // Templates:
  20. // Inputs:
  21. // A n by n matrix of quadratic coefficients
  22. // B n by 1 column of linear coefficients
  23. // known list of indices to known rows in Z
  24. // Y list of fixed values corresponding to known rows in Z
  25. // Aeq meq by n list of linear equality constraint coefficients
  26. // Beq meq by 1 list of linear equality constraint constant values
  27. // Aieq mieq by n list of linear equality constraint coefficients
  28. // Bieq mieq by 1 list of linear equality constraint constant values
  29. // lx n by 1 list of lower bounds [] implies -Inf
  30. // ux n by 1 list of upper bounds [] implies Inf
  31. // params struct of additional parameters (see below)
  32. // Outputs:
  33. // Z n by 1 list of solution values
  34. // Returns true on success, false on error
  35. //
  36. // Benchmark: For a harmonic solve on a mesh with 325K facets, matlab 2.2
  37. // secs, igl/min_quad_with_fixed.h 7.1 secs
  38. //
  39. template <
  40. typename AT,
  41. typename DerivedB,
  42. typename Derivedknown,
  43. typename DerivedY,
  44. typename AeqT,
  45. typename DerivedBeq,
  46. typename AieqT,
  47. typename DerivedBieq,
  48. typename Derivedlx,
  49. typename Derivedux,
  50. typename DerivedZ
  51. >
  52. IGL_INLINE igl::SolverStatus active_set(
  53. const Eigen::SparseMatrix<AT>& A,
  54. const Eigen::PlainObjectBase<DerivedB> & B,
  55. const Eigen::PlainObjectBase<Derivedknown> & known,
  56. const Eigen::PlainObjectBase<DerivedY> & Y,
  57. const Eigen::SparseMatrix<AeqT>& Aeq,
  58. const Eigen::PlainObjectBase<DerivedBeq> & Beq,
  59. const Eigen::SparseMatrix<AieqT>& Aieq,
  60. const Eigen::PlainObjectBase<DerivedBieq> & Bieq,
  61. const Eigen::PlainObjectBase<Derivedlx> & lx,
  62. const Eigen::PlainObjectBase<Derivedux> & ux,
  63. const igl::active_set_params & params,
  64. Eigen::PlainObjectBase<DerivedZ> & Z
  65. );
  66. };
  67. #include "EPS.h"
  68. struct igl::active_set_params
  69. {
  70. // Input parameters for active_set:
  71. // Auu_pd whether Auu is positive definite {false}
  72. // max_iter Maximum number of iterations ({0} = Infinity)
  73. // inactive_threshold Threshold on Lagrange multiplier values to determine
  74. // whether to keep constraints active {EPS}
  75. // constraint_threshold Threshold on whether constraints are violated (0
  76. // is perfect) {EPS}
  77. // solution_diff_threshold Threshold on the squared norm of the difference
  78. // between two consecutive solutions {EPS}
  79. bool Auu_pd;
  80. int max_iter;
  81. double inactive_threshold;
  82. double constraint_threshold;
  83. double solution_diff_threshold;
  84. active_set_params():
  85. Auu_pd(false),
  86. max_iter(-1),
  87. inactive_threshold(igl::DOUBLE_EPS),
  88. constraint_threshold(igl::DOUBLE_EPS),
  89. solution_diff_threshold(igl::DOUBLE_EPS)
  90. {};
  91. };
  92. #ifdef IGL_HEADER_ONLY
  93. # include "active_set.cpp"
  94. #endif
  95. #endif