autogenu-jupyter
An automatic code generator and the continuation/GMRES (C/GMRES) based numerical solvers for nonlinear MPC
Loading...
Searching...
No Matches
control_input_bounds.hpp
Go to the documentation of this file.
1#ifndef CGMRES__CONTROL_INPUT_BOUNDS_HPP_
2#define CGMRES__CONTROL_INPUT_BOUNDS_HPP_
3
4#include <array>
5
6#include "cgmres/types.hpp"
7
9
10namespace cgmres {
11namespace detail {
12namespace ubounds {
13
14template <typename OCP, typename VectorType1, typename VectorType2, typename VectorType3, typename VectorType4>
15void eval_hu(const OCP& ocp, const MatrixBase<VectorType1>& u,
19 constexpr int nub = OCP::nub;
20 if constexpr (nub > 0) {
21 assert(dummy.size() == nub);
22 assert(mu.size() == nub);
23 for (int i=0; i<nub; ++i) {
24 const auto ui = OCP::ubound_indices[i];
26 += mu.coeff(i) * (2.0*u.coeff(ui) - ocp.umin[i] - ocp.umax[i]);
27 }
28 }
29}
30
31template <typename OCP, typename VectorType1, typename VectorType2, typename VectorType3, typename VectorType4>
32void eval_hdummy(const OCP& ocp, const MatrixBase<VectorType1>& u,
36 constexpr int nub = OCP::nub;
37 if constexpr (nub > 0) {
38 assert(dummy.size() == nub);
39 assert(mu.size() == nub);
40 assert(hdummy.size() == nub);
42 = 2.0 * mu.array() * dummy.array() - Map<const Vector<nub>>(ocp.dummy_weight.data()).array();
43 }
44}
45
46template <typename OCP, typename VectorType1, typename VectorType2, typename VectorType3, typename VectorType4>
47void eval_hmu(const OCP& ocp, const MatrixBase<VectorType1>& u,
51 constexpr int nub = OCP::nub;
52 if constexpr (nub > 0) {
53 assert(dummy.size() == nub);
54 assert(mu.size() == nub);
55 assert(hmu.size() == nub);
56 for (int i=0; i<nub; ++i) {
57 const auto ui = OCP::ubound_indices[i];
59 = u.coeff(ui) * (u.coeff(ui) - ocp.umin[i] - ocp.umax[i])
60 + ocp.umin[i] * ocp.umax[i] + dummy.coeff(i) * dummy.coeff(i);
61 }
62 }
63}
64
65template <typename VectorType1, typename VectorType2, typename VectorType3,
66 typename VectorType4, typename VectorType5>
74
75template <typename VectorType1, typename VectorType2, typename VectorType3,
76 typename VectorType4, typename VectorType5, typename VectorType6>
86
87template <typename OCP, typename VectorType1, typename VectorType2, typename VectorType3, typename VectorType4, typename VectorType5>
88void retrieve_dummy_update(const OCP& ocp,
94 constexpr int nub = OCP::nub;
95 if constexpr (nub > 0) {
96 assert(dummy.size() == nub);
97 assert(dummy_update.size() == nub);
98 for (int i=0; i<nub; ++i) {
99 const auto ui = OCP::ubound_indices[i];
101 = (2.0*u.coeff(ui) - ocp.umin[i] - ocp.umax[i]) * u_update.coeff(ui) / (2.0 * dummy.coeff(i));
102 }
103 }
104}
105
106template <typename OCP, typename VectorType1, typename VectorType2, typename VectorType3, typename VectorType4, typename VectorType5>
107void retrieve_mu_update(const OCP& ocp,
113 constexpr int nub = OCP::nub;
114 if constexpr (nub > 0) {
115 assert(dummy.size() == nub);
116 assert(mu_udpate.size() == nub);
117 for (int i=0; i<nub; ++i) {
118 const auto ui = OCP::ubound_indices[i];
120 = - mu.coeff(i) * (2.0*u.coeff(ui) - ocp.umin[i] - ocp.umax[i]) * u_update.coeff(ui)
121 / (2.0 * dummy.coeff(i) * dummy.coeff(i));
122 }
123 }
124}
125
126template <typename VectorType>
128 assert(min >= 0.0);
129 const size_t nub = dummy.size();
130 for (size_t i=0; i<nub; ++i) {
131 CGMRES_EIGEN_CONST_CAST(VectorType, dummy).coeffRef(i) = std::max(dummy.coeff(i), min);
132 }
133}
134
135} // namespace ubounds
136} // namespace detail
137} // namespace cgmres
138
139#endif // CGMRES__CONTROL_INPUT_BOUNDS_HPP_
#define CGMRES_EIGEN_CONST_CAST(TYPE, OBJ)
Definition macros.hpp:7
void retrieve_mu_update(const OCP &ocp, const MatrixBase< VectorType1 > &u, const MatrixBase< VectorType2 > &dummy, const MatrixBase< VectorType3 > &mu, const MatrixBase< VectorType4 > &u_update, const MatrixBase< VectorType5 > &mu_udpate)
Definition control_input_bounds.hpp:107
void clip_dummy(const MatrixBase< VectorType > &dummy, const Scalar min)
Definition control_input_bounds.hpp:127
void eval_hmu(const OCP &ocp, const MatrixBase< VectorType1 > &u, const MatrixBase< VectorType2 > &dummy, const MatrixBase< VectorType3 > &mu, const MatrixBase< VectorType4 > &hmu)
Definition control_input_bounds.hpp:47
void multiply_hmu_inv(const MatrixBase< VectorType1 > &dummy, const MatrixBase< VectorType2 > &mu, const MatrixBase< VectorType3 > &hdummy, const MatrixBase< VectorType4 > &hmu, const MatrixBase< VectorType5 > &hdummy_multiplied, const MatrixBase< VectorType6 > &hmu_multiplied)
Definition control_input_bounds.hpp:77
void retrieve_dummy_update(const OCP &ocp, const MatrixBase< VectorType1 > &u, const MatrixBase< VectorType2 > &dummy, const MatrixBase< VectorType3 > &mu, const MatrixBase< VectorType4 > &u_update, const MatrixBase< VectorType5 > &dummy_update)
Definition control_input_bounds.hpp:88
void multiply_hdummy_inv(const MatrixBase< VectorType1 > &dummy, const MatrixBase< VectorType2 > &mu, const MatrixBase< VectorType3 > &hdummy, const MatrixBase< VectorType4 > &hmu, const MatrixBase< VectorType5 > &hdummy_multiplied)
Definition control_input_bounds.hpp:67
void eval_hdummy(const OCP &ocp, const MatrixBase< VectorType1 > &u, const MatrixBase< VectorType2 > &dummy, const MatrixBase< VectorType3 > &mu, const MatrixBase< VectorType4 > &hdummy)
Definition control_input_bounds.hpp:32
void eval_hu(const OCP &ocp, const MatrixBase< VectorType1 > &u, const MatrixBase< VectorType2 > &dummy, const MatrixBase< VectorType3 > &mu, const MatrixBase< VectorType4 > &hu)
Definition control_input_bounds.hpp:15
Definition continuation_gmres.hpp:11
Eigen::Map< MatrixType > Map
Alias of Eigen::Map.
Definition types.hpp:54
double Scalar
Alias of double.
Definition types.hpp:15