Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
SparseMatricesCOO = "fa32481b-f100-4b48-8dc8-c62f61b13870"

[compat]
Gurobi = "0.10, 0.11"
Gurobi = "1"
QuadraticModels = "0.9"
SolverCore = "0.3"
SparseMatricesCOO = "0.2"
Expand Down
25 changes: 3 additions & 22 deletions src/QuadraticModelsGurobi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,9 @@ gurobi(QM::QuadraticModel{T, S}; kwargs...) where {T, S} = gurobi(
kwargs...
)

function gurobi(QM::QuadraticModel{T, S, M1, M2};
method=2, kwargs...) where {T, S, M1 <: SparseMatrixCOO, M2 <: SparseMatrixCOO}
env = Gurobi.Env()
# -1=automatic, 0=primal simplex, 1=dual simplex, 2=barrier,
# 3=concurrent, 4=deterministic concurrent, 5=deterministic concurrent simplex.
# default to barrier
GRBsetintparam(env, "Method", method)
# use kwargs change to presolve, scaling and crossover mode
# example: gurobi(QM, presolve=0) (see gurobi doc for other options)
for (k, v) in kwargs
if k==:presolve
GRBsetintparam(env, "Presolve", v) # 0 = no presolve
elseif k==:scaling
GRBsetintparam(env, "ScaleFlag", v) # 0 = no scaling
elseif k==:crossover
GRBsetintparam(env, "Crossover", v) # 0 = no crossover
elseif k==:display
GRBsetintparam(env, "OutputFlag", v) # 0 = no display
elseif k==:threads
GRBsetintparam(env, "Threads", v)
end
end
function gurobi(QM::QuadraticModel{T, S, M1, M2}; kwargs...) where {T, S, M1 <: SparseMatrixCOO, M2 <: SparseMatrixCOO}

env = Gurobi.Env(Dict{String,Any}(string(k) => v for (k,v) in kwargs))

model = Ref{Ptr{Cvoid}}()
GRBnewmodel(env, model, "", QM.meta.nvar, QM.data.c, QM.meta.lvar, QM.meta.uvar, C_NULL, C_NULL)
Expand Down
10 changes: 6 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ using Test
c0 = 0.0,
name = "QM_dense",
)
stats_dense = gurobi(qp_dense)
@test isapprox(stats_dense.objective, 1.1249999990782493, atol = 1e-2)
@test stats_dense.status == :acceptable
end
for method in [1,2]
stats_dense = gurobi(qp_dense, Method = method)
@test isapprox(stats_dense.objective, 1.1249999990782493, atol = 1e-2)
@test stats_dense.status == :acceptable
end
end