Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify _cache_primal_status to use XPRS_SOLSTATUS #249

Merged
merged 1 commit into from
Mar 21, 2024
Merged
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
53 changes: 13 additions & 40 deletions src/MOI/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3096,48 +3096,21 @@ 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)
term_stat = MOI.get(model, MOI.TerminationStatus())
if term_stat == MOI.OPTIMAL || term_stat == MOI.LOCALLY_SOLVED
return MOI.FEASIBLE_POINT
elseif term_stat == MOI.LOCALLY_INFEASIBLE
return MOI.INFEASIBLE_POINT
elseif term_stat == MOI.DUAL_INFEASIBLE
if _has_primal_ray(model)
return MOI.INFEASIBILITY_CERTIFICATE
end
elseif is_mip(model)
stat = @_invoke Lib.XPRSgetintattrib(
model.inner,
Lib.XPRS_MIPSTATUS,
_,
)::Int
if stat == Lib.XPRS_MIP_NOT_LOADED
return MOI.NO_SOLUTION
elseif stat == Lib.XPRS_MIP_LP_NOT_OPTIMAL # - is a STOP
return MOI.NO_SOLUTION
elseif stat == Lib.XPRS_MIP_LP_OPTIMAL # - is a STOP
return MOI.INFEASIBLE_POINT
elseif stat == Lib.XPRS_MIP_NO_SOL_FOUND # - is a STOP
return MOI.NO_SOLUTION
elseif stat == Lib.XPRS_MIP_SOLUTION # - is a STOP
return MOI.FEASIBLE_POINT
elseif stat == Lib.XPRS_MIP_INFEAS
return MOI.INFEASIBLE_POINT
elseif stat == Lib.XPRS_MIP_OPTIMAL
return MOI.FEASIBLE_POINT
elseif stat == Lib.XPRS_MIP_UNBOUNDED
return MOI.NO_SOLUTION #? DUAL_INFEASIBLE?
end
stat =
@_invoke Lib.XPRSgetintattrib(model.inner, Lib.XPRS_SOLSTATUS, _)::Int
if stat == Lib.XPRS_SOLSTATUS_UNBOUNDED && _has_primal_ray(model)
return MOI.INFEASIBILITY_CERTIFICATE
end
if is_mip(model)
mip_sols =
@_invoke Lib.XPRSgetintattrib(model.inner, Lib.XPRS_MIPSOLS, _)::Int
if mip_sols > 0
return MOI.FEASIBLE_POINT
end
end
return MOI.NO_SOLUTION
return _SOLSTATUS_MAP[stat]
end

function MOI.get(model::Optimizer, attr::MOI.PrimalStatus)
Expand Down
Loading