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

Fix deleting multiple indicator constraints in MOI wrapper #540

Merged
merged 2 commits into from
Dec 20, 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
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()