linprog.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 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_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 f'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. // Inputs:
  24. // c #x list of linear coefficients
  25. // A #A by #x matrix of linear constraint coefficients
  26. // b #A list of linear constraint right-hand sides
  27. // k number of inequality constraints as first rows of A,b
  28. // Outputs:
  29. // x #x solution vector
  30. //
  31. IGL_INLINE bool linprog(
  32. const Eigen::VectorXd & c,
  33. const Eigen::MatrixXd & A,
  34. const Eigen::VectorXd & b,
  35. const int k,
  36. Eigen::VectorXd & f);
  37. // Wrapper in friendlier general form (no implicit bounds on x)
  38. //
  39. // min f'x
  40. // s.t. A x <= b
  41. // B x = c
  42. //
  43. // Inputs:
  44. // f #x list of linear coefficients
  45. // A #A by #x matrix of linear inequality constraint coefficients
  46. // b #A list of linear constraint right-hand sides
  47. // B #B by #x matrix of linear equality constraint coefficients
  48. // c #B list of linear constraint right-hand sides
  49. // Outputs:
  50. // x #x solution vector
  51. //
  52. IGL_INLINE bool linprog(
  53. const Eigen::VectorXd & f,
  54. const Eigen::MatrixXd & A,
  55. const Eigen::VectorXd & b,
  56. const Eigen::MatrixXd & B,
  57. const Eigen::VectorXd & c,
  58. Eigen::VectorXd & x);
  59. }
  60. #ifndef IGL_STATIC_LIBRARY
  61. # include "linprog.cpp"
  62. #endif
  63. #endif