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 
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
#define JRLQP_DLLAPI
Definition: api.h:35
Definition: BoxAndSingleConstraintSolver.h:37
RandomLeastSquare JRLQP_DLLAPI randomProblem(const ProblemCharacteristics &characs)
Definition: randomProblems.cpp:15
void disp(const std::string &name, const MatrixBase< Derived > &M)
Definition: randomProblems.cpp:268
Definition: problems.h:65
Definition: randomProblems.h:17
ProblemCharacteristics & nStrongActIneq(int n)
Definition: randomProblems.h:79
int nObj_
Definition: randomProblems.h:19
ProblemCharacteristics & strictlyFeasible(bool b=true)
Definition: randomProblems.h:109
ProblemCharacteristics & rankObj(int n)
Definition: randomProblems.h:69
int nVar_
Definition: randomProblems.h:18
ProblemCharacteristics & nWeakActBounds(int n)
Definition: randomProblems.h:94
ProblemCharacteristics(int nVar, int nObj)
Definition: randomProblems.h:34
ProblemCharacteristics & nSharedRank(int n)
Definition: randomProblems.h:74
ProblemCharacteristics & bounds(bool b=true)
Definition: randomProblems.h:99
ProblemCharacteristics & nEq(int n)
Definition: randomProblems.h:59
ProblemCharacteristics(int nVar, int nObj, int nEq, int nIneq)
Definition: randomProblems.h:35
ProblemCharacteristics & nIneq(int n)
Definition: randomProblems.h:64
ProblemCharacteristics & nWeakActIneq(int n)
Definition: randomProblems.h:84
ProblemCharacteristics & doubleSidedIneq(bool b=true)
Definition: randomProblems.h:104
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
ProblemCharacteristics & nStrongActBounds(int n)
Definition: randomProblems.h:89
Definition: randomProblems.h:128
Eigen::VectorXd bndCompl
Definition: randomProblems.h:134
Eigen::VectorXd ineqCompl
Definition: randomProblems.h:133
Eigen::VectorXd ineqViol
Definition: randomProblems.h:131
Eigen::VectorXd eqViol
Definition: randomProblems.h:130
Eigen::VectorXd bndViol
Definition: randomProblems.h:132
Eigen::VectorXd dL
Definition: randomProblems.h:129
Definition: randomProblems.h:119
Eigen::VectorXd x
Definition: randomProblems.h:120
Eigen::VectorXd lambdaEq
Definition: randomProblems.h:121
Eigen::VectorXd lambdaIneq
Definition: randomProblems.h:122
Eigen::VectorXd lambdaBnd
Definition: randomProblems.h:123