ActiveSetSolver.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 #pragma once
20 
23 
24 namespace gtsam {
25 
35 template <class PROBLEM, class POLICY, class INITSOLVER>
37 public:
39  struct State {
44  bool converged;
45  size_t iterations;
48  State()
50  : values(), duals(), workingSet(), converged(false), iterations(0) {}
51 
53  State(const VectorValues& initialValues, const VectorValues& initialDuals,
54  const InequalityFactorGraph& initialWorkingSet, bool _converged,
55  size_t _iterations)
56  : values(initialValues),
57  duals(initialDuals),
58  workingSet(initialWorkingSet),
59  converged(_converged),
60  iterations(_iterations) {}
61  };
62 
63 protected:
64  const PROBLEM& problem_;
71  typedef std::vector<std::pair<Key, Matrix> > TermsContainer;
73 
74 public:
76  ActiveSetSolver(const PROBLEM& problem) : problem_(problem) {
79  constrainedKeys_ = problem_.equalities.keys();
80  constrainedKeys_.merge(problem_.inequalities.keys());
81  }
82 
89  std::pair<VectorValues, VectorValues> optimize(
90  const VectorValues& initialValues,
91  const VectorValues& duals = VectorValues(),
92  bool useWarmStart = false) const;
93 
98  std::pair<VectorValues, VectorValues> optimize() const;
99 
100 protected:
116  std::tuple<double, int> computeStepSize(
117  const InequalityFactorGraph& workingSet, const VectorValues& xk,
118  const VectorValues& p, const double& maxAlpha) const;
119 
124  template<typename FACTOR>
126  const VariableIndex& variableIndex) const {
127  /*
128  * Iterates through each factor in the factor graph and checks
129  * whether it's active. If the factor is active it reutrns the A
130  * term of the factor.
131  */
132  TermsContainer Aterms;
133  if (variableIndex.find(key) != variableIndex.end()) {
134  for (size_t factorIx : variableIndex[key]) {
135  typename FACTOR::shared_ptr factor = graph.at(factorIx);
136  if (!factor->active())
137  continue;
138  Matrix Ai = factor->getA(factor->find(key)).transpose();
139  Aterms.push_back(std::make_pair(factor->dualKey(), Ai));
140  }
141  }
142  return Aterms;
143  }
144 
150  Key key, const InequalityFactorGraph& workingSet,
151  const VectorValues& delta) const;
152 
153 public:
154 
157  const VectorValues &delta) const;
158 
167  const InequalityFactorGraph& workingSet,
168  const VectorValues& xk = VectorValues()) const;
169 
171  State iterate(const State& state) const;
172 
175  const InequalityFactorGraph& inequalities,
176  const VectorValues& initialValues,
177  const VectorValues& duals = VectorValues(),
178  bool useWarmStart = false) const;
179 
181  int identifyLeavingConstraint(const InequalityFactorGraph& workingSet,
182  const VectorValues& lambdas) const;
183 
184 };
185 
190 template <class PROBLEM>
191 Key maxKey(const PROBLEM& problem) {
192  auto keys = problem.cost.keys();
193  Key maxKey = *std::max_element(keys.begin(), keys.end());
194  if (!problem.equalities.empty())
195  maxKey = std::max(maxKey, *problem.equalities.keys().rbegin());
196  if (!problem.inequalities.empty())
197  maxKey = std::max(maxKey, *problem.inequalities.keys().rbegin());
198  return maxKey;
199 }
200 
201 } // namespace gtsam
202 
gtsam::VariableIndex::find
const_iterator find(Key key) const
Find the iterator for the requested variable entry.
Definition: VariableIndex.h:169
GaussianFactorGraph.h
Linear Factor Graph where all factors are Gaussians.
gtsam::ActiveSetSolver::State::duals
VectorValues duals
current values of dual variables at each step
Definition: ActiveSetSolver.h:41
gtsam::ActiveSetSolver::identifyLeavingConstraint
int identifyLeavingConstraint(const InequalityFactorGraph &workingSet, const VectorValues &lambdas) const
Identifies active constraints that shouldn't be active anymore.
gtsam::ActiveSetSolver::State::iterations
size_t iterations
Definition: ActiveSetSolver.h:45
gtsam::ActiveSetSolver::collectDualJacobians
TermsContainer collectDualJacobians(Key key, const FactorGraph< FACTOR > &graph, const VariableIndex &variableIndex) const
Definition: ActiveSetSolver.h:125
keys
const KeyVector keys
Definition: testRegularImplicitSchurFactor.cpp:40
gtsam::maxKey
Key maxKey(const PROBLEM &problem)
Definition: ActiveSetSolver.h:191
gtsam::internal::DoglegState
Definition: DoglegOptimizer.cpp:54
gtsam::ActiveSetSolver::createDualFactor
JacobianFactor::shared_ptr createDualFactor(Key key, const InequalityFactorGraph &workingSet, const VectorValues &delta) const
InequalityFactorGraph.h
Factor graph of all LinearInequality factors.
gtsam::FastSet::merge
void merge(const FastSet &other)
Definition: FastSet.h:121
gtsam::ActiveSetSolver
Definition: ActiveSetSolver.h:36
gtsam::Matrix
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
gtsam::ActiveSetSolver::State
This struct contains the state information for a single iteration.
Definition: ActiveSetSolver.h:39
gtsam::ActiveSetSolver::State::State
State(const VectorValues &initialValues, const VectorValues &initialDuals, const InequalityFactorGraph &initialWorkingSet, bool _converged, size_t _iterations)
Constructor with initial values.
Definition: ActiveSetSolver.h:53
gtsam::FastSet< Key >
gtsam::ActiveSetSolver::computeStepSize
std::tuple< double, int > computeStepSize(const InequalityFactorGraph &workingSet, const VectorValues &xk, const VectorValues &p, const double &maxAlpha) const
gtsam::FactorGraph
Definition: BayesTree.h:34
gtsam::ActiveSetSolver::State::workingSet
InequalityFactorGraph workingSet
Definition: ActiveSetSolver.h:42
gtsam::GaussianFactorGraph
Definition: GaussianFactorGraph.h:73
gtsam.examples.PlanarManipulatorExample.delta
def delta(g0, g1)
Definition: PlanarManipulatorExample.py:45
gtsam::VectorValues
Definition: VectorValues.h:74
gtsam::ActiveSetSolver::constrainedKeys_
KeySet constrainedKeys_
Definition: ActiveSetSolver.h:68
gtsam::ActiveSetSolver::equalityVariableIndex_
VariableIndex equalityVariableIndex_
Definition: ActiveSetSolver.h:65
ActiveSetSolver-inl.h
Implmentation of ActiveSetSolver.
gtsam::ActiveSetSolver::identifyActiveConstraints
InequalityFactorGraph identifyActiveConstraints(const InequalityFactorGraph &inequalities, const VectorValues &initialValues, const VectorValues &duals=VectorValues(), bool useWarmStart=false) const
Identify active constraints based on initial values.
gtsam::ActiveSetSolver::optimize
std::pair< VectorValues, VectorValues > optimize() const
gtsam::ActiveSetSolver::TermsContainer
std::vector< std::pair< Key, Matrix > > TermsContainer
Vector of key matrix pairs. Matrices are usually the A term for a factor.
Definition: ActiveSetSolver.h:72
gtsam::VariableIndex
Definition: VariableIndex.h:41
key
const gtsam::Symbol key('X', 0)
gtsam::ActiveSetSolver::State::converged
bool converged
True if the algorithm has converged to a solution.
Definition: ActiveSetSolver.h:44
gtsam::InequalityFactorGraph
Definition: InequalityFactorGraph.h:32
gtsam::VariableIndex::end
const_iterator end() const
Iterator to the first variable entry.
Definition: VariableIndex.h:166
gtsam
traits
Definition: SFMdata.h:40
gtsam::ActiveSetSolver::ActiveSetSolver
ActiveSetSolver(const PROBLEM &problem)
Constructor.
Definition: ActiveSetSolver.h:76
p
float * p
Definition: Tutorial_Map_using.cpp:9
gtsam::ActiveSetSolver::buildDualGraph
GaussianFactorGraph buildDualGraph(const InequalityFactorGraph &workingSet, const VectorValues &delta) const
Just for testing...
gtsam::ActiveSetSolver::inequalityVariableIndex_
VariableIndex inequalityVariableIndex_
Definition: ActiveSetSolver.h:66
gtsam::JacobianFactor::shared_ptr
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: JacobianFactor.h:97
gtsam::ActiveSetSolver::State::State
State()
Default constructor.
Definition: ActiveSetSolver.h:49
gtsam::ActiveSetSolver::State::values
VectorValues values
current best values at each step
Definition: ActiveSetSolver.h:40
gtsam::ActiveSetSolver::buildWorkingGraph
GaussianFactorGraph buildWorkingGraph(const InequalityFactorGraph &workingSet, const VectorValues &xk=VectorValues()) const
gtsam::ActiveSetSolver::problem_
const PROBLEM & problem_
the particular [convex] problem to solve
Definition: ActiveSetSolver.h:64
graph
NonlinearFactorGraph graph
Definition: doc/Code/OdometryExample.cpp:2
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
max
#define max(a, b)
Definition: datatypes.h:20
gtsam::ActiveSetSolver::iterate
State iterate(const State &state) const
Iterate 1 step, return a new state with a new workingSet and values.
make_changelog.state
state
Definition: make_changelog.py:29


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:31:51