diff --git a/src/MOI_wrapper/MOI_indicator_constraint.jl b/src/MOI_wrapper/MOI_indicator_constraint.jl index 26610c1a..e7143586 100644 --- a/src/MOI_wrapper/MOI_indicator_constraint.jl +++ b/src/MOI_wrapper/MOI_indicator_constraint.jl @@ -195,6 +195,7 @@ function MOI.delete( model::Optimizer, c::MOI.ConstraintIndex{<:MOI.VectorAffineFunction,<:MOI.Indicator}, ) + _update_if_necessary(model) MOI.throw_if_not_valid(model, c) row = _info(model, c).row ind = Ref{Cint}(row - 1) diff --git a/test/MOI/MOI_wrapper.jl b/test/MOI/MOI_wrapper.jl index 9bb0d594..4d01288d 100644 --- a/test/MOI/MOI_wrapper.jl +++ b/test/MOI/MOI_wrapper.jl @@ -6,11 +6,11 @@ module TestMOIWrapper -using Gurobi -using Random using Test -const MOI = Gurobi.MOI +using Gurobi +import MathOptInterface as MOI +import Random function runtests() for name in names(@__MODULE__; all = true) @@ -878,6 +878,26 @@ function test_last_constraint_index() return end +function test_delete_indicator() + model = Gurobi.Optimizer(GRB_ENV) + x = MOI.add_variable(model) + z = MOI.add_variables(model, 3) + MOI.add_constraint.(model, z, MOI.ZeroOne()) + c = map(1:3) do i + return MOI.add_constraint( + model, + MOI.Utilities.operate(vcat, Float64, z[i], 1.0 * i * x), + MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.EqualTo(1.0 * i)), + ) + end + f = MOI.get(model, MOI.ConstraintFunction(), c[2]) + MOI.delete(model, c[1]) + MOI.delete(model, c[3]) + g = MOI.get(model, MOI.ConstraintFunction(), c[2]) + @test isapprox(f, g) + return +end + end TestMOIWrapper.runtests()