l1_stab_edges.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * Software License Agreement
4  *
5  * Copyright (c) 2020,
6  * TU Dortmund - Institute of Control Theory and Systems Engineering.
7  * All rights reserved.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  *
22  * Authors: Christoph Rösmann
23  *********************************************************************/
24 
25 #ifndef SRC_OPTIMAL_CONTROL_INCLUDE_CORBO_OPTIMAL_CONTROL_STRUCTURED_OCP_EDGES_L1_STAB_EDGES_H_
26 #define SRC_OPTIMAL_CONTROL_INCLUDE_CORBO_OPTIMAL_CONTROL_STRUCTURED_OCP_EDGES_L1_STAB_EDGES_H_
27 
29 
35 
36 #include <functional>
37 #include <memory>
38 
39 namespace corbo {
40 
41 class L1StabCostEdge : public Edge<VectorVertex>
42 {
43  public:
44  using Ptr = std::shared_ptr<L1StabCostEdge>;
45  using UPtr = std::unique_ptr<L1StabCostEdge>;
46 
47  explicit L1StabCostEdge(VectorVertex& s, double delta_pow_k) : Edge<VectorVertex>(s)
48  {
49  _s = static_cast<const VectorVertex*>(_vertices[0]);
50  _delta_pow_k = delta_pow_k;
51  }
52 
53  // implements interface method
54  int getDimension() const override { return 1; }
55  // implement in child class:
56  bool isLinear() const override { return false; }
57 
58  // bool providesJacobian() const override { return false; }
59 
60  bool isLeastSquaresForm() const override { return false; }
61 
63  {
64  assert(_s);
65  values[0] = _delta_pow_k * _s->values().sum();
66  }
67 
68  private:
69  const VectorVertex* _s = nullptr;
70 
71  double _delta_pow_k = 1.6;
72 
73  public:
75 };
76 
77 class L1StabInequalityEdge : public Edge<VectorVertex, VectorVertex>
78 {
79  public:
80  using Ptr = std::shared_ptr<L1StabInequalityEdge>;
81  using UPtr = std::unique_ptr<L1StabInequalityEdge>;
82 
83  explicit L1StabInequalityEdge(VectorVertex& x, VectorVertex& s, const Eigen::VectorXd* xref) : Edge<VectorVertex, VectorVertex>(x, s)
84  {
85  _x = static_cast<const VectorVertex*>(_vertices[0]);
86  _s = static_cast<const VectorVertex*>(_vertices[1]);
87  _xref = xref;
88  assert(_x);
89  _dim_x = _x->getDimension();
90  }
91 
92  // implements interface method
93  int getDimension() const override
94  {
95  return 2 * _dim_x; // TODO(roesmann) or unfixed?
96  }
97  // implement in child class:
98  bool isLinear() const override { return false; }
99 
100  // bool providesJacobian() const override { return false; }
101 
102  bool isLeastSquaresForm() const override { return false; }
103 
105  {
106  assert(_s && _x);
107  assert(_s->getDimension() == _dim_x);
108  if (_xref)
109  {
110  assert(_xref->size() == _dim_x);
111  values.head(_dim_x).noalias() = _x->values() - *_xref - _s->values();
112  values.tail(_dim_x).noalias() = *_xref - _x->values() - _s->values();
113  }
114  else
115  {
116  values.head(_dim_x).noalias() = _x->values() - _s->values();
117  values.tail(_dim_x).noalias() = -_x->values() - _s->values();
118  }
119  }
120 
121  private:
122  const VectorVertex* _x = nullptr;
123  const VectorVertex* _s = nullptr;
124  const Eigen::VectorXd* _xref = nullptr;
125 
126  int _dim_x = 0;
127 
128  public:
130 };
131 
132 } // namespace corbo
133 
134 #endif // SRC_OPTIMAL_CONTROL_INCLUDE_CORBO_OPTIMAL_CONTROL_STRUCTURED_OCP_EDGES_L1_STAB_EDGES_H_
int getDimension() const override
Get dimension of the edge (dimension of the cost-function/constraint value vector) ...
Definition: l1_stab_edges.h:54
L1StabCostEdge(VectorVertex &s, double delta_pow_k)
Definition: l1_stab_edges.h:47
Scalar * x
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW
Definition: Memory.h:690
std::shared_ptr< L1StabInequalityEdge > Ptr
Definition: l1_stab_edges.h:80
int getDimension() const override
Get dimension of the edge (dimension of the cost-function/constraint value vector) ...
Definition: l1_stab_edges.h:93
std::unique_ptr< L1StabInequalityEdge > UPtr
Definition: l1_stab_edges.h:81
bool isLinear() const override
Return true if the edge is linear (and hence its Hessian is always zero)
Definition: l1_stab_edges.h:98
const VectorVertex * _s
Definition: l1_stab_edges.h:69
std::unique_ptr< L1StabCostEdge > UPtr
Definition: l1_stab_edges.h:45
bool isLinear() const override
Return true if the edge is linear (and hence its Hessian is always zero)
Definition: l1_stab_edges.h:56
bool isLeastSquaresForm() const override
Defines if the edge is formulated as Least-Squares form.
Definition: l1_stab_edges.h:60
RealScalar s
int getDimension() const override
Return number of elements/values/components stored in this vertex.
Definition: vector_vertex.h:96
bool isLeastSquaresForm() const override
Defines if the edge is formulated as Least-Squares form.
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:192
void computeValues(Eigen::Ref< Eigen::VectorXd > values) override
Compute function values.
Definition: l1_stab_edges.h:62
L1StabInequalityEdge(VectorVertex &x, VectorVertex &s, const Eigen::VectorXd *xref)
Definition: l1_stab_edges.h:83
Templated base edge class that stores an arbitary number of value.
Definition: edge.h:148
Vertex implementation that stores an Eigen::VectorXd (dynamic dimension)
Definition: vector_vertex.h:51
std::shared_ptr< L1StabCostEdge > Ptr
Definition: l1_stab_edges.h:44
const Eigen::VectorXd & values() const
Read-access to the underlying value vector.
const VertexContainer _vertices
Vertex container.
Definition: edge.h:214
void computeValues(Eigen::Ref< Eigen::VectorXd > values) override
Compute function values.


control_box_rst
Author(s): Christoph Rösmann
autogenerated on Mon Feb 28 2022 22:06:57