Skip to content

Commit

Permalink
[FileFormats] revert change to extract_function_and_set (#2321)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Oct 24, 2023
1 parent f0d9b28 commit bca9984
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/FileFormats/MOF/write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ end

_lift_variable_indices(arg) = arg # Recursion fallback.

function _extract_function_and_set(expr::Expr)
# TODO(odow): Used by PolyJuMP. Make private in future.
function extract_function_and_set(expr::Expr)
if expr.head == :call # One-sided constraint or foo-in-set.
@assert length(expr.args) == 3
if expr.args[1] == :in
Expand Down Expand Up @@ -100,7 +101,7 @@ function write_nlpblock(
end
for (row, bounds) in enumerate(nlp_block.constraint_bounds)
constraint = MOI.constraint_expr(nlp_block.evaluator, row)
(func, set) = _extract_function_and_set(constraint)
(func, set) = extract_function_and_set(constraint)
func = _lift_variable_indices(func)
push!(
object["constraints"],
Expand Down
10 changes: 5 additions & 5 deletions test/FileFormats/MOF/MOF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,15 @@ function test_nonlinear_error_handling()
[MOI.VariableIndex(1)],
)
# Function-in-Set
@test_throws Exception MOF._extract_function_and_set(:(foo in set))
@test_throws Exception MOF.extract_function_and_set(:(foo in set))
# Not a constraint.
@test_throws Exception MOF._extract_function_and_set(:(x^2))
@test_throws Exception MOF.extract_function_and_set(:(x^2))
# Two-sided constraints
@test MOF._extract_function_and_set(:(1 <= x <= 2)) ==
MOF._extract_function_and_set(:(2 >= x >= 1)) ==
@test MOF.extract_function_and_set(:(1 <= x <= 2)) ==
MOF.extract_function_and_set(:(2 >= x >= 1)) ==
(:x, MOI.Interval(1, 2))
# Less-than constraint.
@test MOF._extract_function_and_set(:(x <= 2)) == (:x, MOI.LessThan(2))
@test MOF.extract_function_and_set(:(x <= 2)) == (:x, MOI.LessThan(2))
end

function _convert_mof_to_expr(
Expand Down

0 comments on commit bca9984

Please sign in to comment.