active_set.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
  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_ACTIVE_SET_H
  9. #define IGL_ACTIVE_SET_H
  10. #include "igl_inline.h"
  11. #include "SolverStatus.h"
  12. #include <Eigen/Core>
  13. #include <Eigen/Sparse>
  14. namespace igl
  15. {
  16. struct active_set_params;
  17. // Known Bugs: rows of [Aeq;Aieq] **must** be linearly independent. Should be
  18. // using QR decomposition otherwise:
  19. // http://www.okstate.edu/sas/v8/sashtml/ormp/chap5/sect32.htm
  20. //
  21. // ACTIVE_SET Minimize quadratic energy
  22. //
  23. // 0.5*Z'*A*Z + Z'*B + C with constraints
  24. //
  25. // that Z(known) = Y, optionally also subject to the constraints Aeq*Z = Beq,
  26. // and further optionally subject to the linear inequality constraints that
  27. // Aieq*Z <= Bieq and constant inequality constraints lx <= x <= ux
  28. //
  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 inequality constraint coefficients
  37. // Bieq mieq by 1 list of linear inequality 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. // Z if not empty, is taken to be an n by 1 list of initial guess values
  42. // (see output)
  43. // Outputs:
  44. // Z n by 1 list of solution values
  45. // Returns true on success, false on error
  46. //
  47. // Benchmark: For a harmonic solve on a mesh with 325K facets, matlab 2.2
  48. // secs, igl/min_quad_with_fixed.h 7.1 secs
  49. //
  50. template <
  51. typename AT,
  52. typename DerivedB,
  53. typename Derivedknown,
  54. typename DerivedY,
  55. typename AeqT,
  56. typename DerivedBeq,
  57. typename AieqT,
  58. typename DerivedBieq,
  59. typename Derivedlx,
  60. typename Derivedux,
  61. typename DerivedZ
  62. >
  63. IGL_INLINE igl::SolverStatus active_set(
  64. const Eigen::SparseMatrix<AT>& A,
  65. const Eigen::PlainObjectBase<DerivedB> & B,
  66. const Eigen::PlainObjectBase<Derivedknown> & known,
  67. const Eigen::PlainObjectBase<DerivedY> & Y,
  68. const Eigen::SparseMatrix<AeqT>& Aeq,
  69. const Eigen::PlainObjectBase<DerivedBeq> & Beq,
  70. const Eigen::SparseMatrix<AieqT>& Aieq,
  71. const Eigen::PlainObjectBase<DerivedBieq> & Bieq,
  72. const Eigen::PlainObjectBase<Derivedlx> & lx,
  73. const Eigen::PlainObjectBase<Derivedux> & ux,
  74. const igl::active_set_params & params,
  75. Eigen::PlainObjectBase<DerivedZ> & Z
  76. );
  77. };
  78. #include "EPS.h"
  79. struct igl::active_set_params
  80. {
  81. // Input parameters for active_set:
  82. // Auu_pd whether Auu is positive definite {false}
  83. // max_iter Maximum number of iterations (0 = Infinity, {100})
  84. // inactive_threshold Threshold on Lagrange multiplier values to determine
  85. // whether to keep constraints active {EPS}
  86. // constraint_threshold Threshold on whether constraints are violated (0
  87. // is perfect) {EPS}
  88. // solution_diff_threshold Threshold on the squared norm of the difference
  89. // between two consecutive solutions {EPS}
  90. bool Auu_pd;
  91. int max_iter;
  92. double inactive_threshold;
  93. double constraint_threshold;
  94. double solution_diff_threshold;
  95. active_set_params():
  96. Auu_pd(false),
  97. max_iter(100),
  98. inactive_threshold(igl::DOUBLE_EPS),
  99. constraint_threshold(igl::DOUBLE_EPS),
  100. solution_diff_threshold(igl::DOUBLE_EPS)
  101. {};
  102. };
  103. #ifndef IGL_STATIC_LIBRARY
  104. # include "active_set.cpp"
  105. #endif
  106. #endif