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

Implement MOI.default_cache #130

Merged
merged 5 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions src/MOI_wrapper/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const OptimizerCache = MOI.Utilities.GenericModel{
},
}

Base.show(io::IO, ::Type{OptimizerCache}) = print(io, "Clp.OptimizerCache")

const SCALAR_SETS = Union{
MOI.GreaterThan{Float64},
MOI.LessThan{Float64},
Expand Down Expand Up @@ -72,6 +74,10 @@ mutable struct Optimizer <: MOI.AbstractOptimizer
end
end

function MOI.default_cache(::Optimizer, ::Type{Float64})
return MOI.Utilities.UniversalFallback(OptimizerCache())
end

Base.cconvert(::Type{Ptr{Cvoid}}, model::Optimizer) = model
function Base.unsafe_convert(::Type{Ptr{Cvoid}}, model::Optimizer)
return model.inner::Ptr{Cvoid}
Expand Down
17 changes: 7 additions & 10 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ function test_supports_default_copy_to()
end

function test_runtests()
model = MOI.Bridges.full_bridge_optimizer(
MOI.Utilities.CachingOptimizer(
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()),
Clp.Optimizer(),
),
Float64,
# This is what JuMP would construct
model = MOI.Utilities.CachingOptimizer(
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()),
MOI.instantiate(Clp.Optimizer; with_bridge_type = Float64),
)
MOI.set(model, MOI.Silent(), true)
MOI.Test.runtests(
Expand All @@ -50,10 +48,9 @@ function test_runtests()
end

function test_Nonexistant_unbounded_ray()
model = MOI.Utilities.CachingOptimizer(
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()),
Clp.Optimizer(),
)
inner = Clp.Optimizer()
model =
MOI.Utilities.CachingOptimizer(MOI.default_cache(inner, Float64), inner)
MOI.set(model, MOI.Silent(), true)
x = MOI.add_variables(model, 5)
MOI.set(
Expand Down