[REFACTOR] Move ComputeStepSize from subclasses to ActiveSetSolver

release/4.3a0
= 2016-06-16 10:39:32 -04:00
parent e2a28593ab
commit f3a4788193
6 changed files with 9 additions and 35 deletions

View File

@ -89,7 +89,6 @@ GaussianFactorGraph::shared_ptr ActiveSetSolver::buildDualGraph(
} }
return dualGraph; return dualGraph;
} }
/* /*
* Compute step size alpha for the new solution x' = xk + alpha*p, where alpha \in [0,1] * Compute step size alpha for the new solution x' = xk + alpha*p, where alpha \in [0,1]
* *
@ -100,8 +99,8 @@ GaussianFactorGraph::shared_ptr ActiveSetSolver::buildDualGraph(
*/ */
boost::tuple<double, int> ActiveSetSolver::computeStepSize( boost::tuple<double, int> ActiveSetSolver::computeStepSize(
const InequalityFactorGraph& workingSet, const VectorValues& xk, const InequalityFactorGraph& workingSet, const VectorValues& xk,
const VectorValues& p, const double& startAlpha) const { const VectorValues& p) const {
double minAlpha = startAlpha; double minAlpha = startAlpha_;
int closestFactorIx = -1; int closestFactorIx = -1;
for (size_t factorIx = 0; factorIx < workingSet.size(); ++factorIx) { for (size_t factorIx = 0; factorIx < workingSet.size(); ++factorIx) {
const LinearInequality::shared_ptr& factor = workingSet.at(factorIx); const LinearInequality::shared_ptr& factor = workingSet.at(factorIx);

View File

@ -23,7 +23,7 @@ protected:
KeySet constrainedKeys_; //!< all constrained keys, will become factors in dual graphs KeySet constrainedKeys_; //!< all constrained keys, will become factors in dual graphs
VariableIndex equalityVariableIndex_, VariableIndex equalityVariableIndex_,
inequalityVariableIndex_; //!< index to corresponding factors to build dual graphs inequalityVariableIndex_; //!< index to corresponding factors to build dual graphs
double startAlpha_;
public: public:
typedef std::vector<std::pair<Key, Matrix> > TermsContainer; //!< vector of key matrix pairs typedef std::vector<std::pair<Key, Matrix> > TermsContainer; //!< vector of key matrix pairs
//Matrices are usually the A term for a factor. //Matrices are usually the A term for a factor.
@ -86,8 +86,8 @@ protected:
* Protected constructor because this class doesn't have any meaning without * Protected constructor because this class doesn't have any meaning without
* a concrete Programming problem to solve. * a concrete Programming problem to solve.
*/ */
ActiveSetSolver() : ActiveSetSolver(double startAlpha) :
constrainedKeys_() { constrainedKeys_(), startAlpha_(startAlpha) {
} }
/** /**
@ -97,7 +97,7 @@ protected:
*/ */
boost::tuple<double, int> computeStepSize( boost::tuple<double, int> computeStepSize(
const InequalityFactorGraph& workingSet, const VectorValues& xk, const InequalityFactorGraph& workingSet, const VectorValues& xk,
const VectorValues& p, const double& startAlpha) const; const VectorValues& p) const;
}; };
/** /**

View File

@ -14,7 +14,7 @@
namespace gtsam { namespace gtsam {
//****************************************************************************** //******************************************************************************
LPSolver::LPSolver(const LP &lp) : LPSolver::LPSolver(const LP &lp) :
lp_(lp) { ActiveSetSolver(std::numeric_limits<double>::infinity()), lp_(lp) {
// Variable index // Variable index
equalityVariableIndex_ = VariableIndex(lp_.equalities); equalityVariableIndex_ = VariableIndex(lp_.equalities);
inequalityVariableIndex_ = VariableIndex(lp_.inequalities); inequalityVariableIndex_ = VariableIndex(lp_.inequalities);
@ -162,14 +162,6 @@ std::pair<VectorValues, VectorValues> LPSolver::optimize(
} }
} }
//******************************************************************************
boost::tuples::tuple<double, int> LPSolver::computeStepSize(
const InequalityFactorGraph &workingSet, const VectorValues &xk,
const VectorValues &p) const {
return ActiveSetSolver::computeStepSize(workingSet, xk, p,
std::numeric_limits<double>::infinity());
}
//****************************************************************************** //******************************************************************************
pair<VectorValues, VectorValues> LPSolver::optimize() const { pair<VectorValues, VectorValues> LPSolver::optimize() const {
LPInitSolver initSolver(lp_); LPInitSolver initSolver(lp_);

View File

@ -67,12 +67,6 @@ public:
JacobianFactor::shared_ptr createDualFactor(Key key, JacobianFactor::shared_ptr createDualFactor(Key key,
const InequalityFactorGraph &workingSet, const VectorValues &delta) const; const InequalityFactorGraph &workingSet, const VectorValues &delta) const;
/// TODO(comment)
//SAME
boost::tuple<double, int> computeStepSize(
const InequalityFactorGraph &workingSet, const VectorValues &xk,
const VectorValues &p) const;
/** Optimize with the provided feasible initial values /** Optimize with the provided feasible initial values
* TODO: throw exception if the initial values is not feasible wrt inequality constraints * TODO: throw exception if the initial values is not feasible wrt inequality constraints
* TODO: comment duals * TODO: comment duals

View File

@ -30,7 +30,7 @@ namespace gtsam {
//****************************************************************************** //******************************************************************************
QPSolver::QPSolver(const QP& qp) : QPSolver::QPSolver(const QP& qp) :
qp_(qp) { ActiveSetSolver(1.0), qp_(qp) {
equalityVariableIndex_ = VariableIndex(qp_.equalities); equalityVariableIndex_ = VariableIndex(qp_.equalities);
inequalityVariableIndex_ = VariableIndex(qp_.inequalities); inequalityVariableIndex_ = VariableIndex(qp_.inequalities);
constrainedKeys_ = qp_.equalities.keys(); constrainedKeys_ = qp_.equalities.keys();
@ -72,13 +72,6 @@ JacobianFactor::shared_ptr QPSolver::createDualFactor(
} }
} }
//******************************************************************************
boost::tuple<double, int> QPSolver::computeStepSize(
const InequalityFactorGraph& workingSet, const VectorValues& xk,
const VectorValues& p) const {
return ActiveSetSolver::computeStepSize(workingSet, xk, p, 1);
}
//****************************************************************************** //******************************************************************************
QPState QPSolver::iterate(const QPState& state) const { QPState QPSolver::iterate(const QPState& state) const {
// Algorithm 16.3 from Nocedal06book. // Algorithm 16.3 from Nocedal06book.

View File

@ -68,10 +68,6 @@ public:
* *
* We want the minimum of all those alphas among all inactive inequality. * We want the minimum of all those alphas among all inactive inequality.
*/ */
//SAME
boost::tuple<double, int> computeStepSize(
const InequalityFactorGraph& workingSet, const VectorValues& xk,
const VectorValues& p) const;
/// Iterate 1 step, return a new state with a new workingSet and values /// Iterate 1 step, return a new state with a new workingSet and values
QPState iterate(const QPState& state) const; QPState iterate(const QPState& state) const;