jump-dev / HiGHS.jl

A Julia interface to the HiGHS solver
https://highs.dev
MIT License
108 stars 15 forks source link

Quadratic programming #127

Closed maxchendt closed 2 years ago

maxchendt commented 2 years ago

How to solve a QP?

using JuMP
using HiGHS

V = [146    187 145
     187    854 104
     145    104 289] ./10000
E = [62 146 128 ] ./1000

w = [1.0; 1; 1]
EV = Model(HiGHS.Optimizer)
@variable(EV, x[1:3] >= 0)
@constraint(EV, w * x .== 1)
@objective(EV, Min, x' *V * x)

print(EV)

the following error message was thrown

ERROR: MethodError: no method matching *(::Vector{Float64}, ::Vector{VariableRef})
Closest candidates are:
  *(::Any, ::Any, ::Any, ::Any...) at operators.jl:591
  *(::StridedVecOrMat, ::LinearAlgebra.Adjoint{<:Any, <:LinearAlgebra.LQPackedQ}) at /julia/share/julia/stdlib/v1.8/LinearAlgebra/src/lq.jl:269
  *(::StridedVecOrMat, ::LinearAlgebra.LQPackedQ) at /julia/share/julia/stdlib/v1.8/LinearAlgebra/src/lq.jl:293
Ranash1375 commented 2 years ago

Isn't HiGHS a linear solver? "HiGHS.jl is a wrapper for the HiGHS linear solver."

odow commented 2 years ago

The product w * x isn't defined. You need w' * x. You'll run into numerical issues scaling the V matrix by 1e-5. Do this instead:

using JuMP
import HiGHS
V = [146 187 145; 187 854 104; 145 104 289]
w = [1.0, 1.0, 1.0]
EV = Model(HiGHS.Optimizer)
@variable(EV, x[1:3] >= 0)
@constraint(EV, w' * x .== 1)
@objective(EV, Min, x' * V * x)
optimize!(EV)

If you have further questions, please post on the community forum: https://discourse.julialang.org/c/domain/opt/13. We try to keep the GitHub issues for bug reports.

"HiGHS.jl is a wrapper for the HiGHS linear solver."

It supports QPs. I updated the README.