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
14 changes: 6 additions & 8 deletions src/FileFormats/NL/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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
Expand Down
37 changes: 37 additions & 0 deletions test/FileFormats/NL/data/hs071_free_constraint.nl
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions test/FileFormats/NL/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down