![]() |
- 3.0.2 optimal control module.
|
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>
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_ |
The NLP base class. This class serves as abstract base class to use as an interface to the NLP solver IPOPT and SNOPT.
| using ct::optcon::tpl::Nlp< SCALAR >::VectorXs = Eigen::Matrix<SCALAR, Eigen::Dynamic, 1> |
| using ct::optcon::tpl::Nlp< SCALAR >::VectorXi = Eigen::Matrix<int, Eigen::Dynamic, 1> |
| using ct::optcon::tpl::Nlp< SCALAR >::MapVecXs = Eigen::Map<VectorXs> |
| using ct::optcon::tpl::Nlp< SCALAR >::MapVecXi = Eigen::Map<VectorXi> |
| using ct::optcon::tpl::Nlp< SCALAR >::MapConstVecXs = Eigen::Map<const VectorXs> |
|
default |
Default constructor.
|
virtualdefault |
Destructor.
|
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().
|
inline |
{ Evaluates the costfunction at the current nlp iteration }
References ct::optcon::tpl::Nlp< SCALAR >::costEvaluator_.
|
inline |
{ Evaluates the gradient of the costfunction}
| [in] | n | { size of the gradient } |
| [out] | grad | The gradient of the cost function |
References ct::optcon::tpl::Nlp< SCALAR >::costEvaluator_.
|
inline |
{ Evaluates the constraints }
| [out] | values | The values of the constraint violations, wrapped as a vector |
References ct::optcon::tpl::Nlp< SCALAR >::constraints_.
|
inline |
{ Evaluates the constraint jacobian }
| [in] | nele_jac | The number of non zeros in the constraint jacobian |
| [out] | jac | The non zero values of the jacobian |
References ct::optcon::tpl::Nlp< SCALAR >::constraints_.
|
inline |
Evaluates the hessian of the lagrangian.
| [in] | nele_hes | The number of non zeros in the hessian |
| hes | The values of the non-zeros of the hessian | |
| [in] | obj_fac | The costfunction multiplier (zero or one, NLP solver uses this to query for parts of the hessian only) |
| lambda | The constraint multipliers |
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_.
|
inline |
Gets the sparsity pattern.
| [in] | nele_jac | The number of non zero elements in the constraint jacobian |
| [out] | iRow | The row indices of the location of the non zero elements of the constraint jacobian |
| [out] | jCol | The column indices of the location of the non zero elements of the constraint jacobian |
References ct::optcon::tpl::Nlp< SCALAR >::constraints_.
|
inline |
Gets the sparsity pattern of the Hessian of the Lagrangian.
| [in] | nele_hes | The number of non zero elements in the hessian |
| iRow | The row indices | |
| jCol | The column indices |
References ct::optcon::tpl::Nlp< SCALAR >::iRowHessian_, and ct::optcon::tpl::Nlp< SCALAR >::jColHessian_.
|
inline |
Returns the number of constraints in the NLP.
References ct::optcon::tpl::Nlp< SCALAR >::constraints_.
Referenced by ct::optcon::DmsProblem< STATE_DIM, CONTROL_DIM, SCALAR >::DmsProblem().
|
inline |
Returns the number of the non zero elements of the constraint jacobian.
References ct::optcon::tpl::Nlp< SCALAR >::constraints_.
|
inline |
Returns the number of non zeros in the Hessian.
This method intelligently combines sparsity of cost and constraint Hessians using sparse Eigen operations.
References ct::optcon::tpl::Nlp< SCALAR >::constraints_, ct::optcon::tpl::Nlp< SCALAR >::costEvaluator_, i, ct::optcon::tpl::Nlp< SCALAR >::iRowHessian_, ct::optcon::tpl::Nlp< SCALAR >::iRowHessianConstraints_, ct::optcon::tpl::Nlp< SCALAR >::iRowHessianCost_, ct::optcon::tpl::Nlp< SCALAR >::jColHessian_, ct::optcon::tpl::Nlp< SCALAR >::jColHessianConstraints_, ct::optcon::tpl::Nlp< SCALAR >::jColHessianCost_, and ct::optcon::tpl::Nlp< SCALAR >::optVariables_.
|
inline |
Reads the bounds of the constraints.
| [out] | lowerBound | The lower constraint bound |
| [out] | upperBound | The upper constraint bound |
| [in] | m | { The size of the constraints } |
References ct::optcon::tpl::Nlp< SCALAR >::constraints_.
|
inline |
Returns the number of Optimization optimization variables.
References ct::optcon::tpl::Nlp< SCALAR >::optVariables_.
|
inline |
Reads the bounds on the Optimization optimization variables.
| [out] | lowerBound | The lower optimization variable bound |
| [out] | upperBound | The upper optimization variable bound |
| [in] | n | { The number of Optimization variables } |
References ct::optcon::tpl::Nlp< SCALAR >::optVariables_.
|
inline |
{Extracts the Optimization optimization variables from the nlp solvers between nlp iterations}
| [in] | x | { The value of the Optimization variables } |
| [in] | isNew | Indicates whether x differs from a previous call |
References ct::optcon::tpl::Nlp< SCALAR >::optVariables_, and ct::optcon::tpl::Nlp< SCALAR >::updateProblem().
|
inline |
Gets the Optimization variables.
| [in] | n | { The number of Optimization variables } |
| [out] | x | { The values of the Optimization vars } |
References ct::optcon::tpl::Nlp< SCALAR >::optVariables_.
|
inline |
Gets the variable multiplier and the variable state, used in the NLP solver SNOPT. See the snopt documentation for further explanations.
| [in] | n | { The number of Optimization variables } |
| [out] | xMul | The optimization variable multiplier |
| [out] | xState | The optimization variable states |
References ct::optcon::tpl::Nlp< SCALAR >::optVariables_.
|
inline |
Gets the constraint multiplier and state, used in the NLP solver SNOPT.
| [in] | m | { The number of constraints } |
| [out] | zMul | The constraint variable multiplier |
| [out] | zState | The constraint variable state |
References ct::optcon::tpl::Nlp< SCALAR >::optVariables_.
|
inline |
Gets the bound multipliers used in the NLP solver IPOPT.
| [in] | n | { The number of optimization variables } |
| [out] | zLow | The value for the lower bound multiplier |
| [out] | zUp | The value for the upper bound multiplier |
References ct::optcon::tpl::Nlp< SCALAR >::optVariables_.
|
inline |
Gets the values of the constraint multipliers.
| [in] | m | { The number of constraints } |
| [out] | lambda | The values of the constraint multipliers |
References ct::optcon::tpl::Nlp< SCALAR >::optVariables_.
|
inline |
{ Extracts the solution values from IPOPT }
| [in] | x | { The values of the optimization variables } |
| [in] | zL | The value for the lower bound multiplier |
| [in] | zU | The value for the upper bound multiplier |
| [in] | lambda | The values of the constraint multipliers |
References ct::optcon::tpl::Nlp< SCALAR >::optVariables_.
|
inline |
{ Extracts the solution values from SNOPT }
| [in] | x | { The values of the optimization variables } |
| [in] | xMul | The optimization variable multiplier |
| [in] | xState | The optimization variable state |
| [in] | fMul | The constraint variable multiplier |
| [in] | fState | The constraint variable state |
References ct::optcon::tpl::Nlp< SCALAR >::optVariables_.
|
protected |
Ptr to cost evaluator, which approximates the cost evaluation for the discrete problem.
Referenced by ct::optcon::DmsProblem< STATE_DIM, CONTROL_DIM, SCALAR >::DmsProblem(), ct::optcon::tpl::Nlp< SCALAR >::evaluateCostFun(), ct::optcon::tpl::Nlp< SCALAR >::evaluateCostGradient(), ct::optcon::tpl::Nlp< SCALAR >::evaluateHessian(), and ct::optcon::tpl::Nlp< SCALAR >::getNonZeroHessianCount().
|
protected |
Ptr to optimization variable container, which holds the optimization variables used in the NLP solvers.
Referenced by ct::optcon::DmsProblem< STATE_DIM, CONTROL_DIM, SCALAR >::DmsProblem(), ct::optcon::tpl::Nlp< SCALAR >::evaluateHessian(), ct::optcon::tpl::Nlp< SCALAR >::extractIpoptSolution(), ct::optcon::tpl::Nlp< SCALAR >::extractOptimizationVars(), ct::optcon::tpl::Nlp< SCALAR >::extractSnoptSolution(), ct::optcon::tpl::Nlp< SCALAR >::getBoundMultipliers(), ct::optcon::tpl::Nlp< SCALAR >::getConstraintsMultState(), ct::optcon::tpl::Nlp< SCALAR >::getInitialGuess(), ct::optcon::tpl::Nlp< SCALAR >::getLambdaVars(), ct::optcon::tpl::Nlp< SCALAR >::getNonZeroHessianCount(), ct::optcon::tpl::Nlp< SCALAR >::getOptimizationMultState(), ct::optcon::tpl::Nlp< SCALAR >::getVarCount(), and ct::optcon::tpl::Nlp< SCALAR >::getVariableBounds().
|
protected |
Ptr to constraint container, which contains the discretized constraints for the problem.
Referenced by ct::optcon::DmsProblem< STATE_DIM, CONTROL_DIM, SCALAR >::DmsProblem(), ct::optcon::tpl::Nlp< SCALAR >::evaluateConstraintJacobian(), ct::optcon::tpl::Nlp< SCALAR >::evaluateConstraints(), ct::optcon::tpl::Nlp< SCALAR >::evaluateHessian(), ct::optcon::tpl::Nlp< SCALAR >::getConstraintBounds(), ct::optcon::tpl::Nlp< SCALAR >::getConstraintsCount(), ct::optcon::tpl::Nlp< SCALAR >::getNonZeroHessianCount(), ct::optcon::tpl::Nlp< SCALAR >::getNonZeroJacobianCount(), and ct::optcon::tpl::Nlp< SCALAR >::getSparsityPatternJacobian().
|
protected |
helper containers for calculating the sparsity patterns
Referenced by ct::optcon::tpl::Nlp< SCALAR >::evaluateHessian(), and ct::optcon::tpl::Nlp< SCALAR >::getNonZeroHessianCount().
|
protected |
|
protected |
|
protected |
|
protected |
combined Hessian sparsity pattern gets stored here
Referenced by ct::optcon::tpl::Nlp< SCALAR >::getNonZeroHessianCount(), and ct::optcon::tpl::Nlp< SCALAR >::getSparsityPatternHessian().
|
protected |