- 3.0.2 optimal control module.
ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR > Class Template Reference

A cost function which contains only terms that have analytical derivatives. More...

#include <CostFunctionAnalytical.hpp>

Inheritance diagram for ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >:
ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR > ct::optcon::CostFunction< STATE_DIM, CONTROL_DIM, SCALAR >

Public Types

typedef Eigen::Matrix< SCALAR, CONTROL_DIM, CONTROL_DIM > control_matrix_t
 
typedef Eigen::Matrix< SCALAR, CONTROL_DIM, STATE_DIM > control_state_matrix_t
 
typedef core::StateVector< STATE_DIM, SCALARstate_vector_t
 
typedef core::ControlVector< CONTROL_DIM, SCALARcontrol_vector_t
 
- Public Types inherited from ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >
typedef Eigen::Matrix< SCALAR, CONTROL_DIM, CONTROL_DIM > control_matrix_t
 
typedef Eigen::Matrix< SCALAR, CONTROL_DIM, STATE_DIM > control_state_matrix_t
 
typedef core::StateVector< STATE_DIM, SCALARstate_vector_t
 
typedef core::ControlVector< CONTROL_DIM, SCALARcontrol_vector_t
 
typedef CostFunction< STATE_DIM, CONTROL_DIM, SCALARBASE
 
- Public Types inherited from ct::optcon::CostFunction< STATE_DIM, CONTROL_DIM, SCALAR >
typedef core::ControlVector< CONTROL_DIM, SCALARcontrol_vector_t
 

Public Member Functions

 CostFunctionAnalytical ()
 Basic constructor. More...
 
 CostFunctionAnalytical (const CostFunctionAnalytical &arg)
 Copy constructor. More...
 
 CostFunctionAnalytical (const std::string &filename, bool verbose=false)
 Constructor loading function from file. More...
 
CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR > * clone () const override
 
 ~CostFunctionAnalytical ()
 
SCALAR evaluateIntermediate () override
 evaluate intermediate costs More...
 
SCALAR evaluateTerminal () override
 evaluate terminal costs More...
 
state_vector_t stateDerivativeIntermediate () override
 Computes intermediate-cost first-order derivative with respect to state. More...
 
state_vector_t stateDerivativeTerminal () override
 
state_matrix_t stateSecondDerivativeIntermediate () override
 Computes intermediate-cost second-order derivative with respect to state. More...
 
state_matrix_t stateSecondDerivativeTerminal () override
 Computes final-cost second-order derivative with respect to state. More...
 
control_vector_t controlDerivativeIntermediate () override
 Computes intermediate-cost first-order derivative with respect to control. More...
 
control_vector_t controlDerivativeTerminal () override
 Computes terminal-cost first-order derivative with respect to control. More...
 
control_matrix_t controlSecondDerivativeIntermediate () override
 Computes intermediate-cost second-order derivative with respect to input. More...
 
control_matrix_t controlSecondDerivativeTerminal () override
 Computes final-cost second-order derivative with respect to input. More...
 
control_state_matrix_t stateControlDerivativeIntermediate () override
 Computes intermediate-cost derivative with respect to state and control. More...
 
control_state_matrix_t stateControlDerivativeTerminal () override
 Computes final-cost derivative with respect to state and control. More...
 
void loadFromConfigFile (const std::string &filename, bool verbose=false) override
 Loads cost function from config file. More...
 
- Public Member Functions inherited from ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >
 CostFunctionQuadratic ()
 
 CostFunctionQuadratic (const CostFunctionQuadratic &arg)
 
virtual ~CostFunctionQuadratic ()
 
virtual size_t addIntermediateTerm (std::shared_ptr< TermBase< STATE_DIM, CONTROL_DIM, SCALAR >> term, bool verbose=false)
 Adds an intermediate term. More...
 
virtual size_t addFinalTerm (std::shared_ptr< TermBase< STATE_DIM, CONTROL_DIM, SCALAR >> term, bool verbose=false)
 Adds a final term. More...
 
