15 #ifndef _OCRABASE_CONSTRAINT_H_ 16 #define _OCRABASE_CONSTRAINT_H_ 28 #include <boost/static_assert.hpp> 29 #include <boost/type_traits/is_base_of.hpp> 101 :
public Constraint<typename T::functionType_t>
131 Constraint(T*
function,
bool equality,
const VectorXd& v=VectorXd());
149 Constraint(T*
function,
const VectorXd& l=VectorXd(),
const VectorXd& u=VectorXd());
161 typedef boost::is_base_of<Function, T> T_must_derived_from_Function;
162 BOOST_STATIC_ASSERT(T_must_derived_from_Function ::value);
176 ,
public SubjectBase<EVT_CSTR_CHANGE_BOUNDS_NUMBER>
224 Constraint(
Function*
function,
const VectorXd& l=VectorXd(),
const VectorXd& u=VectorXd());
243 inline bool isRespected(
int index=-1)
const;
247 inline bool isEquality()
const;
248 inline bool isInequality()
const;
263 void setB(
const VectorXd& b);
275 void setL(
const VectorXd& l);
287 void setU(
const VectorXd& u);
301 void setLandU(
const VectorXd& l,
const VectorXd& u);
311 const VectorXd& getB()
const;
316 const VectorXd& getL()
const;
321 const VectorXd& getU()
const;
329 void setViolationTolerance(
double tol);
330 double getViolationTolerance()
const;
367 case CSTR_EQUAL_B:
return ((getValue().array()-_u.array()).abs() <= _violation).all();
break;
368 case CSTR_LOWER_ZERO:
return (getValue().array() <= _violation).all();
break;
369 case CSTR_LOWER_U:
return ((getValue().array()-_u.array()) <= _violation).all();
break;
371 case CSTR_GREATER_L:
return ((getValue().array()-_l.array()) >= -_violation).all();
break;
373 && ((getValue().array()-_l.array()) >= -_violation).all();
break;
375 throw std::runtime_error(
"[Constraint<T>::isValid] invalid constraint type");
382 case CSTR_EQUAL_ZERO:
return fabs(getValue(index)) <= _violation;
break;
383 case CSTR_EQUAL_B:
return fabs(getValue(index)-_u[index]) <= _violation;
break;
385 case CSTR_LOWER_U:
return (getValue(index)-_u[index]) <= _violation;
break;
387 case CSTR_GREATER_L:
return (getValue(index)-_l[index]) >= -_violation;
break;
389 && (getValue(index)-_l[index]) >= -_violation;
break;
391 throw std::runtime_error(
"[Constraint<T>::isValid] invalid constraint type");
408 ocra_assert(isEquality() &&
"You can change b only for an equality constraint");
411 ocra_assert(b.size() == getDimension() &&
"b has not the size of the function");
421 ocra_assert(isInequality() &&
"You can change l only for an inequality constraint");
424 ocra_assert(l.size() == getDimension() &&
"l has not the size of the function");
430 || (_u.size() != 0 && (l.array()-_violation < _u.array()).all())
432 &&
"when there is a upper bound, it must be greater than l");
460 ocra_assert(isInequality() &&
"You can change u only for an inequality constraint");
463 ocra_assert(u.size() == getDimension() &&
"u has not the size of the function");
469 || (_l.size() != 0 && (_l.array()-_violation < u.array()).all())
471 &&
"when there is a lower bound, it must be lower than u");
499 ocra_assert(isInequality() &&
"You can change l and u only for an inequality constraint");
502 ocra_assert(l.size() == getDimension() &&
"l has not the size of the function");
505 ocra_assert(u.size() == getDimension() &&
"u has not the size of the function");
506 ocra_assert((l.array()-_violation < u.array()).all() &&
"l must be lower than u");
529 ocra_assert( u.size()>0 &&
"l and u are not initialized, constraint is undefined");
545 ocra_assert(isEquality() &&
"getB() can be called only on an equality constraint");
551 ocra_assert(isInequality() &&
"getL() can be called only on an inequality constraint");
557 ocra_assert(isInequality() &&
"getU() can be called only on an inequality constraint");
563 ocra_assert(tol>=0 &&
"tolerance must be a positive number");
577 :
Constraint<typename T::functionType_t>(function, equality, v)
586 :
Constraint<typename T::functionType_t>(function, l, u)
594 :_function(*function), _u(v), _violation(1.e-7)
600 ocra_assert(v.size() == getDimension() &&
"v has not the size of the function");
610 ocra_assert(v.size() == getDimension() &&
"v has not the size of the function");
619 :_function(*function), _l(l), _u(u), _violation(1.e-7)
623 ocra_assert(l.size() == getDimension() &&
"l has not the size of the function");
626 ocra_assert(_l.size() == _u.size() &&
"l and u don't have the same size");
627 ocra_assert((l.array()-_violation < u.array()).all() &&
"l must be lower than u");
640 ocra_assert(u.size() == getDimension() &&
"u has not the size of the function");
682 #endif //_OCRABASE_CONSTRAINT_H_
Declaration file of the IdentityFunction class.
virtual Function & getFunction()
Constraint< IdentityFunction > IdentityConstraint
Constraint< LinearFunction > LinearConstraint
Constraint< BoundFunction > BoundConstraint
Declaration file of the FunctionInterfaceMapping struct.
Constraint< Function > GenericConstraint
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
Declaration file of the LinearFunction class.
virtual T & getFunction(void)
virtual const Function & getFunction() const
Declaration file of the DiagonalLinearFunction class.
Declaration file of the Function class.
Declaration file of the BoundFunction class.
virtual const T & getFunction(void) const
Constraint< DiagonalLinearFunction > DiagonalLinearConstraint
#define ocra_assert(ocra_expression)
Declaration file of the Variable class.