active_set.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. // ACTIVE_SET Minimize quadratic energy Z'*A*Z + Z'*B + C with constraints
  20. // that Z(known) = Y, optionally also subject to the constraints Aeq*Z = Beq,
  21. // and further optionally subject to the linear inequality constraints that
  22. // Aieq*Z <= Bieq and constant inequality constraints lx <= x <= ux
  23. //
  24. // Templates:
  25. // Inputs:
  26. // A n by n matrix of quadratic coefficients
  27. // B n by 1 column of linear coefficients
  28. // known list of indices to known rows in Z
  29. // Y list of fixed values corresponding to known rows in Z
  30. // Aeq meq by n list of linear equality constraint coefficients
  31. // Beq meq by 1 list of linear equality constraint constant values
  32. // Aieq mieq by n list of linear equality constraint coefficients
  33. // Bieq mieq by 1 list of linear equality constraint constant values
  34. // lx n by 1 list of lower bounds [] implies -Inf
  35. // ux n by 1 list of upper bounds [] implies Inf
  36. // params struct of additional parameters (see below)
  37. // Outputs:
  38. // Z n by 1 list of solution values
  39. // Returns true on success, false on error
  40. //
  41. // Benchmark: For a harmonic solve on a mesh with 325K facets, matlab 2.2
  42. // secs, igl/min_quad_with_fixed.h 7.1 secs
  43. //
  44. template <
  45. typename AT,
  46. typename DerivedB,
  47. typename Derivedknown,
  48. typename DerivedY,
  49. typename AeqT,
  50. typename DerivedBeq,
  51. typename AieqT,
  52. typename DerivedBieq,
  53. typename Derivedlx,
  54. typename Derivedux,
  55. typename DerivedZ
  56. >
  57. IGL_INLINE igl::SolverStatus active_set(
  58. const Eigen::SparseMatrix<AT>& A,
  59. const Eigen::PlainObjectBase<DerivedB> & B,
  60. const Eigen::PlainObjectBase<Derivedknown> & known,
  61. const Eigen::PlainObjectBase<DerivedY> & Y,
  62. const Eigen::SparseMatrix<AeqT>& Aeq,
  63. const Eigen::PlainObjectBase<DerivedBeq> & Beq,
  64. const Eigen::SparseMatrix<AieqT>& Aieq,
  65. const Eigen::PlainObjectBase<DerivedBieq> & Bieq,
  66. const Eigen::PlainObjectBase<Derivedlx> & lx,
  67. const Eigen::PlainObjectBase<Derivedux> & ux,
  68. const igl::active_set_params & params,
  69. Eigen::PlainObjectBase<DerivedZ> & Z
  70. );
  71. };
  72. #include "EPS.h"
  73. struct igl::active_set_params
  74. {
  75. // Input parameters for active_set:
  76. // Auu_pd whethter Auu is positive definite {false}
  77. // max_iter Maximum number of iterations ({0} = Infinity)
  78. // inactive_threshold Threshold on Lagrange multiplier values to determine
  79. // whether to keep constraints active {EPS}
  80. bool Auu_pd;
  81. int max_iter;
  82. double inactive_threshold;
  83. active_set_params():
  84. Auu_pd(false),
  85. max_iter(-1),
  86. inactive_threshold(igl::DOUBLE_EPS)
  87. {};
  88. };
  89. #ifdef IGL_HEADER_ONLY
  90. # include "active_set.cpp"
  91. #endif
  92. #endif