Skip to content

Commit

Permalink
Fix deleting multiple indicator constraints in MOI wrapper (#540)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Dec 20, 2023
1 parent 84750c2 commit 5fa8e23
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/MOI_wrapper/MOI_indicator_constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 23 additions & 3 deletions test/MOI/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()

0 comments on commit 5fa8e23

Please sign in to comment.