qpmad
Eigen-based C++ QP solver.
input_parser.h
Go to the documentation of this file.
1 /**
2  @file
3  @author Alexander Sherikov
4 
5  @copyright 2017 Alexander Sherikov. Licensed under the Apache License,
6  Version 2.0. (see LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
7 
8  @brief
9 */
10 
11 #pragma once
12 
13 namespace qpmad
14 {
16  {
17  protected:
22 
23 
24  protected:
26  {
27  primal_size_ = 0;
28  h_size_ = 0;
31  }
32 
33 
34  template <class t_MatrixType, class t_VectorType>
35  void parseObjective(const t_MatrixType &H, const t_VectorType &h)
36  {
37  primal_size_ = H.rows();
38  h_size_ = h.rows();
39 
40  QPMAD_UTILS_PERSISTENT_ASSERT(primal_size_ > 0, "Hessian must not be empty.");
41  QPMAD_UTILS_PERSISTENT_ASSERT(primal_size_ == H.cols(), "Hessian must be square.");
43  ((primal_size_ == h_size_) && (1 == h.cols())) || (0 == h_size_), "Wrong size of h.");
44  }
45 
46 
47  template <class t_VectorTypelb, class t_VectorTypeub>
48  void parseSimpleBounds(const t_VectorTypelb &lb, const t_VectorTypeub &ub)
49  {
50  num_simple_bounds_ = lb.rows();
51 
54  "Vector of lower simple bounds has wrong size.");
56  ub.rows() == num_simple_bounds_, "Vector of upper simple bounds has wrong size1.");
57 
59  ((num_simple_bounds_ > 0) && (1 == lb.cols())) || (1 == lb.cols()),
60  "Vector of lower simple bounds has wrong size.");
62  ((num_simple_bounds_ > 0) && (1 == ub.cols())) || (1 == ub.cols()),
63  "Vector of upper simple bounds has wrong size2.");
64  }
65 
66 
67  template <class t_MatrixTypeA, class t_VectorTypelb, class t_VectorTypeub>
68  void parseGeneralConstraints(const t_MatrixTypeA &A, const t_VectorTypelb &lb, const t_VectorTypeub &ub)
69  {
70  num_general_constraints_ = A.rows();
71 
73  (A.cols() == primal_size_) || ((0 == num_general_constraints_) && (0 == A.cols())),
74  "Matrix of general constraints has wrong size.");
75 
77  lb.rows() == num_general_constraints_,
78  "Vector of lower bounds of general constraints has wrong size.");
80  ub.rows() == num_general_constraints_,
81  "Vector of upper bounds of general constraints has wrong size.");
82 
84  ((num_general_constraints_ > 0) && (1 == lb.cols())) || (0 == lb.rows()),
85  "Vector of lower bounds of general constraints has wrong size.");
87  ((num_general_constraints_ > 0) && (1 == ub.cols())) || (0 == ub.rows()),
88  "Vector of upper bounds of general constraints has wrong size.");
89  }
90  };
91 } // namespace qpmad
void parseObjective(const t_MatrixType &H, const t_VectorType &h)
Definition: input_parser.h:35
MatrixIndex num_simple_bounds_
Definition: input_parser.h:20
#define QPMAD_UTILS_PERSISTENT_ASSERT(condition, message)
EIGEN_DEFAULT_DENSE_INDEX_TYPE MatrixIndex
Definition: common.h:32
MatrixIndex h_size_
Definition: input_parser.h:19
MatrixIndex num_general_constraints_
Definition: input_parser.h:21
MatrixIndex primal_size_
Definition: input_parser.h:18
void parseGeneralConstraints(const t_MatrixTypeA &A, const t_VectorTypelb &lb, const t_VectorTypeub &ub)
Definition: input_parser.h:68
void parseSimpleBounds(const t_VectorTypelb &lb, const t_VectorTypeub &ub)
Definition: input_parser.h:48