Skip to content

Commit 0e0cc7d

Browse files
authored
Fix deleting from .constypes when deleting MOI.VariableIndex (#327)
1 parent 05446cc commit 0e0cc7d

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

src/MOI_wrapper/variable.jl

+26-5
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,37 @@ function MOI.delete(o::Optimizer, vi::MOI.VariableIndex)
110110
msg = "Can not delete variable while model contains constraints!"
111111
throw(MOI.DeleteNotAllowed(vi, msg))
112112
end
113-
allow_modification(o)
114113
if !haskey(o.inner.vars, VarRef(vi.value))
115114
throw(MOI.InvalidIndex(vi))
116115
end
117-
delete!(o.binbounds, vi)
116+
allow_modification(o)
117+
cref = ConsRef(vi.value)
118+
# Delete integrality constraints
119+
v = var(o, vi)
120+
var_type = SCIPvarGetType(v)
121+
if var_type == SCIP_VARTYPE_BINARY
122+
delete!(o.constypes[MOI.VariableIndex, MOI.ZeroOne], cref)
123+
delete!(o.binbounds, vi)
124+
elseif var_type == SCIP_VARTYPE_INTEGER
125+
delete!(o.constypes[MOI.VariableIndex, MOI.Integer], cref)
126+
end
127+
# Delete bound constraints
128+
type = get(o.bound_types, vi, nothing)
129+
if type == _kSCIP_EQUAL_TO
130+
delete!(o.constypes[MOI.VariableIndex, MOI.EqualTo{Float64}], cref)
131+
elseif type == _kSCIP_INTERVAL
132+
delete!(o.constypes[MOI.VariableIndex, MOI.Interval{Float64}], cref)
133+
elseif type == _kSCIP_LESS_THAN
134+
delete!(o.constypes[MOI.VariableIndex, MOI.LessThan{Float64}], cref)
135+
elseif type == _kSCIP_GREATER_THAN
136+
delete!(o.constypes[MOI.VariableIndex, MOI.GreaterThan{Float64}], cref)
137+
elseif type == _kSCIP_LESS_AND_GREATER_THAN
138+
delete!(o.constypes[MOI.VariableIndex, MOI.LessThan{Float64}], cref)
139+
delete!(o.constypes[MOI.VariableIndex, MOI.GreaterThan{Float64}], cref)
140+
end
118141
delete!(o.bound_types, vi)
119-
delete!(o.reference, var(o, vi))
142+
delete!(o.reference, v)
120143
delete(o.inner, VarRef(vi.value))
121-
# FIXME(odow): delete the associated ConstraintIndex
122-
delete!(o.bound_types, vi)
123144
o.name_to_variable = nothing
124145
return nothing
125146
end

test/MOI_tests.jl

+7-10
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,25 @@ const CONFIG = MOI.Test.Config(;
3636
)
3737

3838
function test_runtests_cached()
39-
model = MOI.Bridges.full_bridge_optimizer(
40-
MOI.Utilities.CachingOptimizer(
41-
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()),
42-
SCIP.Optimizer(),
43-
),
44-
Float64,
39+
model = MOI.instantiate(
40+
SCIP.Optimizer;
41+
with_bridge_type=Float64,
42+
with_cache_type=Float64,
4543
)
4644
MOI.set(model, MOI.Silent(), true)
4745
MOI.Test.runtests(model, CONFIG)
4846
return
4947
end
5048

5149
function test_runtests_bridged()
52-
model = MOI.Bridges.full_bridge_optimizer(SCIP.Optimizer(), Float64)
50+
model = MOI.instantiate(SCIP.Optimizer; with_bridge_type=Float64)
5351
MOI.set(model, MOI.Silent(), true)
54-
# TODO(odow): bugs to fix
55-
MOI.Test.runtests(model, CONFIG; exclude=[r"^test_model_delete$"])
52+
MOI.Test.runtests(model, CONFIG)
5653
return
5754
end
5855

5956
function test_runtests_direct()
60-
model = SCIP.Optimizer()
57+
model = MOI.instantiate(SCIP.Optimizer)
6158
MOI.set(model, MOI.Silent(), true)
6259
MOI.Test.runtests(model, CONFIG)
6360
return

0 commit comments

Comments
 (0)