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

Change SetVariableNames to default false #216

Merged
merged 1 commit into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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