Skip to content

Instantly share code, notes, and snippets.

@VHarisop
Last active October 19, 2021 19:12
Show Gist options
  • Save VHarisop/fdcb1176f57ce062ca91d48daa9bd4d8 to your computer and use it in GitHub Desktop.
Save VHarisop/fdcb1176f57ce062ca91d48daa9bd4d8 to your computer and use it in GitHub Desktop.
using LinearAlgebra
using OSQP
using QPSReader
using SparseArrays
# Example problem from Maros-Meszaros
problem = readqps("AUG3D.QPS", mpsformat=:fixed)
m, n = problem.ncon, problem.nvar
# QPS format only stores the lower triangular part of the matrix.
P = sparse(problem.qrows, problem.qcols, problem.qvals, n, n)
P = P + tril(P, 1)'
A = sparse(problem.arows, problem.acols, problem.avals, m, n)
# Include variable constraints in the constraint matrix.
finite_ind = @. (1:n)[!isinf(problem.lvar) | !isinf(problem.uvar)]
A_var = sparse(
1:length(finite_ind),
finite_ind,
ones(length(finite_ind)),
length(finite_ind),
n,
)
l_var = problem.lvar[finite_ind]
u_var = problem.uvar[finite_ind]
l = [problem.lcon; l_var]
u = [problem.ucon; u_var]
A = [A; A_var]
m = OSQP.Model()
OSQP.setup!(m, P=P, q=problem.c, A=A, l=l, u=u)
results = OSQP.solve!(m)
# The line below outputs something like 6.91526185055335e-310 or NaN
# But the solver log has `optimal_rho_estimate: 1.37e-01`
println(results.info.rho_estimate)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment