32 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR =
double>
36 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
57 : costFct_(costFct), w_(w), timeGrid_(timeGrid), settings_(settings)
59 phi_.resize(settings_.
N_ + 1);
67 void evalGradient(
size_t grad_length, Eigen::Map<Eigen::Matrix<SCALAR, Eigen::Dynamic, 1>>& grad)
override;
75 std::shared_ptr<ct::optcon::CostFunctionQuadratic<STATE_DIM, CONTROL_DIM, SCALAR>> costFct_;
76 std::shared_ptr<OptVectorDms<STATE_DIM, CONTROL_DIM, SCALAR>> w_;
77 std::shared_ptr<tpl::TimeGrid<SCALAR>> timeGrid_;
79 Eigen::Matrix<SCALAR, Eigen::Dynamic, 1> phi_;
84 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR>
90 for (
size_t i = 0;
i < settings_.
N_ + 1; ++
i)
92 costFct_->setCurrentStateAndControl(
93 w_->getOptimizedState(
i), w_->getOptimizedControl(
i), timeGrid_->getShotStartTime(
i));
94 cost += phi_(
i) * costFct_->evaluateIntermediate();
97 costFct_->setCurrentStateAndControl(w_->getOptimizedState(settings_.
N_), control_vector_t::Zero());
98 cost += costFct_->evaluateTerminal();
104 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR>
106 Eigen::Map<Eigen::Matrix<SCALAR, Eigen::Dynamic, 1>>& grad)
110 for (
size_t i = 0;
i < settings_.
N_ + 1; ++
i)
112 costFct_->setCurrentStateAndControl(
113 w_->getOptimizedState(
i), w_->getOptimizedControl(
i), timeGrid_->getShotStartTime(
i));
114 grad.segment(w_->getStateIndex(
i), STATE_DIM) += phi_(
i) * costFct_->stateDerivativeIntermediate();
115 grad.segment(w_->getControlIndex(
i), CONTROL_DIM) += phi_(
i) * costFct_->controlDerivativeIntermediate();
119 costFct_->setCurrentStateAndControl(w_->getOptimizedState(settings_.
N_), control_vector_t::Zero());
120 grad.segment(w_->getStateIndex(settings_.
N_), STATE_DIM) += costFct_->stateDerivativeTerminal();
124 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR>
131 for (
size_t i = 0;
i < settings_.
N_;
i++)
132 phi_(
i) = (timeGrid_->getShotDuration(
i));
139 phi_(0) =
SCALAR(0.5) * (timeGrid_->getShotDuration(0));
141 for (
size_t i = 1;
i < settings_.
N_;
i++)
142 phi_(
i) =
SCALAR(0.5) * (timeGrid_->getShotEndTime(
i) - timeGrid_->getShotStartTime(
i - 1));
144 phi_(settings_.
N_) =
SCALAR(0.5) * (timeGrid_->getShotDuration(settings_.
N_));
148 throw(std::runtime_error(
" ERROR: Unknown spline-type in CostEvaluatorSimple - exiting."));
CostEvaluatorSimple()=delete
Implements an abstract base class which evaluates the cost function and its gradient in the NLP...
Definition: DiscreteCostEvaluatorBase.h:22
Definition: DmsSettings.h:26
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef DmsDimensions< STATE_DIM, CONTROL_DIM, SCALAR > DIMENSIONS
Definition: CostEvaluatorSimple.h:38
This class is a wrapper around the NLP Optvector. It wraps the Vectors from the NLP solvers into stat...
Definition: OptVectorDms.h:37
SCALAR eval() override
Evaluates the cost function.
Definition: CostEvaluatorSimple.h:85
size_t N_
Definition: DmsSettings.h:51
Describes a cost function with a quadratic approximation, i.e. one that can compute first and second ...
Definition: CostFunctionQuadratic.hpp:29
Definition: DmsSettings.h:26
void evalGradient(size_t grad_length, Eigen::Map< Eigen::Matrix< SCALAR, Eigen::Dynamic, 1 >> &grad) override
Evaluates the cost gradient.
Definition: CostEvaluatorSimple.h:105
CppAD::AD< CppAD::cg::CG< double > > SCALAR
Defines basic types used in the DMS algorithm.
Definition: DmsDimensions.h:18
Definition: TimeGrid.h:27
for i
Definition: mpc_unittest_plotting.m:14
~CostEvaluatorSimple() override=default
SplineType_t splineType_
Definition: DmsSettings.h:54
CostEvaluatorSimple(std::shared_ptr< ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >> costFct, std::shared_ptr< OptVectorDms< STATE_DIM, CONTROL_DIM, SCALAR >> w, std::shared_ptr< tpl::TimeGrid< SCALAR >> timeGrid, DmsSettings settings)
Custom constructor.
Definition: CostEvaluatorSimple.h:53
DIMENSIONS::state_vector_t state_vector_t
Definition: CostEvaluatorSimple.h:40
Defines the DMS settings.
Definition: DmsSettings.h:23
Evaluates the cost at the shots and performs some interpolation in between.
Definition: CostEvaluatorSimple.h:33
DIMENSIONS::control_vector_t control_vector_t
Definition: CostEvaluatorSimple.h:41