nlp_functions.cpp
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 
26 
28 
29 namespace corbo {
30 
32  bool single_dt, const Eigen::VectorXd& x0, const std::vector<double>& dts, const DiscretizationGridInterface* grid)
33 {
34  bool dimension_modified = false;
35 
36  if (stage_preprocessor) dimension_modified |= stage_preprocessor->update(n, t, xref, uref, sref, single_dt, x0, dts, grid);
37  if (stage_cost) dimension_modified |= stage_cost->update(n, t, xref, uref, sref, single_dt, x0, stage_preprocessor, dts, grid);
38  if (final_stage_cost) dimension_modified |= final_stage_cost->update(n, t, xref, uref, sref, single_dt, x0, stage_preprocessor, dts, grid);
39  if (stage_equalities) dimension_modified |= stage_equalities->update(n, t, xref, uref, sref, single_dt, x0, stage_preprocessor, dts, grid);
40  if (stage_inequalities) dimension_modified |= stage_inequalities->update(n, t, xref, uref, sref, single_dt, x0, stage_preprocessor, dts, grid);
42  dimension_modified |= final_stage_constraints->update(n, t, xref, uref, sref, single_dt, x0, final_stage_cost, stage_preprocessor, dts, grid);
43 
44  return dimension_modified;
45 }
46 
48 {
49  if (x_lb.size() == 0)
50  x_lb.setConstant(x_dim, -CORBO_INF_DBL);
51  else if (x_lb.size() != x_dim)
52  PRINT_ERROR_NAMED("Error in lower state bounds: dimensions mismatch");
53 
54  if (x_ub.size() == 0)
55  x_ub.setConstant(x_dim, CORBO_INF_DBL);
56  else if (x_ub.size() != x_dim)
57  PRINT_ERROR_NAMED("Error in upper state bounds: dimensions mismatch");
58 
59  if (u_lb.size() == 0)
60  u_lb.setConstant(u_dim, -CORBO_INF_DBL);
61  else if (u_lb.size() != u_dim)
62  PRINT_ERROR_NAMED("Error in lower control input bounds: dimensions mismatch");
63 
64  if (u_ub.size() == 0)
65  u_ub.setConstant(u_dim, CORBO_INF_DBL);
66  else if (u_ub.size() != u_dim)
67  PRINT_ERROR_NAMED("Error in upper control input bounds: dimensions mismatch");
68 }
69 
71  ScalarVertex& u_prev_dt, const StageFunction& stage_fun, std::vector<BaseEdge::Ptr>& edges)
72 {
73  int dim = stage_fun.getNonIntegralStateTermDimension(k);
74  if (dim > 0)
75  {
77  Edge::Ptr edge =
78  std::make_shared<Edge>(dim, k, stage_fun, xk, stage_fun.isLinearNonIntegralStateTerm(k), stage_fun.isLsqFormNonIntegralStateTerm(k));
79  edges.push_back(edge);
80  }
81 
82  dim = stage_fun.getNonIntegralControlTermDimension(k);
83  if (dim > 0)
84  {
86  Edge::Ptr edge =
87  std::make_shared<Edge>(dim, k, stage_fun, uk, stage_fun.isLinearNonIntegralControlTerm(k), stage_fun.isLsqFormNonIntegralControlTerm(k));
88  edges.push_back(edge);
89  }
90 
91  dim = stage_fun.getNonIntegralDtTermDimension(k);
92  if (dim > 0)
93  {
95  Edge::Ptr edge =
96  std::make_shared<Edge>(dim, k, stage_fun, dt, stage_fun.isLinearNonIntegralDtTerm(k), stage_fun.isLsqFormNonIntegralDtTerm(k));
97  edges.push_back(edge);
98  }
99 
100  dim = stage_fun.getNonIntegralDtTermDimension(k);
101  if (dim > 0)
102  {
104  Edge::Ptr edge =
105  std::make_shared<Edge>(dim, k, stage_fun, dt, stage_fun.isLinearNonIntegralDtTerm(k), stage_fun.isLsqFormNonIntegralDtTerm(k));
106  edges.push_back(edge);
107  }
108 
109  dim = stage_fun.getNonIntegralStateControlTermDimension(k);
110  if (dim > 0)
111  {
113  Edge::Ptr edge = std::make_shared<Edge>(dim, k, stage_fun, xk, uk, false, false);
114  edges.push_back(edge);
115  }
116 
118  if (dim > 0)
119  {
121  Edge::Ptr edge = std::make_shared<Edge>(dim, k, stage_fun, uk, u_prev, u_prev_dt, false, false);
122  edges.push_back(edge);
123  }
124 
126  if (dim > 0)
127  {
129  Edge::Ptr edge = std::make_shared<Edge>(dim, k, stage_fun, xk, uk, dt, false, false);
130  edges.push_back(edge);
131  }
132 }
133 
135  ScalarVertex& u_prev_dt, std::vector<BaseEdge::Ptr>& cost_edges,
136  std::vector<BaseEdge::Ptr>& eq_edges, std::vector<BaseEdge::Ptr>& ineq_edges)
137 {
138  if (stage_cost)
139  {
140  getNonIntegralStageFunctionEdges(k, xk, uk, dt, u_prev, u_prev_dt, *stage_cost, cost_edges);
141  }
142  if (stage_equalities)
143  {
144  getNonIntegralStageFunctionEdges(k, xk, uk, dt, u_prev, u_prev_dt, *stage_equalities, eq_edges);
145  }
146  if (stage_inequalities)
147  {
148  getNonIntegralStageFunctionEdges(k, xk, uk, dt, u_prev, u_prev_dt, *stage_inequalities, ineq_edges);
149  }
150 }
151 
153  std::vector<BaseEdge::Ptr>& cost_edges, std::vector<BaseEdge::Ptr>& eq_edges,
154  std::vector<BaseEdge::Ptr>& ineq_edges)
155 {
156  if (stage_cost)
157  {
158  int dim = stage_cost->getNonIntegralControlDeviationTermDimension(n);
159  if (dim > 0)
160  {
162  Edge::Ptr edge = std::make_shared<Edge>(dim, n, *stage_cost, u_ref, u_prev, u_prev_dt, false, false);
163  cost_edges.push_back(edge);
164  }
165  }
166  if (stage_equalities)
167  {
168  int dim = stage_equalities->getNonIntegralControlDeviationTermDimension(n);
169  if (dim > 0)
170  {
172  Edge::Ptr edge = std::make_shared<Edge>(dim, n, *stage_equalities, u_ref, u_prev, u_prev_dt, false, false);
173  eq_edges.push_back(edge);
174  }
175  }
176  if (stage_inequalities)
177  {
178  int dim = stage_inequalities->getNonIntegralControlDeviationTermDimension(n);
179  if (dim > 0)
180  {
182  Edge::Ptr edge = std::make_shared<Edge>(dim, n, *stage_inequalities, u_ref, u_prev, u_prev_dt, false, false);
183  ineq_edges.push_back(edge);
184  }
185  }
186 }
187 
189 {
190  if (final_stage_cost)
191  {
192  int dim = final_stage_cost->getNonIntegralStateTermDimension(k);
193  if (dim > 0)
194  {
196  Edge::Ptr edge = std::make_shared<Edge>(dim, k, *final_stage_cost, xf, final_stage_cost->isLinearNonIntegralStateTerm(k),
197  final_stage_cost->isLsqFormNonIntegralStateTerm(k));
198  return edge;
199  }
200  }
201  return {};
202 }
203 
205 {
207  {
208  int dim = final_stage_constraints->getNonIntegralStateTermDimension(k);
209  if (dim > 0)
210  {
212  Edge::Ptr edge = std::make_shared<Edge>(dim, k, *final_stage_constraints, xf, final_stage_constraints->isLinearNonIntegralStateTerm(k),
213  final_stage_constraints->isLsqFormNonIntegralStateTerm(k));
214  return edge;
215  }
216  }
217  return {};
218 }
219 
220 } // namespace corbo
#define PRINT_ERROR_NAMED(msg)
Definition: console.h:260
Eigen::VectorXd x_lb
Definition: nlp_functions.h:46
virtual int getNonIntegralControlTermDimension(int k) const
BaseEdge::Ptr getFinalStateCostEdge(int k, VectorVertex &xf)
Eigen::VectorXd u_ub
Definition: nlp_functions.h:49
Generic interface class for discretization grids.
FinalStageConstraint::Ptr final_stage_constraints
Definition: nlp_functions.h:43
StageCost::Ptr stage_cost
Definition: nlp_functions.h:39
void checkAndInitializeBoundDimensions(int x_dim, int u_dim)
virtual int getNonIntegralDtTermDimension(int k) const
Eigen::VectorXd u_lb
Definition: nlp_functions.h:48
Vertex implementation for scalar values.
Definition: scalar_vertex.h:50
Eigen::VectorXd x_ub
Definition: nlp_functions.h:47
void getFinalControlDeviationEdges(int n, VectorVertex &u_ref, VectorVertex &u_prev, ScalarVertex &u_prev_dt, std::vector< BaseEdge::Ptr > &cost_edges, std::vector< BaseEdge::Ptr > &eq_edges, std::vector< BaseEdge::Ptr > &ineq_edges)
virtual int getNonIntegralStateControlTermDimension(int k) const
std::shared_ptr< Edge > Ptr
Definition: edge.h:151
constexpr const double CORBO_INF_DBL
Representation for infinity (double version)
FinalStageCost::Ptr final_stage_cost
Definition: nlp_functions.h:40
std::shared_ptr< BaseEdge > Ptr
virtual int getNonIntegralControlDeviationTermDimension(int k) const
void getNonIntegralStageFunctionEdges(int k, VectorVertex &xk, VectorVertex &uk, ScalarVertex &dt, VectorVertex &u_prev, ScalarVertex &u_prev_dt, const StageFunction &stage_fun, std::vector< BaseEdge::Ptr > &edges)
BaseEdge::Ptr getFinalStateConstraintEdge(int k, VectorVertex &xf)
Interface class for reference trajectories.
virtual int getNonIntegralStateTermDimension(int k) const
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
bool update(int n, double t, ReferenceTrajectoryInterface &xref, ReferenceTrajectoryInterface &uref, ReferenceTrajectoryInterface *sref, bool single_dt, const Eigen::VectorXd &x0, const std::vector< double > &dts, const DiscretizationGridInterface *grid)
StageInequalityConstraint::Ptr stage_inequalities
Definition: nlp_functions.h:42
virtual int getNonIntegralStateControlDtTermDimension(int k) const
PlainMatrixType mat * n
Definition: eigenvalues.cpp:41
StageEqualityConstraint::Ptr stage_equalities
Definition: nlp_functions.h:41
StagePreprocessor::Ptr stage_preprocessor
Definition: nlp_functions.h:44


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