Skip to content

Commit

Permalink
Add support for MOI.AbsoluteGapTolerance and MOI.RelativeGapTolerance (
Browse files Browse the repository at this point in the history
  • Loading branch information
hannes-uppman authored Sep 7, 2023
1 parent 537445c commit f495d97
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[compat]
Cbc_jll = "=2.10.5, =200.1000.501, =200.1000.800"
MathOptInterface = "1"
MathOptInterface = "1.7"
julia = "1.6"

[extras]
Expand Down
36 changes: 36 additions & 0 deletions src/MOI_wrapper/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,42 @@ function MOI.get(model::Optimizer, ::MOI.TimeLimitSec)
return value === nothing ? value : parse(Float64, value)
end

MOI.supports(::Optimizer, ::MOI.AbsoluteGapTolerance) = true

function MOI.set(model::Optimizer, ::MOI.AbsoluteGapTolerance, value::Real)
MOI.set(model, MOI.RawOptimizerAttribute("allowableGap"), value)
return
end

function MOI.set(model::Optimizer, ::MOI.AbsoluteGapTolerance, ::Nothing)
delete!(model.params, "allowableGap")
Cbc_setParameter(model, "allowableGap", "InvalidDoubleValue")
return
end

function MOI.get(model::Optimizer, ::MOI.AbsoluteGapTolerance)
value = get(model.params, "allowableGap", nothing)
return value === nothing ? value : parse(Float64, value)
end

MOI.supports(::Optimizer, ::MOI.RelativeGapTolerance) = true

function MOI.set(model::Optimizer, ::MOI.RelativeGapTolerance, value::Real)
MOI.set(model, MOI.RawOptimizerAttribute("ratioGap"), value)
return
end

function MOI.set(model::Optimizer, ::MOI.RelativeGapTolerance, ::Nothing)
delete!(model.params, "ratioGap")
Cbc_setParameter(model, "ratioGap", "InvalidDoubleValue")
return
end

function MOI.get(model::Optimizer, ::MOI.RelativeGapTolerance)
value = get(model.params, "ratioGap", nothing)
return value === nothing ? value : parse(Float64, value)
end

MOI.get(::Optimizer, ::MOI.SolverName) = "COIN Branch-and-Cut (Cbc)"

MOI.get(::Optimizer, ::MOI.SolverVersion) = unsafe_string(Cbc_getVersion())
Expand Down

0 comments on commit f495d97

Please sign in to comment.