Skip to content

Commit 38235af

Browse files
authored
Merge pull request #345 from scipopt/od/fix-344
Fix bug when deleting bound constraint of a ZeroOne variable
2 parents e38c841 + 7a5e30c commit 38235af

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/MOI_wrapper/variable.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,18 @@ function reset_bounds(o::Optimizer, v, lb, ub, ::Type{MOI.LessThan{Float64}})
349349
return
350350
end
351351

352+
function _update_binbounds(set::MOI.Interval, ::Type{<:MOI.LessThan})
353+
return MOI.Interval(-Inf, set.upper)
354+
end
355+
356+
function _update_binbounds(set::MOI.Interval, ::Type{<:MOI.GreaterThan})
357+
return MOI.Interval(set.lower, Inf)
358+
end
359+
360+
function _update_binbounds(::MOI.Interval, ::Type{<:S}) where {S}
361+
return MOI.Interval(-Inf, Inf)
362+
end
363+
352364
function MOI.delete(
353365
o::Optimizer,
354366
ci::MOI.ConstraintIndex{MOI.VariableIndex,S},
@@ -360,12 +372,12 @@ function MOI.delete(
360372
v = var(o, vi)
361373
if SCIPvarGetType(v) == SCIP_VARTYPE_BINARY
362374
reset_bounds(o, v, 0.0, 1.0, S)
375+
old_set = o.binbounds[vi]
376+
o.binbounds[vi] = _update_binbounds(old_set, S)
363377
else
364378
inf = SCIPinfinity(o)
365379
reset_bounds(o, v, -inf, inf, S)
366380
end
367-
# but do delete the constraint reference
368-
delete!(o.binbounds, vi)
369381
type = o.bound_types[vi]
370382
if type == _kSCIP_LESS_AND_GREATER_THAN && S <: MOI.LessThan
371383
o.bound_types[vi] = _kSCIP_GREATER_THAN

test/MOI_tests.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,27 @@ function test_get_binary_with_bounds()
16711671
return
16721672
end
16731673

1674+
function test_fix_binary_variable()
1675+
for set in (
1676+
MOI.GreaterThan(0.0),
1677+
MOI.LessThan(1.0),
1678+
MOI.Interval(0.0, 1.0),
1679+
MOI.EqualTo(1.0),
1680+
)
1681+
model = SCIP.Optimizer()
1682+
MOI.set(model, MOI.Silent(), true)
1683+
x = MOI.add_variable(model)
1684+
c = MOI.add_constraint(model, x, set)
1685+
MOI.add_constraint(model, x, MOI.ZeroOne())
1686+
MOI.delete(model, c)
1687+
MOI.add_constraint(model, x, MOI.EqualTo(0.0))
1688+
MOI.optimize!(model)
1689+
@test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMAL
1690+
@test MOI.get(model, MOI.VariablePrimal(), x) == 0.0
1691+
end
1692+
return
1693+
end
1694+
16741695
end # module TestMOIWrapper
16751696

16761697
TestMOIWrapper.runtests()

0 commit comments

Comments
 (0)