active_set.h 3.5 KB

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