virtual void updateReferenceState (const state_vector_t &x_ref)
 update the reference state for intermediate cost terms More...
 
virtual void updateFinalState (const state_vector_t &x_final)
 update the reference state for final cost terms More...
 
virtual void updateReferenceControl (const control_vector_t &u_ref)
 update the reference control for intermediate cost terms More...
 
bool stateDerivativeIntermediateTest (bool verbose=false)
 compare the state derivative against numerical differentiation More...
 
bool controlDerivativeIntermediateTest (bool verbose=false)
 compare the control derivative against numerical differentiation More...
 
std::shared_ptr< TermBase< STATE_DIM, CONTROL_DIM, SCALAR > > getIntermediateTermById (const size_t id)
 
std::shared_ptr< TermBase< STATE_DIM, CONTROL_DIM, SCALAR > > getFinalTermById (const size_t id)
 
std::shared_ptr< TermBase< STATE_DIM, CONTROL_DIM, SCALAR > > getIntermediateTermByName (const std::string &name)
 
std::shared_ptr< TermBase< STATE_DIM, CONTROL_DIM, SCALAR > > getFinalTermByName (const std::string &name)
 
virtual void initialize ()
 initialize the cost function (e.g. to be used in CostFunctionAD) More...
 
- Public Member Functions inherited from ct::optcon::CostFunction< STATE_DIM, CONTROL_DIM, SCALAR >
 CostFunction ()
 Default constructor. More...
 
virtual ~CostFunction ()
 Destructor. More...
 
 CostFunction (const CostFunction &arg)
 Copy constructor. More...
 
virtual void setCurrentStateAndControl (const state_vector_t &x, const control_vector_t &u, const SCALAR &t=SCALAR(0.0))
 
virtual void getCurrentStateAndControl (Eigen::Matrix< SCALAR, STATE_DIM, 1 > &x, Eigen::Matrix< SCALAR, CONTROL_DIM, 1 > &u, SCALAR &t) const
 sets current state, control and time More...
 
virtual void shiftTime (const SCALAR t)
 

Public Attributes

EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef Eigen::Matrix< SCALAR, STATE_DIM, STATE_DIM > state_matrix_t
 
- Public Attributes inherited from ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef Eigen::Matrix< SCALAR, STATE_DIM, STATE_DIM > state_matrix_t
 
- Public Attributes inherited from ct::optcon::CostFunction< STATE_DIM, CONTROL_DIM, SCALAR >
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef core::StateVector< STATE_DIM, SCALARstate_vector_t
 

Additional Inherited Members

- Protected Member Functions inherited from ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >
SCALAR evaluateIntermediateBase ()
 evaluate intermediate analytical cost terms More...
 
SCALAR evaluateTerminalBase ()
 evaluate terminal analytical cost terms More...
 
state_vector_t stateDerivativeIntermediateBase ()
 evaluate intermediate analytical state derivatives More...
 
state_vector_t stateDerivativeTerminalBase ()
 evaluate terminal analytical state derivatives More...
 
state_matrix_t stateSecondDerivativeIntermediateBase ()
 evaluate intermediate analytical state second derivatives More...
 
state_matrix_t stateSecondDerivativeTerminalBase ()
 evaluate terminal analytical state second derivatives More...
 
control_vector_t controlDerivativeIntermediateBase ()
 evaluate intermediate analytical control derivatives More...
 
control_vector_t controlDerivativeTerminalBase ()
 evaluate terminal analytical control derivatives More...
 
control_matrix_t controlSecondDerivativeIntermediateBase ()
 evaluate intermediate analytical control second derivatives More...
 
control_matrix_t controlSecondDerivativeTerminalBase ()
 evaluate terminal analytical control second derivatives More...
 
control_state_matrix_t stateControlDerivativeIntermediateBase ()
 evaluate intermediate analytical control mixed state control derivatives More...
 
