31 #ifndef COSTFUNCTIONBASE_HPP_
32 #define COSTFUNCTIONBASE_HPP_
34 #include <Eigen/Dense>
36 namespace DirectTrajectoryOptimization {
42 template <
class DIMENSIONS>
43 class CostFunctionBase {
46 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
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;
55 state_size = DIMENSIONS::DimensionsSize::STATE_SIZE;
56 control_size = DIMENSIONS::DimensionsSize::CONTROL_SIZE;
59 virtual ~CostFunctionBase() {};
61 virtual double IntermediateCost(
const state_vector_t & x_k ,
const control_vector_t & u_k ,
const double & h_k) = 0;
63 virtual int getNumberOfDependentVariables() = 0 ;
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;
67 virtual double evaluate() = 0;
68 virtual Eigen::VectorXd evaluate_gradient() = 0;
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()) {
77 trajectory_size = x_trajectory.size();
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;
91 int cost_function_jacobian_size = 0;
92 int node_jacobian_size = 0;