aligator  0.6.1
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
lagrangian.hpp
Go to the documentation of this file.
1#pragma once
2
6
7namespace aligator {
8
10template <typename Scalar> struct LagrangianDerivatives {
12 using TrajOptProblem = TrajOptProblemTpl<Scalar>;
13 using TrajOptData = TrajOptDataTpl<Scalar>;
14 using BlkView = BlkMatrix<ConstVectorRef, -1, 1>;
15
16 static void compute(const TrajOptProblem &problem, const TrajOptData &pd,
17 const std::vector<VectorXs> &lams,
18 const std::vector<VectorXs> &vs,
19 std::vector<VectorXs> &Lxs, std::vector<VectorXs> &Lus) {
20 using ConstraintStack = ConstraintStackTpl<Scalar>;
21 using StageFunctionData = StageFunctionDataTpl<Scalar>;
22 using CostData = CostDataAbstractTpl<Scalar>;
23 using StageModel = StageModelTpl<Scalar>;
24 using StageData = StageDataTpl<Scalar>;
25 const std::size_t nsteps = problem.numSteps();
26
27 ZoneScopedN("LagrangianDerivatives::compute");
29
30 math::setZero(Lxs);
31 math::setZero(Lus);
32
33 // initial condition
34 const StageFunctionData &init_cond = *pd.init_data;
35 Lxs[0].noalias() = init_cond.Jx_.transpose() * lams[0];
36
37 for (std::size_t i = 0; i < nsteps; i++) {
38 const StageModel &sm = *problem.stages_[i];
39 const StageData &sd = *pd.stage_data[i];
40 const ConstraintStack &stack = sm.constraints_;
41 const StageFunctionData &dd = *sd.dynamics_data;
42 Lxs[i].noalias() +=
43 sd.cost_data->Lx_ + dd.Jx_.transpose() * lams[i + 1]; // [1] eqn. 24c
44 Lus[i].noalias() =
45 sd.cost_data->Lu_ + dd.Ju_.transpose() * lams[i + 1]; // [1] eqn. 24b
46
47 BlkView v_(vs[i], stack.dims());
48 for (std::size_t j = 0; j < stack.size(); j++) {
49 const StageFunctionData &cd = *sd.constraint_data[j];
50 Lxs[i].noalias() += cd.Jx_.transpose() * v_[j]; // [1] eqn. 24c
51 Lus[i].noalias() += cd.Ju_.transpose() * v_[j]; // [1] eqn. 24b
52 }
53
54 Lxs[i + 1].noalias() = dd.Jy_.transpose() * lams[i + 1]; // [1] eqn. 24b
55 }
56
57 // terminal node
58 {
59 const CostData &cdterm = *pd.term_cost_data;
60 Lxs[nsteps] += cdterm.Lx_;
61 const ConstraintStack &stack = problem.term_cstrs_;
62 BlkView vN(vs[nsteps], stack.dims());
63 for (std::size_t j = 0; j < stack.size(); j++) {
64 const StageFunctionData &cd = *pd.term_cstr_data[j];
65 Lxs[nsteps].noalias() += cd.Jx_.transpose() * vN[j];
66 }
67 }
68 }
69};
70
71} // namespace aligator
Block matrix class, with a fixed-size number of row and column blocks.
#define ALIGATOR_NOMALLOC_SCOPED
void setZero(std::vector< T > &mats)
Definition math.hpp:70
Main package namespace.
Compute the derivatives of the problem Lagrangian.
BlkMatrix< ConstVectorRef, -1, 1 > BlkView
static void compute(const TrajOptProblem &problem, const TrajOptData &pd, const std::vector< VectorXs > &lams, const std::vector< VectorXs > &vs, std::vector< VectorXs > &Lxs, std::vector< VectorXs > &Lus)
TrajOptProblemTpl< Scalar > TrajOptProblem