- 3.0.2 optimal control module.
ConstraintContainerBase-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  : x_(state_vector_t::Zero()), u_(input_vector_t::Zero()), t_(SCALAR(0.0))
14 {
15 }
16 
17 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
19  : x_(arg.x_),
20  u_(arg.u_),
21  t_(arg.t_),
26 {
27 }
28 
29 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
31 {
32 }
33 
34 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
36  const input_vector_t& u,
37  const SCALAR t)
38 {
39  t_ = t;
40  x_ = x;
41  u_ = u;
42  update();
43 }
44 
45 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
47 {
49 }
50 
51 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
54 {
56 }
57 
58 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
61 {
62  return lowerBoundsTerminal_;
63 }
64 
65 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
68 {
70 }
71 
72 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
75 {
76  return upperBoundsTerminal_;
77 }
78 
79 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
82 {
83  const VectorXs vZero = VectorXs::Zero(upperBoundsIntermediate_.rows());
84  return (evaluateIntermediate() - upperBoundsIntermediate_).array().max(vZero.array());
85 }
86 
87 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
90 {
91  const VectorXs vZero = VectorXs::Zero(lowerBoundsIntermediate_.rows());
92  return (evaluateIntermediate() - lowerBoundsIntermediate_).array().min(vZero.array());
93 }
94 
95 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
98 {
99  const VectorXs vZero = VectorXs::Zero(upperBoundsTerminal_.rows());
100  return (evaluateTerminal() - upperBoundsTerminal_).array().max(vZero.array());
101 }
102 
103 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
106 {
107  const VectorXs vZero = VectorXs::Zero(lowerBoundsTerminal_.rows());
108  return (evaluateTerminal() - lowerBoundsTerminal_).array().min(vZero.array());
109 }
110 
111 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
114 {
115  const VectorXs vZero = VectorXs::Zero(lowerBoundsIntermediate_.rows());
117  return (eval - lowerBoundsIntermediate_).array().min(vZero.array()) +
118  (eval - upperBoundsIntermediate_).array().max(vZero.array());
119 }
120 
121 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
124 {
125  const VectorXs vZero = VectorXs::Zero(lowerBoundsTerminal_.rows());
126  VectorXs eval = evaluateTerminal();
127  return (eval - lowerBoundsTerminal_).array().min(vZero.array()) +
128  (eval - upperBoundsTerminal_).array().max(vZero.array());
129 }
130 
131 } // namespace optcon
132 } // namespace ct
VectorXs getLowerBoundsIntermediate() const
Retrieves the lower constraint bound on the intermediate constraints.
Definition: ConstraintContainerBase-impl.h:53
VectorXs getLowerBoundsTerminal() const
Retrieves the lower constraint bound on the terminal constraints.
Definition: ConstraintContainerBase-impl.h:60
virtual void setCurrentStateAndControl(const state_vector_t &x, const input_vector_t &u, const SCALAR t=SCALAR(0.0))
Definition: ConstraintContainerBase-impl.h:35
input_vector_t u_
Definition: ConstraintContainerBase.h:198
Eigen::Matrix< SCALAR, Eigen::Dynamic, 1 > VectorXs
Definition: ConstraintContainerBase.h:40
VectorXs getUpperBoundsTerminal() const
Retrieves the upper constraint bound on the terminal constraints.
Definition: ConstraintContainerBase-impl.h:74
ct::core::ControlVector< control_dim > u
Definition: LoadFromFileTest.cpp:21
VectorXs lowerBoundsTerminal_
Definition: ConstraintContainerBase.h:202
virtual size_t getIntermediateConstraintsCount()=0
Retrieves the number of intermediate constraints.
VectorXs getUpperBoundsViolationIntermediate()
Retrieves the violation of the upper constraint bound on the intermediate constraints.
Definition: ConstraintContainerBase-impl.h:81
VectorXs upperBoundsTerminal_
Definition: ConstraintContainerBase.h:204
VectorXs lowerBoundsIntermediate_
Definition: ConstraintContainerBase.h:201
VectorXs getTotalBoundsViolationIntermediate()
Retrieves the total violation of the constraints bounds on the intermediate constraints.
Definition: ConstraintContainerBase-impl.h:113
virtual VectorXs evaluateIntermediate()=0
Evaluates the intermediate constraints.
clear all close all load ct GNMSLog0 mat reformat t
Definition: gnmsPlot.m:6
virtual ~ConstraintContainerBase()
Destructor.
Definition: ConstraintContainerBase-impl.h:30
virtual size_t getTerminalConstraintsCount()=0
Retrieves the number of final constraints.
VectorXs getUpperBoundsIntermediate() const
Retrieves the upper constraint bound on the intermediate constraints.
Definition: ConstraintContainerBase-impl.h:67
CppAD::AD< CppAD::cg::CG< double > > SCALAR
VectorXs getTotalBoundsViolationTerminal()
Retrieves the total violation of the constraints bounds on the terminal constraints.
Definition: ConstraintContainerBase-impl.h:123
virtual void update()=0
Gets called by the setCurrentStateAndControl method. Can be used to update container properties...
virtual VectorXs evaluateTerminal()=0
Evaluates the terminal constraints.
VectorXs getUpperBoundsViolationTerminal()
Retrieves the violation of the upper constraint bound on the terminal constraints.
Definition: ConstraintContainerBase-impl.h:97
size_t getConstraintsCount()
Retrieves the total number of constraints.
Definition: ConstraintContainerBase-impl.h:46
SCALAR t_
Definition: ConstraintContainerBase.h:199
ct::core::StateVector< state_dim > x
Definition: LoadFromFileTest.cpp:20
VectorXs upperBoundsIntermediate_
Definition: ConstraintContainerBase.h:203
VectorXs getLowerBoundsViolationTerminal()
Retrieves the violation of the lower constraint bound on the terminal constraints.
Definition: ConstraintContainerBase-impl.h:105
The ConstraintBase Class is the base class for defining the non-linear optimization constraints...
Definition: ConstraintContainerBase.h:31
state_vector_t x_
Definition: ConstraintContainerBase.h:197
Eigen::Matrix< double, nStates, 1 > state_vector_t
VectorXs getLowerBoundsViolationIntermediate()
Retrieves the violation of the lower constraint bound on the intermediate constraints.
Definition: ConstraintContainerBase-impl.h:89
ConstraintContainerBase()
Default constructor.
Definition: ConstraintContainerBase-impl.h:12