ocra-recipes
Doxygen documentation for the ocra-recipes repository
BoundFunction.cpp
Go to the documentation of this file.
2 #include <stdexcept>
3 
4 namespace ocra
5 {
6  BoundFunction::BoundFunction(Variable& x, const VectorXd& bound, eBoundType type)
7  : NamedInstance("bound function")
10  , DiagonalLinearFunction(x, static_cast<double>(type), bound, false)
11  {
12  if (type == BOUND_TYPE_SUPERIOR)
13  _b *= -1;
14  else if (type != BOUND_TYPE_INFERIOR)
15  throw std::runtime_error("[ocra::BoundFunction::BoundFunction] invalid bound type");
16  }
17 
18  BoundFunction::BoundFunction(Variable& x, const double bound, eBoundType type)
19  : NamedInstance("bound function")
22  , DiagonalLinearFunction(x, static_cast<double>(type), bound, true)
23  {
24  if (type == BOUND_TYPE_SUPERIOR)
25  _b *= -1;
26  else if (type != BOUND_TYPE_INFERIOR)
27  throw std::runtime_error("[ocra::BoundFunction::BoundFunction] invalid bound type");
28  }
29 
30  void BoundFunction::doChangeDiagonal(const VectorXd& d)
31  {
32  throw std::runtime_error("[ocra::BoundFunction::changeDiagonal] invalid operation on BoundFunction");
33  }
34 
35 
36  void BoundFunction::doChangeDiagonal(const double diagonalElementValue, const bool changeDefault)
37  {
38  throw std::runtime_error("[ocra::BoundFunction::changeDiagonal] invalid operation on BoundFunction");
39  }
40 
41 
43  {
44  throw std::runtime_error("[ocra::BoundFunction::changeDefaultDiagonalValue] invalid operation on BoundFunction");
45  }
46 
47 
49  {
50  throw std::runtime_error("[ocra::BoundFunction::changeDefaultbValue] invalid operation on BoundFunction");
51  }
52 
53 
54  void BoundFunction::changeBounds(const double bound)
55  {
56  if (_jacobian(0,0) == 1) //SUPERIOR_BOUND
57  _b.setConstant(-bound);
58  else
59  _b.setConstant(bound);
60  }
61 
62 
63  void BoundFunction::changeBounds(const VectorXd& bounds)
64  {
65  _b = bounds;
66  if (_jacobian(0,0) == 1) //SUPERIOR_BOUND
67  _b *= -1.;
68  }
69 
70 
71  void BoundFunction::changeIthBound(const int i, const double bound)
72  {
73  ocra_assert(i<_dim && "[BoundFunction::changeIthBound] Invalid index i");
74  if (_jacobian(0,0) == 1) //SUPERIOR_BOUND
75  _b[i] = -bound;
76  else
77  _b[i] = bound;
78  }
79 }
80 
81 // cmake:sourcegroup=Function
82 
void doChangeDefaultDiagonalValue(const double v)
void changeBounds(const double bound)
Variable & x
Definition: Function.h:309
void doChangeDiagonal(const VectorXd &d)
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
MatrixXd & _jacobian
Definition: Function.h:313
void changeIthBound(const int i, const double bound)
This class represents a variable in a mathematical sense.
Definition: Variable.h:105
void doChangeDefaultbValue(const double v)
Declaration file of the BoundFunction class.
#define ocra_assert(ocra_expression)
Definition: ocra_assert.h:45
const int & _dim
Definition: Function.h:320
DiagonalLinearFunction class.