aligator
0.19.0
A versatile and efficient C++ library for real-time constrained trajectory optimization.
Toggle main menu visibility
Loading...
Searching...
No Matches
value-function.hpp
Go to the documentation of this file.
1
6
#pragma once
7
8
#include "
aligator/context.hpp
"
9
10
#include <ostream>
11
#include <fmt/format.h>
12
13
namespace
aligator
{
14
16
template
<
typename
_Scalar>
struct
ValueFunctionTpl
{
17
using
Scalar
= _Scalar;
18
ALIGATOR_DYNAMIC_TYPEDEFS
(
Scalar
);
19
int
ndx_
;
20
VectorXs
Vx_
;
21
MatrixXs
Vxx_
;
22
Scalar
v_
;
23
24
ValueFunctionTpl
(
const
int
ndx)
25
:
ndx_
(ndx)
26
,
Vx_
(ndx)
27
,
Vxx_
(ndx, ndx) {
28
Vx_
.setZero();
29
Vxx_
.setZero();
30
}
31
32
friend
std::ostream &
operator<<
(std::ostream &oss,
33
const
ValueFunctionTpl
&store) {
34
oss <<
"ValueFunction {\n"
;
35
oss << fmt::format(
"\tndx: {:d}"
, store.
ndx_
);
36
oss <<
"\n}"
;
37
return
oss;
38
}
39
};
40
44
template
<
typename
_Scalar>
struct
QFunctionTpl
{
45
using
Scalar
= _Scalar;
46
ALIGATOR_DYNAMIC_TYPEDEFS
(
Scalar
);
47
48
long
ndx_
;
49
long
nu_
;
50
long
ndy_
;
51
long
ntot
()
const
{
return
ndx_
+
nu_
+
ndy_
; }
52
53
Scalar
q_
= 0.;
54
55
VectorXs
grad_
;
56
MatrixXs
hess_
;
57
58
VectorRef
Qx
;
59
VectorRef
Qu
;
60
61
MatrixRef
Qxx
;
62
MatrixRef
Qxu
;
63
MatrixRef
Qxy
;
64
MatrixRef
Quu
;
65
MatrixRef
Quy
;
66
MatrixRef
Qyy
;
67
68
QFunctionTpl
(
const
long
ndx,
const
long
nu,
const
long
ndy)
69
:
ndx_
(ndx)
70
,
nu_
(nu)
71
,
ndy_
(ndy)
72
,
grad_
(
ndx_
+
nu_
)
73
,
hess_
(
ntot
(),
ntot
())
74
,
Qx
(
grad_
.head(ndx))
75
,
Qu
(
grad_
.segment(ndx, nu))
76
,
Qxx
(
hess_
.topLeftCorner(ndx, ndx))
77
,
Qxu
(
hess_
.block(0, ndx, ndx, nu))
78
,
Qxy
(
hess_
.topRightCorner(ndx, ndy))
79
,
Quu
(
hess_
.block(ndx, ndx, nu, nu))
80
,
Quy
(
hess_
.block(ndx, ndx + nu, nu, ndy))
81
,
Qyy
(
hess_
.bottomRightCorner(ndy, ndy)) {
82
grad_
.setZero();
83
hess_
.setZero();
84
assert(
hess_
.rows() ==
ntot
());
85
assert(
hess_
.cols() ==
ntot
());
86
}
87
88
QFunctionTpl
(
const
QFunctionTpl
&qf)
89
:
QFunctionTpl
(qf.
ndx_
, qf.
nu_
, qf.
ndy_
) {
90
ndx_
= qf.
ndx_
;
91
nu_
= qf.
nu_
;
92
ndy_
= qf.
ndy_
;
93
q_
= qf.
q_
;
94
grad_
= qf.
grad_
;
95
hess_
= qf.
hess_
;
96
97
redef_refs
(*
this
);
98
}
99
100
QFunctionTpl
(
QFunctionTpl
&&qf)
101
:
QFunctionTpl
(0, 0, 0) {
102
swap
(*
this
, qf);
103
}
104
105
QFunctionTpl
&
operator=
(
QFunctionTpl
&&qf) {
106
swap
(*
this
, qf);
107
return
*
this
;
108
}
109
110
QFunctionTpl
&
operator=
(
const
QFunctionTpl
&qf) {
111
ndx_
= qf.
ndx_
;
112
nu_
= qf.
nu_
;
113
ndy_
= qf.
ndy_
;
114
q_
= qf.
q_
;
115
grad_
= qf.
grad_
;
116
hess_
= qf.
hess_
;
117
118
redef_refs
(*
this
);
119
return
*
this
;
120
}
121
122
friend
std::ostream &
operator<<
(std::ostream &oss,
123
const
QFunctionTpl
&store) {
124
oss <<
"QFunction {\n"
;
125
oss << fmt::format(
"ndx: {:d}, nu: {:d}, ndy: {:d}"
, store.
ndx_
, store.
nu_
,
126
store.
ndy_
);
127
oss <<
"\n}"
;
128
return
oss;
129
}
130
131
friend
void
swap
(
QFunctionTpl
&qa,
QFunctionTpl
&qb) {
132
using
std::swap;
133
134
swap
(qa.
ndx_
, qb.
ndx_
);
135
swap
(qa.
nu_
, qb.
nu_
);
136
swap
(qa.
ndy_
, qb.
ndy_
);
137
swap
(qa.
q_
, qb.
q_
);
138
swap
(qa.
grad_
, qb.
grad_
);
139
swap
(qa.
hess_
, qb.
hess_
);
140
141
redef_refs
(qa);
142
redef_refs
(qb);
143
}
144
145
protected
:
146
// reinitialize Ref members
147
static
void
redef_refs
(
QFunctionTpl
&q) {
148
auto
ndx = q.
ndx_
;
149
auto
nu = q.
nu_
;
150
auto
ndy = q.
ndy_
;
151
new
(&q.
Qx
) VectorRef(q.
grad_
.head(ndx));
152
new
(&q.
Qu
) VectorRef(q.
grad_
.segment(ndx, nu));
153
154
new
(&q.
Qxx
) MatrixRef(q.
hess_
.topLeftCorner(ndx, ndx));
155
new
(&q.
Qxu
) MatrixRef(q.
hess_
.block(0, ndx, ndx, nu));
156
new
(&q.
Qxy
) MatrixRef(q.
hess_
.topRightCorner(ndx, ndy));
157
new
(&q.
Quu
) MatrixRef(q.
hess_
.block(ndx, ndx, nu, nu));
158
new
(&q.
Quy
) MatrixRef(q.
hess_
.block(ndx, ndx + nu, nu, ndy));
159
new
(&q.
Qyy
) MatrixRef(q.
hess_
.bottomRightCorner(ndy, ndy));
160
}
161
};
162
163
#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
164
extern
template
struct
ValueFunctionTpl<context::Scalar>;
165
extern
template
struct
QFunctionTpl<context::Scalar>;
166
#endif
167
}
// namespace aligator
context.hpp
aligator
Main package namespace.
Definition
action-model-wrap.hpp:14
aligator::QFunctionTpl< Scalar >::grad_
VectorXs grad_
Definition
value-function.hpp:55
aligator::QFunctionTpl< Scalar >::Scalar
Scalar Scalar
Definition
value-function.hpp:45
aligator::QFunctionTpl::swap
friend void swap(QFunctionTpl &qa, QFunctionTpl &qb)
Definition
value-function.hpp:131
aligator::QFunctionTpl< Scalar >::Quu
MatrixRef Quu
Definition
value-function.hpp:64
aligator::QFunctionTpl< Scalar >::Quy
MatrixRef Quy
Definition
value-function.hpp:65
aligator::QFunctionTpl< Scalar >::nu_
long nu_
Definition
value-function.hpp:49
aligator::QFunctionTpl::operator<<
friend std::ostream & operator<<(std::ostream &oss, const QFunctionTpl &store)
Definition
value-function.hpp:122
aligator::QFunctionTpl::ALIGATOR_DYNAMIC_TYPEDEFS
ALIGATOR_DYNAMIC_TYPEDEFS(Scalar)
aligator::QFunctionTpl< Scalar >::q_
Scalar q_
Definition
value-function.hpp:53
aligator::QFunctionTpl< Scalar >::Qxu
MatrixRef Qxu
Definition
value-function.hpp:62
aligator::QFunctionTpl< Scalar >::ndy_
long ndy_
Definition
value-function.hpp:50
aligator::QFunctionTpl< Scalar >::hess_
MatrixXs hess_
Definition
value-function.hpp:56
aligator::QFunctionTpl::operator=
QFunctionTpl & operator=(const QFunctionTpl &qf)
Definition
value-function.hpp:110
aligator::QFunctionTpl< Scalar >::Qxx
MatrixRef Qxx
Definition
value-function.hpp:61
aligator::QFunctionTpl< Scalar >::ndx_
long ndx_
Definition
value-function.hpp:48
aligator::QFunctionTpl< Scalar >::Qu
VectorRef Qu
Definition
value-function.hpp:59
aligator::QFunctionTpl::QFunctionTpl
QFunctionTpl(const long ndx, const long nu, const long ndy)
Definition
value-function.hpp:68
aligator::QFunctionTpl< Scalar >::Qyy
MatrixRef Qyy
Definition
value-function.hpp:66
aligator::QFunctionTpl< Scalar >::Qxy
MatrixRef Qxy
Definition
value-function.hpp:63
aligator::QFunctionTpl< Scalar >::Qx
VectorRef Qx
Definition
value-function.hpp:58
aligator::QFunctionTpl::QFunctionTpl
QFunctionTpl(const QFunctionTpl &qf)
Definition
value-function.hpp:88
aligator::QFunctionTpl::operator=
QFunctionTpl & operator=(QFunctionTpl &&qf)
Definition
value-function.hpp:105
aligator::QFunctionTpl::ntot
long ntot() const
Definition
value-function.hpp:51
aligator::QFunctionTpl::QFunctionTpl
QFunctionTpl(QFunctionTpl &&qf)
Definition
value-function.hpp:100
aligator::QFunctionTpl::redef_refs
static void redef_refs(QFunctionTpl &q)
Definition
value-function.hpp:147
aligator::ValueFunctionTpl::ALIGATOR_DYNAMIC_TYPEDEFS
ALIGATOR_DYNAMIC_TYPEDEFS(Scalar)
aligator::ValueFunctionTpl::operator<<
friend std::ostream & operator<<(std::ostream &oss, const ValueFunctionTpl &store)
Definition
value-function.hpp:32
aligator::ValueFunctionTpl::ValueFunctionTpl
ValueFunctionTpl(const int ndx)
Definition
value-function.hpp:24
aligator::ValueFunctionTpl< Scalar >::v_
Scalar v_
Definition
value-function.hpp:22
aligator::ValueFunctionTpl< Scalar >::Vxx_
MatrixXs Vxx_
Definition
value-function.hpp:21
aligator::ValueFunctionTpl< Scalar >::Scalar
Scalar Scalar
Definition
value-function.hpp:17
aligator::ValueFunctionTpl< Scalar >::ndx_
int ndx_
Definition
value-function.hpp:19
aligator::ValueFunctionTpl< Scalar >::Vx_
VectorXs Vx_
Definition
value-function.hpp:20
include
aligator
solvers
value-function.hpp
Generated by
1.17.0