- 3.0.2 optimal control module.
ct::optcon::tpl::Nlp< SCALAR > Class Template Referenceabstract

The NLP base class. This class serves as abstract base class to use as an interface to the NLP solver IPOPT and SNOPT. More...

#include <Nlp.h>

Inheritance diagram for ct::optcon::tpl::Nlp< SCALAR >:
ct::optcon::DmsProblem< STATE_DIM, CONTROL_DIM, SCALAR > ExampleProblem< SCALAR > ExampleProblem< SCALAR >

Public Types

using VectorXs = Eigen::Matrix< SCALAR, Eigen::Dynamic, 1 >
 
using VectorXi = Eigen::Matrix< int, Eigen::Dynamic, 1 >
 
using MapVecXs = Eigen::Map< VectorXs >
 
using MapVecXi = Eigen::Map< VectorXi >
 
using MapConstVecXs = Eigen::Map< const VectorXs >
 

Public Member Functions

 Nlp ()=default
 Default constructor. More...
 
virtual ~Nlp ()=default
 Destructor. More...
 
virtual void updateProblem ()=0
 { This method gets called at each update of the Optimization variables. This can be used to distribute or rearrange the optimization variables appropriately } More...
 
SCALAR evaluateCostFun ()
 { Evaluates the costfunction at the current nlp iteration } More...
 
void evaluateCostGradient (const size_t n, MapVecXs &grad)
 { Evaluates the gradient of the costfunction} More...
 
void evaluateConstraints (MapVecXs &values)
 { Evaluates the constraints } More...
 
void evaluateConstraintJacobian (const int nele_jac, MapVecXs &jac)
 { Evaluates the constraint jacobian } More...
 
void evaluateHessian (const int nele_hes, MapVecXs &hes, const SCALAR obj_fac, MapConstVecXs &lambda)
 Evaluates the hessian of the lagrangian. More...
 
void getSparsityPatternJacobian (const int nele_jac, MapVecXi &iRow, MapVecXi &jCol) const
 Gets the sparsity pattern. More...
 
void getSparsityPatternHessian (const int nele_hes, MapVecXi &iRow, MapVecXi &jCol) const
 Gets the sparsity pattern of the Hessian of the Lagrangian. More...
 
size_t getConstraintsCount () const
 Returns the number of constraints in the NLP. More...
 
size_t getNonZeroJacobianCount () const
 Returns the number of the non zero elements of the constraint jacobian. More...
 
size_t getNonZeroHessianCount ()
 Returns the number of non zeros in the Hessian. More...
 
void getConstraintBounds (MapVecXs &lowerBound, MapVecXs &upperBound, const size_t m) const
 Reads the bounds of the constraints. More...
 
size_t getVarCount () const
 Returns the number of Optimization optimization variables. More...
 
void getVariableBounds (MapVecXs &lowerBound, MapVecXs &upperBound, const size_t n) const
 Reads the bounds on the Optimization optimization variables. More...
 
void extractOptimizationVars (const MapConstVecXs &x, bool isNew)
 {Extracts the Optimization optimization variables from the nlp solvers between nlp iterations} More...
 
void getInitialGuess (const size_t n, MapVecXs &x) const
 Gets the Optimization variables. More...
 
void getOptimizationMultState (const size_t n, MapVecXs &xMul, MapVecXi &xState) const
 Gets the variable multiplier and the variable state, used in the NLP solver SNOPT. See the snopt documentation for further explanations. More...
 
void getConstraintsMultState (const size_t m, MapVecXs &zMul, MapVecXi &zState) const
 Gets the constraint multiplier and state, used in the NLP solver SNOPT. More...
 
void getBoundMultipliers (size_t n, MapVecXs &zLow, MapVecXs &zUp) const
 Gets the bound multipliers used in the NLP solver IPOPT. More...
 
void getLambdaVars (size_t m, MapVecXs &lambda) const
 Gets the values of the constraint multipliers. More...
 
