diff --git a/src/FileFormats/NL/read.jl b/src/FileFormats/NL/read.jl index a43604eec4..affa7ee78f 100644 --- a/src/FileFormats/NL/read.jl +++ b/src/FileFormats/NL/read.jl @@ -182,10 +182,14 @@ function _to_model(data::_CacheModel; use_nlp_block::Bool) end end MOI.set.(model, MOI.VariablePrimalStart(), x, data.variable_primal) - MOI.set(model, MOI.ObjectiveSense(), data.sense) + if data.objective != :() + MOI.set(model, MOI.ObjectiveSense(), data.sense) + end if use_nlp_block nlp = MOI.Nonlinear.Model() - MOI.Nonlinear.set_objective(nlp, data.objective) + if data.objective != :() + MOI.Nonlinear.set_objective(nlp, data.objective) + end for (i, expr) in enumerate(data.constraints) lb, ub = data.constraint_lower[i], data.constraint_upper[i] if lb == ub @@ -204,8 +208,10 @@ function _to_model(data::_CacheModel; use_nlp_block::Bool) block = MOI.NLPBlockData(evaluator) MOI.set(model, MOI.NLPBlock(), block) else - obj = _to_scalar_nonlinear_function(data.objective) - MOI.set(model, MOI.ObjectiveFunction{typeof(obj)}(), obj) + if data.objective != :() + obj = _to_scalar_nonlinear_function(data.objective) + MOI.set(model, MOI.ObjectiveFunction{typeof(obj)}(), obj) + end for (i, expr) in enumerate(data.constraints) lb, ub = data.constraint_lower[i], data.constraint_upper[i] f = _to_scalar_nonlinear_function(expr)::MOI.ScalarNonlinearFunction diff --git a/test/FileFormats/NL/data/hs071_no_objective.nl b/test/FileFormats/NL/data/hs071_no_objective.nl new file mode 100644 index 0000000000..8ebd657a09 --- /dev/null +++ b/test/FileFormats/NL/data/hs071_no_objective.nl @@ -0,0 +1,60 @@ +g3 1 1 0 + 4 2 0 0 1 0 + 2 0 + 0 0 + 4 0 0 + 0 0 0 1 + 0 0 0 2 0 + 8 0 + 0 0 + 0 0 0 0 0 +C0 +o2 +v0 +o2 +v2 +o2 +v3 +v1 +C1 +o54 +4 +o5 +v0 +n2 +o5 +v2 +n2 +o5 +v3 +n2 +o5 +v1 +n2 +x4 +0 2.1 +1 2.4 +2 2.2 +3 2.3 +r +2 25 +4 40 +b +0 1.1 5.1 +0 1.4 5.4 +0 1.2 1 +0 1.3 5.3 +k3 +2 +4 +6 +J0 4 +0 0 +1 0 +2 0 +3 0 +J1 4 +0 0 +1 0 +2 0 +3 0 diff --git a/test/FileFormats/NL/read.jl b/test/FileFormats/NL/read.jl index ed34d7d26c..1653702d52 100644 --- a/test/FileFormats/NL/read.jl +++ b/test/FileFormats/NL/read.jl @@ -638,6 +638,16 @@ function test_parse_header_integrality_both_int() return end +function test_no_objective() + model = NL.Model() + open(joinpath(@__DIR__, "data", "hs071_no_objective.nl"), "r") do io + return read!(io, model) + end + @test MOI.get(model, MOI.NumberOfVariables()) == 4 + @test MOI.get(model, MOi.ObjectiveSense()) == MOI.FEASIBILITY_SENSE + return +end + """ test_mac_minlp()