Skip to content
Closed
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
5 changes: 5 additions & 0 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ mutable struct Optimizer <: MOI.AbstractOptimizer
Nothing,
Dict{String,Union{Nothing,MOI.ConstraintIndex}},
}
solution_storage::Vector{Ptr{SCIP_SOL}}

function Optimizer(; kwargs...)
o = new(
Expand All @@ -66,6 +67,7 @@ mutable struct Optimizer <: MOI.AbstractOptimizer
_kSCIP_SOLVE_STATUS_NOT_CALLED,
nothing,
nothing,
Ptr{SCIP_SOL}[],
)
# Set all parameters given as keyword arguments, replacing the
# delimiter, since "/" is used by all SCIP parameters, but is not
Expand Down Expand Up @@ -112,6 +114,7 @@ function MOI.empty!(o::Optimizer)
o.scip_solve_status = _kSCIP_SOLVE_STATUS_NOT_CALLED
o.name_to_variable = nothing
o.name_to_constraint_index = nothing
o.solution_storage = Ptr{SCIP_SOL}[]
return nothing
end

Expand Down Expand Up @@ -428,6 +431,8 @@ function MOI.optimize!(o::Optimizer)
finally
o.scip_solve_status = _kSCIP_SOLVE_STATUS_FINISHED
end
o.solution_storage =
unsafe_wrap(Vector{Ptr{SCIP_SOL}}, SCIPgetSols(o), SCIPgetNSols(o))
return nothing
end

Expand Down
18 changes: 6 additions & 12 deletions src/MOI_wrapper/results.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,13 @@ end
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])
return SCIPgetSolOrigObj(o, o.solution_storage[attr.result_index])
end

function MOI.get(o::Optimizer, attr::MOI.VariablePrimal, vi::MOI.VariableIndex)
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.result_index], var(o, vi))
return SCIPgetSolVal(o, o.solution_storage[attr.result_index], var(o, vi))
end

function MOI.get(
Expand All @@ -99,12 +97,8 @@ function MOI.get(
)
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.result_index],
var(o, MOI.VariableIndex(ci.value)),
)
x = MOI.VariableIndex(ci.value)
return SCIPgetSolVal(o, o.solution_storage[attr.result_index], var(o, x))
end

function MOI.get(
Expand All @@ -114,8 +108,8 @@ function MOI.get(
)
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.result_index])
sols = o.solution_storage[attr.result_index]
return SCIPgetActivityLinear(o, cons(o, ci), sols)
end

function MOI.get(o::Optimizer, ::MOI.ObjectiveBound)
Expand Down
Loading