aligator  0.14.0
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
results-base.hpp
Go to the documentation of this file.
1
3#pragma once
4
5#include "aligator/fwd.hpp"
6
7namespace aligator {
8
9template <typename _Scalar> struct ResultsBaseTpl {
10 using Scalar = _Scalar;
12
13protected:
14 // Whether the results struct was initialized.
17public:
18 std::size_t num_iters = 0;
19 bool conv = false;
27
29 std::vector<MatrixXs> gains_;
31 std::vector<VectorXs> xs;
33 std::vector<VectorXs> us;
34
37 bool isInitialized() const { return m_isInitialized; }
38
40 decltype(auto) getFeedforward(std::size_t i) {
41 return this->gains_[i].col(0);
42 }
43
45 decltype(auto) getFeedforward(std::size_t i) const {
46 return this->gains_[i].col(0);
47 }
48
50 decltype(auto) getFeedback(std::size_t i) {
51 return this->gains_[i].rightCols(this->get_ndx1(i));
52 }
53
55 decltype(auto) getFeedback(std::size_t i) const {
56 return this->gains_[i].rightCols(this->get_ndx1(i));
57 }
58
59 std::vector<MatrixXs> getCtrlFeedbacks() const {
60 const std::size_t N = us.size();
61 std::vector<MatrixXs> out;
62 out.reserve(N);
63 for (std::size_t i = 0; i < N; i++) {
64 const Eigen::Index nu = us[i].rows();
65 out.emplace_back(getFeedback(i).topRows(nu));
66 }
67 return out;
68 }
69
70 std::vector<VectorXs> getCtrlFeedforwards() const {
71 const std::size_t N = us.size();
72 std::vector<VectorXs> out;
73 out.reserve(N);
74 for (std::size_t i = 0; i < N; i++) {
75 const Eigen::Index nu = us[i].rows();
76 out.emplace_back(getFeedforward(i).head(nu));
77 }
78 return out;
79 }
80
81 std::string printBase() const;
82 virtual ~ResultsBaseTpl() = default;
83
84private:
85 Eigen::Index get_ndx1(std::size_t i) const {
86 return this->gains_[i].cols() - 1;
87 }
88};
89
90template <typename Scalar>
92 return fmt::format("\n num_iters: {:d},"
93 "\n converged: {},"
94 "\n traj. cost: {:.3e},"
95 "\n merit.value: {:.3e},"
96 "\n prim_infeas: {:.3e},"
97 "\n dual_infeas: {:.3e},",
100}
101
102template <typename Scalar>
103std::ostream &operator<<(std::ostream &oss,
104 const ResultsBaseTpl<Scalar> &self) {
105 return oss << "Results {" << self.printBase() << "\n}";
106}
107
108} // namespace aligator
109
110#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
111#include "results-base.txx"
112#endif
Forward declarations.
Main package namespace.
std::ostream & operator<<(std::ostream &oss, const ExplicitDynamicsDataTpl< S > &self)
std::vector< VectorXs > getCtrlFeedforwards() const
std::string printBase() const
virtual ~ResultsBaseTpl()=default
decltype(auto) getFeedback(std::size_t i) const
Get expression of the primal-dual feedback gains.
decltype(auto) getFeedforward(std::size_t i)
Get column expression of the primal-dual feedforward gain.
std::vector< MatrixXs > gains_
std::vector< MatrixXs > getCtrlFeedbacks() const
decltype(auto) getFeedforward(std::size_t i) const
Get column expression of the primal-dual feedforward gain.
decltype(auto) getFeedback(std::size_t i)
Get expression of the primal-dual feedback gains.