aligator  0.6.1
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.
16
17public:
18 std::size_t num_iters = 0;
19 bool conv = false;
20
27
29 std::vector<MatrixXs> gains_;
31 std::vector<VectorXs> xs;
33 std::vector<VectorXs> us;
34
36 bool isInitialized() const { return m_isInitialized; }
37
39 decltype(auto) getFeedforward(std::size_t i) {
40 return this->gains_[i].col(0);
41 }
42
44 decltype(auto) getFeedforward(std::size_t i) const {
45 return this->gains_[i].col(0);
46 }
47
49 decltype(auto) getFeedback(std::size_t i) {
50 return this->gains_[i].rightCols(this->get_ndx1(i));
51 }
52
54 decltype(auto) getFeedback(std::size_t i) const {
55 return this->gains_[i].rightCols(this->get_ndx1(i));
56 }
57
58 std::vector<MatrixXs> getCtrlFeedbacks() const {
59 const std::size_t N = us.size();
60 std::vector<MatrixXs> out;
61 for (std::size_t i = 0; i < N; i++) {
62 const Eigen::Index nu = us[i].rows();
63 out.emplace_back(getFeedback(i).topRows(nu));
64 }
65 return out;
66 }
67
68 std::vector<VectorXs> getCtrlFeedforwards() const {
69 const std::size_t N = us.size();
70 std::vector<VectorXs> out;
71 for (std::size_t i = 0; i < N; i++) {
72 const Eigen::Index nu = us[i].rows();
73 out.emplace_back(getFeedforward(i).head(nu));
74 }
75 return out;
76 }
77
78 void printBase(std::ostream &oss) const;
79
80private:
81 Eigen::Index get_ndx1(std::size_t i) const {
82 return this->gains_[i].cols() - 1;
83 }
84};
85
86template <typename Scalar>
87void ResultsBaseTpl<Scalar>::printBase(std::ostream &oss) const {
88 oss << fmt::format("\n num_iters: {:d},", num_iters)
89 << fmt::format("\n converged: {},", conv)
90 << fmt::format("\n traj. cost: {:.3e},", traj_cost_)
91 << fmt::format("\n merit.value: {:.3e},", merit_value_)
92 << fmt::format("\n prim_infeas: {:.3e},", prim_infeas)
93 << fmt::format("\n dual_infeas: {:.3e},", dual_infeas);
94}
95
96template <typename Scalar>
97std::ostream &operator<<(std::ostream &oss,
98 const ResultsBaseTpl<Scalar> &self) {
99 oss << "Results {";
100 self.printBase(oss);
101 oss << "\n}";
102 return oss;
103}
104
105} // namespace aligator
106
107#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
108#include "./results-base.txx"
109#endif
Forward declarations.
Main package namespace.
std::vector< VectorXs > us
Controls.
std::vector< VectorXs > getCtrlFeedforwards() const
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< VectorXs > xs
States.
std::vector< MatrixXs > gains_
Riccati gains.
std::vector< MatrixXs > getCtrlFeedbacks() const
decltype(auto) getFeedforward(std::size_t i) const
Get column expression of the primal-dual feedforward gain.
void printBase(std::ostream &oss) const
Scalar dual_infeas
Overall dual infeasibility measure.
decltype(auto) getFeedback(std::size_t i)
Get expression of the primal-dual feedback gains.
Scalar prim_infeas
Overall primal infeasibility measure/constraint violation.