problems.h
Go to the documentation of this file.
1 /* Copyright 2020 CNRS-AIST JRL */
2 
3 #pragma once
4 
5 #include <Eigen/Core>
6 #include <jrl-qp/api.h>
7 
8 namespace jrl::qp::test
9 {
11 
17 {
18  FeasibilityConstraints() = default;
21  FeasibilityConstraints & operator=(const FeasibilityConstraints &) = default;
22  FeasibilityConstraints & operator=(FeasibilityConstraints &&) = default;
24  bool wellFormed(bool noEq = false) const;
25 
26  Eigen::MatrixXd C;
27  Eigen::VectorXd l;
28  Eigen::VectorXd u;
29  Eigen::VectorXd xl;
30  Eigen::VectorXd xu;
31  bool transposedMat = false;
32 };
33 
42 {
49 
50  bool wellFormed() const;
51 
52  Eigen::MatrixXd E;
53  Eigen::VectorXd f;
54 };
55 
62 template<bool Separated = false>
64 : public std::conditional_t<Separated, SeparatedFeasibilityConstraints, FeasibilityConstraints>
65 {
66  bool wellFormed() const;
67 
68  using Base = std::conditional_t<Separated, SeparatedFeasibilityConstraints, FeasibilityConstraints>;
69  Eigen::MatrixXd A;
70  Eigen::VectorXd b;
71 };
72 
79 template<bool Separated = false>
80 struct QPProblem : public std::conditional_t<Separated, SeparatedFeasibilityConstraints, FeasibilityConstraints>
81 {
82  QPProblem() = default;
83  QPProblem(const QPProblem &) = default;
84  QPProblem(QPProblem &&) = default;
85  QPProblem & operator=(const QPProblem & qp) = default;
86  QPProblem & operator=(QPProblem && qp) = default;
87  QPProblem(const QPProblem<!Separated> & qp);
88  template<bool LSSeparated>
90  template<bool LSSeparated>
93  bool wellFormed() const;
94 
95  using Base = std::conditional_t<Separated, SeparatedFeasibilityConstraints, FeasibilityConstraints>;
96  Eigen::MatrixXd G;
97  Eigen::VectorXd a;
98  double objCst = 0;
99 };
100 
101 template<bool Separated>
103 {
104  bool b1 = Base::wellFormed();
105  bool b2 = this->transposedMat ? (A.cols() == this->C.rows()) : (A.cols() == this->C.cols());
106  bool b3 = A.rows() == b.size();
107  return b1 && b2 && b3;
108 }
109 
110 template<bool Separated>
111 template<bool LSSeparated>
113 : Base(ls), G(ls.A.transpose() * ls.A), a(-ls.A.transpose() * ls.b)
114 {
115 }
116 
117 template<bool Separated>
118 inline QPProblem<Separated>::QPProblem(const QPProblem<!Separated> & qp) : Base(qp), G(qp.G), a(qp.a)
119 {
120 }
121 
122 template<bool Separated>
123 template<bool LSSeparated>
125 {
126  new(this) QPProblem<Separated>(ls);
127  return *this;
128 }
129 
130 template<bool Separated>
132 {
133  new(this) QPProblem<Separated>(qp);
134  return *this;
135 }
136 
137 template<bool Separated>
139 {
140  bool b1 = Base::wellFormed();
141  bool b2 = this->transposedMat ? (G.cols() == this->C.rows()) : (G.cols() == this->C.cols());
142  bool b3 = G.cols() == a.size();
143  bool b4 = G.cols() == this->C.cols();
144  return b1 && b2 && b3 && b4;
145 }
146 } // namespace jrl::qp::test
jrl::qp::test::FeasibilityConstraints::u
Eigen::VectorXd u
Definition: problems.h:28
jrl::qp::test::SeparatedFeasibilityConstraints
struct JRLQP_DLLAPI SeparatedFeasibilityConstraints
Definition: problems.h:10
jrl::qp::test::QPProblem::wellFormed
bool wellFormed() const
Definition: problems.h:138
jrl::qp::test::LeastSquareProblem::wellFormed
bool wellFormed() const
Definition: problems.h:102
jrl::qp::test::LeastSquareProblem
Definition: problems.h:63
jrl::qp::test::QPProblem::a
Eigen::VectorXd a
Definition: problems.h:97
jrl::qp::test
Definition: BoxAndSingleConstraintSolver.h:36
jrl::qp::test::SeparatedFeasibilityConstraints::f
Eigen::VectorXd f
Definition: problems.h:53
jrl::qp::test::SeparatedFeasibilityConstraints::E
Eigen::MatrixXd E
Definition: problems.h:52
jrl::qp::test::QPProblem::Base
std::conditional_t< Separated, SeparatedFeasibilityConstraints, FeasibilityConstraints > Base
Definition: problems.h:95
jrl::qp::test::FeasibilityConstraints::l
Eigen::VectorXd l
Definition: problems.h:27
jrl::qp::test::QPProblem
Definition: problems.h:80
jrl::qp::test::SeparatedFeasibilityConstraints
Definition: problems.h:41
jrl::qp::test::FeasibilityConstraints::xl
Eigen::VectorXd xl
Definition: problems.h:29
jrl::qp::test::LeastSquareProblem::b
Eigen::VectorXd b
Definition: problems.h:70
jrl::qp::test::QPProblem::QPProblem
QPProblem()=default
jrl::qp::test::LeastSquareProblem< true >::Base
std::conditional_t< Separated, SeparatedFeasibilityConstraints, FeasibilityConstraints > Base
Definition: problems.h:68
JRLQP_DLLAPI
#define JRLQP_DLLAPI
Definition: api.h:35
jrl::qp::test::QPProblem::operator=
QPProblem & operator=(const QPProblem &qp)=default
jrl::qp::test::FeasibilityConstraints::xu
Eigen::VectorXd xu
Definition: problems.h:30
jrl::qp::test::LeastSquareProblem::A
Eigen::MatrixXd A
Definition: problems.h:69
jrl::qp::test::FeasibilityConstraints
Definition: problems.h:16
jrl::qp::test::QPProblem::objCst
double objCst
Definition: problems.h:98
jrl::qp::test::QPProblem::G
Eigen::MatrixXd G
Definition: problems.h:96
jrl::qp::test::FeasibilityConstraints::C
Eigen::MatrixXd C
Definition: problems.h:26
api.h