control_state_matrix_t stateControlDerivativeTerminalBase ()
 evaluate terminal analytical control mixed state control derivatives More...
 
state_vector_t stateDerivativeIntermediateNumDiff ()
 compute the state derivative by numerical differentiation (can be used for testing) More...
 
control_vector_t controlDerivativeIntermediateNumDiff ()
 compute the control derivative by numerical differentiation (can be used for testing) More...
 
- Protected Attributes inherited from ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >
SCALAR eps_
 stepsize for numerical differentiation More...
 
bool doubleSidedDerivative_ = true
 use double sided derivatives in numerical differentiation More...
 
std::vector< std::shared_ptr< TermBase< STATE_DIM, CONTROL_DIM, SCALAR > > > intermediateCostAnalytical_
 
std::vector< std::shared_ptr< TermBase< STATE_DIM, CONTROL_DIM, SCALAR > > > finalCostAnalytical_
 
- Protected Attributes inherited from ct::optcon::CostFunction< STATE_DIM, CONTROL_DIM, SCALAR >
state_vector_t x_
 
control_vector_t u_
 
SCALAR t_
 
SCALAR t_shift_
 

Detailed Description

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
class ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >

A cost function which contains only terms that have analytical derivatives.

This class provides functions to evaluate a cost function and computes its first and second order derivatives. This cost function assumes that analytical derivatives for all terms are available.

Examples:
DMS.cpp, NLOC.cpp, NLOC_boxConstrained.cpp, NLOC_generalConstrained.cpp, NLOC_MPC.cpp, and NonlinearSystemTest.h.

Member Typedef Documentation

◆ control_matrix_t

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
typedef Eigen::Matrix<SCALAR, CONTROL_DIM, CONTROL_DIM> ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::control_matrix_t

◆ control_state_matrix_t

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
typedef Eigen::Matrix<SCALAR, CONTROL_DIM, STATE_DIM> ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::control_state_matrix_t

◆ state_vector_t

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
typedef core::StateVector<STATE_DIM, SCALAR> ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::state_vector_t

◆ control_vector_t

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
typedef core::ControlVector<CONTROL_DIM, SCALAR> ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::control_vector_t

Constructor & Destructor Documentation

◆ CostFunctionAnalytical() [1/3]

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR >
ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::CostFunctionAnalytical ( )

◆ CostFunctionAnalytical() [2/3]

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR >
ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::CostFunctionAnalytical ( const CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR > &  arg)

Copy constructor.

Parameters
argcost function to copy

◆ CostFunctionAnalytical() [3/3]

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR >
ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::CostFunctionAnalytical ( const std::string &  filename,
bool  verbose = false 
)

Constructor loading function from file.

Parameters
filenameconfig file location
verboseflag enabling printouts

References ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::loadFromConfigFile().

◆ ~CostFunctionAnalytical()

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR >
ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::~CostFunctionAnalytical ( )

Destructor

Member Function Documentation

◆ clone()

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR >
CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR > * ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::clone ( ) const
overridevirtual

◆ evaluateIntermediate()

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR >
SCALAR ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::evaluateIntermediate ( )
overridevirtual

evaluate intermediate costs

Evaluates the running/intermediate cost function for the control, state and time set in setCurrentStateAndControl()

Returns
costs

Implements ct::optcon::CostFunction< STATE_DIM, CONTROL_DIM, SCALAR >.

References ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >::evaluateIntermediateBase().

◆ evaluateTerminal()

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR >
SCALAR ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::evaluateTerminal ( )
overridevirtual

evaluate terminal costs

Evaluates the terminal cost for a given state and control set in setCurrentStateAndControl(). This usually ignores time.

Returns
costs

Implements ct::optcon::CostFunction< STATE_DIM, CONTROL_DIM, SCALAR >.

References ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >::evaluateTerminalBase().

◆ stateDerivativeIntermediate()

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR >
CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::state_vector_t ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::stateDerivativeIntermediate ( )
overridevirtual

Computes intermediate-cost first-order derivative with respect to state.

