min_quad_with_fixed.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef IGL_MIN_QUAD_WITH_FIXED_H
  2. #define IGL_MIN_QUAD_WITH_FIXED_H
  3. #include "igl_inline.h"
  4. #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
  5. #include <Eigen/Core>
  6. #include <Eigen/Dense>
  7. #include <Eigen/Sparse>
  8. #include <Eigen/SparseExtra>
  9. namespace igl
  10. {
  11. template <typename T>
  12. struct min_quad_with_fixed_data;
  13. // MIN_QUAD_WITH_FIXED Minimize quadratic energy Z'*A*Z + Z'*B + C with
  14. // constraints that Z(known) = Y, optionally also subject to the constraints
  15. // Aeq*Z = Beq
  16. //
  17. // Templates:
  18. // T should be a eigen matrix primitive type like int or double
  19. // Inputs:
  20. // A n by n matrix of quadratic coefficients
  21. // B n by 1 column of linear coefficients
  22. // known list of indices to known rows in Z
  23. // Y list of fixed values corresponding to known rows in Z
  24. // Optional:
  25. // Aeq m by n list of linear equality constraint coefficients
  26. // Beq m by 1 list of linear equality constraint constant values
  27. // pd flag specifying whether A(unknown,unknown) is positive definite
  28. // Outputs:
  29. // data factorization struct with all necessary information to solve
  30. // using min_quad_with_fixed_solve
  31. // Returns true on success, false on error
  32. template <typename T>
  33. IGL_INLINE bool min_quad_with_fixed_precompute(
  34. const Eigen::SparseMatrix<T>& A,
  35. const Eigen::Matrix<int,Eigen::Dynamic,1> & known,
  36. const Eigen::SparseMatrix<T>& Aeq,
  37. const bool pd,
  38. min_quad_with_fixed_data<T> & data
  39. );
  40. // Solves a system previously factored using min_quad_with_fixed_precompute
  41. // Inputs:
  42. // data factorization struct with all necessary precomputation to solve
  43. // Outputs:
  44. // Z n by cols solution
  45. // Returns true on success, false on error
  46. template <typename T>
  47. IGL_INLINE bool min_quad_with_fixed_solve(
  48. const min_quad_with_fixed_data<T> & data,
  49. const Eigen::Matrix<T,Eigen::Dynamic,1> & B,
  50. const Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & Y,
  51. const Eigen::Matrix<T,Eigen::Dynamic,1> & Beq,
  52. Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & Z);
  53. }
  54. template <typename T>
  55. struct igl::min_quad_with_fixed_data
  56. {
  57. // Size of original system: number of unknowns + number of knowns
  58. int n;
  59. // Whether A(unknown,unknown) is positive definite
  60. bool Auu_pd;
  61. // Whether A(unknown,unknown) is symmetric
  62. bool Auu_sym;
  63. // Indices of known variables
  64. Eigen::Matrix<int,Eigen::Dynamic,1> known;
  65. // Indices of unknown variables
  66. Eigen::Matrix<int,Eigen::Dynamic,1> unknown;
  67. // Indices of lagrange variables
  68. Eigen::Matrix<int,Eigen::Dynamic,1> lagrange;
  69. // Indices of unknown variable followed by Indices of lagrange variables
  70. Eigen::Matrix<int,Eigen::Dynamic,1> unknown_lagrange;
  71. // Matrix multiplied against Y when constructing right hand side
  72. Eigen::SparseMatrix<T> preY;
  73. // Tells whether system is sparse
  74. bool sparse;
  75. // Lower triangle of LU decomposition of final system matrix
  76. Eigen::SparseMatrix<T> L;
  77. // Upper triangle of LU decomposition of final system matrix
  78. Eigen::SparseMatrix<T> U;
  79. // Dense LU factorization
  80. Eigen::FullPivLU<Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> > lu;
  81. };
  82. #ifdef IGL_HEADER_ONLY
  83. # include "min_quad_with_fixed.cpp"
  84. #endif
  85. #endif