ocra-recipes
Doxygen documentation for the ocra-recipes repository
CmlQuadraticSolver.h
Go to the documentation of this file.
1 
10 #ifndef _OCRABASE_CML_QUADRATIC_SOLVER_H_
11 #define _OCRABASE_CML_QUADRATIC_SOLVER_H_
12 
13 //ocra includes
14 #include "ocra/optim/CompositeVariable.h"
16 
17 //cml includes
18 #include "cml/QPSolver.h"
19 
20 //std includes
21 #include <vector>
22 
28 namespace ocra
29 {
38  {
39  // ------------------------ structures --------------------------------------
40  public:
42  {
45  };
46  //TODO: A discuter : garder CML ? Oui on le garde,
47  // mais ca signifie qu'il faut sortirCmlQuadraticSolver de base-optim.
48  // -> Oł mettre CmlQuadraticSolver ?
49  // Simplifier la gestion actuelle avec deux enum ocra::cmlQPSolverType / xde::cmlQPSolver ?
50  protected:
51  private:
52 
53  // ------------------------ public static members ---------------------------
54  public:
55 
56  // ------------------------ constructors ------------------------------------
57  private:
59  protected:
60  public:
61  CmlQuadraticSolver(int type = xde::cmlQPSolver::LEMKE_SOLVER);
62 
63  // ------------------------ public interface --------------------------------
64  public:
65  void setTolerance(double epsilon);
66  void setMaxIteration(cfl_size_t maxIter);
67 
68 // const double getTolerance(void) const;
69  cfl_size_t getMaxIteration(void) const;
70 
71  virtual const std::string& getMoreInfo(void) const;
72 
73  virtual void addLinearEqualityConstraint(LinearConstraint* constraint);
74  virtual void addLinearInequalityConstraint(LinearConstraint* constraint);
75  virtual void removeConstraint(LinearConstraint* constraint);
76  virtual void setObjective(QuadraticFunction* obj, real weight=1.);
77  virtual void addObjective(QuadraticFunction* obj, real weight=1.);
78  virtual void removeObjective(QuadraticFunction* obj);
79 // void setVariable(Variable& var);
80 
81  virtual void printValuesAtSolution(void);
82  bool checkConstraints(void);
83 
84 
85  virtual const MatrixBase& getP(void) const;
86  virtual const MatrixBase& getA(void) const;
87  virtual const MatrixBase& getC(void) const;
88  virtual const VectorBase& getq(void) const;
89  virtual const VectorBase& getb(void) const;
90  virtual const VectorBase& getd(void) const;
91  virtual const VectorBase& getu(void) const;
92  virtual const VectorBase& getl(void) const;
93 
94  // ------------------------ public methods ----------------------------------
95  public:
96 
97  // ------------------------ public static methods ---------------------------
98  public:
99 
100  // ------------------------ protected methods -------------------------------
101  protected:
102  virtual const Solver::Result& doSolve(void);
103  virtual void doPrepare(void);
104  virtual void recomputeVariable(void);
105 
106 
107  // ------------------------ protected static methods ------------------------
108  protected:
109 
110  // ------------------------ private methods ---------------------------------
111  private:
112  /*void updateN(void);
113  void updateM(void);
114  void updateP(void);
115  void updateNM(void);
116  void updateNP(void);
117  void updateMNP(void);*/
118  void updateMatrixDimension(void);
119  void updateSize(void);
120 
121  void updateMatrices(void);
122  void updateEqualityEquations(std::vector<cfl_size_t>& workingMapping);
123  void updateInequalityEquations(std::vector<cfl_size_t>& workingMapping);
124  void updateObjectiveEquations(std::vector<cfl_size_t>& workingMapping);
125 
126  // ------------------------ private static methods --------------------------
127  private:
128 
129  // ------------------------ protected members -------------------------------
130  protected:
131 
132  // ------------------------ protected static members ------------------------
133  protected:
134 
135  // ------------------------ private members ---------------------------------
136  private:
137  int _solverType;
138  xde::cmlQPSolver* _solver;
139 
140  Matrix _Q; //< P (nxn)
141  Vector _k; //< q (n)
142  Matrix _H; //< A (mxn)
143  Vector _a; //< b (m)
144  Matrix _G; //< C (pxn)
145  Vector _c; //< d (p)
146 
147  //for output
148  mutable Vector _minus_k;
149  mutable Matrix _minus_G;
150  mutable Vector _minus_c;
151  mutable Vector _l;
152  mutable Vector _u;
153 
154 
155  /*bool _nChanged;
156  bool _mChanged;
157  bool _pChanged;*/
158 
159  // ------------------------ private static members --------------------------
160  private:
161 
162  // ------------------------ friendship declarations -------------------------
163  };
164 
165  void testSolveCmlQP(void);
167 }
168 
169 #endif //_OCRABASE_CML_QUADRATIC_SOLVER_H_
170 
171 // cmake:sourcegroup=toBeUpdated
172 
virtual void addLinearEqualityConstraint(LinearConstraint *constraint)
Declaration file of the QuadraticSolver class.
QuadraticSolver class.
virtual void removeObjective(QuadraticFunction *obj)
void testSolveCmlQPWithNonFeasiblePb(void)
virtual void addLinearInequalityConstraint(LinearConstraint *constraint)
virtual const VectorBase & getd(void) const
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
virtual const MatrixBase & getA(void) const
Constraint class.
Definition: Constraint.h:100
virtual const std::string & getMoreInfo(void) const
virtual const MatrixBase & getC(void) const
virtual void removeConstraint(LinearConstraint *constraint)
virtual const VectorBase & getb(void) const
virtual const Solver::Result & doSolve(void)
virtual const MatrixBase & getP(void) const
void setTolerance(double epsilon)
virtual void recomputeVariable(void)
virtual void addObjective(QuadraticFunction *obj, real weight=1.)
virtual const VectorBase & getu(void) const
double real
Definition: MathTypes.h:27
void setMaxIteration(cfl_size_t maxIter)
virtual void setObjective(QuadraticFunction *obj, real weight=1.)
virtual const VectorBase & getl(void) const
virtual void printValuesAtSolution(void)
void testSolveCmlQP(void)
QuadraticFunction class.
cfl_size_t getMaxIteration(void) const
virtual const VectorBase & getq(void) const
CmlQuadraticSolver class.
virtual void doPrepare(void)