aligator  0.6.1
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
linear-function.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace aligator {
9template <typename Scalar> struct LinearFunctionTpl : StageFunctionTpl<Scalar> {
10 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
12 using Base = StageFunctionTpl<Scalar>;
13 using Data = StageFunctionDataTpl<Scalar>;
14
15 MatrixXs A_;
16 MatrixXs B_;
17 MatrixXs C_;
18 VectorXs d_;
19
20 LinearFunctionTpl(const int ndx, const int nu, const int ndx2, const int nr)
21 : Base(ndx, nu, ndx2, nr), A_(nr, ndx), B_(nr, nu), C_(nr, ndx2), d_(nr) {
22 A_.setZero();
23 B_.setZero();
24 C_.setZero();
25 d_.setZero();
26 }
27
28 LinearFunctionTpl(const ConstMatrixRef A, const ConstMatrixRef B,
29 const ConstMatrixRef C, const ConstVectorRef d)
30 : Base((int)A.cols(), (int)B.cols(), (int)C.cols(), (int)d.rows()), A_(A),
31 B_(B), C_(C), d_(d) {
32 assert((A_.rows() == d_.rows()) && (B_.rows() == d_.rows()) &&
33 (C_.rows() == d_.rows()) && "Number of rows not consistent.");
34 }
35
37 LinearFunctionTpl(const ConstMatrixRef A, const ConstMatrixRef B,
38 const ConstVectorRef d)
39 : LinearFunctionTpl(A, B, MatrixXs::Zero(A.rows(), A.cols()), d) {}
40
41 void evaluate(const ConstVectorRef &x, const ConstVectorRef &u,
42 const ConstVectorRef &y, Data &data) const {
43 data.value_ = A_ * x + B_ * u + C_ * y + d_;
44 }
45
51 void computeJacobians(const ConstVectorRef &, const ConstVectorRef &,
52 const ConstVectorRef &, Data &data) const {
53 data.Jx_ = A_;
54 data.Ju_ = B_;
55 data.Jy_ = C_;
56 }
57
60 virtual shared_ptr<Data> createData() const {
61 auto data =
62 std::make_shared<Data>(this->ndx1, this->nu, this->ndx2, this->nr);
63 data->Jx_ = A_;
64 data->Ju_ = B_;
65 data->Jy_ = C_;
66 return data;
67 }
68};
69
70} // namespace aligator
Base definitions for ternary functions.
Main package namespace.
void computeJacobians(const ConstVectorRef &, const ConstVectorRef &, const ConstVectorRef &, Data &data) const
Compute Jacobians of this function.
LinearFunctionTpl(const int ndx, const int nu, const int ndx2, const int nr)
LinearFunctionTpl(const ConstMatrixRef A, const ConstMatrixRef B, const ConstVectorRef d)
Constructor where is assumed.
void evaluate(const ConstVectorRef &x, const ConstVectorRef &u, const ConstVectorRef &y, Data &data) const
Evaluate the function.
LinearFunctionTpl(const ConstMatrixRef A, const ConstMatrixRef B, const ConstMatrixRef C, const ConstVectorRef d)
virtual shared_ptr< Data > createData() const
Instantiate a Data object.
Class representing ternary functions .
const int ndx2
Next state dimension.
const int ndx1
Current state dimension.
const int nr
Function codimension.