diff --git a/src/FileFormats/NL/read.jl b/src/FileFormats/NL/read.jl index affa7ee78f..0d27000b91 100644 --- a/src/FileFormats/NL/read.jl +++ b/src/FileFormats/NL/read.jl @@ -194,13 +194,12 @@ function _to_model(data::_CacheModel; use_nlp_block::Bool) lb, ub = data.constraint_lower[i], data.constraint_upper[i] if lb == ub MOI.Nonlinear.add_constraint(nlp, expr, MOI.EqualTo(lb)) - elseif -Inf < lb < ub < Inf - MOI.Nonlinear.add_constraint(nlp, expr, MOI.Interval(lb, ub)) elseif -Inf == lb && ub < Inf MOI.Nonlinear.add_constraint(nlp, expr, MOI.LessThan(ub)) - else - @assert -Inf < lb && ub == Inf + elseif -Inf < lb && ub == Inf MOI.Nonlinear.add_constraint(nlp, expr, MOI.GreaterThan(lb)) + else + MOI.Nonlinear.add_constraint(nlp, expr, MOI.Interval(lb, ub)) end end evaluator = @@ -217,13 +216,12 @@ function _to_model(data::_CacheModel; use_nlp_block::Bool) f = _to_scalar_nonlinear_function(expr)::MOI.ScalarNonlinearFunction if lb == ub MOI.add_constraint(model, f, MOI.EqualTo(lb)) - elseif -Inf < lb < ub < Inf - MOI.add_constraint(model, f, MOI.Interval(lb, ub)) elseif -Inf == lb && ub < Inf MOI.add_constraint(model, f, MOI.LessThan(ub)) - else - @assert -Inf < lb && ub == Inf + elseif -Inf < lb && ub == Inf MOI.add_constraint(model, f, MOI.GreaterThan(lb)) + else + MOI.add_constraint(model, f, MOI.Interval(lb, ub)) end end end diff --git a/test/FileFormats/NL/data/hs071_free_constraint.nl b/test/FileFormats/NL/data/hs071_free_constraint.nl new file mode 100644 index 0000000000..aa8bc0fa28 --- /dev/null +++ b/test/FileFormats/NL/data/hs071_free_constraint.nl @@ -0,0 +1,37 @@ +g3 1 1 0 + 2 2 1 0 1 0 + 2 1 + 0 0 + 2 0 0 + 0 0 0 1 + 0 0 0 0 0 + 4 2 + 0 0 + 0 0 0 0 0 +C0 +o0 +v0 +v1 +C1 +o1 +v0 +v1 +O0 1 +n2 +r +2 25 +3 +b +3 +3 +k1 +1 +J0 2 +0 0 +1 0 +J1 2 +0 0 +1 0 +G0 2 +0 1 +1 1 diff --git a/test/FileFormats/NL/read.jl b/test/FileFormats/NL/read.jl index ae410a91ff..3628987c47 100644 --- a/test/FileFormats/NL/read.jl +++ b/test/FileFormats/NL/read.jl @@ -638,6 +638,35 @@ function test_parse_header_integrality_both_int() return end +function test_hs071_free_constraint_nlexpr() + model = NL.Model(; use_nlp_block = false) + open(joinpath(@__DIR__, "data", "hs071_free_constraint.nl"), "r") do io + return read!(io, model) + end + @test MOI.get(model, MOI.ListOfConstraintTypesPresent()) == [ + (MOI.ScalarNonlinearFunction, MOI.GreaterThan{Float64}), + (MOI.ScalarNonlinearFunction, MOI.Interval{Float64}), + ] + for (F, S) in MOI.get(model, MOI.ListOfConstraintTypesPresent()) + @test MOI.get(model, MOI.NumberOfConstraints{F,S}()) == 1 + end + F, S = MOI.ScalarNonlinearFunction, MOI.Interval{Float64} + ci = first(MOI.get(model, MOI.ListOfConstraintIndices{F,S}())) + @test MOI.get(model, MOI.ConstraintSet(), ci) == MOI.Interval(-Inf, Inf) + return +end + +function test_hs071_free_constraint() + model = NL.Model() + open(joinpath(@__DIR__, "data", "hs071_free_constraint.nl"), "r") do io + return read!(io, model) + end + block = MOI.get(model, MOI.NLPBlock()) + @test block.constraint_bounds == + [MOI.NLPBoundsPair(25.0, Inf), MOI.NLPBoundsPair(-Inf, Inf)] + return +end + function test_no_objective() model = NL.Model() open(joinpath(@__DIR__, "data", "hs071_no_objective.nl"), "r") do io