mosek_quadprog.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #ifndef IGL_MOSEK_QUADPROG_H
  2. #define IGL_MOSEK_QUADPROG_H
  3. #include "../igl_inline.h"
  4. #include <vector>
  5. namespace igl
  6. {
  7. // Solve a convex quadratic optimization problem with linear and constant
  8. // bounds, that is:
  9. //
  10. // Minimize: ½ * xT * Q⁰ * x + cT * x + cf
  11. //
  12. // Subject to: lc ≤ Ax ≤ uc
  13. // lx ≤ x ≤ ux
  14. //
  15. // where we are trying to find the optimal vector of values x.
  16. //
  17. // Note: Q⁰ must be symmetric and the ½ is a convention of MOSEK
  18. //
  19. // Note: Because of how MOSEK accepts different parts of the system, Q should
  20. // be stored in IJV (aka Coordinate) format and should only include entries in
  21. // the lower triangle. A should be stored in Column compressed (aka Harwell
  22. // Boeing) format. As described:
  23. // http://netlib.org/linalg/html_templates/node92.html
  24. // or
  25. // http://en.wikipedia.org/wiki/Sparse_matrix
  26. // #Compressed_sparse_column_.28CSC_or_CCS.29
  27. //
  28. //
  29. // Templates:
  30. // Index type for index variables
  31. // Scalar type for floating point variables (gets cast to double?)
  32. // Input:
  33. // n number of variables, i.e. size of x
  34. // Qi vector of qnnz row indices of non-zeros in LOWER TRIANGLE ONLY of Q⁰
  35. // Qj vector of qnnz column indices of non-zeros in LOWER TRIANGLE ONLY of
  36. // Q⁰
  37. // Qv vector of qnnz values of non-zeros in LOWER TRIANGLE ONLY of Q⁰,
  38. // such that:
  39. // Q⁰(Qi[k],Qj[k]) = Qv[k] for k ∈ [0,Qnnz-1], where Qnnz is the number of
  40. // non-zeros in Q⁰
  41. // c (optional) vector of n values of c, transpose of coefficient row vector
  42. // of linear terms, EMPTY means c == 0
  43. // cf (optional) value of constant term in objective, 0 means cf == 0, so
  44. // optional only in the sense that it is mandatory
  45. // m number of constraints, therefore also number of rows in linear
  46. // constraint coefficient matrix A, and in linear constraint bound vectors
  47. // lc and uc
  48. // Ari vector of row indices corresponding to non-zero values of A,
  49. // Acp vector of indices into Ari and Av of the first entry for each column
  50. // of A, size(Acp) = (# columns of A) + 1 = n + 1
  51. // Av vector of non-zero values of A, in column compressed order
  52. // lc vector of m linear constraint lower bounds
  53. // uc vector of m linear constraint upper bounds
  54. // lx vector of n constant lower bounds
  55. // ux vector of n constant upper bounds
  56. // Output:
  57. // x vector of size n to hold output of optimization
  58. // Return:
  59. // true only if optimization was successful with no errors
  60. //
  61. // Note: All indices are 0-based
  62. //
  63. template <typename Index, typename Scalar>
  64. IGL_INLINE bool mosek_quadprog(
  65. const Index n,
  66. const std::vector<Index> & Qi,
  67. const std::vector<Index> & Qj,
  68. const std::vector<Scalar> & Qv,
  69. const std::vector<Scalar> & c,
  70. const Scalar cf,
  71. const Index m,
  72. const std::vector<Index> & Ari,
  73. const std::vector<Index> & Acp,
  74. const std::vector<Scalar> & Av,
  75. const std::vector<Scalar> & lc,
  76. const std::vector<Scalar> & uc,
  77. const std::vector<Scalar> & lx,
  78. const std::vector<Scalar> & ux,
  79. std::vector<Scalar> & x);
  80. }
  81. #ifdef IGL_HEADER_ONLY
  82. # include "mosek_quadprog.cpp"
  83. #endif
  84. #endif