- 3.0.2 optimal control module.
ConstraintContainerAnalytical.h
Go to the documentation of this file.
1 /**********************************************************************************************************************
2 This file is part of the Control Toolbox (https://github.com/ethz-adrl/control-toolbox), copyright by ETH Zurich.
3 Licensed under the BSD-2 license (see LICENSE file in main directory)
4 **********************************************************************************************************************/
5 
6 #pragma once
7 
8 #include <ct/core/core.h>
9 
11 #include "term/ConstraintBase.h"
12 
13 
14 namespace ct {
15 namespace optcon {
16 
26 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
27 class ConstraintContainerAnalytical : public LinearConstraintContainer<STATE_DIM, CONTROL_DIM, SCALAR>
28 {
29 public:
30  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
31 
34 
36  typedef Eigen::Matrix<SCALAR, Eigen::Dynamic, 1> VectorXs;
37  typedef Eigen::Matrix<SCALAR, Eigen::Dynamic, Eigen::Dynamic> MatrixXs;
38 
40 
48  ConstraintContainerAnalytical(const state_vector_t& x, const input_vector_t& u, const SCALAR& t = 0.0);
49 
56 
62  virtual ConstraintContainerAnalytical_Raw_Ptr_t clone() const override;
63 
68 
76  bool verbose);
77 
85  bool verbose);
86 
87  virtual VectorXs evaluateIntermediate() override;
88 
89  virtual VectorXs evaluateTerminal() override;
90 
91  virtual size_t getIntermediateConstraintsCount() override;
92 
93  virtual size_t getTerminalConstraintsCount() override;
94 
95  virtual VectorXs jacobianStateSparseIntermediate() override;
96 
97  virtual MatrixXs jacobianStateIntermediate() override;
98 
99  virtual VectorXs jacobianStateSparseTerminal() override;
100 
101  virtual MatrixXs jacobianStateTerminal() override;
102 
103  virtual VectorXs jacobianInputSparseIntermediate() override;
104 
105  virtual MatrixXs jacobianInputIntermediate() override;
106 
107  virtual VectorXs jacobianInputSparseTerminal() override;
108 
109  virtual MatrixXs jacobianInputTerminal() override;
110 
111  virtual void sparsityPatternStateIntermediate(Eigen::VectorXi& iRows, Eigen::VectorXi& jCols) override;
112 
113  virtual void sparsityPatternStateTerminal(Eigen::VectorXi& iRows, Eigen::VectorXi& jCols) override;
114 
115  virtual void sparsityPatternInputIntermediate(Eigen::VectorXi& iRows, Eigen::VectorXi& jCols) override;
116 
117  virtual void sparsityPatternInputTerminal(Eigen::VectorXi& iRows, Eigen::VectorXi& jCols) override;
118 
119  virtual size_t getJacobianStateNonZeroCountIntermediate() override;
120 
121  virtual size_t getJacobianStateNonZeroCountTerminal() override;
122 
123  virtual size_t getJacobianInputNonZeroCountIntermediate() override;
124 
125  virtual size_t getJacobianInputNonZeroCountTerminal() override;
126 
127  virtual bool initializeIntermediate() override;
128 
129  virtual bool initializeTerminal() override;
130 
131 
132 private:
133  virtual void update() override;
134 
139  void checkIntermediateConstraints();
140 
145  void checkTerminalConstraints();
146 
147 
148  std::vector<std::shared_ptr<ConstraintBase<STATE_DIM, CONTROL_DIM, SCALAR>>> constraintsIntermediate_;
149  std::vector<std::shared_ptr<ConstraintBase<STATE_DIM, CONTROL_DIM, SCALAR>>> constraintsTerminal_;
150 
151  VectorXs evalIntermediate_;
152  VectorXs evalJacSparseStateIntermediate_;
153  VectorXs evalJacSparseInputIntermediate_;
154  MatrixXs evalJacDenseStateIntermediate_;
155  MatrixXs evalJacDenseInputIntermediate_;
156 
157  VectorXs evalTerminal_;
158  VectorXs evalJacSparseStateTerminal_;
159  VectorXs evalJacSparseInputTerminal_;
160  MatrixXs evalJacDenseStateTerminal_;
161  MatrixXs evalJacDenseInputTerminal_;
162 };
163 
164 
165 } // namespace optcon
166 } // namespace ct
core::ControlVector< CONTROL_DIM, SCALAR > input_vector_t
Definition: ConstraintContainerAnalytical.h:33
virtual void sparsityPatternInputTerminal(Eigen::VectorXi &iRows, Eigen::VectorXi &jCols) override
Returns the sparsity pattern for the jacobian wrt control.
Definition: ConstraintContainerAnalytical-impl.h:421
virtual ConstraintContainerAnalytical_Raw_Ptr_t clone() const override
Deep-cloning of Constraint.
Definition: ConstraintContainerAnalytical-impl.h:56
virtual MatrixXs jacobianStateIntermediate() override
Evaluates the constraint jacobian wrt the state.
Definition: ConstraintContainerAnalytical-impl.h:172
virtual size_t getJacobianInputNonZeroCountIntermediate() override
Returns the number of non zero elements in the constraint jacobian wrt input.
Definition: ConstraintContainerAnalytical-impl.h:479
virtual VectorXs jacobianStateSparseTerminal() override
Evaluates the constraint jacobian wrt the state using sparse representation.
Definition: ConstraintContainerAnalytical-impl.h:191
virtual void sparsityPatternStateTerminal(Eigen::VectorXi &iRows, Eigen::VectorXi &jCols) override
Returns the sparsity pattern for the jacobian wrt state.
Definition: ConstraintContainerAnalytical-impl.h:346
A base function for linear constraint functions which have a first derivative.
Definition: LinearConstraintContainer.h:27
void addTerminalConstraint(std::shared_ptr< ConstraintBase< STATE_DIM, CONTROL_DIM, SCALAR >> constraint, bool verbose)
Adds a terminal constraint.
Definition: ConstraintContainerAnalytical-impl.h:82
virtual size_t getJacobianInputNonZeroCountTerminal() override
Returns the number of non zero elements in the constraint jacobian wrt input.
Definition: ConstraintContainerAnalytical-impl.h:489
ct::core::ControlVector< control_dim > u
Definition: LoadFromFileTest.cpp:21
virtual bool initializeTerminal() override
Initializes the terminal constraints.
Definition: ConstraintContainerAnalytical-impl.h:534
virtual MatrixXs jacobianStateTerminal() override
Evaluates the constraint jacobian wrt the state.
Definition: ConstraintContainerAnalytical-impl.h:212
virtual VectorXs jacobianInputSparseIntermediate() override
Evaluates the constraint jacobian wrt the control input using sparse representation.
Definition: ConstraintContainerAnalytical-impl.h:230
virtual size_t getIntermediateConstraintsCount() override
Retrieves the number of intermediate constraints.
Definition: ConstraintContainerAnalytical-impl.h:129
virtual size_t getTerminalConstraintsCount() override
Retrieves the number of final constraints.
Definition: ConstraintContainerAnalytical-impl.h:140
virtual VectorXs evaluateTerminal() override
Evaluates the terminal constraints.
Definition: ConstraintContainerAnalytical-impl.h:114
virtual VectorXs jacobianStateSparseIntermediate() override
Evaluates the constraint jacobian wrt the state using sparse representation.
Definition: ConstraintContainerAnalytical-impl.h:151
virtual void sparsityPatternInputIntermediate(Eigen::VectorXi &iRows, Eigen::VectorXi &jCols) override
Returns the sparsity pattern for the jacobian wrt control.
Definition: ConstraintContainerAnalytical-impl.h:384
void addIntermediateConstraint(std::shared_ptr< ConstraintBase< STATE_DIM, CONTROL_DIM, SCALAR >> constraint, bool verbose)
Adds an intermedaite constraint.
Definition: ConstraintContainerAnalytical-impl.h:67
virtual VectorXs evaluateIntermediate() override
Evaluates the intermediate constraints.
Definition: ConstraintContainerAnalytical-impl.h:98
clear all close all load ct GNMSLog0 mat reformat t
Definition: gnmsPlot.m:6
virtual void sparsityPatternStateIntermediate(Eigen::VectorXi &iRows, Eigen::VectorXi &jCols) override
Returns the sparsity pattern for the jacobian wrt state.
Definition: ConstraintContainerAnalytical-impl.h:308
Eigen::Matrix< SCALAR, Eigen::Dynamic, 1 > VectorXs
Definition: ConstraintContainerAnalytical.h:36
CppAD::AD< CppAD::cg::CG< double > > SCALAR
virtual VectorXs jacobianInputSparseTerminal() override
Evaluates the constraint jacobian wrt the control input using sparse representation.
Definition: ConstraintContainerAnalytical-impl.h:269
virtual size_t getJacobianStateNonZeroCountIntermediate() override
Returns the number of non zero elements in the constraint jacobian wrt state.
Definition: ConstraintContainerAnalytical-impl.h:459
Eigen::Matrix< SCALAR, Eigen::Dynamic, Eigen::Dynamic > MatrixXs
Definition: ConstraintContainerAnalytical.h:37
ConstraintContainerAnalytical()
Definition: ConstraintContainerAnalytical-impl.h:12
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef core::StateVector< STATE_DIM, SCALAR > state_vector_t
Definition: ConstraintContainerAnalytical.h:32
Contains all the constraints using analytically calculated jacobians.
Definition: ConstraintContainerAnalytical.h:27
ct::core::StateVector< state_dim > x
Definition: LoadFromFileTest.cpp:20
virtual MatrixXs jacobianInputIntermediate() override
Evaluates the constraint jacobian wrt the control input.
Definition: ConstraintContainerAnalytical-impl.h:251
virtual bool initializeIntermediate() override
Initializes the intermediate constraints.
Definition: ConstraintContainerAnalytical-impl.h:499
ConstraintContainerAnalytical< STATE_DIM, CONTROL_DIM, SCALAR > * ConstraintContainerAnalytical_Raw_Ptr_t
Definition: ConstraintContainerAnalytical.h:35
virtual size_t getJacobianStateNonZeroCountTerminal() override
Returns the number of non zero elements in the constraint jacobian wrt state.
Definition: ConstraintContainerAnalytical-impl.h:469
virtual ~ConstraintContainerAnalytical()
Destructor.
Definition: ConstraintContainerAnalytical-impl.h:62
virtual MatrixXs jacobianInputTerminal() override
Evaluates the constraint jacobian wrt the control input.
Definition: ConstraintContainerAnalytical-impl.h:290
const bool verbose
Definition: ConstraintComparison.h:18
Base class for the constraints used in this toolbox.
Definition: ConstraintBase.h:21