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 Base.isless for sorting AbstractModelAttribute during MOI.copy_to #2369

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 4 additions & 0 deletions src/Bridges/Objective/bridges/slack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@
# Pretend that every model supports, and silently skip in set if unsupported
MOI.supports_fallback(::MOI.ModelLike, ::SlackBridgePrimalDualStart) = true

# Sort priority: SlackBridgePrimalDualStart after ObjectiveFunction
Base.isless(::SlackBridgePrimalDualStart, ::MOI.ObjectiveFunction) = false
Base.isless(::MOI.ObjectiveFunction, ::SlackBridgePrimalDualStart) = true

Check warning on line 204 in src/Bridges/Objective/bridges/slack.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Objective/bridges/slack.jl#L203-L204

Added lines #L203 - L204 were not covered by tests

function MOI.throw_set_error_fallback(
::MOI.ModelLike,
::SlackBridgePrimalDualStart,
Expand Down
26 changes: 17 additions & 9 deletions src/Utilities/copy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,22 @@

include("copy/index_map.jl")

_sort_priority(::Any) = 2
_sort_priority(::MOI.UserDefinedFunction) = 0
_sort_priority(::MOI.ObjectiveSense) = 1
function Base.isless(

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
x::MOI.AbstractModelAttribute,
y::MOI.AbstractModelAttribute,
)
# We need an arbitrary fallback comparison. Pick their `string`
# representations.
return isless("$x", "$y")

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

View check run for this annotation

Codecov / codecov/patch

src/Utilities/copy.jl#L18

Added line #L18 was not covered by tests
end

# Sort priority: ObjectiveSense before ObjectiveFunction
Base.isless(::MOI.ObjectiveSense, ::MOI.ObjectiveFunction) = true

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

View check run for this annotation

Codecov / codecov/patch

src/Utilities/copy.jl#L22

Added line #L22 was not covered by tests
Base.isless(::MOI.ObjectiveFunction, ::MOI.ObjectiveSense) = false

# Sort priority: UserDefinedFunction before ObjectiveFunction
Base.isless(::MOI.UserDefinedFunction, ::MOI.ObjectiveFunction) = true
Base.isless(::MOI.ObjectiveFunction, ::MOI.UserDefinedFunction) = false

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

View check run for this annotation

Codecov / codecov/patch

src/Utilities/copy.jl#L26-L27

Added lines #L26 - L27 were not covered by tests

"""
pass_attributes(
Expand All @@ -27,12 +40,7 @@
src::MOI.ModelLike,
index_map::IndexMap,
)
attrs = MOI.get(src, MOI.ListOfModelAttributesSet())
# We need to deal with the UserDefinedFunctions first, so that they are in
# the model before we deal with the objective function or the constraints.
# We also need `ObjectiveSense` to be set before `ObjectiveFunction`.
sort!(attrs; by = _sort_priority)
for attr in attrs
for attr in sort!(MOI.get(src, MOI.ListOfModelAttributesSet()))
if !MOI.supports(dest, attr)
if attr == MOI.Name()
continue # Skipping names is okay.
Expand Down
Loading