- 3.0.2 optimal control module.
StateConstraint.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 namespace ct {
9 namespace optcon {
10 
11 
21 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
22 class StateConstraint : public BoxConstraintBase<STATE_DIM, STATE_DIM, CONTROL_DIM, SCALAR>
23 {
24 public:
25  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
26 
29 
32 
33  using VectorXi = Eigen::Matrix<int, Eigen::Dynamic, 1>;
34  using VectorXs = Eigen::Matrix<SCALAR, Eigen::Dynamic, 1>;
35  using MatrixXs = Eigen::Matrix<SCALAR, Eigen::Dynamic, Eigen::Dynamic>;
36 
37  using sparsity_matrix_t = Eigen::Matrix<SCALAR, Eigen::Dynamic, STATE_DIM>;
38 
45  StateConstraint(const state_vector_t& xLow, const state_vector_t& xHigh);
46 
53  StateConstraint(const VectorXs& lb, const VectorXs& ub, const Eigen::VectorXi& state_sparsity);
54 
55  StateConstraint(const StateConstraint& arg);
56 
57  virtual ~StateConstraint();
58 
60 
61  virtual VectorXs evaluate(const state_vector_t& x, const control_vector_t& u, const SCALAR t) override;
62 
63 #ifdef CPPADCG
64  virtual Eigen::Matrix<ct::core::ADCGScalar, Eigen::Dynamic, 1> evaluateCppadCg(
67  ct::core::ADCGScalar t) override;
68 #endif
69 
70  virtual MatrixXs jacobianState(const state_vector_t& x, const control_vector_t& u, const SCALAR t) override;
71 
72  virtual MatrixXs jacobianInput(const state_vector_t& x, const control_vector_t& u, const SCALAR t) override;
73 
74  virtual size_t getNumNonZerosJacobianState() const override;
75 
76  virtual size_t getNumNonZerosJacobianInput() const override;
77 
78  virtual VectorXs jacobianStateSparse(const state_vector_t& x, const control_vector_t& u, const SCALAR t) override;
79 
80  virtual VectorXs jacobianInputSparse(const state_vector_t& x, const control_vector_t& u, const SCALAR t) override;
81 
82  virtual void sparsityPatternState(VectorXi& rows, VectorXi& cols) override;
83 
84  virtual void sparsityPatternInput(VectorXi& rows, VectorXi& cols) override;
85 };
86 
87 } // namespace optcon
88 } // namespace ct
virtual MatrixXs jacobianState(const state_vector_t &x, const control_vector_t &u, const SCALAR t) override
Returns the constraint jacobian wrt state.
Definition: StateConstraint-impl.h:64
virtual VectorXs jacobianInputSparse(const state_vector_t &x, const control_vector_t &u, const SCALAR t) override
Returns the constraint jacobian wrt control input in sparse structure. The default implementation map...
Definition: StateConstraint-impl.h:113
virtual StateConstraint< STATE_DIM, CONTROL_DIM, SCALAR > * clone() const override
Creates a new instance of the object with same properties than original.
Definition: StateConstraint-impl.h:37
ct::core::ControlVector< control_dim > u
Definition: LoadFromFileTest.cpp:21
virtual size_t getNumNonZerosJacobianState() const override
Returns the number of nonzeros in the jacobian wrt state. The default implementation assumes a dense ...
Definition: StateConstraint-impl.h:83
Eigen::Matrix< SCALAR, Eigen::Dynamic, Eigen::Dynamic > MatrixXs
Definition: ConstraintBase.h:32
typename ct::core::tpl::TraitSelector< SCALAR >::Trait Trait
Definition: StateConstraint.h:27
Eigen::Matrix< SCALAR, Eigen::Dynamic, 1 > VectorXs
Definition: ConstraintBase.h:31
clear all close all load ct GNMSLog0 mat reformat t
Definition: gnmsPlot.m:6
CppAD::AD< CppAD::cg::CG< double > > SCALAR
virtual MatrixXs jacobianInput(const state_vector_t &x, const control_vector_t &u, const SCALAR t) override
Returns the constraint jacobian wrt input.
Definition: StateConstraint-impl.h:73
virtual ~StateConstraint()
Definition: StateConstraint-impl.h:32
virtual VectorXs evaluate(const state_vector_t &x, const control_vector_t &u, const SCALAR t) override
The evaluation of the constraint violation. Note this method is SCALAR typed.
Definition: StateConstraint-impl.h:44
ct::core::StateVector< state_dim > x
Definition: LoadFromFileTest.cpp:20
virtual size_t getNumNonZerosJacobianInput() const override
Returns the number of nonzeros in the jacobian wrt control input. The default implementation assumes ...
Definition: StateConstraint-impl.h:89
Eigen::Matrix< SCALAR, Eigen::Dynamic, STATE_DIM > sparsity_matrix_t
Definition: StateConstraint.h:37
Eigen::Matrix< int, Eigen::Dynamic, 1 > VectorXi
Definition: StateConstraint.h:33
Class for state box constraint.
Definition: StateConstraint.h:22
StateConstraint(const state_vector_t &xLow, const state_vector_t &xHigh)
Constructor taking lower and upper state bounds directly. Assumes state box constraint is dense...
Definition: StateConstraint-impl.h:12
Base for box constraint, templated on dimension of the decision vector of the derived class...
Definition: BoxConstraintBase.h:20
virtual void sparsityPatternInput(VectorXi &rows, VectorXi &cols) override
Definition: StateConstraint-impl.h:121
virtual void sparsityPatternState(VectorXi &rows, VectorXi &cols) override
Definition: StateConstraint-impl.h:106
virtual VectorXs jacobianStateSparse(const state_vector_t &x, const control_vector_t &u, const SCALAR t) override
Returns the constraint jacobian wrt state in sparse structure. The default implementation maps the Ja...
Definition: StateConstraint-impl.h:96