LPSolver.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
23 
24 #include <limits>
25 #include <algorithm>
26 
27 namespace gtsam {
28 
30 struct LPPolicy {
33  static constexpr double maxAlpha = std::numeric_limits<double>::infinity();
34 
48  const VectorValues& xk) {
50  for (LinearCost::const_iterator it = lp.cost.begin(); it != lp.cost.end();
51  ++it) {
52  size_t dim = lp.cost.getDim(it);
53  Vector b = xk.at(*it) - lp.cost.getA(it).transpose(); // b = xk-g
54  graph.emplace_shared<JacobianFactor>(*it, Matrix::Identity(dim, dim), b);
55  }
56 
57  KeySet allKeys = lp.inequalities.keys();
58  allKeys.merge(lp.equalities.keys());
59  allKeys.merge(KeySet(lp.cost.keys()));
60  // Add corresponding factors for all variables that are not explicitly in
61  // the cost function. Gradients of the cost function wrt to these variables
62  // are zero (g=0), so b=xk
63  if (lp.cost.keys().size() != allKeys.size()) {
64  KeySet difference;
65  std::set_difference(allKeys.begin(), allKeys.end(), lp.cost.begin(),
66  lp.cost.end(),
67  std::inserter(difference, difference.end()));
68  for (Key k : difference) {
69  size_t dim = lp.constrainedKeyDimMap().at(k);
70  graph.emplace_shared<JacobianFactor>(k, Matrix::Identity(dim, dim), xk.at(k));
71  }
72  }
73  return graph;
74  }
75 };
76 
78 
79 }
EqualityFactorGraph equalities
Linear equality constraints: cE(x) = 0.
Definition: LP.h:55
InequalityFactorGraph inequalities
Linear inequality constraints: cI(x) <= 0.
Definition: LP.h:56
static constexpr double maxAlpha
Definition: LPSolver.h:33
KeySet keys() const
const_iterator end() const
Definition: Factor.h:130
Active set method for solving LP, QP problems.
FastSet< Key > KeySet
Definition: Key.h:90
void merge(const FastSet &other)
Definition: FastSet.h:121
Vector & at(Key j)
Definition: VectorValues.h:137
NonlinearFactorGraph graph
Definition: LP.h:51
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&...args)
Emplace a shared pointer to factor of given type.
Definition: FactorGraph.h:172
Eigen::VectorXd Vector
Definition: Vector.h:38
Policy for ActivetSetSolver to solve Linear Programming.
Definition: LPSolver.h:30
const KeyDimMap & constrainedKeyDimMap() const
Definition: LP.h:80
const_iterator begin() const
Definition: Factor.h:127
LinearCost cost
Linear cost factor.
Definition: LP.h:54
DenseIndex getDim(const_iterator variable) const override
constABlock getA(const_iterator variable) const
const G & b
Definition: Group.h:83
static GaussianFactorGraph buildCostFunction(const LP &lp, const VectorValues &xk)
Definition: LPSolver.h:47
const mpreal dim(const mpreal &a, const mpreal &b, mp_rnd_t r=mpreal::get_default_rnd())
Definition: mpreal.h:2201
traits
Definition: chartTesting.h:28
Struct used to hold a Linear Programming Problem.
const KeyVector & keys() const
Access the factor&#39;s involved variable keys.
Definition: Factor.h:124
KeyVector::const_iterator const_iterator
Const iterator over keys.
Definition: Factor.h:67
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61
This finds a feasible solution for an LP problem.


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:42:34