aligator
0.19.0
A versatile and efficient C++ library for real-time constrained trajectory optimization.
Toggle main menu visibility
Loading...
Searching...
No Matches
results-base.hpp
Go to the documentation of this file.
1
3
#pragma once
4
5
#include "
aligator/context.hpp
"
6
#include <fmt/format.h>
7
8
namespace
aligator
{
9
10
template
<
typename
_Scalar>
struct
ResultsBaseTpl
{
11
using
Scalar
= _Scalar;
12
ALIGATOR_DYNAMIC_TYPEDEFS
(
Scalar
);
13
14
protected
:
15
// Whether the results struct was initialized.
16
bool
m_isInitialized
;
17
18
public
:
19
std::size_t
num_iters
= 0;
20
bool
conv
=
false
;
21
22
Scalar
traj_cost_
= 0.;
23
Scalar
merit_value_
= 0.;
25
Scalar
prim_infeas
= 0.;
27
Scalar
dual_infeas
= 0.;
28
30
std::vector<MatrixXs>
gains_
;
32
std::vector<VectorXs>
xs
;
34
std::vector<VectorXs>
us
;
35
36
ResultsBaseTpl
()
37
:
m_isInitialized
(false) {}
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
85
private
:
86
Eigen::Index get_ndx1(std::size_t i)
const
{
87
return
this->gains_[i].cols() - 1;
88
}
89
};
90
91
template
<
typename
Scalar>
92
std::string
ResultsBaseTpl<Scalar>::printBase
()
const
{
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},"
,
99
num_iters
,
conv
,
traj_cost_
,
merit_value_
,
prim_infeas
,
100
dual_infeas
);
101
}
102
103
template
<
typename
Scalar>
104
std::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
110
extern
template
struct
ResultsBaseTpl<context::Scalar>;
111
#endif
112
}
// namespace aligator
context.hpp
aligator
Main package namespace.
Definition
action-model-wrap.hpp:14
aligator::operator<<
std::ostream & operator<<(std::ostream &oss, const StageFunctionDataTpl< T > &self)
aligator::ResultsBaseTpl
Definition
results-base.hpp:10
aligator::ResultsBaseTpl< Scalar >::us
std::vector< VectorXs > us
Definition
results-base.hpp:34
aligator::ResultsBaseTpl< Scalar >::Scalar
Scalar Scalar
Definition
results-base.hpp:11
aligator::ResultsBaseTpl::isInitialized
bool isInitialized() const
Definition
results-base.hpp:38
aligator::ResultsBaseTpl< Scalar >::merit_value_
Scalar merit_value_
Definition
results-base.hpp:23
aligator::ResultsBaseTpl::getCtrlFeedforwards
std::vector< VectorXs > getCtrlFeedforwards() const
Definition
results-base.hpp:71
aligator::ResultsBaseTpl::printBase
std::string printBase() const
Definition
results-base.hpp:92
aligator::ResultsBaseTpl::ALIGATOR_DYNAMIC_TYPEDEFS
ALIGATOR_DYNAMIC_TYPEDEFS(Scalar)
aligator::ResultsBaseTpl::~ResultsBaseTpl
virtual ~ResultsBaseTpl()=default
aligator::ResultsBaseTpl< Scalar >::conv
bool conv
Definition
results-base.hpp:20
aligator::ResultsBaseTpl::getFeedback
decltype(auto) getFeedback(std::size_t i) const
Get expression of the primal-dual feedback gains.
Definition
results-base.hpp:56
aligator::ResultsBaseTpl< Scalar >::num_iters
std::size_t num_iters
Definition
results-base.hpp:19
aligator::ResultsBaseTpl::ResultsBaseTpl
ResultsBaseTpl()
Definition
results-base.hpp:36
aligator::ResultsBaseTpl::getFeedforward
decltype(auto) getFeedforward(std::size_t i)
Get column expression of the primal-dual feedforward gain.
Definition
results-base.hpp:41
aligator::ResultsBaseTpl< Scalar >::xs
std::vector< VectorXs > xs
Definition
results-base.hpp:32
aligator::ResultsBaseTpl< Scalar >::gains_
std::vector< MatrixXs > gains_
Definition
results-base.hpp:30
aligator::ResultsBaseTpl::getCtrlFeedbacks
std::vector< MatrixXs > getCtrlFeedbacks() const
Definition
results-base.hpp:60
aligator::ResultsBaseTpl::getFeedforward
decltype(auto) getFeedforward(std::size_t i) const
Get column expression of the primal-dual feedforward gain.
Definition
results-base.hpp:46
aligator::ResultsBaseTpl< Scalar >::traj_cost_
Scalar traj_cost_
Definition
results-base.hpp:22
aligator::ResultsBaseTpl< Scalar >::m_isInitialized
bool m_isInitialized
Definition
results-base.hpp:16
aligator::ResultsBaseTpl< Scalar >::dual_infeas
Scalar dual_infeas
Definition
results-base.hpp:27
aligator::ResultsBaseTpl::getFeedback
decltype(auto) getFeedback(std::size_t i)
Get expression of the primal-dual feedback gains.
Definition
results-base.hpp:51
aligator::ResultsBaseTpl< Scalar >::prim_infeas
Scalar prim_infeas
Definition
results-base.hpp:25
include
aligator
solvers
results-base.hpp
Generated by
1.17.0