quadrature_interface.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_NUMERICS_INCLUDE_CORBO_NUMERICS_QUADRATURE_INTERFACE_H_
26 #define SRC_NUMERICS_INCLUDE_CORBO_NUMERICS_QUADRATURE_INTERFACE_H_
27 
28 #include <corbo-core/factory.h>
29 #include <corbo-core/time.h>
30 #include <corbo-core/time_series.h>
31 #include <corbo-core/types.h>
33 
34 #ifdef MESSAGE_SUPPORT
35 #include <corbo-communication/messages/numerics/quadrature.pb.h>
36 #endif
37 
38 #include <functional>
39 #include <memory>
40 
41 namespace corbo {
42 
43 class QuadratureCollocationInterface : public CollocationInterface
44 {
45  public:
46  using Ptr = std::shared_ptr<QuadratureCollocationInterface>;
47  using UPtr = std::unique_ptr<QuadratureCollocationInterface>;
48 
49  using UnaryFunction = const std::function<void(const Eigen::VectorXd&, Eigen::Ref<Eigen::VectorXd>)>;
50  using BinaryFunction = const std::function<void(const Eigen::VectorXd&, const Eigen::VectorXd&, Eigen::Ref<Eigen::VectorXd>)>;
51 
55  DynamicsEvalInterface::Ptr getInstance() const override = 0;
56 
57  // useful for collocation
58  virtual bool isSupportingCompressedStatesMode() const = 0;
59  virtual bool isIntermediateControlSubjectToOptim() const = 0;
60  virtual int getNumIntermediatePoints() const = 0;
61 
62  // TODO(roesmann): PROPOSAL:
63  virtual int getNumIntermediateControls() const = 0;
64  virtual int getNumIntermediateStates() const = 0;
65 
72  // virtual void initialize(int state_dim) {}
73 
74  virtual void quadrature(const std::vector<const Eigen::VectorXd*>& x1_points, const std::vector<const Eigen::VectorXd*>& u1_points,
75  const Eigen::VectorXd& u2, const Eigen::VectorXd& x2, double dt, const SystemDynamicsInterface& system,
76  Eigen::Ref<Eigen::VectorXd> integral_value) = 0;
77 
78  // integral of f(x(t), u(t)) over the interval [0, dt]
79  virtual void quadrature(const std::vector<const Eigen::VectorXd*>& x1_points, const std::vector<const Eigen::VectorXd*>& u1_points,
80  const Eigen::VectorXd& u2, const Eigen::VectorXd& x2, double dt,
81  const BinaryFunction& fun, Eigen::Ref<Eigen::VectorXd> integral_value) = 0;
82 
83  virtual bool interpolate(const std::vector<const Eigen::VectorXd*>& x1_points, const std::vector<const Eigen::VectorXd*>& u1_points,
84  const Eigen::VectorXd& u2, const Eigen::VectorXd& x2, double t1, double dt, double dt_interp,
85  const SystemDynamicsInterface& system, bool skip_u2_x2, TimeSeries& ts_x, TimeSeries& ts_u) = 0;
86 
87  virtual void quadrature(const StateVector& x1, const InputVector& u1, const StateVector& x2, double dt, const SystemDynamicsInterface& system,
88  Eigen::Ref<Eigen::VectorXd> integral_value) = 0;
89 
90  virtual void quadrature(const StateVector& x1, const InputVector& u1, const StateVector& x2, const InputVector& u2, double dt,
91  const SystemDynamicsInterface& system, Eigen::Ref<Eigen::VectorXd> integral_value) = 0;
92 
93  virtual void quadrature(const StateVector& x1, const InputVector& u1, const StateVector& x2, double dt, const SystemDynamicsInterface& system,
94  Eigen::Ref<Eigen::VectorXd> integral_value, std::vector<Eigen::VectorXd*>& intermediate_x) = 0;
95 
96  virtual void quadrature(const StateVector& x1, const InputVector& u1, const StateVector& x2, const InputVector& u2, double dt,
97  const SystemDynamicsInterface& system, const std::vector<Eigen::VectorXd*>& intermediate_x,
98  const std::vector<Eigen::VectorXd*>& intermediate_u, Eigen::Ref<Eigen::VectorXd> integral_value,
99  Eigen::Ref<Eigen::VectorXd> interm_x_error) = 0;
100 
101  virtual void quadrature(const StateVector& x1, const InputVector& u1, const StateVector& x2, const InputVector& u2, double dt,
102  const SystemDynamicsInterface& system, const std::vector<Eigen::VectorXd*>& intermediate_u,
103  Eigen::Ref<Eigen::VectorXd> integral_value, std::vector<Eigen::VectorXd*>& intermediate_x) = 0;
104 
105  virtual void quadrature(const StateVector& x1, const InputVector& u1, const StateVector& x2, const InputVector& u2, double dt,
106  const SystemDynamicsInterface& system, Eigen::Ref<Eigen::VectorXd> integral_value,
107  std::vector<Eigen::VectorXd*>& intermediate_x, std::vector<Eigen::VectorXd*>& intermediate_u) = 0;
108 
109  // integral of f(x(t)) over the interval [0, dt]
110  virtual void quadrature(const Eigen::Ref<const Eigen::VectorXd>& x1, const Eigen::Ref<const Eigen::VectorXd>& x2, double dt,
111  const UnaryFunction& fun, Eigen::Ref<Eigen::VectorXd> integral_value) = 0;
112 
113  // integral of f(x(t)) over the interval [0, dt] with precomputed intermediate points
114  virtual void quadrature(const Eigen::Ref<const Eigen::VectorXd>& x1, const Eigen::Ref<const Eigen::VectorXd>& x2, double dt,
115  const std::vector<Eigen::VectorXd*>& intermediate_x, const UnaryFunction& fun,
116  Eigen::Ref<Eigen::VectorXd> integral_value) = 0;
117 
118  // integral of f(x(t)) over the interval [0, dt] and return intermediate points (preallocate the intermediate_points container!!!)
119  virtual void quadrature(const Eigen::Ref<const Eigen::VectorXd>& x1, const Eigen::Ref<const Eigen::VectorXd>& x2, double dt,
120  const UnaryFunction& fun, Eigen::Ref<Eigen::VectorXd> integral_value, std::vector<Eigen::VectorXd*>& intermediate_x) = 0;
121 
122  // integral of f(x(t), u(t)) over the interval [0, dt]
125  const BinaryFunction& fun, Eigen::Ref<Eigen::VectorXd> integral_value) = 0;
126 
127  // integral of f(x(t), u(t)) over the interval [0, dt] with precomputed intermediate points
130  const std::vector<Eigen::VectorXd*>& intermediate_x, const std::vector<Eigen::VectorXd*>& intermediate_u,
131  const BinaryFunction& fun, Eigen::Ref<Eigen::VectorXd> integral_value) = 0;
132 
133  // integral of f(x(t), u(t)) over the interval [0, dt] and return intermediate points (preallocate the intermediate_points container!!!)
136  const BinaryFunction& fun, Eigen::Ref<Eigen::VectorXd> integral_value, std::vector<Eigen::VectorXd*>& intermediate_x,
137  std::vector<Eigen::VectorXd*>& intermediate_u) = 0;
138 
140  std::vector<Eigen::VectorXd*>& intermediate_u) = 0;
141 
142  void computeEqualityConstraint(const StateVector& x1, const InputVector& u1, const StateVector& x2, double dt,
143  const SystemDynamicsInterface& system, Eigen::Ref<Eigen::VectorXd> error) override
144  {
145  quadrature(x1, u1, x2, dt, system, error);
146  error += x1 - x2;
147  }
148 
149  void computeEqualityConstraint(const StateVector& x1, const InputVector& u1, const StateVector& x2, const InputVector& u2, double dt,
151  {
152  quadrature(x1, u1, x2, u2, dt, system, error);
153  error += x1 - x2;
154  }
155 
157  const UnaryFunction& fun, Eigen::Ref<Eigen::VectorXd> error)
158  {
159  quadrature(x1, x2, dt, fun, error);
160  error += x1 - x2;
161  }
162 
165  const SystemDynamicsInterface& system, const Range& range, std::vector<Eigen::VectorXd>& states,
166  std::vector<Eigen::VectorXd>& controls) override = 0;
167 
168 #ifdef MESSAGE_SUPPORT
169  virtual void toMessage(messages::Quadrature& message) const {}
172  virtual void fromMessage(const messages::Quadrature& message, std::stringstream* issues = nullptr) {}
173 
175  void toMessage(corbo::messages::Collocation& message) const override { toMessage(*message.mutable_quadrature()); }
177  void fromMessage(const corbo::messages::Collocation& message, std::stringstream* issues = nullptr) override
178  {
179  if (message.has_quadrature()) fromMessage(message.quadrature());
180  }
181 
183 // void toMessage(corbo::messages::DynamicsEval& message) const override { toMessage(*message.mutable_integrator()); }
185 // void fromMessage(const corbo::messages::DynamicsEval& message, std::stringstream* issues = nullptr) override
186 //{
187 // if (message.has_integrator()) fromMessage(message.integrator());
188 //}
189 #endif
190 };
191 
192 #define FACTORY_REGISTER_QUADRATURE_COLLOCATION(type) FACTORY_REGISTER_COLLOCATION(type)
193 
194 } // namespace corbo
195 
196 #endif // SRC_NUMERICS_INCLUDE_CORBO_NUMERICS_QUADRATURE_INTERFACE_H_
corbo::SystemDynamicsInterface
Interface class for system dynamic equations.
Definition: system_dynamics_interface.h:88
factory.h
corbo::CollocationInterface::InputVector
Eigen::VectorXd InputVector
Definition: collocation_interface.h:114
corbo
Definition: communication/include/corbo-communication/utilities.h:37
corbo::QuadratureCollocationInterface::UnaryFunction
const std::function< void(const Eigen::VectorXd &, Eigen::Ref< Eigen::VectorXd >)> UnaryFunction
Definition: quadrature_interface.h:93
corbo::QuadratureCollocationInterface::interpolate
virtual bool interpolate(const std::vector< const Eigen::VectorXd * > &x1_points, const std::vector< const Eigen::VectorXd * > &u1_points, const Eigen::VectorXd &u2, const Eigen::VectorXd &x2, double t1, double dt, double dt_interp, const SystemDynamicsInterface &system, bool skip_u2_x2, TimeSeries &ts_x, TimeSeries &ts_u)=0
corbo::QuadratureCollocationInterface::isSupportingCompressedStatesMode
virtual bool isSupportingCompressedStatesMode() const =0
corbo::QuadratureCollocationInterface::~QuadratureCollocationInterface
virtual ~QuadratureCollocationInterface()
Virtual destructor.
Definition: quadrature_interface.h:97
corbo::QuadratureCollocationInterface::computeIntermediateControls
virtual bool computeIntermediateControls(const Eigen::Ref< const Eigen::VectorXd > &u1, const Eigen::Ref< const Eigen::VectorXd > &u2, std::vector< Eigen::VectorXd * > &intermediate_u)=0
corbo::QuadratureCollocationInterface::BinaryFunction
const std::function< void(const Eigen::VectorXd &, const Eigen::VectorXd &, Eigen::Ref< Eigen::VectorXd >)> BinaryFunction
Definition: quadrature_interface.h:94
time.h
time_series.h
corbo::QuadratureCollocationInterface::isIntermediateControlSubjectToOptim
virtual bool isIntermediateControlSubjectToOptim() const =0
corbo::TimeSeries
Time Series (trajectory resp. sequence of values w.r.t. time)
Definition: time_series.h:76
corbo::CollocationInterface::StateVector
Eigen::VectorXd StateVector
Definition: collocation_interface.h:113
Eigen::Ref
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:192
corbo::QuadratureCollocationInterface::getNumIntermediatePoints
virtual int getNumIntermediatePoints() const =0
collocation_interface.h
types.h
corbo::QuadratureCollocationInterface::getNumIntermediateStates
virtual int getNumIntermediateStates() const =0
corbo::QuadratureCollocationInterface::quadrature
virtual void quadrature(const std::vector< const Eigen::VectorXd * > &x1_points, const std::vector< const Eigen::VectorXd * > &u1_points, const Eigen::VectorXd &u2, const Eigen::VectorXd &x2, double dt, const SystemDynamicsInterface &system, Eigen::Ref< Eigen::VectorXd > integral_value)=0
Allocate memory for a given state dimension.
corbo::QuadratureCollocationInterface::Ptr
std::shared_ptr< QuadratureCollocationInterface > Ptr
Definition: quadrature_interface.h:90
corbo::QuadratureCollocationInterface::computeEqualityConstraint
void computeEqualityConstraint(const StateVector &x1, const InputVector &u1, const StateVector &x2, double dt, const SystemDynamicsInterface &system, Eigen::Ref< Eigen::VectorXd > error) override
Compute differentiation error (system dynamics)
Definition: quadrature_interface.h:186
corbo::QuadratureCollocationInterface::getNumIntermediateControls
virtual int getNumIntermediateControls() const =0
corbo::QuadratureCollocationInterface::getInstance
DynamicsEvalInterface::Ptr getInstance() const override=0
Return a newly created shared instance of the implemented class.
corbo::DynamicsEvalInterface::Ptr
std::shared_ptr< DynamicsEvalInterface > Ptr
Definition: dynamics_eval_interface.h:101
corbo::QuadratureCollocationInterface::UPtr
std::unique_ptr< QuadratureCollocationInterface > UPtr
Definition: quadrature_interface.h:91


control_box_rst
Author(s): Christoph Rösmann
autogenerated on Wed Mar 2 2022 00:06:08