LPInitSolver.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* ----------------------------------------------------------------------------
  2. * GTSAM Copyright 2010, Georgia Tech Research Corporation,
  3. * Atlanta, Georgia 30332-0415
  4. * All Rights Reserved
  5. * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
  6. * See LICENSE for the license information
  7. * -------------------------------------------------------------------------- */
  8. /**
  9. * @file LPInitSolver.h
  10. * @brief This LPInitSolver implements the strategy in Matlab.
  11. * @author Duy Nguyen Ta
  12. * @author Ivan Dario Jimenez
  13. * @date 1/24/16
  14. */
  15. #pragma once
  16. #include <gtsam_unstable/linear/LP.h>
  17. #include <gtsam/linear/GaussianFactorGraph.h>
  18. namespace gtsam {
  19. /**
  20. * This LPInitSolver implements the strategy in Matlab:
  21. * http://www.mathworks.com/help/optim/ug/linear-programming-algorithms.html#brozyzb-9
  22. * Solve for x and y:
  23. * min y
  24. * st Ax = b
  25. * Cx - y <= d
  26. * where y \in R, x \in R^n, and Ax = b and Cx <= d is the constraints of the original problem.
  27. *
  28. * If the solution for this problem {x*,y*} has y* <= 0, we'll have x* a feasible initial point
  29. * of the original problem
  30. * otherwise, if y* > 0 or the problem has no solution, the original problem is infeasible.
  31. *
  32. * The initial value of this initial problem can be found by solving
  33. * min ||x||^2
  34. * s.t. Ax = b
  35. * to have a solution x0
  36. * then y = max_j ( Cj*x0 - dj ) -- due to the constraints y >= Cx - d
  37. *
  38. * WARNING: If some xj in the inequality constraints does not exist in the equality constraints,
  39. * set them as zero for now. If that is the case, the original problem doesn't have a unique
  40. * solution (it could be either infeasible or unbounded).
  41. * So, if the initialization fails because we enforce xj=0 in the problematic
  42. * inequality constraint, we can't conclude that the problem is infeasible.
  43. * However, whether it is infeasible or unbounded, we don't have a unique solution anyway.
  44. */
  45. class LPInitSolver {
  46. private:
  47. const LP& lp_;
  48. public:
  49. /// Construct with an LP problem
  50. LPInitSolver(const LP& lp) : lp_(lp) {}
  51. ///@return a feasible initialization point
  52. VectorValues solve() const;
  53. private:
  54. /// build initial LP
  55. LP::shared_ptr buildInitialLP(Key yKey) const;
  56. /**
  57. * Build the following graph to solve for an initial value of the initial problem
  58. * min ||x||^2 s.t. Ax = b
  59. */
  60. GaussianFactorGraph::shared_ptr buildInitOfInitGraph() const;
  61. /// y = max_j ( Cj*x0 - dj ) -- due to the inequality constraints y >= Cx - d
  62. double compute_y0(const VectorValues& x0) const;
  63. /// Collect all terms of a factor into a container.
  64. std::vector<std::pair<Key, Matrix>> collectTerms(
  65. const LinearInequality& factor) const;
  66. /// Turn Cx <= d into Cx - y <= d factors
  67. InequalityFactorGraph addSlackVariableToInequalities(Key yKey,
  68. const InequalityFactorGraph& inequalities) const;
  69. // friend class for unit-testing private methods
  70. friend class LPInitSolverInitializationTest;
  71. };
  72. }