linprog.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 Alec Jacobson <[email protected]>
  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_LINPROG_H
  9. #define IGL_LINPROG_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. namespace igl
  13. {
  14. /// Solve a linear program given in "standard form"
  15. ///
  16. /// min c'x
  17. /// s.t. A( 1:k,:) x <= b(1:k)
  18. /// A(k+1:end,:) x = b(k+1:end)
  19. /// ** x >= 0 **
  20. ///
  21. /// In contrast to other APIs the entries in b may be negative.
  22. ///
  23. /// @param[in] c #x list of linear coefficients
  24. /// @param[in] A #A by #x matrix of linear constraint coefficients
  25. /// @param[in] b #A list of linear constraint right-hand sides
  26. /// @param[in] k number of inequality constraints as first rows of A,b
  27. /// @param[out] x #x solution vector
  28. /// @return false on failure or detected infeasibility, returns true on termination
  29. ///
  30. /// \note It appears that this implementation does not detect all infeasibile
  31. /// problems (e.g., https://github.com/libigl/libigl/issues/2051). Therefor,
  32. /// it's worth double-checking that the output actually satisfies the
  33. /// constraints even if the return value is `true`.
  34. IGL_INLINE bool linprog(
  35. const Eigen::VectorXd & c,
  36. const Eigen::MatrixXd & A,
  37. const Eigen::VectorXd & b,
  38. const int k,
  39. Eigen::VectorXd & x);
  40. /// \overload
  41. /// \brief Wrapper in friendlier general form (no implicit bounds on x)
  42. ///
  43. /// min f'x
  44. /// s.t. A x <= b
  45. /// B x = c
  46. ///
  47. /// @param[in] f #x list of linear coefficients
  48. /// @param[in] A #A by #x matrix of linear inequality constraint coefficients
  49. /// @param[in] b #A list of linear constraint right-hand sides
  50. /// @param[in] B #B by #x matrix of linear equality constraint coefficients
  51. /// @param[in] c #B list of linear constraint right-hand sides
  52. /// @param[out] x #x solution vector
  53. /// @return false on failure or detected infeasibility, returns true on termination
  54. ///
  55. IGL_INLINE bool linprog(
  56. const Eigen::VectorXd & f,
  57. const Eigen::MatrixXd & A,
  58. const Eigen::VectorXd & b,
  59. const Eigen::MatrixXd & B,
  60. const Eigen::VectorXd & c,
  61. Eigen::VectorXd & x);
  62. }
  63. #ifndef IGL_STATIC_LIBRARY
  64. # include "linprog.cpp"
  65. #endif
  66. #endif