From 336c2105cba68a43f77b57c9e89f40e0d5f9a61e Mon Sep 17 00:00:00 2001 From: odow Date: Fri, 30 Aug 2024 09:11:58 +1200 Subject: [PATCH] Fix macro issue in indicator constraints --- src/indicator.jl | 7 +++++-- test/test_constraint.jl | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/indicator.jl b/src/indicator.jl index 58dfaaba49b..1342898faf9 100644 --- a/src/indicator.jl +++ b/src/indicator.jl @@ -71,13 +71,16 @@ function parse_constraint_call( ) end f, lhs_parse_code = _rewrite_expression(variable) - push!(rhs_parsecode.args, lhs_parse_code) + parsecode = quote + $rhs_parsecode + $lhs_parse_code + end build_call = if vectorized :(_build_indicator_constraint.($error_fn, $f, $rhs_build_call, $S)) else :(_build_indicator_constraint($error_fn, $f, $rhs_build_call, $S)) end - return rhs_parsecode, build_call + return parsecode, build_call end function constraint_string( diff --git a/test/test_constraint.jl b/test/test_constraint.jl index fa6dc9b04a7..2f183a36092 100644 --- a/test/test_constraint.jl +++ b/test/test_constraint.jl @@ -2107,4 +2107,15 @@ function test_real_hermitian_in_zeros() return end +function test_issue_3812() + model = Model() + @variable(model, b, Bin) + @variable(model, x) + c = @constraint(model, b => {x in MOI.EqualTo(1.0)}) + o = constraint_object(c) + @test o.func == [b, x] + @test o.set == MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.EqualTo(1.0)) + return +end + end # module