QLDDirect.h
Go to the documentation of this file.
1 /*
2  * Copyright 2012-2020 CNRS-UM LIRMM, CNRS-AIST JRL
3  */
4 
5 #pragma once
6 
7 // includes
8 // std
9 #include <cassert>
10 
11 // Eigen
12 #include <Eigen/Core>
13 
14 // eigen-qld
15 #include "eigen_qld_api.h"
16 
17 namespace Eigen
18 {
19 
23 class QLDDirect
24 {
25 public:
30 
34  EIGEN_QLD_API QLDDirect(int nrvar, int nreq, int nrineq, int ldq = -1, int lda = -1, bool verbose = false);
35 
37  EIGEN_QLD_API void fdOut(int fd);
39  EIGEN_QLD_API int fdOut() const;
40 
42  EIGEN_QLD_API void verbose(bool v);
44  EIGEN_QLD_API bool verbose() const;
45 
47  EIGEN_QLD_API int fail() const;
48 
76  EIGEN_QLD_API void problem(int nrvar, int nreq, int nrineq, int ldq = -1, int lda = -1);
77 
79  EIGEN_QLD_API const VectorXd & result() const;
80 
85  EIGEN_QLD_API const VectorXd & multipliers() const;
86 
110  template<typename MatObj, typename VecObj, typename MatConstr, typename VecConstr, typename VecVar>
111  bool solve(const MatrixBase<MatObj> & Q,
112  const MatrixBase<VecObj> & c,
113  const MatrixBase<MatConstr> & A,
114  const MatrixBase<VecConstr> & b,
115  const MatrixBase<VecVar> & xl,
116  const MatrixBase<VecVar> & xu,
117  int nreq,
118  bool isDecomp = false,
119  double eps = 1e-12);
120 
121 private:
122  EIGEN_QLD_API int fortran_ql(const int * m,
123  const int * me,
124  const int * mmax,
125  const int * n,
126  const int * nmax,
127  const int * mnn,
128  const double * c,
129  const double * d,
130  const double * a,
131  const double * b,
132  const double * xl,
133  const double * xu,
134  double * x,
135  double * u,
136  const double * eps,
137  const int * mode,
138  const int * iout,
139  int * ifail,
140  const int * iprint,
141  double * war,
142  int * lwar,
143  int * iwar,
144  int * liwar);
145 
146  VectorXd X_;
147  int fdOut_;
148  int verbose_;
149  int fail_;
150  VectorXd U_;
151  VectorXd WAR_;
152  VectorXi IWAR_;
153 };
154 
155 template<typename MatObj, typename VecObj, typename MatConstr, typename VecConstr, typename VecVar>
156 inline bool QLDDirect::solve(const MatrixBase<MatObj> & Q,
157  const MatrixBase<VecObj> & c,
158  const MatrixBase<MatConstr> & A,
159  const MatrixBase<VecConstr> & b,
160  const MatrixBase<VecVar> & xl,
161  const MatrixBase<VecVar> & xu,
162  int nreq,
163  bool isDecomp,
164  double eps)
165 {
166  assert(A.rows() == b.rows()); // check constraint size
167  assert(A.cols() == X_.rows());
168  assert(Q.rows() == Q.cols()); // check Q is square
169  assert(Q.cols() == X_.rows()); // check Q has the good number of variable
170  assert(c.rows() == X_.rows()); // check C size
171  assert(xl.rows() == X_.rows()); // check XL size
172  assert(xu.rows() == X_.rows()); // check XU size
173 
174  int mode = isDecomp ? 0 : 1;
175 
176  int M = int(A.rows());
177  int N = int(X_.rows());
178 
179  int MMAX = std::max(int(A.stride()), 1);
180  int NMAX = std::max(int(Q.stride()), 1);
181 
182  int NMN = M + 2 * N;
183  int LWAR = int(WAR_.rows());
184  int LIWAR = int(IWAR_.rows());
185 
186  assert(LWAR >= (3. * NMAX * NMAX) / 2. + 10. * NMAX + MMAX + M + 1.
187  && "Please call QLD::problem with the correct dimensions.");
188  assert(LIWAR >= N && "Please call QLD::problem with the correct dimensions.");
189 
190  fortran_ql(&M, &nreq, &MMAX, &N, &NMAX, &NMN, Q.derived().data(), c.derived().data(), A.derived().data(),
191  b.derived().data(), xl.derived().data(), xu.derived().data(), X_.data(), U_.data(), &eps, &mode, &fdOut_,
192  &fail_, &verbose_, WAR_.data(), &LWAR, IWAR_.data(), &LIWAR);
193 
194  return fail_ == 0;
195 }
196 
197 } // namespace Eigen
A lightweight wrapper of the ql algorithm by Professor Schittkowski. It handles the workspace memory ...
Definition: QLDDirect.h:24
EIGEN_QLD_API const VectorXd & result() const
EIGEN_QLD_API const VectorXd & multipliers() const
EIGEN_QLD_API int fdOut() const
EIGEN_QLD_API void problem(int nrvar, int nreq, int nrineq, int ldq=-1, int lda=-1)
EIGEN_QLD_API void fdOut(int fd)
EIGEN_QLD_API QLDDirect()
EIGEN_QLD_API void verbose(bool v)
bool solve(const MatrixBase< MatObj > &Q, const MatrixBase< VecObj > &c, const MatrixBase< MatConstr > &A, const MatrixBase< VecConstr > &b, const MatrixBase< VecVar > &xl, const MatrixBase< VecVar > &xu, int nreq, bool isDecomp=false, double eps=1e-12)
Definition: QLDDirect.h:156
EIGEN_QLD_API QLDDirect(int nrvar, int nreq, int nrineq, int ldq=-1, int lda=-1, bool verbose=false)
EIGEN_QLD_API bool verbose() const
EIGEN_QLD_API int fail() const
#define EIGEN_QLD_API
Definition: eigen_qld_api.h:18
Definition: QLD.h:10