ocra-recipes
Doxygen documentation for the ocra-recipes repository
FSQPConstraintManager.h
Go to the documentation of this file.
1 
11 #ifndef _OCRABASE_FSQP_CONSTRAINT_MANAGER_H_
12 #define _OCRABASE_FSQP_CONSTRAINT_MANAGER_H_
13 
14 // includes
15 #include "Constraint.h"
16 #include <vector>
17 
18 namespace ocra
19 {
35  {
36  // ------------------------ structures --------------------------------------
37  public:
38  typedef CwiseUnaryOp<internal::scalar_multiple_op<double>, MatrixXdRow> ScalarMultMatrixXdRow;
39 
40  struct Mapping
41  {
42  int length;
43  int index;
44 
45  Mapping() : length(0), index(0) {}
46  Mapping(int i) : length(0), index(i) {}
47  Mapping(int l, int i) : length(l), index(i) {}
48  };
49 
50  // ------------------------ constructors ------------------------------------
51  private:
54  protected:
55  public:
57 
58  // ------------------------ public interface --------------------------------
59  public:
60  void addConstraint(LinearConstraint& constraint);
61  void addConstraint(GenericConstraint& constraint);
62  void removeConstraint(LinearConstraint& constraint);
63  void removeConstraint(GenericConstraint& constraint);
64 
65  double getValue(int i) const;
66  const ScalarMultMatrixXdRow getGradient(int i) const;
67  const ScalarMultMatrixXdRow getGradient(const std::pair<GenericConstraint*, int>& p) const;
68 
69  int nineqn() const {updateMapping(); return _nineqn;}
70  int nineq() const {updateMapping(); return _nineq;}
71  int neqn() const {updateMapping(); return _neqn;}
72  int neq() const {updateMapping(); return _neq;}
73 
74  void updateMapping() const; //force the update of the mapping which is otherwise done lazily when calling operator[]
75  void invalidateMapping();
76 
77  std::pair<GenericConstraint*, int> operator[] (int i) const;
78 
79 
80  // ------------------------ private members ---------------------------------
81  private:
82  mutable int _nineqn;
83  mutable int _nineq;
84  mutable int _neqn;
85  mutable int _neq;
86  std::vector<GenericConstraint*> _nonLinearIneq;
87  std::vector<LinearConstraint*> _linearIneq;
88  std::vector<GenericConstraint*> _nonLinearEq;
89  std::vector<LinearConstraint*> _linearEq;
90 
91  mutable std::vector<Mapping> _mappings;
92  mutable int _invalidatedIndex;
93  };
94 
95  void testFsqpMapping();
96 }
97 
98 #endif //_OCRABASE_FSQP_CONSTRAINT_MANAGER_H_
void addConstraint(LinearConstraint &constraint)
FSQPConstraintManager class.
void testFsqpMapping()
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
Constraint class.
Definition: Constraint.h:100
std::pair< GenericConstraint *, int > operator[](int i) const
void removeConstraint(LinearConstraint &constraint)
const ScalarMultMatrixXdRow getGradient(int i) const
Declaration file of the Constraint class.
Eigen::DenseBase< MatrixXd >::ConstRowXpr MatrixXdRow
Definition: MathTypes.h:29
CwiseUnaryOp< internal::scalar_multiple_op< double >, MatrixXdRow > ScalarMultMatrixXdRow