8000 Interface to HiGHS as an LP solver · Issue #72 · cvanaret/Uno · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Closed
cvanaret opened this issue Nov 4, 2024 · 6 comments
Closed

Interface to HiGHS as an LP solver #72

cvanaret opened this issue Nov 4, 2024 · 6 comments
Assignees
Labels

Comments

@cvanaret
Copy link
Owner
cvanaret commented Nov 4, 2024

Add an interface to HiGHS as an LP solver. This should be relatively simple, since HiGHS is implemented in C++.

@cvanaret cvanaret self-assigned this Nov 4, 2024
@cvanaret
Copy link
Owner Author
cvanaret commented Nov 5, 2024

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:

  • column-wise lower triangular;
  • row-wise upper triangular.

At the moment, the CSC sparse format in Uno is only column-wise upper triangular. I need to investigate this further.

@amontoison
Copy link
Contributor
amontoison commented Nov 6, 2024

@cvanaret
I did this Julia code a few months ago to get the sparse CSC format of A' based on the CSC format of A.
It could be what you need:

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++.

@cvanaret
Copy link
Owner Author
cvanaret commented Nov 6, 2024

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 B_colptr = Vector{T)(undef, nnzA) should be B_nzval = Vector{T)(undef, nnzA)?

@amontoison
Copy link
Contributor

Yes, it's a typo. It should be B_nzval = Vector{T}(undef, nnzA).
I just wanted the sparsity pattern of A' in my Julia application (coloring of Hessian).

@odow
Copy link
Contributor
odow commented Nov 7, 2024

How do I enable the tests with the LP solver? Is there a preset that will use the LP solver and not the QP?

@cvanaret
Copy link
Owner Author

We now have CI (#77) for testing the filterslp preset (#88), a trust-region filter Sequential Linear Programming (SLP) method that solves subproblem LPs with HiGHS.

@cvanaret cvanaret changed the title Interface to HiGHS as an LP/QP solver Interface to HiGHS as an LP solver Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants
0