This forum has been archived. All content is frozen. Please use KDE Discuss instead.

QuadProg with no constraints

Tags: None
(comma "," separated)
daviddoria
Registered Member
Posts
46
Karma
0
OS

QuadProg with no constraints

Thu Jun 06, 2013 7:39 pm
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):

Code: Select all
#include <iostream>

#include "uQuadProg++.hh"

#include <Eigen/Eigen>
#include <EigenQP.h>

int main (int argc, char *const argv[])
{
  int n = 2;
  Eigen::MatrixXd G(n,n);

  Eigen::MatrixXd Ci(n,0);
  Eigen::MatrixXd Ce(n,0);

//  Eigen::MatrixXd Ci;
//  Eigen::MatrixXd Ce;

  Eigen::VectorXd g0(n);

  int zero = 0;
  Eigen::VectorXd ce(zero);
  Eigen::VectorXd ci(zero);

//  Eigen::VectorXd ce;
//  Eigen::VectorXd ci;

  Eigen::VectorXd x(n);

  double objectiveValue = QP::solve_quadprog(G, g0, Ce, ce, Ci, ci, x);
  std::cout << "objectiveValue: " << objectiveValue << std::endl;
  std::cout <<"Solution:" << std::endl <<  x << std::endl;

}
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: QuadProg with no constraints

Thu Jun 06, 2013 8:19 pm
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)
daviddoria
Registered Member
Posts
46
Karma
0
OS

Re: QuadProg with no constraints

Thu Jun 06, 2013 8:25 pm
Sorry, I assumed it was complaining from the solve_quadprog function, but this was the line it was complaining on:

Code: Select all
  int zero = 0;
  Eigen::VectorXd ce(zero); // <- this line


I couldn't do
Code: Select all
  Eigen::VectorXd ce(0);


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
jitseniesen
Registered Member
Posts
204
Karma
2

Re: QuadProg with no constraints

Fri Jun 07, 2013 8:59 am
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.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]