aligator 0.19.0
A versatile and efficient C++ library for real-time constrained trajectory optimization.
Loading...
Searching...
No Matches
workspace.hpp
Go to the documentation of this file.
1
4#pragma once
5
9
11
12#include <fmt/format.h>
13
14namespace aligator {
15
16template <typename Scalar>
18 std::vector<xyz::polymorphic<ConstraintSetTpl<Scalar>>> components;
19 for (size_t i = 0; i < constraints.size(); i++) {
20 components.push_back(constraints.sets[i]);
21 }
22 return ConstraintSetProductTpl<Scalar>{components, constraints.dims()};
23}
24
29template <typename Scalar> struct WorkspaceTpl : WorkspaceBaseTpl<Scalar> {
33 using VecBool = Eigen::Matrix<bool, Eigen::Dynamic, 1>;
36 using BlkJacobianType = BlkMatrix<MatrixXs, -1, 2>; // jacobians
37
38 using Base::dyn_slacks;
39 using Base::nsteps;
41
43
44 gar::LqrProblemTpl<Scalar> lqr_problem; //< Linear-quadratic subproblem
45
48 std::vector<VectorXs> Lxs; //< State gradients
49 std::vector<VectorXs> Lus; //< Control gradients
50 std::vector<VectorXs> Lvs; //< Path multiplier gradients
52
55 using Base::trial_us;
56 using Base::trial_xs;
57 std::vector<VectorXs> trial_vs;
58 std::vector<VectorXs> trial_lams;
60
63 // used for linesearch
64 std::vector<VectorXs> lams_plus;
65 std::vector<VectorXs> vs_plus;
66 std::vector<VectorXs> vs_pdal;
68
70 std::vector<VectorXs> shifted_constraints;
73 std::vector<VectorXs> cstr_lx_corr;
74 std::vector<VectorXs> cstr_lu_corr;
77 std::vector<BlkJacobianType> cstr_proj_jacs;
79 std::vector<VecBool> active_constraints;
81 std::vector<ConstraintSetProduct> cstr_product_sets;
82
85 std::vector<VectorXs> dxs;
86 std::vector<VectorXs> dus;
87 std::vector<VectorXs> dvs;
88 std::vector<VectorXs> dlams;
90
93 std::vector<VectorXs> prev_xs;
94 std::vector<VectorXs> prev_us;
95 std::vector<VectorXs> prev_vs;
97
103 std::vector<VectorXs> stage_infeasibilities;
109 Scalar inner_criterion = 0.;
110
112 : Base() {}
113 explicit WorkspaceTpl(const allocator_type &alloc)
114 : Base()
115 , lqr_problem(alloc) {}
117 const allocator_type &alloc = {});
118
119 WorkspaceTpl(const WorkspaceTpl &) = delete;
121
124
126 shared_ptr<StageDataTpl<Scalar>> data);
127
128 allocator_type get_allocator() const { return lqr_problem.get_allocator(); }
129
130 friend std::ostream &operator<<(std::ostream &oss, const WorkspaceTpl &self) {
131 return oss << fmt::format("{}", self);
132 }
133};
134
135#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
136extern template struct WorkspaceTpl<context::Scalar>;
137#endif
138} // namespace aligator
139
140template <typename Scalar>
141struct fmt::formatter<aligator::WorkspaceTpl<Scalar>> {
142 constexpr auto parse(format_parse_context &ctx) const
143 -> decltype(ctx.begin()) {
144 return ctx.end();
145 }
146
147 auto format(const aligator::WorkspaceTpl<Scalar> &ws,
148 format_context &ctx) const -> decltype(ctx.out()) {
149 return fmt::format_to(ctx.out(),
150 "Workspace {{"
151 "\n nsteps: \t{:d}"
152 "\n n_multipliers:\t{:d}"
153 "\n}}",
154 ws.nsteps, ws.dlams.size());
155 }
156};
Block matrix class, with a fixed or dynamic-size number of row and column blocks.
A convenience subclass of std::pmr::polymorphic_allocator for bytes.
Definition allocator.hpp:16
Main package namespace.
auto getConstraintProductSet(const ConstraintStackTpl< Scalar > &constraints)
Definition workspace.hpp:17
Cartesian product of multiple constraint sets. This class makes computing multipliers and Jacobian ma...
Convenience class to manage a stack of constraints.
const std::vector< long > & dims() const
Get the set of dimensions for each constraint in the stack.
std::size_t size() const
std::vector< PolySet > sets
Data struct for stage models StageModelTpl.
A stage in the control problem.
Trajectory optimization problem.
std::size_t nsteps
Number of steps in the problem.
std::vector< VectorXs > trial_us
TrajOptDataTpl< Scalar > problem_data
Problem data.
std::vector< VectorXs > dyn_slacks
Dynamical infeasibility gaps.
std::vector< VectorXs > trial_xs
Workspace for solver SolverProxDDP.
Definition workspace.hpp:29
ALIGATOR_DYNAMIC_TYPEDEFS(Scalar)
WorkspaceTpl(const WorkspaceTpl &)=delete
VectorXs state_dual_infeas
Dual infeasibility in the states for each stage of the problem.
WorkspaceTpl(const allocator_type &alloc)
std::vector< VectorXs > dlams
Definition workspace.hpp:88
std::vector< VectorXs > dvs
Definition workspace.hpp:87
allocator_type get_allocator() const
ConstraintSetProductTpl< Scalar > ConstraintSetProduct
Definition workspace.hpp:35
std::vector< VectorXs > trial_lams
Definition workspace.hpp:58
std::vector< VectorXs > vs_plus
Definition workspace.hpp:65
std::vector< VecBool > active_constraints
Masks for active constraint sets.
Definition workspace.hpp:79
std::vector< VectorXs > dxs
Definition workspace.hpp:85
std::vector< VectorXs > lams_plus
Definition workspace.hpp:64
std::vector< VectorXs > Lus
Definition workspace.hpp:49
std::vector< VectorXs > shifted_constraints
Shifted constraints the projection operators should be applied to.
Definition workspace.hpp:70
WorkspaceTpl(const TrajOptProblemTpl< Scalar > &problem, const allocator_type &alloc={})
std::vector< VectorXs > Lxs
Definition workspace.hpp:48
std::vector< VectorXs > Lvs
Definition workspace.hpp:50
Eigen::Matrix< bool, Eigen::Dynamic, 1 > VecBool
Definition workspace.hpp:33
VectorXs stage_cstr_violations
Constraint violation measures for each stage and constraint.
std::vector< BlkJacobianType > cstr_proj_jacs
Definition workspace.hpp:77
gar::LqrProblemTpl< Scalar > lqr_problem
Definition workspace.hpp:44
std::vector< VectorXs > vs_pdal
Definition workspace.hpp:66
std::vector< VectorXs > prev_vs
Definition workspace.hpp:95
std::vector< VectorXs > prev_us
Definition workspace.hpp:94
std::vector< VectorXs > dus
Definition workspace.hpp:86
VectorXs stage_inner_crits
Subproblem termination criterion for each stage.
Definition workspace.hpp:99
StageModelTpl< Scalar > StageModel
Definition workspace.hpp:31
std::vector< VectorXs > stage_infeasibilities
Stagewise infeasibilities.
WorkspaceTpl & operator=(const WorkspaceTpl &)=delete
WorkspaceTpl & operator=(WorkspaceTpl &&)=default
::aligator::polymorphic_allocator allocator_type
Definition workspace.hpp:42
WorkspaceBaseTpl< Scalar > Base
Definition workspace.hpp:32
friend std::ostream & operator<<(std::ostream &oss, const WorkspaceTpl &self)
std::vector< ConstraintSetProduct > cstr_product_sets
Cartesian products of the constraint sets of each stage.
Definition workspace.hpp:81
BlkMatrix< MatrixXs, -1, 2 > BlkJacobianType
Definition workspace.hpp:36
gar::LqrKnotTpl< Scalar > KnotType
Definition workspace.hpp:34
std::vector< VectorXs > cstr_lu_corr
Definition workspace.hpp:74
Scalar inner_criterion
Overall subproblem termination criterion.
std::vector< VectorXs > prev_xs
Definition workspace.hpp:93
std::vector< VectorXs > cstr_lx_corr
Definition workspace.hpp:73
WorkspaceTpl(WorkspaceTpl &&)=default
void cycleAppend(const TrajOptProblemTpl< Scalar > &problem, shared_ptr< StageDataTpl< Scalar > > data)
VectorXs control_dual_infeas
Dual infeasibility in the controls for each stage of the problem.
std::vector< VectorXs > trial_vs
Definition workspace.hpp:57
Struct describing a stage of a constrained LQ problem.