ocra-recipes
Doxygen documentation for the ocra-recipes repository
QuadraticSolver.h
Go to the documentation of this file.
1 
14 #ifndef _OCRABASE_QUADRATIC_SOLVER_H_
15 #define _OCRABASE_QUADRATIC_SOLVER_H_
16 
17 // includes
18 #include "ocra/optim/Solver.h"
19 #include "ocra/optim/Constraint.h"
20 #include "ocra/optim/Objective.h"
23 
29 namespace ocra
30 {
46  class QuadraticSolver: public Solver
47  {
48  // ------------------------ constructors ------------------------------------
49  private:
52  QuadraticSolver& operator= (const QuadraticSolver&);
53 
54  protected:
59  QuadraticSolver(bool boundsAsConstraints = false)
60  : NamedInstance("quadratic solver")
61  , _m(0), _p(0), _ps(0), _boundsAsConstraints(boundsAsConstraints)
62  {
63  }
64 
65  // ------------------------ public interface --------------------------------
66  public:
76 
81  void addConstraint(LinearConstraint& constraint);
82  void removeConstraint(LinearConstraint& constraint);
84 
89  void addBounds(BoundConstraint& constraint);
90  void addBounds(IdentityConstraint& constraint);
91  void removeBounds(BoundConstraint& constraint);
92  void removeBounds(IdentityConstraint& constraint);
94 
97  void clearObjectives();
98  void clearConstraints();
101  void clearBounds();
103 
111  void printValuesAtSolution();
112 
116  std::string toString();
117  virtual MatrixXd getP() const = 0;
118  virtual VectorXd getq() const = 0;
119  virtual MatrixXd getA() const = 0;
120  virtual VectorXd getb() const = 0;
121  virtual VectorXd getbp() const = 0;
122  virtual MatrixXd getC() const = 0;
123  virtual VectorXd getd() const = 0;
124  virtual VectorXd getl() const = 0;
125  virtual VectorXd getu() const = 0;
126  virtual VectorXd getxl() const = 0;
127  virtual VectorXd getxu() const = 0;
129 
130  // ------------------------ protected methods ---------------------------------
131  protected:
133  void onConstraintResize(int timestamp);
134 
138  void recomputeMP();
139 
140  // ------------------------ private methods ---------------------------------
141  private:
144  void addBounds_(DiagonalLinearConstraint& constraint);
145  void removeBounds_(DiagonalLinearConstraint& constraint);
147 
148  // ------------------------ protected members -------------------------------
149  protected:
150  std::vector<LinearConstraint*> _equalityConstraints; //< all the equality constraints in the problem
151  std::vector<LinearConstraint*> _inequalityConstraints; //< all the inequality constraints in the problem
152  std::vector<QuadraticObjective*> _objectives; //< all the objectives in the problem
153  std::vector<DiagonalLinearConstraint*> _bounds; //< all the bounds in the problem
154 
155  size_t _m; //< number of unidimensional equality constraints (i.e. sum of dimension of equality constraints)
156  size_t _p; //< number of unidimensional inequality constraints (i.e. sum of dimension of inequality constraints)
157  size_t _ps; //< number of simple unidimensional inequality constraints (i.e. of the type Ax+b<=b' or Ax+b>=b')
158 
159  const bool _boundsAsConstraints; //< true if the bounds should be treated as generic constraints
160  bool _invalidatedMP; //< true when _m, _p and _ps are not up-to-date.
161  };
162 }
163 
164 #endif //_OCRABASE_QUADRATIC_SOLVER_H_
165 
166 // cmake:sourcegroup=Solvers
Objective class.
Definition: Objective.h:44
virtual VectorXd getxl() const =0
virtual MatrixXd getC() const =0
QuadraticSolver class.
virtual VectorXd getb() const =0
std::vector< LinearConstraint * > _equalityConstraints
void removeConstraint(LinearConstraint &constraint)
virtual VectorXd getu() const =0
void addBounds(BoundConstraint &constraint)
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
virtual VectorXd getd() const =0
void removeBounds(BoundConstraint &constraint)
Constraint class.
Definition: Constraint.h:100
QuadraticSolver(bool boundsAsConstraints=false)
Declaration file of the LinearFunction class.
void addConstraint(LinearConstraint &constraint)
virtual VectorXd getq() const =0
virtual VectorXd getxu() const =0
Declaration file of the Solver class.
std::vector< LinearConstraint * > _inequalityConstraints
Declaration file of the Constraint class.
virtual VectorXd getbp() const =0
void addObjective(QuadraticObjective &obj)
void removeObjective(QuadraticFunction &obj)
virtual MatrixXd getP() const =0
std::vector< DiagonalLinearConstraint * > _bounds
std::vector< QuadraticObjective * > _objectives
virtual MatrixXd getA() const =0
virtual VectorXd getl() const =0
const bool _boundsAsConstraints
void onConstraintResize(int timestamp)
Declaration file of the Objective class.
QuadraticFunction class.
Solver class.
Definition: Solver.h:70
Declaration file of the QuadraticFunction class.