26#define Template template <class PROBLEM, class POLICY, class INITSOLVER>
27#define This ActiveSetSolver<PROBLEM, POLICY, INITSOLVER>
48Template boost::tuple<double, int> This::computeStepSize(
51 double minAlpha = maxAlpha;
52 int closestFactorIx = -1;
53 for (
size_t factorIx = 0; factorIx < workingSet.size(); ++factorIx) {
55 double b = factor->getb()[0];
57 if (!factor->active()) {
59 double aTp = factor->dotProductRow(p);
66 double aTx = factor->dotProductRow(xk);
69 double alpha = (b - aTx) / aTp;
71 if (alpha < minAlpha) {
72 closestFactorIx = factorIx;
77 return boost::make_tuple(minAlpha, closestFactorIx);
115Template
int This::identifyLeavingConstraint(
118 int worstFactorIx = -1;
121 double maxLambda = 0.0;
122 for (
size_t factorIx = 0; factorIx < workingSet.size(); ++factorIx) {
124 if (factor->active()) {
125 double lambda = lambdas.at(factor->dualKey())[0];
126 if (lambda > maxLambda) {
127 worstFactorIx = factorIx;
132 return worstFactorIx;
141 TermsContainer Aterms = collectDualJacobians<LinearEquality>(
142 key, problem_.equalities, equalityVariableIndex_);
143 TermsContainer AtermsInequalities = collectDualJacobians<LinearInequality>(
144 key, workingSet, inequalityVariableIndex_);
145 Aterms.insert(Aterms.end(), AtermsInequalities.begin(),
146 AtermsInequalities.end());
149 if (Aterms.size() > 0) {
150 Vector b = problem_.costGradient(key, delta);
152 return boost::make_shared<JacobianFactor>(Aterms, b);
173 for (
Key key : constrainedKeys_) {
175 auto dualFactor = createDualFactor(key, workingSet, delta);
176 if (dualFactor) dualGraph.push_back(dualFactor);
186 workingGraph.
push_back(POLICY::buildCostFunction(problem_, xk));
187 workingGraph.push_back(problem_.equalities);
189 if (factor->active()) workingGraph.push_back(factor);
194Template
typename This::State This::iterate(
195 const typename This::State& state)
const {
198 auto workingGraph = buildWorkingGraph(state.workingSet, state.values);
203 if (newValues.equals(state.values, 1e-7)) {
205 auto dualGraph = buildDualGraph(state.workingSet, newValues);
207 int leavingFactor = identifyLeavingConstraint(state.workingSet, duals);
209 if (leavingFactor < 0) {
210 return State(newValues, duals, state.workingSet,
true,
211 state.iterations + 1);
215 newWorkingSet.
at(leavingFactor)->inactivate();
216 return State(newValues, duals, newWorkingSet,
false,
217 state.iterations + 1);
225 boost::tie(alpha, factorIx) =
226 computeStepSize(state.workingSet, state.values, p, POLICY::maxAlpha);
230 newWorkingSet.
at(factorIx)->activate();
232 newValues = state.values + alpha * p;
233 return State(newValues, state.duals, newWorkingSet,
false,
234 state.iterations + 1);
242 bool useWarmStart)
const {
246 if (useWarmStart && duals.size() > 0) {
247 if (duals.exists(workingFactor->dualKey())) workingFactor->activate();
248 else workingFactor->inactivate();
250 double error = workingFactor->error(initialValues);
253 if (std::abs(error) < 1e-7)
254 workingFactor->activate();
256 workingFactor->inactivate();
258 workingSet.push_back(workingFactor);
264Template std::pair<VectorValues, VectorValues> This::optimize(
266 bool useWarmStart)
const {
269 problem_.inequalities, initialValues, duals, useWarmStart);
270 State state(initialValues, duals, workingSet,
false, 0);
273 while (!state.converged) state = iterate(state);
275 return std::make_pair(state.values, state.duals);
279Template std::pair<VectorValues, VectorValues> This::optimize()
const {
280 INITSOLVER initSolver(problem_);
Exception thrown when given Infeasible Initial Values.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
Point3 optimize(const NonlinearFactorGraph &graph, const Values &values, Key landmarkKey)
Optimize for triangulation.
Definition triangulation.cpp:155
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:100
IsDerived< DERIVEDFACTOR > push_back(boost::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
Definition FactorGraph.h:186
const sharedFactor at(size_t i) const
Get a specific factor by index (this checks array bounds and may throw an exception,...
Definition FactorGraph.h:335
A Linear Factor Graph is a factor graph where all factors are Gaussian, i.e.
Definition GaussianFactorGraph.h:75
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition JacobianFactor.h:96
VectorValues represents a collection of vector-valued variables associated each with a unique integer...
Definition VectorValues.h:74
Collection of all Linear Inequality constraints Ax-b <= 0 of a Programming problem as a Factor Graph.
Definition InequalityFactorGraph.h:32
An exception indicating that the provided initial value is infeasible Also used to inzdicatethat the ...
Definition InfeasibleInitialValues.h:27
This class defines a linear inequality constraint Ax-b <= 0, inheriting JacobianFactor with the speci...
Definition LinearInequality.h:33
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition LinearInequality.h:37