Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Sep 28, 2023
1 parent 06b0d60 commit 892bc1f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
8 changes: 4 additions & 4 deletions docs/src/developers/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,20 +200,20 @@ julia> model = Model(); @variable(model, x);
julia> function JuMP.parse_constraint_head(
_error::Function,
::Val{:},
::Val{:},
lhs,
rhs,
)
println("Rewriting as ==")
println("Rewriting as ==")
new_lhs, parse_code = MutableArithmetics.rewrite(lhs)
build_code = :(
build_constraint($(_error), $(new_lhs), MOI.EqualTo($(rhs)))
)
return false, parse_code, build_code
end
julia> @constraint(model, x + x 1.0)
Rewriting as ==
julia> @constraint(model, x + x 1.0)
Rewriting as ==
2 x = 1
```

Expand Down
13 changes: 2 additions & 11 deletions src/constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1543,13 +1543,7 @@ function relax_with_penalty!(
return relax_with_penalty!(model, Dict(); default = default)
end


function parse_constraint_head(
error_fn::Function,
::Val{:(:=)},
lhs,
rhs,
)
function parse_constraint_head(error_fn::Function, ::Val{:(:=)}, lhs, rhs)
new_lhs, parse_code_lhs = _rewrite_expression(lhs)
new_rhs, parse_code_rhs = _rewrite_expression(rhs)
parse_code = quote
Expand All @@ -1562,10 +1556,7 @@ function parse_constraint_head(
elseif $new_lhs isa Bool
ScalarConstraint($new_rhs, MOI.EqualTo($new_lhs))
else
ScalarConstraint(
op_equal_to($new_lhs, $new_rhs),
MOI.EqualTo(true),
)
ScalarConstraint(op_equal_to($new_lhs, $new_rhs), MOI.EqualTo(true))
end
end
return false, parse_code, build_code
Expand Down
4 changes: 2 additions & 2 deletions test/test_macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ end

struct CustomType end

function JuMP.parse_constraint_head(_error::Function, ::Val{:}, lhs, rhs)
function JuMP.parse_constraint_head(_error::Function, ::Val{:}, lhs, rhs)
return false, :(), :(build_constraint($_error, $(esc(lhs)), $(esc(rhs))))
end

Expand Down Expand Up @@ -326,7 +326,7 @@ function test_extension_custom_expression_test(
)
model = ModelType()
@variable(model, x)
@constraint(model, con_ref, x CustomType())
@constraint(model, con_ref, x CustomType())
con = constraint_object(con_ref)
@test jump_function(con) == x
@test moi_set(con) isa CustomSet
Expand Down

0 comments on commit 892bc1f

Please sign in to comment.