9 return 2*c->getDimension();
10 else return c->getDimension();
23 : _invalidatedIndex(0)
34 const int ni = (int)(_nonLinearIneq.size()+_linearIneq.size());
35 if (constraint.isEquality())
37 _invalidatedIndex = std::min(_invalidatedIndex, ni+(
int)(_nonLinearEq.size()+_linearEq.size()));
38 _linearEq.push_back(&constraint);
42 _invalidatedIndex = std::min(_invalidatedIndex, ni);
43 _linearIneq.push_back(&constraint);
51 _invalidatedIndex = std::min(_invalidatedIndex, (
int)(_nonLinearIneq.size()+_linearIneq.size()+_nonLinearIneq.size()));
52 _nonLinearEq.push_back(&constraint);
56 _invalidatedIndex = std::min(_invalidatedIndex, (
int)_nonLinearIneq.size());
57 _nonLinearIneq.push_back(&constraint);
63 if (constraint.isEquality())
65 std::vector<LinearConstraint*>::iterator it = std::find(_linearEq.begin(), _linearEq.end(), &constraint);
66 if (it != _linearEq.end())
68 _invalidatedIndex = std::min(_invalidatedIndex, (
int)(_nonLinearIneq.size()+_linearIneq.size()+_nonLinearEq.size())+(
int)(it-_linearEq.begin()));
74 std::vector<LinearConstraint*>::iterator it = std::find(_linearIneq.begin(), _linearIneq.end(), &constraint);
75 if (it != _linearIneq.end())
77 _invalidatedIndex = std::min(_invalidatedIndex, (
int)_nonLinearIneq.size()+(int)(it-_linearIneq.begin()));
78 _linearIneq.erase(it);
87 std::vector<GenericConstraint*>::iterator it = std::find(_nonLinearEq.begin(), _nonLinearEq.end(), &constraint);
88 if (it != _nonLinearEq.end())
90 _invalidatedIndex = std::min(_invalidatedIndex, (
int)(_nonLinearIneq.size()+_linearIneq.size())+(
int)(it-_nonLinearEq.begin()));
91 _nonLinearEq.erase(it);
96 std::vector<GenericConstraint*>::iterator it = std::find(_nonLinearIneq.begin(), _nonLinearIneq.end(), &constraint);
97 if (it != _nonLinearIneq.end())
99 _invalidatedIndex = std::min(_invalidatedIndex, (
int)(it-_nonLinearIneq.begin()));
100 _nonLinearIneq.erase(it);
107 if (_invalidatedIndex == std::numeric_limits<int>::max())
110 const size_t n1 = _nonLinearIneq.size();
111 const size_t n2 = _linearIneq.size() + n1;
112 const size_t n3 = _nonLinearEq.size() + n2;
113 const size_t n4 = _linearEq.size() + n3;
114 const size_t n = n4+1;
117 if (n<_mappings.size())
121 for (
size_t i=_mappings.size(); i<n; ++i)
122 _mappings.push_back(
Mapping(static_cast<int>(i)));
126 size_t i = _invalidatedIndex;
128 _mappings[i+1].length = _mappings[i].length + getConstraintOnesidedDimension(_nonLinearIneq[i]);
129 _nineqn = _mappings[i].length;
131 _mappings[i+1].length = _mappings[i].length + getConstraintOnesidedDimension(_linearIneq[i-n1]);
132 _nineq = _mappings[i].length;
134 _mappings[i+1].length = _mappings[i].length + getConstraintOnesidedDimension(_nonLinearEq[i-n2]);
135 _neqn = _mappings[i].length - _nineq;
137 _mappings[i+1].length = _mappings[i].length + getConstraintOnesidedDimension(_linearEq[i-n3]);
138 _neq = _mappings[i].length - _nineq;
140 _invalidatedIndex = std::numeric_limits<int>::max();
145 _invalidatedIndex = 0;
150 if (_invalidatedIndex != std::numeric_limits<int>::max())
153 std::vector<Mapping>::iterator it = std::upper_bound(_mappings.begin(), _mappings.end(),
Mapping(i,0));
154 assert(it != _mappings.end());
156 size_t j = it->index;
157 if (j<_nonLinearIneq.size())
158 return std::make_pair(_nonLinearIneq[j], i-it->length);
160 j -= _nonLinearIneq.size();
161 if (j<_linearIneq.size())
162 return std::make_pair(_linearIneq[j], i-it->length);
164 j -= _linearIneq.size();
165 if (j<_nonLinearEq.size())
166 return std::make_pair(_nonLinearEq[j], i-it->length);
168 j -= _nonLinearEq.size();
169 return std::make_pair(_linearEq[j], i-it->length);
174 std::pair<const GenericConstraint*, int> p = (*this)[i];
176 switch (p.first->getType())
179 case CSTR_EQUAL_B:
return p.first->getValue(p.second) - p.first->getB()[p.second];
181 case CSTR_LOWER_U:
return p.first->getValue(p.second) - p.first->getU()[p.second];
183 case CSTR_GREATER_L:
return -p.first->getValue(p.second) + p.first->getL()[p.second];
185 if (p.second<p.first->getDimension())
186 return -p.first->getValue(p.second) + p.first->getL()[p.second];
189 const int n = p.second - p.first->getDimension();
190 return p.first->getValue(n) - p.first->getU()[n];
201 std::pair<GenericConstraint*, int> p = (*this)[i];
210 switch (p.first->getType())
213 case CSTR_EQUAL_B:
return 1.*p.first->getJacobian(p.second);
215 case CSTR_LOWER_U:
return 1.*p.first->getJacobian(p.second);
219 if (p.second<p.first->getDimension())
220 return -1.*p.first->getJacobian(p.second);
222 return 1.*p.first->getJacobian(p.second - p.first->getDimension());
247 MatrixXd P = MatrixXd::Random(n,n);
bool operator<(const FSQPConstraintManager::Mapping &m1, const FSQPConstraintManager::Mapping &m2)
void addConstraint(LinearConstraint &constraint)
FSQPConstraintManager class.
double getValue(int i) const
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
std::pair< GenericConstraint *, int > operator[](int i) const
Declaration file of the LinearFunction class.
void removeConstraint(LinearConstraint &constraint)
const ScalarMultMatrixXdRow getGradient(int i) const
Declaration file of the FSQPConstraintManager class.
eConstraintType getType() const
#define ocra_assert(ocra_expression)
CwiseUnaryOp< internal::scalar_multiple_op< double >, MatrixXdRow > ScalarMultMatrixXdRow
Implements a basic variable.
void updateMapping() const
Declaration file of the QuadraticFunction class.