Skip to content

Commit

Permalink
Fix macro issue in indicator constraints (#3813)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Aug 29, 2024
1 parent ad1dd7f commit 89f3033
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/indicator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 11 additions & 0 deletions test/test_constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 89f3033

Please sign in to comment.