1#ifndef CGMRES__MULTIPLE_SHOOTING_NLP_HPP_
2#define CGMRES__MULTIPLE_SHOOTING_NLP_HPP_
15template <
class OCP,
int N>
18 static constexpr int nx = OCP::nx;
19 static constexpr int nu = OCP::nu;
20 static constexpr int nc = OCP::nc;
22 static constexpr int nub = OCP::nub;
28 static_assert(OCP::nx > 0);
29 static_assert(OCP::nu > 0);
30 static_assert(OCP::nc >= 0);
31 static_assert(OCP::nub >= 0);
39 template <
typename VectorType>
48 ocp_.eval_hu(t, x0.derived().data(), solution.template head<nuc>().data(), lmd[1].data(),
49 fonc_hu.template head<nuc>().data());
50 for (
size_t i=1; i<N; ++i) {
51 ocp_.eval_hu(t+i*dt, x[i].data(), solution.template segment<nuc>(
nuc*i).data(),
52 lmd[i+1].data(), fonc_hu.template segment<nuc>(
nuc*i).data());
56 template <
typename VectorType>
64 ocp_.eval_f(t, x0.derived().data(), solution.template head<nuc>().data(), dx_.data());
65 fonc_f[0] = x[1] - x0 - dt * dx_;
66 for (
size_t i=1; i<N; ++i) {
67 ocp_.eval_f(t+i*dt, x[i].data(), solution.template segment<nuc>(
nuc*i).data(), dx_.data());
68 fonc_f[i] = x[i+1] - x[i] - dt * dx_;
72 template <
typename VectorType>
80 ocp_.eval_f(t, x0.derived().data(), solution.template head<nuc>().data(), dx_.data());
81 x[1] = x0 + dt * dx_ + fonc_f[0];
82 for (
size_t i=1; i<N; ++i) {
83 ocp_.eval_f(t+i*dt, x[i].data(), solution.template segment<nuc>(
nuc*i).data(), dx_.data());
84 x[i+1] = x[i] + dt * dx_ + fonc_f[i];
88 template <
typename VectorType>
96 ocp_.eval_phix(t+T, x[N].data(), dx_.data());
97 fonc_hx[N] = lmd[N] - dx_;
98 for (
size_t i=N-1; i>=1; --i) {
99 ocp_.eval_hx(t+i*dt, x[i].data(), solution.template segment<nuc>(
nuc*i).data(),
100 lmd[i+1].data(), dx_.data());
101 fonc_hx[i] = lmd[i] - lmd[i+1] - dt * dx_;
105 template <
typename VectorType>
109 const Scalar T = horizon_.
T(t);
113 ocp_.eval_phix(t+T, x[N].data(), dx_.data());
114 lmd[N] = dx_ + fonc_hx[N];
115 for (
size_t i=N-1; i>=1; --i) {
116 ocp_.eval_hx(t+i*dt, x[i].data(), solution.template segment<nuc>(
nuc*i).data(),
117 lmd[i+1].data(), dx_.data());
118 lmd[i] = lmd[i+1] + dt * dx_ + fonc_hx[i];
126 ubounds::eval_fonc_hu<OCP, N>(ocp_, solution, dummy, mu, fonc_hu);
133 ubounds::eval_fonc_hdummy<OCP, N>(ocp_, solution, dummy, mu, fonc_hdummy);
140 ubounds::eval_fonc_hmu<OCP, N>(ocp_, solution, dummy, mu, fonc_hmu);
148 ubounds::multiply_hdummy_inv<OCP, N>(dummy, mu, fonc_hdummy, fonc_hmu,
158 ubounds::multiply_hmu_inv<OCP, N>(dummy, mu, fonc_hdummy, fonc_hmu,
159 fonc_hdummy_inv, fonc_hmu_inv);
167 ubounds::retrive_dummy_update<OCP, N>(ocp_, solution, dummy, mu, solution_update, dummy_update);
175 ubounds::retrive_mu_update<OCP, N>(ocp_, solution, dummy, mu, solution_update, mu_update);
179 ubounds::clip_dummy<OCP, N>(dummy, min);
184 const OCP&
ocp()
const {
return ocp_; }
188 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
Horizon of MPC.
Definition: horizon.hpp:18
Scalar T(const Scalar t) const
Gets the length of the horizon.
Definition: horizon.hpp:50
Definition: multiple_shooting_nlp.hpp:16
MultipleShootingNLP(const OCP &ocp, const Horizon &horizon)
Definition: multiple_shooting_nlp.hpp:25
void eval_fonc_f(const Scalar t, const MatrixBase< VectorType > &x0, const Vector< dim > &solution, const std::array< Vector< nx >, N+1 > &x, std::array< Vector< nx >, N+1 > &fonc_f)
Definition: multiple_shooting_nlp.hpp:57
static constexpr int nc
Definition: multiple_shooting_nlp.hpp:20
void clip_dummy(std::array< Vector< OCP::nub >, N > &dummy, const Scalar min)
Definition: multiple_shooting_nlp.hpp:178
void eval_fonc_hdummy(const Vector< dim > &solution, const std::array< Vector< nub >, N > &dummy, const std::array< Vector< nub >, N > &mu, std::array< Vector< nub >, N > &fonc_hdummy) const
Definition: multiple_shooting_nlp.hpp:129
static constexpr int dim
Definition: multiple_shooting_nlp.hpp:23
void eval_fonc_hu(const Scalar t, const MatrixBase< VectorType > &x0, const Vector< dim > &solution, const std::array< Vector< nx >, N+1 > &x, const std::array< Vector< nx >, N+1 > &lmd, Vector< dim > &fonc_hu)
Definition: multiple_shooting_nlp.hpp:40
MultipleShootingNLP()=default
static void multiply_hdummy_inv(const std::array< Vector< nub >, N > &dummy, const std::array< Vector< nub >, N > &mu, const std::array< Vector< nub >, N > &fonc_hdummy, const std::array< Vector< nub >, N > &fonc_hmu, std::array< Vector< nub >, N > &fonc_hdummy_inv)
Definition: multiple_shooting_nlp.hpp:143
static constexpr int nub
Definition: multiple_shooting_nlp.hpp:22
void retrive_dummy_update(const Vector< OCP::nuc *N > &solution, const std::array< Vector< OCP::nub >, N > &dummy, const std::array< Vector< OCP::nub >, N > &mu, const Vector< OCP::nuc *N > &solution_update, std::array< Vector< OCP::nub >, N > &dummy_update)
Definition: multiple_shooting_nlp.hpp:162
void retrive_x(const Scalar t, const MatrixBase< VectorType > &x0, const Vector< dim > &solution, std::array< Vector< nx >, N+1 > &x, const std::array< Vector< nx >, N+1 > &fonc_f)
Definition: multiple_shooting_nlp.hpp:73
static constexpr int nuc
Definition: multiple_shooting_nlp.hpp:21
~MultipleShootingNLP()=default
void eval_fonc_hx(const Scalar t, const MatrixBase< VectorType > &x0, const Vector< dim > &solution, const std::array< Vector< nx >, N+1 > &x, const std::array< Vector< nx >, N+1 > &lmd, std::array< Vector< nx >, N+1 > &fonc_hx)
Definition: multiple_shooting_nlp.hpp:89
void eval_fonc_hmu(const Vector< dim > &solution, const std::array< Vector< nub >, N > &dummy, const std::array< Vector< nub >, N > &mu, std::array< Vector< nub >, N > &fonc_hmu) const
Definition: multiple_shooting_nlp.hpp:136
static constexpr int nx
Definition: multiple_shooting_nlp.hpp:18
static constexpr int nu
Definition: multiple_shooting_nlp.hpp:19
void synchronize_ocp()
Definition: multiple_shooting_nlp.hpp:182
const OCP & ocp() const
Definition: multiple_shooting_nlp.hpp:184
void retrive_lmd(const Scalar t, const MatrixBase< VectorType > &x0, const Vector< dim > &solution, const std::array< Vector< nx >, N+1 > &x, std::array< Vector< nx >, N+1 > &lmd, const std::array< Vector< nx >, N+1 > &fonc_hx)
Definition: multiple_shooting_nlp.hpp:106
void retrive_mu_update(const Vector< OCP::nuc *N > &solution, const std::array< Vector< OCP::nub >, N > &dummy, const std::array< Vector< OCP::nub >, N > &mu, const Vector< OCP::nuc *N > &solution_update, std::array< Vector< OCP::nub >, N > &mu_update)
Definition: multiple_shooting_nlp.hpp:170
static void multiply_hmu_inv(const std::array< Vector< nub >, N > &dummy, const std::array< Vector< nub >, N > &mu, const std::array< Vector< nub >, N > &fonc_hdummy, const std::array< Vector< nub >, N > &fonc_hmu, const std::array< Vector< nub >, N > &fonc_hdummy_inv, std::array< Vector< nub >, N > &fonc_hmu_inv)
Definition: multiple_shooting_nlp.hpp:152
const Horizon & horizon() const
Definition: multiple_shooting_nlp.hpp:186
void eval_fonc_hu(const Vector< dim > &solution, const std::array< Vector< nub >, N > &dummy, const std::array< Vector< nub >, N > &mu, Vector< dim > &fonc_hu) const
Definition: multiple_shooting_nlp.hpp:122
Definition: continuation_gmres.hpp:11
Eigen::Matrix< Scalar, size, 1 > Vector
Alias of Eigen::Vector.
Definition: types.hpp:23
double Scalar
Alias of double.
Definition: types.hpp:11
Eigen::MatrixBase< MatrixType > MatrixBase
Alias of Eigen::MatrixBase.
Definition: types.hpp:29