ocra-recipes
Doxygen documentation for the ocra-recipes repository
Objective.h
Go to the documentation of this file.
1 
10 #ifndef _OCRABASE_OBJECTIVE_H_
11 #define _OCRABASE_OBJECTIVE_H_
12 
13 #ifdef WIN32
14 # pragma once
15 #endif
16 
17 // includes
18 #include "ocra/optim/Variable.h"
19 #include "ocra/optim/Function.h"
21 
22 #include <boost/static_assert.hpp>
23 #include <boost/type_traits/is_base_of.hpp>
25 
26 namespace ocra
27 {
43  template<class T>
44  class Objective
45  : public Objective<typename T::functionType_t>
46  , public FunctionInterfaceMapping<Objective<T> >
47  {
48  private:
52  Objective(const Objective&);
53  Objective& operator= (const Objective&);
55 
56  public:
57  Objective(T* function, double weight=1.);
58 
60  inline operator const T& () {return static_cast<T&>(ObjectiveBase::getFunction());}
61 
64  inline virtual T& getFunction(void) {return static_cast<T&>(ObjectiveBase::getFunction());}
65  inline virtual const T& getFunction(void) const {return static_cast<const T&>(ObjectiveBase::getFunction());}
67 
68  private:
69  typedef boost::is_base_of<Function, T> T_must_derived_from_Function;
70  BOOST_STATIC_ASSERT(T_must_derived_from_Function ::value);
71  };
72 
73 
74 
75  template<>
77  : public FunctionInterfaceMapping<Objective<Function> >
78  {
79  // ------------------------ constructors ------------------------------------
80  private:
83  Objective(const Objective&);
84  Objective& operator= (const Objective&);
86 
87  public:
90  Objective(Function* function, double weight=1.);
92 
93  // ------------------------ public interface --------------------------------
94  public:
97  inline virtual Function& getFunction() {return _function;}
98  inline virtual const Function& getFunction() const {return _function;}
100 
101  double getWeight() const;
102  void setWeight(double weight);
103  // void changeWeight(const Eigen::VectorXd& weight);
104 
105  protected:
106  Function& _function; //< the function on which the constaint is built
107 
108  private:
109  double _weight;
110  };
111 
112 
113  template<class T>
114  inline Objective<T>::Objective(T* function, double weight)
115  : Objective<typename T::functionType_t>(function, weight)
116  {}
117 
118  inline Objective<Function>::Objective(Function* function, double weight)
119  : _function(*function), _weight(weight)
120  {}
121 
122 
123  inline double Objective<Function>::getWeight() const
124  {
125  return _weight;
126  }
127 
128  inline void Objective<Function>::setWeight(double weight)
129  {
130  _weight = weight;
131  }
132 
133  // inline void Objective<SquaredLinearFunction>::changeWeight(const Eigen::VectorXd& weight)
134  // {
135  // _function.changeWeight(weight);
136  // }
137 
138 }
139 
140 
141 
144 
145 namespace ocra
146 {
151 }
152 
153 
154 #endif //_OCRABASE_OBJECTIVE_H_
155 
156 // cmake:sourcegroup=Constraint
Objective class.
Definition: Objective.h:44
Objective< SquaredLinearFunction > SquaredLinearObjective
Definition: Objective.h:150
Declaration file of the SquaredLinearFunction class.
Objective< LinearFunction > LinearObjective
Definition: Objective.h:148
Declaration file of the FunctionInterfaceMapping struct.
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
Function class.
Definition: Function.h:77
virtual const T & getFunction(void) const
Definition: Objective.h:65
Declaration file of the LinearFunction class.
virtual T & getFunction(void)
Definition: Objective.h:64
Objective< QuadraticFunction > QuadraticObjective
Definition: Objective.h:149
Objective< Function > GenericObjective
Definition: Objective.h:147
Declaration file of the Function class.
virtual Function & getFunction()
Definition: Objective.h:97
Declaration file of the Variable class.
virtual const Function & getFunction() const
Definition: Objective.h:98
Declaration file of the QuadraticFunction class.