void extractIpoptSolution (const MapConstVecXs &x, const MapConstVecXs &zL, const MapConstVecXs &zU, const MapConstVecXs &lambda)
 { Extracts the solution values from IPOPT } More...
 
void extractSnoptSolution (const MapVecXs &x, const MapVecXs &xMul, const MapVecXi &xState, const MapVecXs &fMul, const MapVecXi &fState)
 { Extracts the solution values from SNOPT } More...
 

Protected Attributes

std::shared_ptr< DiscreteCostEvaluatorBase< SCALAR > > costEvaluator_
 Ptr to cost evaluator, which approximates the cost evaluation for the discrete problem. More...
 
std::shared_ptr< OptVector< SCALAR > > optVariables_
 Ptr to optimization variable container, which holds the optimization variables used in the NLP solvers. More...
 
std::shared_ptr< DiscreteConstraintContainerBase< SCALAR > > constraints_
 Ptr to constraint container, which contains the discretized constraints for the problem. More...
 
Eigen::VectorXi iRowHessianCost_
 helper containers for calculating the sparsity patterns More...
 
Eigen::VectorXi iRowHessianConstraints_
 
Eigen::VectorXi jColHessianCost_
 
Eigen::VectorXi jColHessianConstraints_
 
Eigen::VectorXi iRowHessian_
 combined Hessian sparsity pattern gets stored here More...
 
Eigen::VectorXi jColHessian_
 

Detailed Description

template<typename SCALAR>
class ct::optcon::tpl::Nlp< SCALAR >

The NLP base class. This class serves as abstract base class to use as an interface to the NLP solver IPOPT and SNOPT.

Member Typedef Documentation

◆ VectorXs

template<typename SCALAR >
using ct::optcon::tpl::Nlp< SCALAR >::VectorXs = Eigen::Matrix<SCALAR, Eigen::Dynamic, 1>

◆ VectorXi

template<typename SCALAR >
using ct::optcon::tpl::Nlp< SCALAR >::VectorXi = Eigen::Matrix<int, Eigen::Dynamic, 1>

◆ MapVecXs

template<typename SCALAR >
using ct::optcon::tpl::Nlp< SCALAR >::MapVecXs = Eigen::Map<VectorXs>

◆ MapVecXi

template<typename SCALAR >
using ct::optcon::tpl::Nlp< SCALAR >::MapVecXi = Eigen::Map<VectorXi>

◆ MapConstVecXs

template<typename SCALAR >
using ct::optcon::tpl::Nlp< SCALAR >::MapConstVecXs = Eigen::Map<const VectorXs>

Constructor & Destructor Documentation

◆ Nlp()

template<typename SCALAR >
ct::optcon::tpl::Nlp< SCALAR >::Nlp ( )
default

Default constructor.

◆ ~Nlp()

template<typename SCALAR >
virtual ct::optcon::tpl::Nlp< SCALAR >::~Nlp ( )
virtualdefault

Destructor.

Member Function Documentation

◆ updateProblem()

template<typename SCALAR >
virtual void ct::optcon::tpl::Nlp< SCALAR >::updateProblem ( )
pure virtual

{ This method gets called at each update of the Optimization variables. This can be used to distribute or rearrange the optimization variables appropriately }

Implemented in ExampleProblem< SCALAR >, ExampleProblem< SCALAR >, and ct::optcon::DmsProblem< STATE_DIM, CONTROL_DIM, SCALAR >.

Referenced by ct::optcon::tpl::Nlp< SCALAR >::extractOptimizationVars().

◆ evaluateCostFun()

template<typename SCALAR >
SCALAR ct::optcon::tpl::Nlp< SCALAR >::evaluateCostFun ( )
inline

{ Evaluates the costfunction at the current nlp iteration }

Returns
{ Scalar value of the resulting cost }

