Skip to content

Commit 31a216c

Browse files
matbesanconodow
authored andcommitted
solutions stored in cachde
1 parent 887184d commit 31a216c

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

src/MOI_wrapper.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ mutable struct Optimizer <: MOI.AbstractOptimizer
4848
Nothing,
4949
Dict{String,Union{Nothing,MOI.ConstraintIndex}},
5050
}
51+
solution_storage::Vector{Ptr{SCIP_SOL}}
5152

5253
function Optimizer(; kwargs...)
5354
o = new(
@@ -66,6 +67,7 @@ mutable struct Optimizer <: MOI.AbstractOptimizer
6667
_kSCIP_SOLVE_STATUS_NOT_CALLED,
6768
nothing,
6869
nothing,
70+
Ptr{SCIP_SOL}[],
6971
)
7072
# Set all parameters given as keyword arguments, replacing the
7173
# delimiter, since "/" is used by all SCIP parameters, but is not
@@ -112,6 +114,7 @@ function MOI.empty!(o::Optimizer)
112114
o.scip_solve_status = _kSCIP_SOLVE_STATUS_NOT_CALLED
113115
o.name_to_variable = nothing
114116
o.name_to_constraint_index = nothing
117+
empty!(o.solution_storage)
115118
return nothing
116119
end
117120

@@ -428,6 +431,8 @@ function MOI.optimize!(o::Optimizer)
428431
finally
429432
o.scip_solve_status = _kSCIP_SOLVE_STATUS_FINISHED
430433
end
434+
o.solution_storage =
435+
unsafe_wrap(Vector{Ptr{SCIP_SOL}}, SCIPgetSols(o), SCIPgetNSols(o))
431436
return nothing
432437
end
433438

src/MOI_wrapper/results.jl

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,13 @@ end
8181
function MOI.get(o::Optimizer, attr::MOI.ObjectiveValue)
8282
assert_solved(o)
8383
MOI.check_result_index_bounds(o, attr)
84-
sols = unsafe_wrap(Array{Ptr{SCIP_SOL}}, SCIPgetSols(o), SCIPgetNSols(o))
85-
return SCIPgetSolOrigObj(o, sols[attr.result_index])
84+
return SCIPgetSolOrigObj(o, o.solution_storage[attr.result_index])
8685
end
8786

8887
function MOI.get(o::Optimizer, attr::MOI.VariablePrimal, vi::MOI.VariableIndex)
8988
assert_solved(o)
9089
MOI.check_result_index_bounds(o, attr)
91-
sols = unsafe_wrap(Array{Ptr{SCIP_SOL}}, SCIPgetSols(o), SCIPgetNSols(o))
92-
return SCIPgetSolVal(o, sols[attr.result_index], var(o, vi))
90+
return SCIPgetSolVal(o, o.solution_storage[attr.result_index], var(o, vi))
9391
end
9492

9593
function MOI.get(
@@ -99,12 +97,8 @@ function MOI.get(
9997
)
10098
assert_solved(o)
10199
MOI.check_result_index_bounds(o, attr)
102-
sols = unsafe_wrap(Array{Ptr{SCIP_SOL}}, SCIPgetSols(o), SCIPgetNSols(o))
103-
return SCIPgetSolVal(
104-
o,
105-
sols[attr.result_index],
106-
var(o, MOI.VariableIndex(ci.value)),
107-
)
100+
x = MOI.VariableIndex(ci.value)
101+
return SCIPgetSolVal(o, o.solution_storage[attr.result_index], var(o, x))
108102
end
109103

110104
function MOI.get(
@@ -114,8 +108,7 @@ function MOI.get(
114108
)
115109
assert_solved(o)
116110
MOI.check_result_index_bounds(o, attr)
117-
sols = unsafe_wrap(Array{Ptr{SCIP_SOL}}, SCIPgetSols(o), SCIPgetNSols(o))
118-
return SCIPgetActivityLinear(o, cons(o, ci), sols[attr.result_index])
111+
return SCIPgetActivityLinear(o, cons(o, ci), o.solution_storage[attr.result_index])
119112
end
120113

121114
function MOI.get(o::Optimizer, ::MOI.ObjectiveBound)

0 commit comments

Comments
 (0)