autogenu-jupyter
An automatic code generator and the continuation/GMRES (C/GMRES) based numerical solvers for nonlinear MPC
Loading...
Searching...
No Matches
horizon.hpp
Go to the documentation of this file.
1#ifndef CGMRES__HORIZON_HPP_
2#define CGMRES__HORIZON_HPP_
3
4#include <cmath>
5#include <stdexcept>
6#include <cassert>
7#include <iostream>
8
9#include "cgmres/types.hpp"
10
11
12namespace cgmres {
13
18class Horizon {
19public:
27 Horizon(const Scalar Tf, const Scalar alpha=0.0, const Scalar t0=0.0)
28 : Tf_(Tf), alpha_(alpha), t0_(t0) {
29 if (Tf <= 0.0) {
30 throw std::invalid_argument("[Horizon]: 'Tf' must be positive!");
31 }
32 time_varying_length_ = (alpha > 0.0);
33 }
34
38 Horizon() = default;
39
43 ~Horizon() = default;
44
50 Scalar T(const Scalar t) const {
51 if (time_varying_length_) {
52 if (t < t0_) {
53 throw std::invalid_argument("[Horizon]: 't' must be greater than or equal to 't0' (" + std::to_string(t0_) + ") !");
54 }
55 return Tf_ * (1.0-std::exp(-alpha_*(t-t0_)));
56 }
57 else {
58 return Tf_;
59 }
60 }
61
66 void reset(const Scalar t0) {
67 t0_ = t0;
68 }
69
70 void disp(std::ostream& os) const {
71 os << "Horizon: ";
72 if (time_varying_length_) {
73 os << "time-varying length" << std::endl;
74 }
75 else {
76 os << "fixed length" << std::endl;
77 }
78 os << " Tf: " << Tf_ << std::endl;
79 os << " alpha: " << alpha_ << std::endl;
80 os << " t0: " << t0_ << std::endl;
81 }
82
83 friend std::ostream& operator<<(std::ostream& os, const Horizon& horizon) {
84 horizon.disp(os);
85 return os;
86 }
87
88private:
89 Scalar Tf_, alpha_, t0_;
90 bool time_varying_length_;
91};
92
93} // namespace cgmres
94
95#endif // CGMRES__HORIZON_HPP_
Horizon of MPC.
Definition: horizon.hpp:18
~Horizon()=default
Default destructor.
Horizon(const Scalar Tf, const Scalar alpha=0.0, const Scalar t0=0.0)
Constructs the horizon. If alpha <= 0.0, then the fixed-length Tf is used. If alpha > 0....
Definition: horizon.hpp:27
Scalar T(const Scalar t) const
Gets the length of the horizon.
Definition: horizon.hpp:50
Horizon()=default
Default constructor.
friend std::ostream & operator<<(std::ostream &os, const Horizon &horizon)
Definition: horizon.hpp:83
void disp(std::ostream &os) const
Definition: horizon.hpp:70
void reset(const Scalar t0)
Resets the length of the horizon (for time-varying horizon).
Definition: horizon.hpp:66
Definition: continuation_gmres.hpp:11
double Scalar
Alias of double.
Definition: types.hpp:11