References ct::optcon::tpl::Nlp< SCALAR >::costEvaluator_.

◆ evaluateCostGradient()

template<typename SCALAR >
void ct::optcon::tpl::Nlp< SCALAR >::evaluateCostGradient ( const size_t  n,
MapVecXs grad 
)
inline

{ Evaluates the gradient of the costfunction}

Parameters
[in]n{ size of the gradient }
[out]gradThe gradient of the cost function

References ct::optcon::tpl::Nlp< SCALAR >::costEvaluator_.

◆ evaluateConstraints()

template<typename SCALAR >
void ct::optcon::tpl::Nlp< SCALAR >::evaluateConstraints ( MapVecXs values)
inline

{ Evaluates the constraints }

Parameters
[out]valuesThe values of the constraint violations, wrapped as a vector

References ct::optcon::tpl::Nlp< SCALAR >::constraints_.

◆ evaluateConstraintJacobian()

template<typename SCALAR >
void ct::optcon::tpl::Nlp< SCALAR >::evaluateConstraintJacobian ( const int  nele_jac,
MapVecXs jac 
)
inline

{ Evaluates the constraint jacobian }

Parameters
[in]nele_jacThe number of non zeros in the constraint jacobian
[out]jacThe non zero values of the jacobian

References ct::optcon::tpl::Nlp< SCALAR >::constraints_.

◆ evaluateHessian()

template<typename SCALAR >
void ct::optcon::tpl::Nlp< SCALAR >::evaluateHessian ( const int  nele_hes,
MapVecXs hes,
const SCALAR  obj_fac,
MapConstVecXs lambda 
)
inline

Evaluates the hessian of the lagrangian.

Parameters
[in]nele_hesThe number of non zeros in the hessian
hesThe values of the non-zeros of the hessian
[in]obj_facThe costfunction multiplier (zero or one, NLP solver uses this to query for parts of the hessian only)
lambdaThe constraint multipliers
Note
it is important to note that our NLP-solvers expect the Hessian reduced to triangular form (symmetry).

References ct::optcon::tpl::Nlp< SCALAR >::constraints_, ct::optcon::tpl::Nlp< SCALAR >::costEvaluator_, i, ct::optcon::tpl::Nlp< SCALAR >::iRowHessianConstraints_, ct::optcon::tpl::Nlp< SCALAR >::iRowHessianCost_, ct::optcon::tpl::Nlp< SCALAR >::jColHessianConstraints_, ct::optcon::tpl::Nlp< SCALAR >::jColHessianCost_, and ct::optcon::tpl::Nlp< SCALAR >::optVariables_.

◆ getSparsityPatternJacobian()

template<typename SCALAR >
void ct::optcon::tpl::Nlp< SCALAR >::getSparsityPatternJacobian ( const int  nele_jac,
MapVecXi iRow,
MapVecXi jCol 
) const
inline

Gets the sparsity pattern.

Parameters
[in]nele_jacThe number of non zero elements in the constraint jacobian
[out]iRowThe row indices of the location of the non zero elements of the constraint jacobian
[out]jColThe column indices of the location of the non zero elements of the constraint jacobian

References ct::optcon::tpl::Nlp< SCALAR >::constraints_.

◆ getSparsityPatternHessian()

template<typename SCALAR >
void ct::optcon::tpl::Nlp< SCALAR >::getSparsityPatternHessian ( const int  nele_hes,
MapVecXi iRow,
MapVecXi jCol 
) const
inline

Gets the sparsity pattern of the Hessian of the Lagrangian.

Parameters
[in]nele_hesThe number of non zero elements in the hessian
iRowThe row indices
jColThe column indices

References ct::optcon::tpl::Nlp< SCALAR >::iRowHessian_, and ct::optcon::tpl::Nlp< SCALAR >::jColHessian_.

◆ getConstraintsCount()

template<typename SCALAR >
size_t ct::optcon::tpl::Nlp< SCALAR >::getConstraintsCount ( ) const
inline

