23 #include <boost/range/adaptor/map.hpp> 36 template <
class PROBLEM,
class POLICY,
class INITSOLVER>
51 : values(), duals(), workingSet(), converged(false), iterations(0) {}
57 : values(initialValues),
59 workingSet(initialWorkingSet),
60 converged(_converged),
61 iterations(_iterations) {}
79 inequalityVariableIndex_ =
VariableIndex(problem_.inequalities);
80 constrainedKeys_ = problem_.equalities.keys();
81 constrainedKeys_.
merge(problem_.inequalities.keys());
90 std::pair<VectorValues, VectorValues>
optimize(
93 bool useWarmStart =
false)
const;
99 std::pair<VectorValues, VectorValues>
optimize()
const;
125 template<
typename FACTOR>
133 TermsContainer Aterms;
134 if (variableIndex.
find(key) != variableIndex.
end()) {
135 for (
size_t factorIx : variableIndex[key]) {
136 typename FACTOR::shared_ptr factor = graph.
at(factorIx);
137 if (!factor->active())
139 Matrix Ai = factor->getA(factor->find(key)).transpose();
140 Aterms.push_back(std::make_pair(factor->dualKey(), Ai));
179 bool useWarmStart =
false)
const;
191 template <
class PROBLEM>
193 auto keys = problem.cost.keys();
195 if (!problem.equalities.empty())
196 maxKey =
std::max(maxKey, *problem.equalities.keys().rbegin());
197 if (!problem.inequalities.empty())
198 maxKey =
std::max(maxKey, *problem.inequalities.keys().rbegin());
ActiveSetSolver(const PROBLEM &problem)
Constructor.
bool converged
True if the algorithm has converged to a solution.
VectorValues values
current best values at each step
State iterate(const State &state) const
Iterate 1 step, return a new state with a new workingSet and values.
const_iterator find(Key key) const
Find the iterator for the requested variable entry.
GaussianFactorGraph buildWorkingGraph(const InequalityFactorGraph &workingSet, const VectorValues &xk=VectorValues()) const
void merge(const FastSet &other)
Factor graph of all LinearInequality factors.
NonlinearFactorGraph graph
Key maxKey(const PROBLEM &problem)
InequalityFactorGraph identifyActiveConstraints(const InequalityFactorGraph &inequalities, const VectorValues &initialValues, const VectorValues &duals=VectorValues(), bool useWarmStart=false) const
Identify active constraints based on initial values.
TermsContainer collectDualJacobians(Key key, const FactorGraph< FACTOR > &graph, const VariableIndex &variableIndex) const
const PROBLEM & problem_
the particular [convex] problem to solve
int identifyLeavingConstraint(const InequalityFactorGraph &workingSet, const VectorValues &lambdas) const
Identifies active constraints that shouldn't be active anymore.
State()
Default constructor.
std::pair< VectorValues, VectorValues > optimize() const
InequalityFactorGraph workingSet
boost::tuple< double, int > computeStepSize(const InequalityFactorGraph &workingSet, const VectorValues &xk, const VectorValues &p, const double &maxAlpha) const
VariableIndex inequalityVariableIndex_
Linear Factor Graph where all factors are Gaussians.
State(const VectorValues &initialValues, const VectorValues &initialDuals, const InequalityFactorGraph &initialWorkingSet, bool _converged, size_t _iterations)
Constructor with initial values.
const_iterator end() const
Iterator to the first variable entry.
GaussianFactorGraph buildDualGraph(const InequalityFactorGraph &workingSet, const VectorValues &delta) const
Just for testing...
JacobianFactor::shared_ptr createDualFactor(Key key, const InequalityFactorGraph &workingSet, const VectorValues &delta) const
const sharedFactor at(size_t i) const
This struct contains the state information for a single iteration.
VectorValues duals
current values of dual variables at each step
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
std::vector< std::pair< Key, Matrix > > TermsContainer
Vector of key matrix pairs. Matrices are usually the A term for a factor.
VariableIndex equalityVariableIndex_
std::uint64_t Key
Integer nonlinear key type.
Implmentation of ActiveSetSolver.