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 getter of MOI.ListOfConstraintIndices #261

Merged
merged 4 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 8 additions & 3 deletions src/MOI/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3582,21 +3582,26 @@ function MOI.get(
return sort!(indices; by = x -> x.value)
end

_function_enums(::Type{<:MOI.ScalarAffineFunction}) = (AFFINE,)
_function_enums(::Type{<:MOI.ScalarQuadraticFunction}) = (QUADRATIC,)
_function_enums(::Type{<:MOI.VectorAffineFunction}) = (INDICATOR,)
_function_enums(::Type{<:MOI.VectorOfVariables}) = (SOS, RSOC)
odow marked this conversation as resolved.
Show resolved Hide resolved

function MOI.get(
model::Optimizer,
::MOI.ListOfConstraintIndices{F,S},
) where {
S,
F<:Union{
MOI.ScalarAffineFunction{Float64},
MOI.VectorAffineFunction{Float64},
MOI.ScalarQuadraticFunction{Float64},
MOI.VectorAffineFunction{Float64},
MOI.VectorOfVariables,
},
S,
}
indices = MOI.ConstraintIndex{F,S}[]
for (key, info) in model.affine_constraint_info
if typeof(info.set) == S
if info.type in _function_enums(F) && typeof(info.set) == S
push!(indices, MOI.ConstraintIndex{F,S}(key))
end
end
Expand Down
12 changes: 12 additions & 0 deletions test/test_MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2087,6 +2087,18 @@ function test_modify_different_sparsity()
return
end

function test_ListOfConstraintIndices()
model = Xpress.Optimizer()
x = MOI.add_variable(model)
c = MOI.add_constraint(model, 1.0 * x[1], MOI.LessThan(0.0))
F, S = MOI.ScalarAffineFunction{Float64}, MOI.LessThan{Float64}
G = MOI.ScalarQuadraticFunction{Float64}
@test MOI.get(model, MOI.ListOfConstraintIndices{F,S}()) == [c]
@test isempty(MOI.get(model, MOI.ListOfConstraintIndices{G,S}()))
return
end

odow marked this conversation as resolved.
Show resolved Hide resolved

function test_ListOfConstraintTypesPresent()
model = Xpress.Optimizer()
sets = (
Expand Down
Loading