DirectTrajectoryOptimization  v0.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
CostFunctionBase.hpp
Go to the documentation of this file.
1 /***********************************************************************************
2 Copyright (c) 2017, Diego Pardo. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without modification,
5 are permitted provided that the following conditions are met:
6  * Redistributions of source code must retain the above copyright notice,
7  this list of conditions and the following disclaimer.
8  * Redistributions in binary form must reproduce the above copyright notice,
9  this list of conditions and the following disclaimer in the documentation
10  and/or other materials provided with the distribution.
11  * Neither the name of ETH ZURICH nor the names of its contributors may be used
12  to endorse or promote products derived from this software without specific
13  prior written permission.
14 
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
16 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
18 SHALL ETH ZURICH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
19 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 ***************************************************************************************/
25 
31 #ifndef COSTFUNCTIONBASE_HPP_
32 #define COSTFUNCTIONBASE_HPP_
33 
34 #include <Eigen/Dense>
35 
36 namespace DirectTrajectoryOptimization {
37 namespace BaseClass{
38 
39 /*
40  * \brief Base class to derive cost functions
41  */
42 template <class DIMENSIONS>
43 class CostFunctionBase {
44 public:
45 
46  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
47 
48  typedef typename DIMENSIONS::state_vector_t state_vector_t;
49  typedef typename DIMENSIONS::state_vector_array_t state_vector_array_t;
50  typedef typename DIMENSIONS::control_vector_t control_vector_t;
51  typedef typename DIMENSIONS::control_vector_array_t control_vector_array_t;
52 
53  CostFunctionBase() {
54 
55  state_size = DIMENSIONS::DimensionsSize::STATE_SIZE;
56  control_size = DIMENSIONS::DimensionsSize::CONTROL_SIZE;
57 
58  };
59  virtual ~CostFunctionBase() {};
60 
61  virtual double IntermediateCost(const state_vector_t & x_k , const control_vector_t & u_k , const double & h_k) = 0;
62 
63  virtual int getNumberOfDependentVariables() = 0 ;
64 
65  virtual void gradient_xuh(const state_vector_t & x_k , const control_vector_t & u_k , const double & h_k, Eigen::VectorXd & f0_gradient) = 0;
66 
67  virtual double evaluate() = 0;
68  virtual Eigen::VectorXd evaluate_gradient() = 0;
69 
70  virtual void setCurrentTrajectory(const state_vector_array_t & x_t , const control_vector_array_t & u_t , const Eigen::VectorXd & h,
71  const Eigen::VectorXi & l_index = Eigen::VectorXi()) {
72 
73  x_trajectory = x_t;
74  u_trajectory = u_t;
75  h_trajectory = h;
76  left_index = l_index;
77  trajectory_size = x_trajectory.size();
78  }
79 
80 protected:
81 
82  int state_size = 0;
83  int control_size = 0;
84 
85  state_vector_array_t x_trajectory;
86  control_vector_array_t u_trajectory;
87  Eigen::VectorXd h_trajectory;
88  Eigen::VectorXi left_index;
89  int trajectory_size = 0;
90 
91  int cost_function_jacobian_size = 0;
92  int node_jacobian_size = 0;
93 };
94 } // namespace BaseClass
95 } // namespace DirectTrajectoryOptimization
96 
97 #endif /* COSTFUNCTIONBASE_HPP_ */