-
Notifications
You must be signed in to change notification settings - Fork 26
Interface to HiGHS as an LP solver #72
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
Comments
An interface to the LP solver HiGHS was added in #74. For QPs, it's a bit trickier because HiGHS expects a compressed sparse Hessian in one of the following shapes:
At the moment, the CSC sparse format in Uno is only column-wise upper triangular. I need to investigate this further. |
@cvanaret function MyTranspose(A::SparseMatrixCSC{T,Cint}) where {T}
m, n = size(A)
nnzA = nnz(A)
A_colptr = A.colptr
A_rowval = A.rowval
A_nzval = A.nzval
# Allocate storage for the column pointers and row indices of B = Aᵀ
B_colptr = zeros(Cint, m + 1)
B_rowval = Vector{Cint}(undef, nnzA)
B_nzval = Vector{T}(undef,
8000
nnzA)
# Count the number of non-zeros for each row of A.
# It corresponds to the number of non-zeros for each column of B = Aᵀ.
for k in 1:nnzA
i = A_rowval[k]
B_colptr[i] += 1
end
# Compute the cumulative sum to determine the starting positions of rows in B_rowval
counter = 1
for col in 1:m
nnz_col = B_colptr[col]
B_colptr[col] = counter
counter += nnz_col
end
B_colptr[m + 1] = counter
# Store the row indices for each column of B = Aᵀ
for j in 1:n
for index in A_colptr[j]:(A_colptr[j + 1] - 1)
i = A_rowval[index]
# Update B_rowval for the non-zero B[j,i].
# It corresponds to the non-zero A[i,j].
pos = B_colptr[i]
B_rowval[pos] = j
B_nzval[pos] = A_nzval[index]
B_colptr[i] += 1
end
end
# Fix offsets of B_colptr to restore correct starting positions
for col in m:-1:2
B_colptr[col] = B_colptr[col - 1]
end
B_colptr[1] = 1
return SparseMatrixCSC{T,Cint}(n, m, B_colptr, B_rowval, B_nzval)
end It should not be hard to adapt in C++. |
Thanks a lot, much appreciated! This is a dumb situation when you think that the immense majority of the Hessian occurrences in HiGHS are matrix-vector products :) I think |
Yes, it's a typo. It should be |
How do I enable the tests with the LP solver? Is there a preset that will use the LP solver and not the QP? |
Add an interface to HiGHS as an LP solver. This should be relatively simple, since HiGHS is implemented in C++.
The text was updated successfully, but these errors were encountered: