Registered Member
|
I am trying to solve a problem with no constraints using https://github.com/wingsit/QP. I tried creating an "empty" constraint matrix/vector like:
Eigen::MatrixXd Ci; Eigen::MatrixXd Ce; Eigen::VectorXd ce; Eigen::VectorXd ci; as well as tried to make them zero rows: int zero = 0; Eigen::MatrixXd Ci(n,zero); Eigen::MatrixXd Ce(n,zero); Eigen::VectorXd ce(zero); Eigen::VectorXd ci(zero); but in the first case I get terminate called after throwing an instance of 'std::logic_error' what(): The ublas::matrix CE is incompatible (incorrect number of rows 0 , expecting 2) and in the second I get: QPDemo: /home/doriad/src/QP/eigen/Eigen/src/Core/Matrix.h:235: Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::Matrix(Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::Index) [with _Scalar = double; int _Rows = -1; int _Cols = 1; int _Options = 0; int _MaxRows = -1; int _MaxCols = 1; Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::Index = long int]: Assertion `dim > 0' failed. Is there a different way to create these empty matrices? Thanks, David Here is the full demo code (note that a problem is not setup, I am just trying to get the structure correct):
|
Moderator
|
What is the call stack in the second case. Initializing a matrix like this:
Eigen::MatrixXd Ce(n,0); is perfectly fine (unless you have a very old Eigen copy). Also, if there is no constraint, what's the point of using a QP solver? A linear solver is sufficient. Same if you have only equalities. You can use PartialPivLU to compute the kernel and reduce the dimensionality of your problem (http://en.wikipedia.org/wiki/Null_space ... _equations) |
Registered Member
|
Sorry, I assumed it was complaining from the solve_quadprog function, but this was the line it was complaining on:
I couldn't do
because of the compiler error "call of ofverloaded Matrix(int) is ambiguous". Also, I need a non-linear solver if I have a non-linear objective function right? e.g. min x^T x David |
Registered Member
|
If I comment out all the lines from QP, your program runs fine. So it looks like the error is in the QP library. I saw it is three years old, so it may well be incompatible with the current version of Eigen.
The general form of an unconstrained quadratic minimization problem is min x^T A x + b^T x. To solve this, note that the gradient of the objective function is 2 A x + b. At the minimum, the gradient vanishes, so 2 A x + b = 0 or x = - (1/2) A^(-1) b. In other words, you only need a linear solver. If your matrix A is not positive definite, then the minimization problem does not have a uniqie solution. |
Registered users: Bing [Bot], Google [Bot], Sogou [Bot]