Skip to content

Commit

Permalink
Use a CachingOptimizer for the MIP solver and test Cbc (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Mar 13, 2022
1 parent 594c334 commit fd366da
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
6 changes: 4 additions & 2 deletions Project.toml
@@ -1,13 +1,14 @@
name = "Pavito"
uuid = "cd433a01-47d1-575d-afb7-6db927ee8d8f"
repo = "https://github.com/jump-dev/Pavito.jl.git"
version = "0.3.3"
version = "0.3.4"

[deps]
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[compat]
Cbc = "0.9, 1"
GLPK = "0.15, 1"
Ipopt = "0.8, 0.9, 1"
JuMP = "0.22, 0.23"
Expand All @@ -16,11 +17,12 @@ MathOptInterface = "0.10.3, 1"
julia = "1.6"

[extras]
Cbc = "9961bab8-2fa3-5c5a-9d89-47fab24efd76"
GLPK = "60bf3e95-4087-53dc-ae20-288a0d20c6a6"
Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
MINLPTests = "ee0a3090-8ee9-5cdb-b8cb-8eeba3165522"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["GLPK", "Ipopt", "JuMP", "MINLPTests", "Test"]
test = ["Cbc", "GLPK", "Ipopt", "JuMP", "MINLPTests", "Test"]
37 changes: 19 additions & 18 deletions src/MOI_wrapper.jl
Expand Up @@ -335,24 +335,25 @@ end
# utilities:

function _mip(model::Optimizer)
if isnothing(model.mip_optimizer)
if isnothing(model.mip_solver)
error("No MIP solver specified (set `mip_solver` attribute)\n")
end

model.mip_optimizer =
MOI.instantiate(model.mip_solver, with_bridge_type = Float64)

supports_lazy =
MOI.supports(model.mip_optimizer, MOI.LazyConstraintCallback())
if isnothing(model.mip_solver_drives)
model.mip_solver_drives = supports_lazy
elseif model.mip_solver_drives && !supports_lazy
error(
"MIP solver (`mip_solver`) does not support lazy constraint " *
"callbacks (cannot set `mip_solver_drives` attribute to `true`)",
)
end
if model.mip_optimizer !== nothing
return model.mip_optimizer
end
if model.mip_solver === nothing
error("No MIP solver specified (set `mip_solver` attribute)\n")
end
model.mip_optimizer = MOI.Utilities.CachingOptimizer(
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()),
MOI.instantiate(model.mip_solver, with_bridge_type = Float64),
)
supports_lazy =
MOI.supports(model.mip_optimizer, MOI.LazyConstraintCallback())
if model.mip_solver_drives === nothing
model.mip_solver_drives = supports_lazy
elseif model.mip_solver_drives && !supports_lazy
error(
"MIP solver (`mip_solver`) does not support lazy constraint " *
"callbacks (cannot set `mip_solver_drives` attribute to `true`)",
)
end
return model.mip_optimizer
end
Expand Down
17 changes: 17 additions & 0 deletions test/runtests.jl
Expand Up @@ -6,6 +6,7 @@

using Test

import Cbc
import GLPK
import Ipopt
import MathOptInterface
Expand All @@ -15,6 +16,14 @@ const MOI = MathOptInterface
include("MOI_wrapper.jl")
include("jump_tests.jl")

# !!! info
# We test with both Cbc and GLPK because they have very different
# implementations of the MOI API: GLPK supports incremental modification and
# supports lazy constraints, whereas Cbc supports copy_to and does not
# support lazy constraints. In addition, Cbc uses MatrixOfConstraints to
# simplify the copy process, needing an additional cache if we modify after
# the solve.

@testset "MOI" begin
TestMOIWrapper.runtests(
MOI.OptimizerWithAttributes(
Expand All @@ -28,6 +37,14 @@ include("jump_tests.jl")
)
end

@testset "Cbc" begin
TestMOIWrapper._run_moi_tests(
false, # mip_solver_drives
MOI.OptimizerWithAttributes(Cbc.Optimizer, MOI.Silent() => true),
MOI.OptimizerWithAttributes(Ipopt.Optimizer, MOI.Silent() => true),
)
end

@testset "JuMP" begin
TestJuMP.runtests(
MOI.OptimizerWithAttributes(
Expand Down

2 comments on commit fd366da

@odow
Copy link
Member Author

@odow odow commented on fd366da Mar 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/56539

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.4 -m "<description of version>" fd366dad8257684d0adb34ad38edf1482631db60
git push origin v0.3.4

Please sign in to comment.