Skip to content

Commit d389ba1

Browse files
authored
[Utilities] add test for indicator constraints in Model (#2619)
1 parent 33976af commit d389ba1

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/Utilities/model.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,24 @@ function test_copy_to_unsupported_scalar_function()
544544
return
545545
end
546546

547+
function test_indicator_constraints()
548+
model = MOI.Utilities.Model{Float64}()
549+
x = MOI.add_variable(model)
550+
z, _ = MOI.add_constrained_variable(model, MOI.ZeroOne())
551+
f = MOI.Utilities.operate(vcat, Float64, 1.0 * x, z)
552+
for si in (MOI.LessThan(1.0), MOI.GreaterThan(1.0), MOI.EqualTo(1.0))
553+
for a in (MOI.ACTIVATE_ON_ONE, MOI.ACTIVATE_ON_ZERO)
554+
s = MOI.Indicator{a}(si)
555+
MOI.supports_constraint(model, typeof(f), typeof(s))
556+
ci = MOI.add_constraint(model, f, s)
557+
@test MOI.is_valid(model, ci)
558+
@test MOI.get(model, MOI.ConstraintFunction(), ci) f
559+
@test MOI.get(model, MOI.ConstraintSet(), ci) == s
560+
end
561+
end
562+
return
563+
end
564+
547565
end # module
548566

549567
TestModel.runtests()

0 commit comments

Comments
 (0)