Skip to content

Commit

Permalink
[FileFormats.NL] fix copy_to if MOI.Name is set (#2446)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Feb 26, 2024
1 parent dcfb033 commit 41dce2e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/FileFormats/NL/NL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ function MOI.copy_to(dest::Model, model::MOI.ModelLike)
dest.sense = MOI.get(model, MOI.ObjectiveSense())
elseif !has_nlp_objective && attr isa MOI.ObjectiveFunction
dest.f = _NLExpr(MOI.get(model, attr))
elseif attr == MOI.Name()
dest.name = MOI.get(model, MOI.Name())
else
throw(MOI.UnsupportedAttribute(attr))
end
Expand Down
9 changes: 9 additions & 0 deletions test/FileFormats/NL/NL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,15 @@ J3 1
return
end

function test_copy_name_issue_2445()
src = MOI.Utilities.Model{Float64}()
MOI.set(src, MOI.Name(), "TestModel")
dest = NL.Model()
MOI.copy_to(dest, src)
@test MOI.get(dest, MOI.Name()) == "TestModel"
return
end

function runtests()
for name in names(@__MODULE__; all = true)
if startswith("$(name)", "test_")
Expand Down

0 comments on commit 41dce2e

Please sign in to comment.