aligator
0.19.0
A versatile and efficient C++ library for real-time constrained trajectory optimization.
Toggle main menu visibility
Loading...
Searching...
No Matches
expose-costs.cpp
Go to the documentation of this file.
1
3
#include "
aligator/python/costs.hpp
"
4
#include "
aligator/python/visitors.hpp
"
5
6
#include "
aligator/modelling/costs/quad-costs.hpp
"
7
#include "
aligator/modelling/costs/constant-cost.hpp
"
8
#include "
aligator/python/fwd.hpp
"
9
10
namespace
aligator
{
11
namespace
python
{
12
using
context::ConstMatrixRef;
13
using
context::ConstVectorRef;
14
using
context::CostAbstract
;
15
using
context::CostData
;
16
using
context::Manifold
;
17
using
context::MatrixXs;
18
using
context::Scalar
;
19
using
context::VectorXs;
20
using
QuadraticCost
=
QuadraticCostTpl<Scalar>
;
21
using
PolyCost
= xyz::polymorphic<CostAbstract>;
22
23
struct
CostDataWrapper
:
CostData
, bp::wrapper<CostData> {
24
using
CostData::CostData;
25
};
26
27
PolymorphicVisitor<PolyCost>
poly_visitor
;
28
29
void
exposeQuadCost
() {
30
31
bp::class_<ConstantCostTpl<Scalar>, bp::bases<CostAbstract>>(
32
"ConstantCost"
,
"A constant cost term."
,
33
bp::init<xyz::polymorphic<Manifold>, int,
Scalar
>(
34
bp::args(
"self"
,
"space"
,
"nu"
,
"value"
)))
35
.def_readwrite(
"value"
, &
ConstantCostTpl<Scalar>::value_
)
36
.def(
CopyableVisitor
<
ConstantCostTpl<Scalar>
>())
37
.def(
poly_visitor
);
38
39
bp::class_<QuadraticCost, bp::bases<CostAbstract>>(
40
"QuadraticCost"
,
41
"Quadratic cost in both state and control - only for Euclidean spaces."
,
42
bp::no_init)
43
.def(bp::init<ConstMatrixRef, ConstMatrixRef, ConstMatrixRef,
44
ConstVectorRef, ConstVectorRef>(
45
bp::args(
"self"
,
"w_x"
,
"w_u"
,
"w_cross"
,
"interp_x"
,
"interp_u"
)))
46
.def(bp::init<ConstMatrixRef, ConstMatrixRef, ConstVectorRef,
47
ConstVectorRef>(
48
bp::args(
"self"
,
"w_x"
,
"w_u"
,
"interp_x"
,
"interp_u"
)))
49
.def(bp::init<ConstMatrixRef, ConstMatrixRef>(
50
"Constructor with just weights (no cross-term)."
,
51
bp::args(
"self"
,
"w_x"
,
"w_u"
)))
52
.def(bp::init<ConstMatrixRef, ConstMatrixRef, ConstMatrixRef>(
53
"Constructor with just weights (with cross-term)."
,
54
bp::args(
"self"
,
"w_x"
,
"w_u"
,
"w_cross"
)))
55
.def_readwrite(
"w_x"
, &
QuadraticCost::Wxx_
,
"Weights on the state."
)
56
.def_readwrite(
"w_u"
, &
QuadraticCost::Wuu_
,
"Weights on the control."
)
57
.def_readwrite(
"interp_x"
, &
QuadraticCost::interp_x
)
58
.def_readwrite(
"interp_u"
, &
QuadraticCost::interp_u
)
59
.add_property(
"has_cross_term"
, &
QuadraticCost::hasCrossTerm
,
60
"Whether there is a cross term."
)
61
.add_property(
"weights_cross"
, &
QuadraticCost::getCrossWeights
,
62
&
QuadraticCost::setCrossWeight
,
"Cross term weight."
)
63
.def(
CopyableVisitor
<
QuadraticCostTpl<Scalar>
>())
64
.def(
poly_visitor
);
65
66
bp::class_<QuadraticCost::Data, bp::bases<CostData>>(
67
"QuadraticCostData"
,
"Quadratic cost data."
, bp::no_init);
68
}
69
71
void
exposeComposites
();
72
74
void
exposeContactMap
();
75
void
exposeCentroidalFunctions
();
77
void
exposeCostStack
();
78
79
void
exposeCostAbstract
() {
80
register_polymorphic_to_python<PolyCost>
();
81
bp::class_<PyCostFunction, boost::noncopyable>(
82
"CostAbstract"
,
"Base class for cost functions."
, bp::no_init)
83
.def(bp::init<
const
xyz::polymorphic<Manifold> &,
const
int
>(
84
bp::args(
"self"
,
"space"
,
"nu"
)))
85
.def(
"evaluate"
, bp::pure_virtual(&
CostAbstract::evaluate
),
86
bp::args(
"self"
,
"x"
,
"u"
,
"data"
),
"Evaluate the cost function."
)
87
.def(
"computeGradients"
,
88
bp::pure_virtual(&
CostAbstract::computeGradients
),
89
bp::args(
"self"
,
"x"
,
"u"
,
"data"
),
90
"Compute the cost function gradients."
)
91
.def(
"computeHessians"
, bp::pure_virtual(&
CostAbstract::computeHessians
),
92
bp::args(
"self"
,
"x"
,
"u"
,
"data"
),
93
"Compute the cost function hessians."
)
94
.def_readonly(
"space"
, &
CostAbstract::space
)
95
.add_property(
"nx"
, &
CostAbstract::nx
)
96
.add_property(
"ndx"
, &
CostAbstract::ndx
)
97
.add_property(
"nu"
, &
CostAbstract::nu
)
98
.def(
CreateDataPolymorphicPythonVisitor<CostAbstract, PyCostFunction>
())
99
.def(
poly_visitor
);
100
101
bp::register_ptr_to_python<shared_ptr<CostData>>();
102
bp::class_<CostDataWrapper, boost::noncopyable>(
103
"CostData"
,
"Cost function data struct."
, bp::no_init)
104
.def(bp::init<const int, const int>(bp::args(
"self"
,
"ndx"
,
"nu"
)))
105
.def(bp::init<const CostAbstract &>(bp::args(
"self"
,
"cost"
)))
106
.def_readwrite(
"value"
, &
CostData::value_
)
107
.def_readwrite(
"grad"
, &
CostData::grad_
)
108
.def_readwrite(
"hess"
, &
CostData::hess_
)
109
.add_property(
110
"Lx"
, bp::make_getter(&
CostData::Lx_
,
111
bp::return_value_policy<bp::return_by_value>()))
112
.add_property(
113
"Lu"
, bp::make_getter(&
CostData::Lu_
,
114
bp::return_value_policy<bp::return_by_value>()))
115
.add_property(
"Lxx"
, bp::make_getter(
116
&
CostData::Lxx_
,
117
bp::return_value_policy<bp::return_by_value>()))
118
.add_property(
"Lxu"
, bp::make_getter(
119
&
CostData::Lxu_
,
120
bp::return_value_policy<bp::return_by_value>()))
121
.add_property(
"Lux"
, bp::make_getter(
122
&
CostData::Lux_
,
123
bp::return_value_policy<bp::return_by_value>()))
124
.add_property(
"Luu"
, bp::make_getter(
125
&
CostData::Luu_
,
126
bp::return_value_policy<bp::return_by_value>()));
127
128
StdVectorPythonVisitor<std::vector<PolyCost>,
true
>::expose(
129
"StdVec_CostAbstract"
,
130
eigenpy::details::overload_base_get_item_for_std_vector<
131
std::vector<PolyCost>>{});
132
StdVectorPythonVisitor<std::vector<shared_ptr<CostData>>,
true
>::expose(
133
"StdVec_CostData"
);
134
}
135
136
void
exposeCostOps
();
137
138
void
exposeCosts
() {
139
exposeCostAbstract
();
140
exposeCostStack
();
141
exposeQuadCost
();
142
exposeComposites
();
143
exposeCostOps
();
144
exposeContactMap
();
145
exposeCentroidalFunctions
();
146
}
147
148
}
// namespace python
149
}
// namespace aligator
fwd.hpp
constant-cost.hpp
costs.hpp
Define cost functions.
aligator::context::CostAbstract
CostAbstractTpl< Scalar > CostAbstract
Definition
context.hpp:25
aligator::context::Manifold
ManifoldAbstractTpl< Scalar > Manifold
Definition
context.hpp:14
aligator::context::Scalar
double Scalar
Definition
context.hpp:9
aligator::context::CostData
CostDataAbstractTpl< Scalar > CostData
Definition
context.hpp:26
aligator::python
The Python bindings.
Definition
blk-matrix.hpp:7
aligator::python::poly_visitor
PolymorphicVisitor< PolyCost > poly_visitor
Definition
expose-costs.cpp:27
aligator::python::exposeContactMap
void exposeContactMap()
Centroidal cost functions.
Definition
expose-centroidal.cpp:28
aligator::python::exposeCostOps
void exposeCostOps()
Definition
expose-cost-ops.cpp:15
aligator::python::exposeCentroidalFunctions
void exposeCentroidalFunctions()
Definition
expose-centroidal.cpp:49
aligator::python::exposeQuadCost
void exposeQuadCost()
Definition
expose-costs.cpp:29
aligator::python::exposeComposites
void exposeComposites()
Composite cost functions.
Definition
expose-composite-costs.cpp:22
aligator::python::exposeCostAbstract
void exposeCostAbstract()
Definition
expose-costs.cpp:79
aligator::python::exposeCosts
void exposeCosts()
Expose cost functions.
Definition
expose-costs.cpp:138
aligator::python::register_polymorphic_to_python
void register_polymorphic_to_python()
Expose a polymorphic value type, e.g. xyz::polymorphic<T, A>.
Definition
polymorphic.hpp:23
aligator::python::PolyCost
xyz::polymorphic< CostAbstract > PolyCost
Definition
expose-costs.cpp:21
aligator::python::exposeCostStack
void exposeCostStack()
fwd-declare exposeCostStack()
Definition
expose-cost-stack.cpp:34
aligator::python::QuadraticCost
QuadraticCostTpl< Scalar > QuadraticCost
Definition
expose-costs.cpp:20
aligator
Main package namespace.
Definition
action-model-wrap.hpp:14
quad-costs.hpp
aligator::ConstantCostTpl
Constant cost.
Definition
constant-cost.hpp:8
aligator::ConstantCostTpl::value_
Scalar value_
Definition
constant-cost.hpp:15
aligator::CostAbstractTpl< Scalar >::space
xyz::polymorphic< Manifold > space
Definition
cost-abstract.hpp:20
aligator::CostAbstractTpl< Scalar >::evaluate
virtual void evaluate(const ConstVectorRef &x, const ConstVectorRef &u, CostData &data) const
aligator::CostAbstractTpl< Scalar >::nx
int nx() const
Definition
cost-abstract.hpp:24
aligator::CostAbstractTpl< Scalar >::nu
int nu
Definition
cost-abstract.hpp:22
aligator::CostAbstractTpl< Scalar >::ndx
int ndx() const
Definition
cost-abstract.hpp:25
aligator::CostAbstractTpl< Scalar >::computeGradients
virtual void computeGradients(const ConstVectorRef &x, const ConstVectorRef &u, CostData &data) const
aligator::CostAbstractTpl< Scalar >::computeHessians
virtual void computeHessians(const ConstVectorRef &x, const ConstVectorRef &u, CostData &data) const
aligator::CostDataAbstractTpl< Scalar >::Lx_
VectorRef Lx_
Definition
cost-abstract.hpp:82
aligator::CostDataAbstractTpl< Scalar >::Lux_
MatrixRef Lux_
Definition
cost-abstract.hpp:90
aligator::CostDataAbstractTpl< Scalar >::grad_
VectorXs grad_
Definition
cost-abstract.hpp:78
aligator::CostDataAbstractTpl< Scalar >::Luu_
MatrixRef Luu_
Definition
cost-abstract.hpp:92
aligator::CostDataAbstractTpl< Scalar >::Lxx_
MatrixRef Lxx_
Definition
cost-abstract.hpp:86
aligator::CostDataAbstractTpl< Scalar >::hess_
MatrixXs hess_
Definition
cost-abstract.hpp:79
aligator::CostDataAbstractTpl< Scalar >::value_
Scalar value_
Definition
cost-abstract.hpp:77
aligator::CostDataAbstractTpl< Scalar >::Lxu_
MatrixRef Lxu_
Definition
cost-abstract.hpp:88
aligator::CostDataAbstractTpl< Scalar >::Lu_
VectorRef Lu_
Definition
cost-abstract.hpp:84
aligator::QuadraticCostTpl
Euclidean quadratic cost.
Definition
quad-costs.hpp:13
aligator::QuadraticCostTpl< Scalar >::Wuu_
MatrixXs Wuu_
Definition
quad-costs.hpp:27
aligator::QuadraticCostTpl< Scalar >::interp_x
VectorXs interp_x
Definition
quad-costs.hpp:35
aligator::QuadraticCostTpl< Scalar >::interp_u
VectorXs interp_u
Definition
quad-costs.hpp:37
aligator::QuadraticCostTpl< Scalar >::getCrossWeights
ConstMatrixRef getCrossWeights() const
Definition
quad-costs.hpp:115
aligator::QuadraticCostTpl< Scalar >::hasCrossTerm
bool hasCrossTerm() const
Definition
quad-costs.hpp:123
aligator::QuadraticCostTpl< Scalar >::setCrossWeight
void setCrossWeight(const ConstMatrixRef &w)
Definition
quad-costs.hpp:116
aligator::QuadraticCostTpl< Scalar >::Wxx_
MatrixXs Wxx_
Definition
quad-costs.hpp:25
aligator::python::CopyableVisitor
Definition
visitors.hpp:38
aligator::python::CostDataWrapper
Definition
expose-costs.cpp:23
aligator::python::CreateDataPolymorphicPythonVisitor
Definition
visitors.hpp:30
aligator::python::PolymorphicVisitor
Definition
polymorphic.hpp:30
visitors.hpp
bindings
python
src
expose-costs.cpp
Generated by
1.17.0