gtsam
Loading...
Searching...
No Matches
QPInitSolver.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
22#include <gtsam/config.h>
23
24#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
25
28
29#include <algorithm>
30
31namespace gtsam {
32namespace internal {
33
34/* ************************************************************************* */
35inline Key maxKey(const QP& qp) {
36 Key maxKey = 0;
37 bool initialized = false;
38 auto update = [&](const KeySet& keys) {
39 if (!keys.empty()) {
40 maxKey = initialized ? std::max(maxKey, *keys.rbegin()) : *keys.rbegin();
41 initialized = true;
42 }
43 };
44 update(qp.cost.keys());
45 update(qp.equalities.keys());
46 update(qp.inequalities.keys());
47 return maxKey;
48}
49
50} // namespace internal
51
60class QPInitSolver {
61 const QP& qp_;
62
63 public:
65 QPInitSolver(const QP& qp) : qp_(qp) {}
66
68 VectorValues solve() const {
69 // Make an LP with any linear cost function. It doesn't matter for
70 // initialization.
71 LP initProblem;
72 // make an unrelated key for a random variable cost
73 Key newKey = internal::maxKey(qp_) + 1;
74 initProblem.cost = LinearCost(newKey, Vector::Ones(1));
75 initProblem.equalities = qp_.equalities;
76 initProblem.inequalities = qp_.inequalities;
77 LPInitSolver initSolver(initProblem);
78 return initSolver.solve();
79 }
80};
81
82} // namespace gtsam
83
84#endif // GTSAM_ALLOW_DEPRECATED_SINCE_V43
This finds a feasible solution for an LP problem.
Factor graphs of a Quadratic Programming problem.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43