Skip to content

Commit

Permalink
Merge pull request #134 from SCIP-Interfaces/rs/moi095
Browse files Browse the repository at this point in the history
Compatibility with MOI 0.9.5
  • Loading branch information
rschwarz authored Oct 11, 2019
2 parents 2fccb13 + 568f56e commit 3e648c9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"

[compat]
CEnum = "^0.1.0"
MathOptInterface = "^0.9.0"
MathOptInterface = "= 0.9.5"
julia = "^1.0.0"

[extras]
Expand Down
14 changes: 11 additions & 3 deletions src/MOI_wrapper/results.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ function MOI.get(o::Optimizer, ::MOI.TerminationStatus)
return term_status_map[SCIPgetStatus(o)]
end

function MOI.get(o::Optimizer, ::MOI.PrimalStatus)
return SCIPgetNSols(o) > 0 ? MOI.FEASIBLE_POINT : MOI.NO_SOLUTION
function MOI.get(o::Optimizer, attr::MOI.PrimalStatus)
return if 1 <= attr.N <= MOI.get(o, MOI.ResultCount())
MOI.FEASIBLE_POINT
else
MOI.NO_SOLUTION
end
end

function MOI.get(o::Optimizer, ::MOI.ResultCount)
function MOI.get(o::Optimizer, ::MOI.ResultCount)::Int
status = SCIPgetStatus(o)
if status in [SCIP_STATUS_UNBOUNDED, SCIP_STATUS_INFORUNBD]
return 0
Expand Down Expand Up @@ -66,24 +70,28 @@ assert_after_prob(o::Optimizer) = assert_stage(o, SCIP_Stage.(3:10))

function MOI.get(o::Optimizer, attr::MOI.ObjectiveValue)
assert_solved(o)
MOI.check_result_index_bounds(o, attr)
sols = unsafe_wrap(Array{Ptr{SCIP_SOL}}, SCIPgetSols(o), SCIPgetNSols(o))
return SCIPgetSolOrigObj(o, sols[attr.result_index])
end

function MOI.get(o::Optimizer, attr::MOI.VariablePrimal, vi::VI)
assert_solved(o)
MOI.check_result_index_bounds(o, attr)
sols = unsafe_wrap(Array{Ptr{SCIP_SOL}}, SCIPgetSols(o), SCIPgetNSols(o))
return SCIPgetSolVal(o, sols[attr.N], var(o, vi))
end

function MOI.get(o::Optimizer, attr::MOI.ConstraintPrimal, ci::CI{SVF,<:BOUNDS})
assert_solved(o)
MOI.check_result_index_bounds(o, attr)
sols = unsafe_wrap(Array{Ptr{SCIP_SOL}}, SCIPgetSols(o), SCIPgetNSols(o))
return SCIPgetSolVal(o, sols[attr.N], var(o, VI(ci.value)))
end

function MOI.get(o::Optimizer, attr::MOI.ConstraintPrimal, ci::CI{SAF,<:BOUNDS})
assert_solved(o)
MOI.check_result_index_bounds(o, attr)
sols = unsafe_wrap(Array{Ptr{SCIP_SOL}}, SCIPgetSols(o), SCIPgetNSols(o))
return SCIPgetActivityLinear(o, cons(o, ci), sols[attr.N])
end
Expand Down
2 changes: 2 additions & 0 deletions test/MOI_wrapper_cached.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const CONFIG3 = MOIT.TestConfig(atol=1e-3, rtol=1e-2, duals=false, infeas_certif
excluded = [
"feasibility_sense", # TODO: support feasibility sense
"solve_qp_edge_cases", # needs objective bridge
"number_threads", # can't set num. threads in single-threaded SCIP!
"delete_soc_variables", # SCIP requires non-negative "rhs variable"
]
MOIT.unittest(BRIDGED2, CONFIG, excluded)
end
Expand Down

0 comments on commit 3e648c9

Please sign in to comment.