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: 10 additions & 4 deletions src/FileFormats/NL/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
60 changes: 60 additions & 0 deletions test/FileFormats/NL/data/hs071_no_objective.nl
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions test/FileFormats/NL/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down