Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I'm using osqp-eigen v0.7.0, wondering if Hessian Matrix is supporting only symmetric matrix, rather than upper triangular matrix. #152

Open
ZhiDaoYongYuan opened this issue Dec 7, 2023 · 2 comments

Comments

@ZhiDaoYongYuan
Copy link

My partial code as follows:

// symmetric matrix
for (int i = 0; i < n - 1; ++i)
{
    hessian.insert(i, i + 1) = 1.0;
    hessian.insert(i + 1, i) = 1.0;
}
// upper triangular matrix
for (int i = 0; i < n - 1; ++i)
{
    hessian.insert(i, i + 1) = 2.0;
}

When I used the symmetric matrix, I got the true solution(I guess). Instead, solver return
status: problem non convex
while using upper triangular matrix.

@traversaro
Copy link
Member

Strictly speaking according to the documentation the hessian matrix is required to be symmetric, but looking in the code actually only an upper triangular view is used (see

// set the hessian matrix
// osqp 0.6.0 required only the upper triangular part of the hessian matrix
Derived hessianMatrixUpperTriangular = hessianMatrix.template triangularView<Eigen::Upper>();
if (!OsqpEigen::SparseMatrixHelper::createOsqpSparseMatrix(hessianMatrixUpperTriangular,
m_data->P))
), even if this behavior is not part of the public docs so it could change without notice.

Are you sure that in your example you are actually passing the two matrices in the two cases? Can you provide a full example in the two cases, instead an incomplete snippet of code? Thanks!

@S-Dafarra
Copy link
Collaborator

Hi @ZhiDaoYongYuan, did you fill the diagonal as well? If $n=2$, the corresponding matrix would be

$$\begin{bmatrix} 0 & 2 \\\ 2 & 0 \end{bmatrix}$$

whose eigenvalues are +2 and -2. Hence the matrix would not be positive semidefinite. So I would say that the error message is correct. I am not sure why it did not print it in the first case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants