12 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR_EVAL,
typename SCALAR>
20 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR_EVAL,
typename SCALAR>
25 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR_EVAL,
typename SCALAR>
31 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR_EVAL,
typename SCALAR>
33 const Eigen::Matrix<SCALAR_EVAL, STATE_DIM, 1>&
x,
34 const Eigen::Matrix<SCALAR_EVAL, CONTROL_DIM, 1>&
u,
41 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR_EVAL,
typename SCALAR>
45 ct::core::ADCGScalar
t)
47 throw std::runtime_error(
"The cost function term term " +
name_ +
" does not implement evaluate CppadCg.");
51 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR_EVAL,
typename SCALAR>
54 return c_i_->isActive(t);
57 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR_EVAL,
typename SCALAR>
60 return c_i_->computeActivation(t);
63 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR_EVAL,
typename SCALAR>
69 throw std::runtime_error(
70 "This cost function element is not implemented " 71 "for the given term. Please use either auto-diff cost function " 72 "or implement the analytical derivatives manually.");
75 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR_EVAL,
typename SCALAR>
82 throw std::runtime_error(
83 "This cost function element is not implemented " 84 "for the given term. Please use either auto-diff cost function or " 85 "implement the analytical derivatives manually.");
88 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR_EVAL,
typename SCALAR>
94 throw std::runtime_error(
95 "This cost function element is not implemented " 96 "for the given term. Please use either auto-diff cost function " 97 "or implement the analytical derivatives manually.");
100 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR_EVAL,
typename SCALAR>
105 const SCALAR_EVAL& t)
107 throw std::runtime_error(
108 "This cost function element is not implemented " 109 "for the given term. Please use either auto-diff cost function " 110 "or implement the analytical derivatives manually.");
113 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR_EVAL,
typename SCALAR>
118 const SCALAR_EVAL& t)
120 throw std::runtime_error(
121 "This cost function element is not implemented " 122 "for the given term. Please use either auto-diff cost function " 123 "or implement the analytical derivatives manually.");
126 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR_EVAL,
typename SCALAR>
128 const std::string& termName,
131 throw std::runtime_error(
132 "This cost function element is not implemented for the given term. Please use either auto-diff cost function " 133 "or implement the analytical derivatives manually.");
136 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR_EVAL,
typename SCALAR>
146 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR_EVAL,
typename SCALAR>
148 const std::string& termName,
152 std::cout <<
"TermBase: loading TimeActivation ..." << std::endl;
154 boost::property_tree::ptree pt;
155 boost::property_tree::read_info(filename, pt);
159 std::string activationKind = pt.get<std::string>(termName +
".time_activation" +
".kind");
160 boost::algorithm::to_lower(activationKind);
161 std::shared_ptr<ct::core::tpl::ActivationBase<SCALAR_EVAL>> c_i;
163 c_i->loadConfigFile(filename, termName +
".time_activation", verbose);
166 throw std::runtime_error(
"Activation type \"" + activationKind +
"\" not supported");
174 }
catch (std::exception& e)
177 std::cout <<
"TermBase: encountered exception while loading TimeActivation." << std::endl;
182 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR_EVAL,
typename SCALAR>
188 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR_EVAL,
typename SCALAR>
194 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR_EVAL,
typename SCALAR>
196 const Eigen::Matrix<SCALAR_EVAL, STATE_DIM, 1>& newRefState)
200 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR_EVAL,
typename SCALAR>
202 const Eigen::Matrix<SCALAR_EVAL, CONTROL_DIM, 1>& newRefControl)
206 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR_EVAL,
typename SCALAR>
210 throw std::runtime_error(
"getReferenceState is not implemented for the current term!");
virtual Eigen::Matrix< SCALAR_EVAL, STATE_DIM, 1 > getReferenceState() const
retrieve this term's current reference state
Definition: TermBase-impl.hpp:207
virtual SCALAR evaluate(const Eigen::Matrix< SCALAR, STATE_DIM, 1 > &x, const Eigen::Matrix< SCALAR, CONTROL_DIM, 1 > &u, const SCALAR &t)=0
Evaluates the term at x, u, t.
void setName(const std::string &termName)
Sets the name of the term.
Definition: TermBase-impl.hpp:189
ct::core::ControlVector< control_dim > u
Definition: LoadFromFileTest.cpp:21
SCALAR_EVAL eval(const Eigen::Matrix< SCALAR_EVAL, STATE_DIM, 1 > &x, const Eigen::Matrix< SCALAR_EVAL, CONTROL_DIM, 1 > &u, const SCALAR_EVAL &t)
Gets called by the analytical costfunction. Adds time dependent activations on top of the term...
Definition: TermBase-impl.hpp:32
virtual ~TermBase()
Destructor.
Definition: TermBase-impl.hpp:26
virtual void loadConfigFile(const std::string &filename, const std::string &termName, bool verbose=false)
load this term from a configuration file
Definition: TermBase-impl.hpp:127
An interface for a term, supporting both analytical and auto-diff terms.
Definition: TermBase.hpp:30
Eigen::Matrix< SCALAR_EVAL, CONTROL_DIM, STATE_DIM > control_state_matrix_t
Definition: TermBase.hpp:41
clear all close all load ct GNMSLog0 mat reformat t
Definition: gnmsPlot.m:6
TermBase(std::string name="Unnamed")
Default constructor.
Definition: TermBase-impl.hpp:13
tpl::ActivationBase< double > ActivationBase
virtual void updateReferenceState(const Eigen::Matrix< SCALAR_EVAL, STATE_DIM, 1 > &newRefState)
updates the reference state for this term
Definition: TermBase-impl.hpp:195
ct::core::StateVector< state_dim > x
Definition: LoadFromFileTest.cpp:20
const std::string & getName() const
Returns the name of the term.
Definition: TermBase-impl.hpp:183
virtual control_state_matrix_t stateControlDerivative(const core::StateVector< STATE_DIM, SCALAR_EVAL > &x, const core::ControlVector< CONTROL_DIM, SCALAR_EVAL > &u, const SCALAR_EVAL &t)
compute the cross-term derivative (state-control) of this cost function term
Definition: TermBase-impl.hpp:115
std::shared_ptr< ct::core::tpl::ActivationBase< SCALAR_EVAL > > c_i_
time activations for this term
Definition: TermBase.hpp:36
SCALAR_EVAL computeActivation(SCALAR_EVAL t)
compute time activation
Definition: TermBase-impl.hpp:58
Eigen::Matrix< SCALAR_EVAL, STATE_DIM, STATE_DIM > state_matrix_t
Definition: TermBase.hpp:39
#define CT_LOADABLE_ACTIVATIONS(SCALAR)
void setTimeActivation(std::shared_ptr< ct::core::tpl::ActivationBase< SCALAR_EVAL >> c_i, bool verbose=false)
set the time activation functions for this term
Definition: TermBase-impl.hpp:137
virtual void updateReferenceControl(const Eigen::Matrix< SCALAR_EVAL, CONTROL_DIM, 1 > &newRefControl)
updates the reference control for this term
Definition: TermBase-impl.hpp:201
const bool verbose
Definition: ConstraintComparison.h:18
virtual core::StateVector< STATE_DIM, SCALAR_EVAL > stateDerivative(const core::StateVector< STATE_DIM, SCALAR_EVAL > &x, const core::ControlVector< CONTROL_DIM, SCALAR_EVAL > &u, const SCALAR_EVAL &t)
compute derivative of this cost term w.r.t. the state
Definition: TermBase-impl.hpp:64
virtual state_matrix_t stateSecondDerivative(const core::StateVector< STATE_DIM, SCALAR_EVAL > &x, const core::ControlVector< CONTROL_DIM, SCALAR_EVAL > &u, const SCALAR_EVAL &t)
compute second order derivative of this cost term w.r.t. the state
Definition: TermBase-impl.hpp:77
std::string name_
a name identifier for this term
Definition: TermBase.hpp:34
void loadTimeActivation(const std::string &filename, const std::string &termName, bool verbose=false)
load the time activation functions for this term from file
Definition: TermBase-impl.hpp:147
virtual core::ControlVector< CONTROL_DIM, SCALAR_EVAL > controlDerivative(const core::StateVector< STATE_DIM, SCALAR_EVAL > &x, const core::ControlVector< CONTROL_DIM, SCALAR_EVAL > &u, const SCALAR_EVAL &t)
compute derivative of this cost term w.r.t. the control input
Definition: TermBase-impl.hpp:89
virtual control_matrix_t controlSecondDerivative(const core::StateVector< STATE_DIM, SCALAR_EVAL > &x, const core::ControlVector< CONTROL_DIM, SCALAR_EVAL > &u, const SCALAR_EVAL &t)
compute second order derivative of this cost term w.r.t. the control input
Definition: TermBase-impl.hpp:102
virtual bool isActiveAtTime(SCALAR_EVAL t)
Returns if term is non-zero at a specific time By default, all terms are evaluated at all times...
Definition: TermBase-impl.hpp:52
Eigen::Matrix< SCALAR_EVAL, CONTROL_DIM, CONTROL_DIM > control_matrix_t
Definition: TermBase.hpp:40