gtsam
Loading...
Searching...
No Matches
QP.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
18
19#pragma once
20
21#include <gtsam/config.h>
22
23#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
24
28#include <gtsam/slam/dataset.h>
29
30namespace gtsam {
31
35struct QP {
36 GaussianFactorGraph cost;
37 EqualityFactorGraph equalities;
38 InequalityFactorGraph inequalities;
39
40private:
41 mutable VariableIndex cachedCostVariableIndex_;
42
43public:
45 QP() :
46 cost(), equalities(), inequalities() {
47 }
48
50 QP(const GaussianFactorGraph& _cost,
51 const EqualityFactorGraph& _linearEqualities,
52 const InequalityFactorGraph& _linearInequalities) :
53 cost(_cost), equalities(_linearEqualities), inequalities(
54 _linearInequalities) {
55 }
56
58 void print(const std::string& s = "") {
59 std::cout << s << std::endl;
60 cost.print("Quadratic cost factors: ");
61 equalities.print("Linear equality factors: ");
62 inequalities.print("Linear inequality factors: ");
63 }
64
65 const VariableIndex& costVariableIndex() const {
66 if (cachedCostVariableIndex_.size() == 0)
67 cachedCostVariableIndex_ = VariableIndex(cost);
68 return cachedCostVariableIndex_;
69 }
70
71 Vector costGradient(Key key, const VectorValues& delta) const {
72 Vector g = Vector::Zero(delta.at(key).size());
73 if (costVariableIndex().find(key) != costVariableIndex().end()) {
74 for (size_t factorIx : costVariableIndex()[key]) {
75 GaussianFactor::shared_ptr factor = cost.at(factorIx);
76 g += factor->gradient(key, delta);
77 }
78 }
79 return g;
80 }
81};
82
83} // namespace gtsam
84
85#endif // GTSAM_ALLOW_DEPRECATED_SINCE_V43
Linear Factor Graph where all factors are Gaussians.
utility functions for loading datasets
Factor graph of all LinearInequality factors.
Factor graph of all LinearEquality factors.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:143