Returns the number of constraints in the NLP.

Returns
The number of constraints.

References ct::optcon::tpl::Nlp< SCALAR >::constraints_.

Referenced by ct::optcon::DmsProblem< STATE_DIM, CONTROL_DIM, SCALAR >::DmsProblem().

◆ getNonZeroJacobianCount()

template<typename SCALAR >
size_t ct::optcon::tpl::Nlp< SCALAR >::getNonZeroJacobianCount ( ) const
inline

Returns the number of the non zero elements of the constraint jacobian.

Returns
The number of the non zero elements of the constraint jacobian.

References ct::optcon::tpl::Nlp< SCALAR >::constraints_.

◆ getNonZeroHessianCount()

◆ getConstraintBounds()

template<typename SCALAR >
void ct::optcon::tpl::Nlp< SCALAR >::getConstraintBounds ( MapVecXs lowerBound,
MapVecXs upperBound,
const size_t  m 
) const
inline

Reads the bounds of the constraints.

Parameters
[out]lowerBoundThe lower constraint bound
[out]upperBoundThe upper constraint bound
[in]m{ The size of the constraints }

References ct::optcon::tpl::Nlp< SCALAR >::constraints_.

◆ getVarCount()

template<typename SCALAR >
size_t ct::optcon::tpl::Nlp< SCALAR >::getVarCount ( ) const
inline

Returns the number of Optimization optimization variables.

Returns
The number of Optimization variables.

References ct::optcon::tpl::Nlp< SCALAR >::optVariables_.

◆ getVariableBounds()

template<typename SCALAR >
void ct::optcon::tpl::Nlp< SCALAR >::getVariableBounds ( MapVecXs lowerBound,
MapVecXs upperBound,
const size_t  n 
) const
inline

Reads the bounds on the Optimization optimization variables.

Parameters
[out]lowerBoundThe lower optimization variable bound
[out]upperBoundThe upper optimization variable bound
[in]n{ The number of Optimization variables }

References ct::optcon::tpl::Nlp< SCALAR >::optVariables_.

◆ extractOptimizationVars()

template<typename SCALAR >
void ct::optcon::tpl::Nlp< SCALAR >::extractOptimizationVars ( const MapConstVecXs x,
bool  isNew 
)
inline

{Extracts the Optimization optimization variables from the nlp solvers between nlp iterations}

Parameters
[in]x{ The value of the Optimization variables }
[in]isNewIndicates whether x differs from a previous call

References ct::optcon::tpl::Nlp< SCALAR >::optVariables_, and ct::optcon::tpl::Nlp< SCALAR >::updateProblem().

◆ getInitialGuess()

template<typename SCALAR >
void ct::optcon::tpl::Nlp< SCALAR >::getInitialGuess ( const size_t  n,
MapVecXs x 
) const
inline

Gets the Optimization variables.

Parameters
[in]n{ The number of Optimization variables }
[out]x{ The values of the Optimization vars }

References ct::optcon::tpl::Nlp< SCALAR >::optVariables_.

◆ getOptimizationMultState()

template<typename SCALAR >
void ct::optcon::tpl::Nlp< SCALAR >::getOptimizationMultState ( const size_t  n,
MapVecXs xMul,
MapVecXi xState 
) const
inline

Gets the variable multiplier and the variable state, used in the NLP solver SNOPT. See the snopt documentation for further explanations.

Parameters
[in]n{ The number of Optimization variables }
[out]xMulThe optimization variable multiplier
[out]xStateThe optimization variable states

References ct::optcon::tpl::Nlp< SCALAR >::optVariables_.

◆ getConstraintsMultState()

template<typename SCALAR >
void ct::optcon::tpl::Nlp< SCALAR >::getConstraintsMultState ( const size_t  m,
MapVecXs zMul,
MapVecXi zState 
) const
inline

