9#ifndef _CLASS_LINEAR_PROBLEM_DETAILS
10#define _CLASS_LINEAR_PROBLEM_DETAILS
19namespace optimization {
20template <
typename Po
int,
typename Numeric,
bool Safe = true>
49 bezier =
new bezier_t(b.waypoints().begin(), b.waypoints().end(), b.T_min_,
64template <
typename Numeric,
typename LinearVar>
66 const std::size_t startVariableIndex,
67 const std::size_t numVariables,
68 const std::size_t
Dim) {
69 typedef Eigen::Matrix<Numeric, Eigen::Dynamic, Eigen::Dynamic>
matrix_t;
70 typename LinearVar::matrix_x_t B;
71 B = matrix_t::Zero(
Dim, numVariables *
Dim);
72 if (startVariableIndex <=
i &&
i <= startVariableIndex + numVariables - 1 &&
74 B.block(0,
Dim * (
i - startVariableIndex),
Dim,
Dim) =
var.B();
78template <
typename Po
int,
typename Numeric,
typename Bezier,
typename LinearVar>
81 const Numeric totalTime) {
82 std::vector<LinearVar>
res;
89 return new Bezier(
res.begin(),
res.end(), 0., totalTime);
92template <
typename Po
int,
typename Numeric,
bool Safe>
95 typedef Numeric num_t;
96 typedef Point point_t;
100 const std::size_t& degree =
pDef.degree;
103 const std::size_t numControlPoints =
pDef.degree + 1;
106 throw std::runtime_error(
107 "In setup_control_points; too many constraints for the considered "
111 typename problem_data_t::T_var_t& variables_ =
problemData.variables_;
116 variables_.push_back(var_t(
pDef.init_pos));
121 pDef.init_pos + (
pDef.init_vel / (num_t)degree) /
pDef.totalTime;
122 variables_.push_back(var_t(
vel));
126 point_t
acc = (
pDef.init_acc / (num_t)(degree * (degree - 1))) /
130 variables_.push_back(var_t(
acc));
136 (num_t)(degree * (degree - 1) * (degree - 2)) +
138 variables_.push_back(var_t(
jerk));
147 for (;
i + 4 < numControlPoints; ++
i)
148 variables_.push_back(var_t::X(
pDef.dim_));
153 pDef.end_pos - (
pDef.end_vel / (num_t)degree) /
pDef.totalTime;
155 point_t
acc = (
pDef.end_acc / (num_t)(degree * (degree - 1))) /
156 (
pDef.totalTime) * (
pDef.totalTime) +
161 (num_t)(degree * (degree - 1) * (degree - 2)) +
163 variables_.push_back(var_t(
jerk));
167 while (
i < numControlPoints - 3) {
168 variables_.push_back(var_t::X(
pDef.dim_));
171 variables_.push_back(var_t(
acc));
175 while (
i < numControlPoints - 2) {
176 variables_.push_back(var_t::X(
pDef.dim_));
179 variables_.push_back(var_t(
vel));
183 while (
i < numControlPoints - 1) {
184 variables_.push_back(var_t::X(
pDef.dim_));
188 variables_.push_back(var_t(
pDef.end_pos));
193 for (;
i < numControlPoints; ++
i) variables_.push_back(var_t::X(
pDef.dim_));
196 throw std::runtime_error(
"numControlPoints < numConstants");
198 if (numControlPoints != variables_.size()) {
199 throw std::runtime_error(
"numControlPoints != variables_.size()");
214template <
typename Po
int,
typename Numeric>
221 for (
typename problem_definition_t::CIT_vector_x_t
cit =
222 pDef.inequalityVectors_.begin();
228template <
typename Po
int,
typename Numeric>
229std::vector<bezier_curve<Numeric, Numeric, true, linear_variable<Numeric> > >
236 const Eigen::VectorXd&
times =
pDef.splitTimes_;
241 for (
int i = 0;
i <
times.rows(); ++
i) {
243 std::pair<bezier_t, bezier_t>
pairsplit =
253template <
typename Po
int,
typename Numeric>
257 const std::size_t&
Dim =
pData.dim_;
259 typedef typename problem_definition_t::matrix_x_t matrix_x_t;
260 typedef typename problem_definition_t::vector_x_t vector_x_t;
264 typedef typename T_bezier_t::const_iterator
CIT_bezier_t;
271 prob.ineqVector = vector_x_t::Zero(
rows);
273 if (
pDef.inequalityMatrices_.size() == 0)
return;
278 if (
pDef.inequalityMatrices_.size() !=
pDef.inequalityVectors_.size()) {
279 throw std::invalid_argument(
280 "The sizes of the inequality matrices and vectors do not match.");
282 if (
pDef.inequalityMatrices_.size() !=
beziers.size()) {
283 throw std::invalid_argument(
284 "The sizes of the inequality matrices and the bezier degree do not "
289 typename problem_definition_t::CIT_matrix_x_t
cmit =
290 pDef.inequalityMatrices_.begin();
291 typename problem_definition_t::CIT_vector_x_t
cvit =
292 pDef.inequalityVectors_.begin();
312template <
typename Po
int,
typename Numeric,
typename In>
315 const std::size_t ) {
316 typedef Eigen::Matrix<Numeric, Eigen::Dynamic, 1> vector_x_t;
322 throw std::runtime_error(
323 "This should never happen because an unsigned int cannot go negative "
324 "without underflowing.");
340 for (
unsigned int i = 0;
i <
newDeg + 1; ++
i) {
342 for (;
j < std::min(
deg1,
i) + 1; ++
j) {
359 static_cast<int>(b));
364 static_cast<int>(b));
369 static_cast<int>(b));
class allowing to create a Bezier curve of dimension 1 <= n <= 3.
struct to define constraints on start / end velocities and acceleration on a curve
utils for defining optimization problems
storage for variable points of the form p_i = B_i x + c_i
constraint_flag operator&(constraint_flag a, constraint_flag b)
Definition details.h:362
constraint_flag operator|(constraint_flag a, constraint_flag b)
Definition details.h:357
constraint_flag operator^(constraint_flag a, constraint_flag b)
Definition details.h:367
long compute_num_ineq_control_points(const problem_definition< Point, Numeric > &pDef, const problem_data< Point, Numeric > &pData)
Definition details.h:215
constraint_flag
Definition definitions.h:20
@ INIT_ACC
Definition definitions.h:23
@ NONE
Definition definitions.h:30
@ INIT_JERK
Definition definitions.h:24
@ END_POS
Definition definitions.h:25
@ END_ACC
Definition definitions.h:27
@ END_JERK
Definition definitions.h:28
@ INIT_POS
Definition definitions.h:21
@ INIT_VEL
Definition definitions.h:22
@ END_VEL
Definition definitions.h:26
Bezier * compute_linear_control_points(const problem_data< Point, Numeric > &pData, const std::vector< LinearVar > &linearVars, const Numeric totalTime)
Definition details.h:79
problem_data< Point, Numeric, Safe > setup_control_points(const problem_definition< Point, Numeric > &pDef)
Definition details.h:93
quadratic_variable< Numeric > bezier_product(In PointsBegin1, In PointsEnd1, In PointsBegin2, In PointsEnd2, const std::size_t)
Definition details.h:313
void initInequalityMatrix(const problem_definition< Point, Numeric > &pDef, problem_data< Point, Numeric > &pData, quadratic_problem< Point, Numeric > &prob)
Definition details.h:254
std::vector< bezier_curve< Numeric, Numeric, true, linear_variable< Numeric > > > split(const problem_definition< Point, Numeric > &pDef, problem_data< Point, Numeric > &pData)
Definition details.h:230
constraint_flag & operator&=(constraint_flag &a, constraint_flag b)
Definition details.h:376
constraint_flag & operator|=(constraint_flag &a, constraint_flag b)
Definition details.h:372
constraint_flag & operator^=(constraint_flag &a, constraint_flag b)
Definition details.h:380
std::size_t num_active_constraints(const constraint_flag &flag)
Definition details.h:54
LinearVar fill_with_zeros(const LinearVar &var, const std::size_t i, const std::size_t startVariableIndex, const std::size_t numVariables, const std::size_t Dim)
Definition details.h:65
constraint_flag operator~(constraint_flag a)
Definition details.h:353
Definition bernstein.h:20
bezier_curve< double, double, true, pointX_t > bezier_t
Definition fwd.h:107
bool isApprox(const T a, const T b, const T eps=1e-6)
Definition curve_abc.h:25
linear_variable< double, true > linear_variable_t
Definition fwd.h:108
Definition bezier_curve.h:31
std::vector< point_t, Eigen::aligned_allocator< point_t > > t_point_t
Definition bezier_curve.h:38
bool isApprox(const bezier_curve_t &other, const Numeric prec=Eigen::NumTraits< Numeric >::dummy_precision()) const
isApprox check if other and *this are approximately equals. Only two curves of the same class can be ...
Definition bezier_curve.h:166
Definition linear_variable.h:26
std::size_t startVariableIndex
Definition details.h:36
bezier_curve< Numeric, Numeric, true, linear_variable< Numeric > > bezier_t
Definition details.h:30
std::size_t numControlPoints
Definition details.h:34
std::size_t numVariables
Definition details.h:33
linear_variable< Numeric > var_t
Definition details.h:27
std::vector< var_t > variables_
Definition details.h:32
std::vector< var_t > T_var_t
Definition details.h:28
problem_data(const std::size_t dim)
Definition details.h:22
bezier_t * bezier
Definition details.h:38
problem_data(const problem_data &other)
Definition details.h:41
const std::size_t dim_
Definition details.h:39
std::size_t numStateConstraints
Definition details.h:37
~problem_data()
Definition details.h:23
Definition definitions.h:41
Definition definitions.h:34
Definition quadratic_variable.h:25