Hi,
I am trying to add quadratic support to CPLEX.jl with MOI.
I use this test example from matlab doc (the first one with numerical results):
[Quadratic programming - MATLAB quadprog - MathWorks France](qp example)
My test code is the following :
using JuMP, CPLEX
m = Model(with_optimizer(CPLEX.Optimizer))
@variable(m, x)
@variable(m, y)
@constraint(m, x+y <= 2)
@constraint(m, -x+2*y <= 2)
@constraint(m, 2*x+y <= 3)
@objective(m, Min, 0.5*x*x + y*y - x*y - 2*x - 6*y)
optimize!(m)
value(x), value(y), objective_value(m)
And I added the following code as suggested above in MOI_wrapper.jl of the CPLEX.jl package :
function LQOI.set_quadratic_objective!(model::Optimizer, I::Vector{Int}, J::Vector{Int}, V::Vector{Float64})
@assert length(I) == length(J) == length(V)
#scalediagonal!(V, I, J, 0.5)
CPLEX.add_qpterms!(model.inner, I, J, V)
#scalediagonal!(V, I, J, 2.0)
return
end
LQOI.solve_quadratic_problem!(model::Optimizer) = LQOI.solve_linear_problem!(model)
I commented the scalediagonal!
function @odow as CPLEX kept returning that the matrix Q was not positive semi definite in my test case (which is absurd).
Now CPLEX seems to solve the problem properly. I obtain the same objective value as the matlab page, that is, -8.222 in the CPLEX log.
Now I have to define the get_quadratic_primal_solution!
in MOI_wrapper as the call to optimize!
returns
ERROR: LoadError: MethodError: no method matching get_quadratic_primal_solution!(::CPLEX.Optimizer, ::Array{Float64,1})
after the CPLEX output.
I tried this
function LQOI.get_quadratic_primal_solution!(model::Optimizer, dest)
dest = CPLEX.get_solution(model.inner)
return
end
function LQOI.get_quadratic_dual_solution!(model::Optimizer, dest)
dest = CPLEX.get_constr_duals(model.inner)
return
end
and the test example runs perfectly.
BUT the inconsistency with the definitions of LQOI.get_linear_primal_solution!
LQOI.get_linear_dual_solution!
is troubling me. I wonder if I miss some MOI feature.
Could you check my implementation?
Finally everything works fine with small QP and QCP examples from MOIT.contquadratictest
written with JuMP macros.
However I added the MOIT.contquadratictest
tests in the Tests of CPLEX.jl and 6 out of 42 quadratic tests do not pass. Should I do a pull request to get some help?
Thanks