Skip to content

Commit

Permalink
Change SetVariableNames to default false (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Apr 25, 2023
1 parent c61c118 commit be9aeba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/MOI_wrapper/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ Create a new Cbc Optimizer.
## Variable names
By default, Cbc.jl will pass variable names to the C model. In some instances,
this has caused segfaults. Disable names being passed to the C model using
By default, Cbc.jl will not pass variable names to the C model because, in some
instances, this has caused segfaults. Enable names being passed to the C model
using:
```julia
using JuMP, Cbc
model = Model(
optimizer_with_attributes(Cbc.Optimizer, Cbc.SetVariableNames() => false),
optimizer_with_attributes(Cbc.Optimizer, Cbc.SetVariableNames() => true),
)
```
"""
Expand Down Expand Up @@ -88,7 +89,7 @@ mutable struct Optimizer <: MOI.AbstractOptimizer
false,
nothing,
nothing,
true,
false,
)
finalizer(Cbc_deleteModel, model)
return model
Expand Down
3 changes: 3 additions & 0 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ function test_variable_name()
x = MOI.add_variable(model)
MOI.set(model, MOI.VariableName(), x, name)
cbc = Cbc.Optimizer()
MOI.set(cbc, Cbc.SetVariableNames(), true)
index_map = MOI.copy_to(cbc, model)
@test MOI.get(cbc, MOI.VariableName(), index_map[x]) == inner
end
Expand All @@ -451,6 +452,8 @@ function test_segfault()
MOI.read_from_file(src, joinpath(@__DIR__, "segfault.mof.json"))
cbc = Cbc.Optimizer()
@test MOI.supports(cbc, Cbc.SetVariableNames())
@test MOI.get(cbc, Cbc.SetVariableNames()) == false
MOI.set(cbc, Cbc.SetVariableNames(), true)
@test MOI.get(cbc, Cbc.SetVariableNames()) == true
MOI.set(cbc, Cbc.SetVariableNames(), false)
@test MOI.get(cbc, Cbc.SetVariableNames()) == false
Expand Down

0 comments on commit be9aeba

Please sign in to comment.