Skip to content

Commit

Permalink
Fix uses of code that are not supported by Xpress v8
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Mar 29, 2024
1 parent 1b075d1 commit d274a71
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
25 changes: 12 additions & 13 deletions src/MOI/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ function MOI.supports(model::Optimizer, attr::MOI.RawOptimizerAttribute)
end
p_id, p_type = Ref{Cint}(), Ref{Cint}()
ret = Lib.XPRSgetcontrolinfo(model.inner, attr.name, p_id, p_type)
if ret != 0
if ret != 0 || p_type[] == Lib.XPRS_TYPE_NOTDEFINED
ret = Lib.XPRSgetattribinfo(model.inner, attr.name, p_id, p_type)
end
p_type_fail = p_type[] in (Lib.XPRS_TYPE_NOTDEFINED, Lib.XPRS_TYPE_INT64)
Expand Down Expand Up @@ -3073,21 +3073,20 @@ function _has_primal_ray(model::Optimizer)
return has_Ray[] != 0
end

const _SOLSTATUS_MAP = Dict(
Lib.XPRS_SOLSTATUS_NOTFOUND => MOI.NO_SOLUTION,
Lib.XPRS_SOLSTATUS_OPTIMAL => MOI.FEASIBLE_POINT,
Lib.XPRS_SOLSTATUS_FEASIBLE => MOI.FEASIBLE_POINT,
Lib.XPRS_SOLSTATUS_INFEASIBLE => MOI.NO_SOLUTION,
Lib.XPRS_SOLSTATUS_UNBOUNDED => MOI.NO_SOLUTION,
)

function _cache_primal_status(model)
stat =
@_invoke Lib.XPRSgetintattrib(model.inner, Lib.XPRS_SOLSTATUS, _)::Int
if stat == Lib.XPRS_SOLSTATUS_UNBOUNDED && _has_primal_ray(model)
if _has_primal_ray(model)
return MOI.INFEASIBILITY_CERTIFICATE
end
return _SOLSTATUS_MAP[stat]
dict, attr = if is_mip(model)
_MIPSTATUS, Lib.XPRS_MIPSTATUS
else
_LPSTATUS, Lib.XPRS_LPSTATUS
end
stat = @_invoke Lib.XPRSgetintattrib(model.inner, attr, _)::Int
if dict[stat][2] in (MOI.OPTIMAL, MOI.LOCALLY_SOLVED)
return MOI.FEASIBLE_POINT
end
return MOI.NO_SOLUTION
end

function MOI.get(model::Optimizer, attr::MOI.PrimalStatus)
Expand Down
3 changes: 3 additions & 0 deletions test/test_MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,9 @@ function test_name_empty_names()
end

function test_dummy_nlp()
if Xpress.get_version() < v"41"
return
end
model = Xpress.Optimizer(; OUTPUTLOG = 0)
x = MOI.add_variables(model, 2)
c = [1.0, 2.0]
Expand Down
7 changes: 4 additions & 3 deletions test/test_helper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ function test_show_xpress_error()
end

function test_xpress_problem_logfile()
p = Xpress.XpressProblem(; logfile = "test.log")
@test isfile("test.log")
rm("test.log")
# Use mktempdir so that the file is removed on process exit
filename = joinpath(mktempdir(), "test.log")
p = Xpress.XpressProblem(; logfile = filename)
@test isfile(filename)
return
end

Expand Down

0 comments on commit d274a71

Please sign in to comment.