randomProblems.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 #include <jrl-qp/test/problems.h>
8 
9 namespace jrl::qp::test
10 {
11 // Description of the characteristics of a least-square problem
12 // min. 0.5 ||A x - b||^2
13 // s.t. E x = f
14 // l <= C x <= u
15 // x^- <= x <= x^+
17 {
18  int nVar_; // Number of variables
19  int nObj_; // Row size of A
20  int nEq_ = 0; // Row size of E
21  int nIneq_ = 0; // Row size of C
22  int rankObj_ = 0; // Rank of A
23  int nSharedRank_ =
24  0; // rk(A)+nAct - rk([A;C_act]) where C_act is the matrix of active constraints and nAct its row size
25  int nStrongActIneq_ = 0; // Number of strongly active general inequality constraints
26  int nWeakActIneq_ = 0; // Number of weakly active general inequality constraints
27  int nStrongActBounds_ = 0; // Number of strongly active bounds
28  int nWeakActBounds_ = 0; // Number of weakly active bounds
29  bool bounds_ = false; // whether to use bounds or not
30  bool doubleSidedIneq_ = false; // whether to use double-sided general constraints or not
31  bool strictlyFeasible_ =
32  false; // If true, the set of feasible points must not be reduced to a singleton (except if nEq == nVar_)
33 
34  ProblemCharacteristics(int nVar, int nObj) : nVar_(nVar), nObj_(nObj), rankObj_(nObj) {}
35  ProblemCharacteristics(int nVar, int nObj, int nEq, int nIneq)
36  : nVar_(nVar), nObj_(nObj), nEq_(nEq), nIneq_(nIneq), rankObj_(nObj)
37  {
38  }
40  int nObj,
41  int nEq,
42  int nIneq,
43  int rankObj,
44  int nSharedRank,
45  int nStrongActIneq,
46  int nWeakActIneq,
47  int nStrongActBounds,
48  int nWeakActBounds,
49  int bounds,
50  bool doubleSidedIneq,
51  bool strictlyFeasible)
52  : nVar_(nVar), nObj_(nObj), nEq_(nEq), nIneq_(nIneq), rankObj_(rankObj), nSharedRank_(nSharedRank),
53  nStrongActIneq_(nStrongActIneq), nWeakActIneq_(nWeakActIneq), nStrongActBounds_(nStrongActBounds),
54  nWeakActBounds_(nWeakActBounds), bounds_(bounds), doubleSidedIneq_(doubleSidedIneq),
55  strictlyFeasible_(strictlyFeasible)
56  {
57  }
58 
60  {
61  nEq_ = n;
62  return *this;
63  }
65  {
66  nIneq_ = n;
67  return *this;
68  }
70  {
71  rankObj_ = n;
72  return *this;
73  }
75  {
76  nSharedRank_ = n;
77  return *this;
78  }
80  {
81  nStrongActIneq_ = n;
82  return *this;
83  }
85  {
86  nWeakActIneq_ = n;
87  return *this;
88  }
90  {
91  nStrongActBounds_ = n;
92  return *this;
93  }
95  {
96  nWeakActBounds_ = n;
97  return *this;
98  }
99  ProblemCharacteristics & bounds(bool b = true)
100  {
101  bounds_ = b;
102  return *this;
103  }
105  {
106  doubleSidedIneq_ = b;
107  return *this;
108  }
110  {
111  strictlyFeasible_ = b;
112  return *this;
113  }
114 
115  void check() const;
116 };
117 
119 {
120  Eigen::VectorXd x;
121  Eigen::VectorXd lambdaEq;
122  Eigen::VectorXd lambdaIneq;
123  Eigen::VectorXd lambdaBnd;
124  bool doubleSidedIneq = false;
125  bool bounds = false;
126 
127  struct KKT
128  {
129  Eigen::VectorXd dL;
130  Eigen::VectorXd eqViol;
131  Eigen::VectorXd ineqViol;
132  Eigen::VectorXd bndViol;
133  Eigen::VectorXd ineqCompl;
134  Eigen::VectorXd bndCompl;
135  };
136 
137  KKT computeKKTValues() const;
138  bool checkKKT() const;
139  bool testKKT() const;
140  bool dispKKT() const;
141 
142  void disp() const;
143 };
144 
146 
147 } // namespace jrl::qp::test
jrl::qp::test::ProblemCharacteristics::ProblemCharacteristics
ProblemCharacteristics(int nVar, int nObj, int nEq, int nIneq, int rankObj, int nSharedRank, int nStrongActIneq, int nWeakActIneq, int nStrongActBounds, int nWeakActBounds, int bounds, bool doubleSidedIneq, bool strictlyFeasible)
Definition: randomProblems.h:39
jrl::qp::test::ProblemCharacteristics::nWeakActBounds
ProblemCharacteristics & nWeakActBounds(int n)
Definition: randomProblems.h:94
jrl::qp::test::ProblemCharacteristics::rankObj
ProblemCharacteristics & rankObj(int n)
Definition: randomProblems.h:69
jrl::qp::test::testKKT
bool JRLQP_DLLAPI testKKT(const VectorConstRef &x, const VectorConstRef &u, const MatrixConstRef &G, const VectorConstRef &a, const MatrixConstRef &C, const VectorConstRef &bl, const VectorConstRef &bu, const VectorConstRef &xl, const VectorConstRef &xu, bool transposedC=false, double tau_p=1e-6, double tau_d=1e-6)
Definition: kkt.cpp:87
jrl::qp::test::randomProblem
RandomLeastSquare JRLQP_DLLAPI randomProblem(const ProblemCharacteristics &characs)
Definition: randomProblems.cpp:15
jrl::qp::test::RandomLeastSquare::KKT::bndCompl
Eigen::VectorXd bndCompl
Definition: randomProblems.h:134
jrl::qp::test::LeastSquareProblem
Definition: problems.h:63
jrl::qp::test::ProblemCharacteristics::nObj_
int nObj_
Definition: randomProblems.h:19
jrl::qp::test
Definition: BoxAndSingleConstraintSolver.h:36
jrl::qp::test::RandomLeastSquare
Definition: randomProblems.h:118
jrl::qp::test::ProblemCharacteristics::nStrongActIneq
ProblemCharacteristics & nStrongActIneq(int n)
Definition: randomProblems.h:79
jrl::qp::test::ProblemCharacteristics::bounds
ProblemCharacteristics & bounds(bool b=true)
Definition: randomProblems.h:99
jrl::qp::test::RandomLeastSquare::KKT::ineqViol
Eigen::VectorXd ineqViol
Definition: randomProblems.h:131
jrl::qp::test::RandomLeastSquare::KKT
Definition: randomProblems.h:127
jrl::qp::test::ProblemCharacteristics::nEq
ProblemCharacteristics & nEq(int n)
Definition: randomProblems.h:59
jrl::qp::test::RandomLeastSquare::KKT::eqViol
Eigen::VectorXd eqViol
Definition: randomProblems.h:130
problems.h
jrl::qp::test::ProblemCharacteristics::ProblemCharacteristics
ProblemCharacteristics(int nVar, int nObj, int nEq, int nIneq)
Definition: randomProblems.h:35
jrl::qp::test::RandomLeastSquare::KKT::dL
Eigen::VectorXd dL
Definition: randomProblems.h:129
jrl::qp::test::RandomLeastSquare::KKT::bndViol
Eigen::VectorXd bndViol
Definition: randomProblems.h:132
jrl::qp::test::RandomLeastSquare::KKT::ineqCompl
Eigen::VectorXd ineqCompl
Definition: randomProblems.h:133
jrl::qp::test::RandomLeastSquare::lambdaBnd
Eigen::VectorXd lambdaBnd
Definition: randomProblems.h:123
jrl::qp::test::ProblemCharacteristics::nSharedRank
ProblemCharacteristics & nSharedRank(int n)
Definition: randomProblems.h:74
jrl::qp::test::ProblemCharacteristics::nStrongActBounds
ProblemCharacteristics & nStrongActBounds(int n)
Definition: randomProblems.h:89
jrl::qp::test::RandomLeastSquare::x
Eigen::VectorXd x
Definition: randomProblems.h:120
jrl::qp::test::ProblemCharacteristics::nIneq
ProblemCharacteristics & nIneq(int n)
Definition: randomProblems.h:64
jrl::qp::test::ProblemCharacteristics::nVar_
int nVar_
Definition: randomProblems.h:18
jrl::qp::test::disp
void disp(const std::string &name, const MatrixBase< Derived > &M)
Definition: randomProblems.cpp:268
jrl::qp::test::RandomLeastSquare::lambdaIneq
Eigen::VectorXd lambdaIneq
Definition: randomProblems.h:122
JRLQP_DLLAPI
#define JRLQP_DLLAPI
Definition: api.h:35
jrl::qp::test::RandomLeastSquare::lambdaEq
Eigen::VectorXd lambdaEq
Definition: randomProblems.h:121
jrl::qp::test::ProblemCharacteristics::strictlyFeasible
ProblemCharacteristics & strictlyFeasible(bool b=true)
Definition: randomProblems.h:109
jrl::qp::test::ProblemCharacteristics::ProblemCharacteristics
ProblemCharacteristics(int nVar, int nObj)
Definition: randomProblems.h:34
jrl::qp::test::ProblemCharacteristics
Definition: randomProblems.h:16
jrl::qp::test::ProblemCharacteristics::doubleSidedIneq
ProblemCharacteristics & doubleSidedIneq(bool b=true)
Definition: randomProblems.h:104
jrl::qp::test::ProblemCharacteristics::nWeakActIneq
ProblemCharacteristics & nWeakActIneq(int n)
Definition: randomProblems.h:84
api.h