aligator  0.10.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;
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 virtual ~ResultsBaseTpl() = default;
80
81private:
82 Eigen::Index get_ndx1(std::size_t i) const {
83 return this->gains_[i].cols() - 1;
84 }
85};
86
87template <typename Scalar>
88void ResultsBaseTpl<Scalar>::printBase(std::ostream &oss) const {
89 oss << fmt::format("\n num_iters: {:d},", num_iters)
90 << fmt::format("\n converged: {},", conv)
91 << fmt::format("\n traj. cost: {:.3e},", traj_cost_)
92 << fmt::format("\n merit.value: {:.3e},", merit_value_)
93 << fmt::format("\n prim_infeas: {:.3e},", prim_infeas)
94 << fmt::format("\n dual_infeas: {:.3e},", dual_infeas);
95}
96
97template <typename Scalar>
98std::ostream &operator<<(std::ostream &oss,
99 const ResultsBaseTpl<Scalar> &self) {
100 oss << "Results {";
101 self.printBase(oss);
102 oss << "\n}";
103 return oss;
104}
105
106} // namespace aligator
107
108#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
109#include "./results-base.txx"
110#endif
Forward declarations.
Main package namespace.
std::ostream & operator<<(std::ostream &oss, const ExplicitDynamicsDataTpl< S > &self)
std::vector< VectorXs > xs
States.
virtual ~ResultsBaseTpl()=default
decltype(auto) getFeedback(std::size_t i)
Get expression of the primal-dual feedback gains.
decltype(auto) getFeedback(std::size_t i) const
Get expression of the primal-dual feedback gains.
std::vector< VectorXs > getCtrlFeedforwards() const
Scalar dual_infeas
Overall dual infeasibility measure.
decltype(auto) getFeedforward(std::size_t i)
Get column expression of the primal-dual feedforward gain.
Scalar prim_infeas
Overall primal infeasibility measure/constraint violation.
decltype(auto) getFeedforward(std::size_t i) const
Get column expression of the primal-dual feedforward gain.
std::vector< VectorXs > us
Controls.
std::vector< MatrixXs > gains_
Riccati gains.
void printBase(std::ostream &oss) const
std::vector< MatrixXs > getCtrlFeedbacks() const