gtsam 4.2
gtsam
Loading...
Searching...
No Matches
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
19
20#pragma once
21
25
26#include <limits>
27#include <algorithm>
28
29namespace gtsam {
30
32struct LPPolicy {
35 static constexpr double maxAlpha = std::numeric_limits<double>::infinity();
36
50 const VectorValues& xk) {
52 for (LinearCost::const_iterator it = lp.cost.begin(); it != lp.cost.end();
53 ++it) {
54 size_t dim = lp.cost.getDim(it);
55 Vector b = xk.at(*it) - lp.cost.getA(it).transpose(); // b = xk-g
56 graph.emplace_shared<JacobianFactor>(*it, Matrix::Identity(dim, dim), b);
57 }
58
59 KeySet allKeys = lp.inequalities.keys();
60 allKeys.merge(lp.equalities.keys());
61 allKeys.merge(KeySet(lp.cost.keys()));
62 // Add corresponding factors for all variables that are not explicitly in
63 // the cost function. Gradients of the cost function wrt to these variables
64 // are zero (g=0), so b=xk
65 if (lp.cost.keys().size() != allKeys.size()) {
66 KeySet difference;
67 std::set_difference(allKeys.begin(), allKeys.end(), lp.cost.begin(),
68 lp.cost.end(),
69 std::inserter(difference, difference.end()));
70 for (Key k : difference) {
71 size_t dim = lp.constrainedKeyDimMap().at(k);
72 graph.emplace_shared<JacobianFactor>(k, Matrix::Identity(dim, dim), xk.at(k));
73 }
74 }
75 return graph;
76 }
77};
78
79using LPSolver = ActiveSetSolver<LP, LPPolicy, LPInitSolver>;
80
81}
Active set method for solving LP, QP problems.
This finds a feasible solution for an LP problem.
Struct used to hold a Linear Programming Problem.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:100
void merge(const FastSet &other)
insert another set: handy for MATLAB access
Definition FastSet.h:119
KeySet keys() const
Potentially slow function to return all keys involved, sorted, as a set.
Definition FactorGraph-inst.h:85
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&... args)
Emplace a shared pointer to factor of given type.
Definition FactorGraph.h:192
const KeyVector & keys() const
Access the factor's involved variable keys.
Definition Factor.h:140
const_iterator begin() const
Iterator at beginning of involved variable keys.
Definition Factor.h:143
KeyVector::const_iterator const_iterator
Const iterator over keys.
Definition Factor.h:80
const_iterator end() const
Iterator at end of involved variable keys.
Definition Factor.h:146
A Linear Factor Graph is a factor graph where all factors are Gaussian, i.e.
Definition GaussianFactorGraph.h:75
A Gaussian factor in the squared-error form.
Definition JacobianFactor.h:91
DenseIndex getDim(const_iterator variable) const override
Return the dimension of the variable pointed to by the given key iterator todo: Remove this in favor ...
Definition JacobianFactor.h:276
constABlock getA(const_iterator variable) const
Get a view of the A matrix for the variable pointed to by the given key iterator.
Definition JacobianFactor.h:300
VectorValues represents a collection of vector-valued variables associated each with a unique integer...
Definition VectorValues.h:74
Vector & at(Key j)
Read/write access to the vector value with key j, throws std::out_of_range if j does not exist,...
Definition VectorValues.h:139
Data structure of a Linear Program.
Definition LP.h:51
InequalityFactorGraph inequalities
Linear inequality constraints: cI(x) <= 0.
Definition LP.h:56
LinearCost cost
Linear cost factor.
Definition LP.h:54
EqualityFactorGraph equalities
Linear equality constraints: cE(x) = 0.
Definition LP.h:55
Policy for ActivetSetSolver to solve Linear Programming.
Definition LPSolver.h:32
static constexpr double maxAlpha
Maximum alpha for line search x'=xk + alpha*p, where p is the cost gradient For LP,...
Definition LPSolver.h:35
static GaussianFactorGraph buildCostFunction(const LP &lp, const VectorValues &xk)
Create the factor ||x-xk - (-g)||^2 where xk is the current feasible solution on the constraint surfa...
Definition LPSolver.h:49