- 3.0.2 optimal control module.
StateConstraint-impl.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 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
13  const state_vector_t& xHigh)
14  : Base(xLow, xHigh)
15 {
16 }
17 
18 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
20  const VectorXs& ub,
21  const Eigen::VectorXi& state_sparsity)
22  : Base(lb, ub, state_sparsity)
23 {
24 }
25 
26 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
28 {
29 }
30 
31 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
33 {
34 }
35 
36 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
38 {
40 }
41 
42 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
45  const control_vector_t& u,
46  const SCALAR t)
47 {
48  return this->sparsity_J_ * x;
49 }
50 
51 #ifdef CPPADCG
52 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
53 Eigen::Matrix<ct::core::ADCGScalar, Eigen::Dynamic, 1> StateConstraint<STATE_DIM, CONTROL_DIM, SCALAR>::evaluateCppadCg(
56  ct::core::ADCGScalar t)
57 {
58  return this->sparsity_J_.template cast<ct::core::ADCGScalar>() * x;
59 }
60 #endif
61 
62 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
65  const control_vector_t& u,
66  const SCALAR t)
67 {
68  return this->sparsity_J_;
69 }
70 
71 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
74  const control_vector_t& u,
75  const SCALAR t)
76 {
77  MatrixXs jac(this->constrSize_, CONTROL_DIM);
78  jac.setZero();
79  return jac;
80 }
81 
82 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
84 {
85  return this->constrSize_;
86 }
87 
88 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
90 {
91  return 0;
92 }
93 
94 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
97  const control_vector_t& u,
98  const SCALAR t)
99 {
100  VectorXs jac(this->constrSize_);
101  jac.setConstant(1.0);
102  return jac;
103 }
104 
105 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
107 {
108  this->sparsityPatternSparseJacobian(this->sparsity_, this->constrSize_, rows, cols);
109 }
110 
111 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
114  const control_vector_t& u,
115  const SCALAR t)
116 {
117  return VectorXs();
118 }
119 
120 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
122 {
123  //do nothing
124 }
125 
126 } // namespace optcon
127 } // 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
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
size_t constrSize_
size of the constraint
Definition: BoxConstraintBase.h:113
sparsity_matrix_t sparsity_J_
sparsity matrix
Definition: BoxConstraintBase.h:110
CppAD::AD< CppAD::cg::CG< double > > SCALAR
Eigen::Matrix< SCALAR, Eigen::Dynamic, Eigen::Dynamic > MatrixXs
Definition: StateConstraint.h:35
static void sparsityPatternSparseJacobian(const VectorXi &sparsity_vec, const size_t &constrSize, VectorXi &rows, VectorXi &cols)
generate sparsity pattern for sparse box constraint
Definition: BoxConstraintBase-impl.h:121
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
Eigen::Matrix< SCALAR, Eigen::Dynamic, 1 > VectorXs
Definition: StateConstraint.h:34
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< 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
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
VectorXi sparsity_
sparsity in vector form
Definition: BoxConstraintBase.h:107
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