Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix order of model attributes during copy_to #2372

Merged
merged 1 commit into from
Dec 21, 2023
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
7 changes: 4 additions & 3 deletions src/Utilities/copy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

include("copy/index_map.jl")

_sort_priority(::Any) = 2
_sort_priority(::MOI.UserDefinedFunction) = 0
_sort_priority(::MOI.ObjectiveSense) = 1
_sort_priority(::MOI.UserDefinedFunction) = 0.0

Check warning on line 12 in src/Utilities/copy.jl

View check run for this annotation

Codecov / codecov/patch

src/Utilities/copy.jl#L12

Added line #L12 was not covered by tests
_sort_priority(::MOI.ObjectiveSense) = 10.0
_sort_priority(::MOI.ObjectiveFunction) = 20.0
_sort_priority(::MOI.AbstractModelAttribute) = 30.0

Check warning on line 15 in src/Utilities/copy.jl

View check run for this annotation

Codecov / codecov/patch

src/Utilities/copy.jl#L15

Added line #L15 was not covered by tests

"""
pass_attributes(
Expand Down
22 changes: 22 additions & 0 deletions test/Utilities/copy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,28 @@ function test_sorted_variable_sets_by_cost_2()
return
end

function test_sorted_copy_to()
src = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}())
x = MOI.add_variable(src)
f = MOI.ScalarNonlinearFunction(:sqr, Any[x])
attr_1 = MOI.UserDefinedFunction(:sqr, 1)
attr_2 = MOI.ObjectiveSense()
attr_3 = MOI.ObjectiveFunction{typeof(f)}()
attr_4 = MOI.Name()
MOI.set(src, attr_4, "abc")
MOI.set(src, attr_1, (sqrt,))
MOI.set(src, attr_3, f)
MOI.set(src, attr_2, MOI.MAX_SENSE)
dest = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}())
index_map = MOI.copy_to(dest, src)
@test MOI.get(dest, attr_1) == (sqrt,)
@test MOI.get(dest, attr_2) == MOI.MAX_SENSE
g = MOI.ScalarNonlinearFunction(:sqr, Any[index_map[x]])
@test ≈(g, MOI.get(dest, attr_3))
@test MOI.get(dest, attr_4) == "abc"
return
end

end # module

TestCopy.runtests()
Loading