- 3.0.2 optimal control module.
ControlInputConstraint-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 control_vector_t& ub)
14  : Base(lb, ub)
15 {
16 }
17 
18 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
20  const VectorXs& ub,
21  const Eigen::VectorXi& control_sparsity)
22  : Base(lb, ub, control_sparsity)
23 {
24 }
25 
26 
27 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
29  : Base(arg)
30 {
31 }
32 
33 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
35 {
36 }
37 
38 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
40  const
41 {
43 }
44 
45 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
47  const state_vector_t& x,
48  const control_vector_t& u,
49  const SCALAR t)
50 {
51  return this->sparsity_J_ * u;
52 }
53 
54 #ifdef CPPADCG
55 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
56 Eigen::Matrix<ct::core::ADCGScalar, Eigen::Dynamic, 1>
60  ct::core::ADCGScalar t)
61 {
62  return this->sparsity_J_.template cast<ct::core::ADCGScalar>() * u;
63 }
64 #endif
65 
66 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
69  const control_vector_t& u,
70  const SCALAR t)
71 {
72  MatrixXs jac(this->constrSize_, STATE_DIM);
73  jac.setZero();
74  return jac;
75 }
76 
77 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
80  const control_vector_t& u,
81  const SCALAR t)
82 {
83  return this->sparsity_J_;
84 }
85 
86 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
88 {
89  return 0;
90 }
91 
92 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
94 {
95  return this->constrSize_;
96 }
97 
98 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
101  const control_vector_t& u,
102  const SCALAR t)
103 {
104  return VectorXs();
105 }
106 
107 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
109 {
110  // do nothing
111 }
112 
113 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
116  const control_vector_t& u,
117  const SCALAR t)
118 {
119  VectorXs jac(this->constrSize_);
120  jac.setConstant(1.0);
121  return jac;
122 }
123 
124 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
126 {
127  this->sparsityPatternSparseJacobian(this->sparsity_, this->constrSize_, rows, cols);
128 }
129 
130 } // namespace optcon
131 } // namespace ct
virtual MatrixXs jacobianInput(const state_vector_t &x, const control_vector_t &u, const SCALAR t) override
Returns the constraint jacobian wrt input.
Definition: ControlInputConstraint-impl.h:79
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: ControlInputConstraint-impl.h:115
virtual void sparsityPatternInput(VectorXi &rows, VectorXi &cols) override
Definition: ControlInputConstraint-impl.h:125
ct::core::ControlVector< control_dim > u
Definition: LoadFromFileTest.cpp:21
Class for control input box constraint term.
Definition: ControlInputConstraint.h:21
Eigen::Matrix< SCALAR, Eigen::Dynamic, 1 > VectorXs
Definition: ControlInputConstraint.h:33
virtual MatrixXs jacobianState(const state_vector_t &x, const control_vector_t &u, const SCALAR t) override
Returns the constraint jacobian wrt state.
Definition: ControlInputConstraint-impl.h:68
Eigen::Matrix< SCALAR, Eigen::Dynamic, Eigen::Dynamic > MatrixXs
Definition: ConstraintBase.h:32
Eigen::Matrix< SCALAR, Eigen::Dynamic, 1 > VectorXs
Definition: ConstraintBase.h:31
ControlInputConstraint(const control_vector_t &uLow, const control_vector_t &uHigh)
Constructor taking lower and upper state bounds directly. Assumes state box constraint is dense...
Definition: ControlInputConstraint-impl.h:12
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
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: ControlInputConstraint-impl.h:46
Eigen::Matrix< SCALAR, Eigen::Dynamic, Eigen::Dynamic > MatrixXs
Definition: ControlInputConstraint.h:34
CppAD::AD< CppAD::cg::CG< double > > SCALAR
virtual size_t getNumNonZerosJacobianInput() const override
Returns the number of nonzeros in the jacobian wrt control input. The default implementation assumes ...
Definition: ControlInputConstraint-impl.h:93
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 size_t getNumNonZerosJacobianState() const override
Returns the number of nonzeros in the jacobian wrt state. The default implementation assumes a dense ...
Definition: ControlInputConstraint-impl.h:87
ct::core::StateVector< state_dim > x
Definition: LoadFromFileTest.cpp:20
virtual ~ControlInputConstraint()
Definition: ControlInputConstraint-impl.h:34
Eigen::Matrix< int, Eigen::Dynamic, 1 > VectorXi
Definition: ControlInputConstraint.h:32
virtual ControlInputConstraint< STATE_DIM, CONTROL_DIM, SCALAR > * clone() const override
Creates a new instance of the object with same properties than original.
Definition: ControlInputConstraint-impl.h:39
virtual void sparsityPatternState(VectorXi &rows, VectorXi &cols) override
Definition: ControlInputConstraint-impl.h:108
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: ControlInputConstraint-impl.h:100