Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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