Gets the constraint multiplier and state, used in the NLP solver SNOPT.

Parameters
[in]m{ The number of constraints }
[out]zMulThe constraint variable multiplier
[out]zStateThe constraint variable state

References ct::optcon::tpl::Nlp< SCALAR >::optVariables_.

◆ getBoundMultipliers()

template<typename SCALAR >
void ct::optcon::tpl::Nlp< SCALAR >::getBoundMultipliers ( size_t  n,
MapVecXs zLow,
MapVecXs zUp 
) const
inline

Gets the bound multipliers used in the NLP solver IPOPT.

Parameters
[in]n{ The number of optimization variables }
[out]zLowThe value for the lower bound multiplier
[out]zUpThe value for the upper bound multiplier

References ct::optcon::tpl::Nlp< SCALAR >::optVariables_.

◆ getLambdaVars()

template<typename SCALAR >
void ct::optcon::tpl::Nlp< SCALAR >::getLambdaVars ( size_t  m,
MapVecXs lambda 
) const
inline

Gets the values of the constraint multipliers.

Parameters
[in]m{ The number of constraints }
[out]lambdaThe values of the constraint multipliers

References ct::optcon::tpl::Nlp< SCALAR >::optVariables_.

◆ extractIpoptSolution()

template<typename SCALAR >
void ct::optcon::tpl::Nlp< SCALAR >::extractIpoptSolution ( const MapConstVecXs x,
const MapConstVecXs zL,
const MapConstVecXs zU,
const MapConstVecXs lambda 
)
inline

{ Extracts the solution values from IPOPT }

Parameters
[in]x{ The values of the optimization variables }
[in]zLThe value for the lower bound multiplier
[in]zUThe value for the upper bound multiplier
[in]lambdaThe values of the constraint multipliers

References ct::optcon::tpl::Nlp< SCALAR >::optVariables_.

◆ extractSnoptSolution()

template<typename SCALAR >
void ct::optcon::tpl::Nlp< SCALAR >::extractSnoptSolution ( const MapVecXs x,
const MapVecXs xMul,
const MapVecXi xState,
const MapVecXs fMul,
const MapVecXi fState 
)
inline

{ Extracts the solution values from SNOPT }

Parameters
[in]x{ The values of the optimization variables }
[in]xMulThe optimization variable multiplier
[in]xStateThe optimization variable state
[in]fMulThe constraint variable multiplier
[in]fStateThe constraint variable state

References ct::optcon::tpl::Nlp< SCALAR >::optVariables_.

Member Data Documentation

◆ costEvaluator_

◆ optVariables_

◆ constraints_

◆ iRowHessianCost_

template<typename SCALAR >
Eigen::VectorXi ct::optcon::tpl::Nlp< SCALAR >::iRowHessianCost_
protected

helper containers for calculating the sparsity patterns

Referenced by ct::optcon::tpl::Nlp< SCALAR >::evaluateHessian(), and ct::optcon::tpl::Nlp< SCALAR >::getNonZeroHessianCount().

◆ iRowHessianConstraints_

template<typename SCALAR >
Eigen::VectorXi ct::optcon::tpl::Nlp< SCALAR >::iRowHessianConstraints_
protected

◆ jColHessianCost_

template<typename SCALAR >
Eigen::VectorXi ct::optcon::tpl::Nlp< SCALAR >::jColHessianCost_
protected

◆ jColHessianConstraints_

template<typename SCALAR >
Eigen::VectorXi ct::optcon::tpl::Nlp< SCALAR >::jColHessianConstraints_
protected

◆ iRowHessian_

template<typename SCALAR >
Eigen::VectorXi ct::optcon::tpl::Nlp< SCALAR >::iRowHessian_
protected

◆ jColHessian_

template<typename SCALAR >
Eigen::VectorXi ct::optcon::tpl::Nlp< SCALAR >::jColHessian_
protected

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