Skip to content

Commit 47b69c4

Browse files
authored
[FileFormats.NL] fix writing free nonlinear constraint (#2437)
1 parent 50a1284 commit 47b69c4

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/FileFormats/NL/NL.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,8 @@ function Base.write(io::IO, model::Model)
690690
println(io, " ", _str(g.upper))
691691
elseif g.opcode == 2
692692
println(io, " ", _str(g.lower))
693-
# Free constraints aren't supported for nonlinear.
694-
# elseif g.opcode == 3
695-
# println(io)
693+
elseif g.opcode == 3
694+
println(io)
696695
else
697696
@assert g.opcode == 4
698697
println(io, " ", _str(g.lower))

test/FileFormats/NL/NL.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,17 @@ function test_empty_constraint()
10901090
@test haskey(mapping, ci)
10911091
end
10921092

1093+
function test_writing_free_constraint()
1094+
model = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}())
1095+
x = MOI.add_variable(model)
1096+
f = MOI.ScalarNonlinearFunction(:log, Any[x])
1097+
MOI.add_constraint(model, f, MOI.Interval(-Inf, Inf))
1098+
n = NL.Model()
1099+
_ = MOI.copy_to(n, model)
1100+
@test occursin("r\n3\nb", sprint(write, n))
1101+
return
1102+
end
1103+
10931104
function test_malformed_constraint_error()
10941105
model = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}())
10951106
x = MOI.add_variable(model)

0 commit comments

Comments
 (0)