Returns
derivative vector (Jacobian)

Implements ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >.

References ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >::stateDerivativeIntermediateBase().

Referenced by ct::optcon::example::TEST().

◆ stateDerivativeTerminal()

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR >
CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::state_vector_t ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::stateDerivativeTerminal ( )
overridevirtual

Computes terminal-cost first-order derivative with respect to state

Returns
derivative vector (Jacobian)

Implements ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >.

References ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >::stateDerivativeTerminalBase().

Referenced by ct::optcon::example::TEST().

◆ stateSecondDerivativeIntermediate()

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR >
CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::state_matrix_t ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::stateSecondDerivativeIntermediate ( )
overridevirtual

Computes intermediate-cost second-order derivative with respect to state.

Returns
derivative matrix (Jacobian)

Implements ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >.

References ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >::stateSecondDerivativeIntermediateBase().

Referenced by ct::optcon::example::TEST().

◆ stateSecondDerivativeTerminal()

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR >
CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::state_matrix_t ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::stateSecondDerivativeTerminal ( )
overridevirtual

Computes final-cost second-order derivative with respect to state.

Returns
derivative matrix (Jacobian)

Implements ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >.

References ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >::stateSecondDerivativeTerminalBase().

Referenced by ct::optcon::example::TEST().

◆ controlDerivativeIntermediate()

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR >
CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::control_vector_t ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::controlDerivativeIntermediate ( )
overridevirtual

Computes intermediate-cost first-order derivative with respect to control.

Returns
derivative vector (Jacobian)

Implements ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >.

References ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >::controlDerivativeIntermediateBase().

Referenced by ct::optcon::example::TEST().

◆ controlDerivativeTerminal()

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR >
CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::control_vector_t ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::controlDerivativeTerminal ( )
overridevirtual

Computes terminal-cost first-order derivative with respect to control.

Not available for all cost functions. Throws an exception if not available.

Returns
derivative vector (Jacobian)

Reimplemented from ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >.

References ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >::controlDerivativeTerminalBase().

◆ controlSecondDerivativeIntermediate()

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR >
CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::control_matrix_t ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::controlSecondDerivativeIntermediate ( )
overridevirtual

Computes intermediate-cost second-order derivative with respect to input.

Returns
derivative matrix (Jacobian)

Implements ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >.

References ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >::controlSecondDerivativeIntermediateBase().

Referenced by ct::optcon::example::TEST().

◆ controlSecondDerivativeTerminal()

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR >
CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::control_matrix_t ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::controlSecondDerivativeTerminal ( )
overridevirtual

Computes final-cost second-order derivative with respect to input.

Not available for all cost functions. Throws an exception if not available.

Returns
derivative matrix (Jacobian)

Reimplemented from ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >.

References ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >::controlSecondDerivativeTerminalBase().

◆ stateControlDerivativeIntermediate()

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR >
CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::control_state_matrix_t ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::stateControlDerivativeIntermediate ( )
overridevirtual

Computes intermediate-cost derivative with respect to state and control.

Returns
derivative matrix (Jacobian)

Implements ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >.

References ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >::stateControlDerivativeIntermediateBase().

◆ stateControlDerivativeTerminal()

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR >
CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::control_state_matrix_t ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::stateControlDerivativeTerminal ( )
overridevirtual

Computes final-cost derivative with respect to state and control.

Returns
derivative matrix (Jacobian)

Reimplemented from ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >.

References ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >::stateControlDerivativeTerminalBase().

◆ loadFromConfigFile()

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR >
void ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::loadFromConfigFile ( const std::string &  filename,
bool  verbose = false 
)
overridevirtual

Member Data Documentation

◆ state_matrix_t

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef Eigen::Matrix<SCALAR, STATE_DIM, STATE_DIM> ct::optcon::CostFunctionAnalytical< STATE_DIM, CONTROL_DIM, SCALAR >::state_matrix_t

The documentation for this class was generated from the following files: