aligator 0.19.0
A versatile and efficient C++ library for real-time constrained trajectory optimization.
Loading...
Searching...
No Matches
results-base.hpp
Go to the documentation of this file.
1
3#pragma once
4
6#include <fmt/format.h>
7
8namespace aligator {
9
10template <typename _Scalar> struct ResultsBaseTpl {
11 using Scalar = _Scalar;
13
14protected:
15 // Whether the results struct was initialized.
18public:
19 std::size_t num_iters = 0;
20 bool conv = false;
21
28
30 std::vector<MatrixXs> gains_;
32 std::vector<VectorXs> xs;
34 std::vector<VectorXs> us;
35
38 bool isInitialized() const { return m_isInitialized; }
39
41 decltype(auto) getFeedforward(std::size_t i) {
42 return this->gains_[i].col(0);
43 }
44
46 decltype(auto) getFeedforward(std::size_t i) const {
47 return this->gains_[i].col(0);
48 }
49
51 decltype(auto) getFeedback(std::size_t i) {
52 return this->gains_[i].rightCols(this->get_ndx1(i));
53 }
54
56 decltype(auto) getFeedback(std::size_t i) const {
57 return this->gains_[i].rightCols(this->get_ndx1(i));
58 }
59
60 std::vector<MatrixXs> getCtrlFeedbacks() const {
61 const std::size_t N = us.size();
62 std::vector<MatrixXs> out;
63 out.reserve(N);
64 for (std::size_t i = 0; i < N; i++) {
65 const Eigen::Index nu = us[i].rows();
66 out.emplace_back(getFeedback(i).topRows(nu));
67 }
68 return out;
69 }
70
71 std::vector<VectorXs> getCtrlFeedforwards() const {
72 const std::size_t N = us.size();
73 std::vector<VectorXs> out;
74 out.reserve(N);
75 for (std::size_t i = 0; i < N; i++) {
76 const Eigen::Index nu = us[i].rows();
77 out.emplace_back(getFeedforward(i).head(nu));
78 }
79 return out;
80 }
81
82 std::string printBase() const;
83 virtual ~ResultsBaseTpl() = default;
84
85private:
86 Eigen::Index get_ndx1(std::size_t i) const {
87 return this->gains_[i].cols() - 1;
88 }
89};
90
91template <typename Scalar>
93 return fmt::format("\n num_iters: {:d},"
94 "\n converged: {},"
95 "\n traj. cost: {:.3e},"
96 "\n merit.value: {:.3e},"
97 "\n prim_infeas: {:.3e},"
98 "\n dual_infeas: {:.3e},",
101}
102
103template <typename Scalar>
104std::ostream &operator<<(std::ostream &oss,
105 const ResultsBaseTpl<Scalar> &self) {
106 return oss << "Results {" << self.printBase() << "\n}";
107}
108
109#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
110extern template struct ResultsBaseTpl<context::Scalar>;
111#endif
112} // namespace aligator
Main package namespace.
std::ostream & operator<<(std::ostream &oss, const StageFunctionDataTpl< T > &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.