ocra-recipes
Doxygen documentation for the ocra-recipes repository
FunctionUtilities.cpp
Go to the documentation of this file.
2 #include "ocra/optim/Variable.h"
3 #include <sstream>
4 
5 
6 namespace ocra
7 {
8  namespace utils
9  {
10  int getAddType(const Function& f1, const Function& f2)
11  {
12  int i = f1.getType();
13  int j = f2.getType();
14 
15  if (i==j)
16  return i;
17 
18  if (i>j)
19  {
20  int e = i;
21  i = j;
22  j = e;
23  }
24 
25  switch (j)
26  {
28  return LINEARITY_UNDEFINED;
32  break;
35  return LINEARITY_QUADRATIC;
36  break;
37  case LINEARITY_LINEAR:
38  if (i==LINEARITY_CONSTANT)
39  return LINEARITY_LINEAR;
40  break;
41  default:
42  return LINEARITY_UNDEFINED;
43  }
44  return LINEARITY_UNDEFINED;
45  }
46 
47 
48  int getAddContinuityProperty(const Function& f1, const Function& f2)
49  {
50  return std::min(f1.getContinuityProperty(), f2.getContinuityProperty());
51  }
52 
53  bool computeGradient(const Function& f1, const Function& f2)
54  {
55  return f1.canCompute<PARTIAL_X>() && f2.canCompute<PARTIAL_X>();
56  }
57 
58  bool computeHessian(const Function& f1, const Function& f2)
59  {
60  return f1.canCompute<PARTIAL_XX>() && f2.canCompute<PARTIAL_XX>();
61  }
62 
63  /*Variable* getConcatenatedVariable(Function& f1, Function& f2)
64  {
65  const std::string& n1 = f1.getVariable().getName();
66  const std::string& n2 = f2.getVariable().getName();
67  std::string name = n1+n2;
68 
69  CompositeVariable* v = new CompositeVariable(name, f1.getVariable());
70 
71  v->addByMerge(f2.getVariable());
72  return v;
73  }*/
74 
76  {
77  switch (f.getConvexityProperty())
78  {
79  case CONVEXITY_CONVEX :
80  return CONVEXITY_CONCAVE;
81 
84 
85  case CONVEXITY_CONCAVE :
86  return CONVEXITY_CONVEX;
87 
90 
93 
95  return CONVEXITY_UNDEFINED;
96 
98  return CONVEXITY_UNDEFINED;
99 
100  case CONVEXITY_QUASICONVEX :
101  return CONVEXITY_QUASICONCAVE;
102 
104  return CONVEXITY_QUASICONVEX;
105 
106  case CONVEXITY_QUASILINEAR :
107  return CONVEXITY_QUASILINEAR;
108 
109  default:
110  return CONVEXITY_UNDEFINED;
111  }
112  }
113 
114 
116  {
117  static int cpt = 0;
118  std::stringstream s;
119  s << "undefVar";
120  s << cpt++;
121  return new BaseVariable(s.str(), f.getDimension());
122  }
123  }
124 }
125 
126 // cmake:sourcegroup=Function
eFunctionConvexity getConvexityProperty(void) const
int getDimension() const
Definition: Function.cpp:41
Variable * createOutputVariable(Function &f)
int getContinuityProperty(void) const
bool computeGradient(const Function &f1, const Function &f2)
int getOppositeConvexityProperty(const Function &f)
bool computeHessian(const Function &f1, const Function &f2)
Declaration file of the FunctionProperties class.
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
Function class.
Definition: Function.h:77
eFunctionLinearity getType(void) const
bool canCompute() const
Definition: Function.h:347
This class represents a variable in a mathematical sense.
Definition: Variable.h:105
int getAddContinuityProperty(const Function &f1, const Function &f2)
int getAddType(const Function &f1, const Function &f2)
Declaration file of the Variable class.
Implements a basic variable.
Definition: Variable.h:304