From c56d62335ace5ebbf1748f6a8754405b9542e103 Mon Sep 17 00:00:00 2001 From: odow Date: Fri, 30 Apr 2021 12:22:22 +1200 Subject: [PATCH 1/2] [breaking] Rename ListOfConstraints -> ListOfConstraintTypesPresent --- docs/src/manual/implementing.md | 2 +- docs/src/reference/models.md | 2 +- docs/src/submodules/Bridges/overview.md | 8 ++++---- src/Bridges/bridge_optimizer.jl | 5 ++++- src/FileFormats/MOF/write.jl | 2 +- src/FileFormats/utils.jl | 4 ++-- src/Test/contconic.jl | 12 ++++++------ src/Test/intconic.jl | 2 +- src/Test/modellike.jl | 18 +++++++++--------- src/Utilities/copy.jl | 9 +++++---- src/Utilities/functions.jl | 2 +- src/Utilities/model.jl | 5 ++++- src/Utilities/results.jl | 4 ++-- src/Utilities/struct_of_constraints.jl | 4 ++-- src/Utilities/universalfallback.jl | 5 ++++- src/Utilities/vector_of_constraints.jl | 2 +- src/attributes.jl | 8 ++++---- src/precompile.jl | 2 +- test/Bridges/Constraint/slack.jl | 8 ++++---- test/Bridges/Variable/free.jl | 2 +- test/Bridges/bridge_optimizer.jl | 10 +++++----- test/Bridges/utilities.jl | 5 +++-- test/Utilities/cachingoptimizer.jl | 4 ++-- test/Utilities/model.jl | 6 +++--- test/Utilities/universalfallback.jl | 2 +- 25 files changed, 72 insertions(+), 61 deletions(-) diff --git a/docs/src/manual/implementing.md b/docs/src/manual/implementing.md index f582d044d3..a5bc4c509f 100644 --- a/docs/src/manual/implementing.md +++ b/docs/src/manual/implementing.md @@ -420,7 +420,7 @@ Constraint-related attributes: | ---------------------- | --------------| ------------- | ------------------ | | [`ListOfConstraintAttributesSet`](@ref) | Yes | No | No | | [`NumberOfConstraints`](@ref) | Yes | No | No | -| [`ListOfConstraints`](@ref) | Yes | No | No | +| [`ListOfConstraintTypesPresent`](@ref) | Yes | No | No | | [`ConstraintFunction`](@ref) | Yes | Yes | No | | [`ConstraintSet`](@ref) | Yes | Yes | No | diff --git a/docs/src/reference/models.md b/docs/src/reference/models.md index a8009726c2..6eada8d2da 100644 --- a/docs/src/reference/models.md +++ b/docs/src/reference/models.md @@ -41,7 +41,7 @@ ObjectiveFunctionType ObjectiveSense NumberOfVariables ListOfVariableIndices -ListOfConstraints +ListOfConstraintTypesPresent NumberOfConstraints ListOfConstraintIndices ListOfOptimizerAttributesSet diff --git a/docs/src/submodules/Bridges/overview.md b/docs/src/submodules/Bridges/overview.md index 679c61bd7e..2de7370646 100644 --- a/docs/src/submodules/Bridges/overview.md +++ b/docs/src/submodules/Bridges/overview.md @@ -135,11 +135,11 @@ MOI.VariableIndex(1) julia> MOI.add_constraint(optimizer, MOI.SingleVariable(x), MOI.Interval(0.0, 1.0)) MathOptInterface.ConstraintIndex{MathOptInterface.SingleVariable,MathOptInterface.Interval{Float64}}(1) -julia> MOI.get(optimizer, MOI.ListOfConstraints()) +julia> MOI.get(optimizer, MOI.ListOfConstraintTypesPresent()) 1-element Array{Tuple{DataType,DataType},1}: (MathOptInterface.SingleVariable, MathOptInterface.Interval{Float64}) -julia> MOI.get(inner_optimizer, MOI.ListOfConstraints()) +julia> MOI.get(inner_optimizer, MOI.ListOfConstraintTypesPresent()) 2-element Array{Tuple{DataType,DataType},1}: (MathOptInterface.SingleVariable, MathOptInterface.GreaterThan{Float64}) (MathOptInterface.SingleVariable, MathOptInterface.LessThan{Float64}) @@ -181,11 +181,11 @@ MOI.VariableIndex(1) julia> MOI.add_constraint(optimizer, MOI.SingleVariable(x), MOI.Interval(0.0, 1.0)) MathOptInterface.ConstraintIndex{MathOptInterface.SingleVariable,MathOptInterface.Interval{Float64}}(1) -julia> MOI.get(optimizer, MOI.ListOfConstraints()) +julia> MOI.get(optimizer, MOI.ListOfConstraintTypesPresent()) 1-element Array{Tuple{DataType,DataType},1}: (MathOptInterface.SingleVariable, MathOptInterface.Interval{Float64}) -julia> MOI.get(inner_optimizer, MOI.ListOfConstraints()) +julia> MOI.get(inner_optimizer, MOI.ListOfConstraintTypesPresent()) 1-element Array{Tuple{DataType,DataType},1}: (MathOptInterface.SingleVariable, MathOptInterface.Interval{Float64}) ``` diff --git a/src/Bridges/bridge_optimizer.jl b/src/Bridges/bridge_optimizer.jl index 3949f148e4..c13c961b1c 100644 --- a/src/Bridges/bridge_optimizer.jl +++ b/src/Bridges/bridge_optimizer.jl @@ -695,7 +695,10 @@ function MOI.get( end return s end -function MOI.get(b::AbstractBridgeOptimizer, attr::MOI.ListOfConstraints) +function MOI.get( + b::AbstractBridgeOptimizer, + attr::MOI.ListOfConstraintTypesPresent, +) if Constraint.has_bridges(Constraint.bridges(b)) && Variable.has_bridges(Variable.bridges(b)) set_of_types = Constraint.list_of_key_types(Constraint.bridges(b)) diff --git a/src/FileFormats/MOF/write.jl b/src/FileFormats/MOF/write.jl index 4c22716f18..f0a2e3aba4 100644 --- a/src/FileFormats/MOF/write.jl +++ b/src/FileFormats/MOF/write.jl @@ -59,7 +59,7 @@ function write_constraints( model::Model, name_map::Dict{MOI.VariableIndex,String}, ) - for (F, S) in MOI.get(model, MOI.ListOfConstraints()) + for (F, S) in MOI.get(model, MOI.ListOfConstraintTypesPresent()) for index in MOI.get(model, MOI.ListOfConstraintIndices{F,S}()) push!(object["constraints"], moi_to_object(index, model, name_map)) end diff --git a/src/FileFormats/utils.jl b/src/FileFormats/utils.jl index 53f3de271c..a6d2d1651a 100644 --- a/src/FileFormats/utils.jl +++ b/src/FileFormats/utils.jl @@ -38,14 +38,14 @@ function create_unique_constraint_names( replacements::Vector{Function}, ) original_names = Set{String}() - for (F, S) in MOI.get(model, MOI.ListOfConstraints()) + for (F, S) in MOI.get(model, MOI.ListOfConstraintTypesPresent()) for index in MOI.get(model, MOI.ListOfConstraintIndices{F,S}()) name = MOI.get(model, MOI.ConstraintName(), index) push!(original_names, _replace(name, replacements)) end end added_names = Set{String}() - for (F, S) in MOI.get(model, MOI.ListOfConstraints()) + for (F, S) in MOI.get(model, MOI.ListOfConstraintTypesPresent()) for index in MOI.get(model, MOI.ListOfConstraintIndices{F,S}()) original_name = MOI.get(model, MOI.ConstraintName(), index) new_name = _replace( diff --git a/src/Test/contconic.jl b/src/Test/contconic.jl index dbf0a1a919..e943734ce9 100644 --- a/src/Test/contconic.jl +++ b/src/Test/contconic.jl @@ -76,7 +76,7 @@ function _lin1test(model::MOI.ModelLike, config::TestConfig, vecofvars::Bool) model, MOI.NumberOfConstraints{MOI.VectorAffineFunction{Float64},MOI.Zeros}(), ) == 1 - loc = MOI.get(model, MOI.ListOfConstraints()) + loc = MOI.get(model, MOI.ListOfConstraintTypesPresent()) @test length(loc) == 2 @test ( vecofvars ? MOI.VectorOfVariables : MOI.VectorAffineFunction{Float64}, @@ -599,7 +599,7 @@ function _norminf1test( MOI.NormInfinityCone, }(), ) == 1 - loc = MOI.get(model, MOI.ListOfConstraints()) + loc = MOI.get(model, MOI.ListOfConstraintTypesPresent()) @test length(loc) == 2 @test (MOI.VectorAffineFunction{Float64}, MOI.Zeros) in loc @test ( @@ -819,7 +819,7 @@ function norminf3test(model::MOI.ModelLike, config::TestConfig) MOI.Nonnegatives, }(), ) == 1 - loc = MOI.get(model, MOI.ListOfConstraints()) + loc = MOI.get(model, MOI.ListOfConstraintTypesPresent()) @test length(loc) == 2 @test (MOI.VectorAffineFunction{Float64}, MOI.NormInfinityCone) in loc @test (MOI.VectorAffineFunction{Float64}, MOI.Nonnegatives) in loc @@ -955,7 +955,7 @@ function _normone1test( MOI.NormOneCone, }(), ) == 1 - loc = MOI.get(model, MOI.ListOfConstraints()) + loc = MOI.get(model, MOI.ListOfConstraintTypesPresent()) @test length(loc) == 2 @test (MOI.VectorAffineFunction{Float64}, MOI.Zeros) in loc @test ( @@ -1175,7 +1175,7 @@ function normone3test(model::MOI.ModelLike, config::TestConfig) MOI.Nonnegatives, }(), ) == 1 - loc = MOI.get(model, MOI.ListOfConstraints()) + loc = MOI.get(model, MOI.ListOfConstraintTypesPresent()) @test length(loc) == 2 @test (MOI.VectorAffineFunction{Float64}, MOI.NormOneCone) in loc @test (MOI.VectorAffineFunction{Float64}, MOI.Nonnegatives) in loc @@ -1298,7 +1298,7 @@ function _soc1test(model::MOI.ModelLike, config::TestConfig, vecofvars::Bool) MOI.SecondOrderCone, }(), ) == 1 - loc = MOI.get(model, MOI.ListOfConstraints()) + loc = MOI.get(model, MOI.ListOfConstraintTypesPresent()) @test length(loc) == 2 @test (MOI.VectorAffineFunction{Float64}, MOI.Zeros) in loc @test ( diff --git a/src/Test/intconic.jl b/src/Test/intconic.jl index e36bc2fc6c..f698129ad1 100644 --- a/src/Test/intconic.jl +++ b/src/Test/intconic.jl @@ -64,7 +64,7 @@ function intsoc1test(model::MOI.ModelLike, config::TestConfig) model, MOI.NumberOfConstraints{MOI.VectorOfVariables,MOI.SecondOrderCone}(), ) == 1 - loc = MOI.get(model, MOI.ListOfConstraints()) + loc = MOI.get(model, MOI.ListOfConstraintTypesPresent()) @test length(loc) == 2 @test (MOI.VectorAffineFunction{Float64}, MOI.Zeros) in loc @test (MOI.VectorOfVariables, MOI.SecondOrderCone) in loc diff --git a/src/Test/modellike.jl b/src/Test/modellike.jl index 9d51eda101..265254eb05 100644 --- a/src/Test/modellike.jl +++ b/src/Test/modellike.jl @@ -455,7 +455,7 @@ function emptytest(model::MOI.ModelLike) model, MOI.NumberOfConstraints{MOI.VectorAffineFunction{Float64},MOI.Zeros}(), ) == 0 - @test isempty(MOI.get(model, MOI.ListOfConstraints())) + @test isempty(MOI.get(model, MOI.ListOfConstraintTypesPresent())) @test !MOI.is_valid(model, v[1]) @test !MOI.is_valid(model, vc) @@ -471,7 +471,7 @@ MOI.get(::BadModel, ::MOI.ListOfVariableIndices) = [MOI.VariableIndex(1)] function MOI.get(::BadModel, ::MOI.ListOfVariableAttributesSet) return MOI.AbstractVariableAttribute[] end -function MOI.get(::BadModel, ::MOI.ListOfConstraints) +function MOI.get(::BadModel, ::MOI.ListOfConstraintTypesPresent) return [(MOI.SingleVariable, MOI.EqualTo{Float64})] end function MOI.get(::BadModel, ::MOI.ListOfConstraintIndices{F,S}) where {F,S} @@ -496,7 +496,7 @@ function MOI.get(::BadModel, ::MOI.ListOfConstraintAttributesSet) end struct BadConstraintModel <: BadModel end -function MOI.get(::BadConstraintModel, ::MOI.ListOfConstraints) +function MOI.get(::BadConstraintModel, ::MOI.ListOfConstraintTypesPresent) return [ (MOI.SingleVariable, MOI.EqualTo{Float64}), (MOI.SingleVariable, UnknownScalarSet{Float64}), @@ -902,7 +902,7 @@ function copytest(dest::MOI.ModelLike, src::MOI.ModelLike; copy_names = false) MOI.Zeros, }(), ) == [dict[cva]] - loc = MOI.get(dest, MOI.ListOfConstraints()) + loc = MOI.get(dest, MOI.ListOfConstraintTypesPresent()) @test length(loc) == 4 @test (MOI.SingleVariable, MOI.EqualTo{Float64}) in loc @test (MOI.VectorOfVariables, MOI.Nonnegatives) in loc @@ -1151,7 +1151,7 @@ function delete_test(model::MOI.ModelLike) @test MOI.get(model, MOI.ConstraintFunction(), cy) == MOI.VectorOfVariables(y) @test MOI.get(model, MOI.ConstraintSet(), cy) == MOI.Nonpositives(4) - @test Set(MOI.get(model, MOI.ListOfConstraints())) == Set([ + @test Set(MOI.get(model, MOI.ListOfConstraintTypesPresent())) == Set([ (MOI.SingleVariable, MOI.GreaterThan{Float64}), (MOI.VectorOfVariables, MOI.Nonpositives), ]) @@ -1179,7 +1179,7 @@ function delete_test(model::MOI.ModelLike) @test MOI.get(model, MOI.ConstraintFunction(), cy) == MOI.VectorOfVariables(y[[1, 2, 4]]) @test MOI.get(model, MOI.ConstraintSet(), cy) == MOI.Nonpositives(3) - @test Set(MOI.get(model, MOI.ListOfConstraints())) == Set([ + @test Set(MOI.get(model, MOI.ListOfConstraintTypesPresent())) == Set([ (MOI.SingleVariable, MOI.GreaterThan{Float64}), (MOI.VectorOfVariables, MOI.Nonpositives), ]) @@ -1207,7 +1207,7 @@ function delete_test(model::MOI.ModelLike) @test MOI.get(model, MOI.ConstraintFunction(), cy) == MOI.VectorOfVariables(y[[2, 4]]) @test MOI.get(model, MOI.ConstraintSet(), cy) == MOI.Nonpositives(2) - @test Set(MOI.get(model, MOI.ListOfConstraints())) == Set([ + @test Set(MOI.get(model, MOI.ListOfConstraintTypesPresent())) == Set([ (MOI.SingleVariable, MOI.GreaterThan{Float64}), (MOI.VectorOfVariables, MOI.Nonpositives), ]) @@ -1233,7 +1233,7 @@ function delete_test(model::MOI.ModelLike) @test MOI.get(model, MOI.ConstraintFunction(), cy) == MOI.VectorOfVariables(y[[2, 4]]) @test MOI.get(model, MOI.ConstraintSet(), cy) == MOI.Nonpositives(2) - @test MOI.get(model, MOI.ListOfConstraints()) == + @test MOI.get(model, MOI.ListOfConstraintTypesPresent()) == [(MOI.VectorOfVariables, MOI.Nonpositives)] @test isempty( MOI.get( @@ -1256,7 +1256,7 @@ function delete_test(model::MOI.ModelLike) @test !MOI.is_valid(model, y[4]) @test !MOI.is_valid(model, cx) @test !MOI.is_valid(model, cy) - @test isempty(MOI.get(model, MOI.ListOfConstraints())) + @test isempty(MOI.get(model, MOI.ListOfConstraintTypesPresent())) @test isempty( MOI.get( model, diff --git a/src/Utilities/copy.jl b/src/Utilities/copy.jl index 74995ac7af..cff63ceb3f 100644 --- a/src/Utilities/copy.jl +++ b/src/Utilities/copy.jl @@ -526,7 +526,8 @@ function pass_constraints( end nonvariable_constraint_types = [ - (F, S) for (F, S) in MOI.get(src, MOI.ListOfConstraints()) if + (F, S) for + (F, S) in MOI.get(src, MOI.ListOfConstraintTypesPresent()) if F != MOI.SingleVariable && F != MOI.VectorOfVariables ] pass_nonvariable_constraints( @@ -576,7 +577,7 @@ function default_copy_to(dest::MOI.ModelLike, src::MOI.ModelLike) end function sorted_variable_sets_by_cost(dest::MOI.ModelLike, src::MOI.ModelLike) - constraint_types = MOI.get(src, MOI.ListOfConstraints()) + constraint_types = MOI.get(src, MOI.ListOfConstraintTypesPresent()) single_or_vector_variables_types = [ (F, S) for (F, S) in constraint_types if F === MOI.SingleVariable || F === MOI.VectorOfVariables @@ -673,7 +674,7 @@ function default_copy_to( # The `NLPBlock` assumes that the order of variables does not change (#849) if MOI.NLPBlock() in MOI.get(src, MOI.ListOfModelAttributesSet()) - constraint_types = MOI.get(src, MOI.ListOfConstraints()) + constraint_types = MOI.get(src, MOI.ListOfConstraintTypesPresent()) single_variable_types = [S for (F, S) in constraint_types if F == MOI.SingleVariable] vector_of_variables_types = @@ -1044,7 +1045,7 @@ function allocate_load( vis_src = MOI.get(src, MOI.ListOfVariableIndices()) idxmap = index_map_for_variable_indices(vis_src) - constraint_types = MOI.get(src, MOI.ListOfConstraints()) + constraint_types = MOI.get(src, MOI.ListOfConstraintTypesPresent()) single_variable_types = [S for (F, S) in constraint_types if F === MOI.SingleVariable] vector_of_variables_types = diff --git a/src/Utilities/functions.jl b/src/Utilities/functions.jl index 2a1810bd07..f8ba821fdf 100644 --- a/src/Utilities/functions.jl +++ b/src/Utilities/functions.jl @@ -806,7 +806,7 @@ function test_variablenames_equal(model, variablenames) end function test_constraintnames_equal(model, constraintnames) seen_name = Dict(name => false for name in constraintnames) - for (F, S) in MOI.get(model, MOI.ListOfConstraints()) + for (F, S) in MOI.get(model, MOI.ListOfConstraintTypesPresent()) for index in MOI.get(model, MOI.ListOfConstraintIndices{F,S}()) cname = MOI.get(model, MOI.ConstraintName(), index) if !haskey(seen_name, cname) diff --git a/src/Utilities/model.jl b/src/Utilities/model.jl index f9c7aaa0dc..e58350c398 100644 --- a/src/Utilities/model.jl +++ b/src/Utilities/model.jl @@ -625,7 +625,10 @@ function _add_contraint_type( end return end -function MOI.get(model::AbstractModel{T}, loc::MOI.ListOfConstraints) where {T} +function MOI.get( + model::AbstractModel{T}, + loc::MOI.ListOfConstraintTypesPresent, +) where {T} list = copy(MOI.get(model.constraints, loc)) for S in ( MOI.EqualTo{T}, diff --git a/src/Utilities/results.jl b/src/Utilities/results.jl index 3afd095f2a..2e65250caa 100644 --- a/src/Utilities/results.jl +++ b/src/Utilities/results.jl @@ -145,7 +145,7 @@ function get_fallback( T::Type, ) value = zero(T) # sum will not work if there are zero constraints - for (F, S) in MOI.get(model, MOI.ListOfConstraints()) + for (F, S) in MOI.get(model, MOI.ListOfConstraintTypesPresent()) value += dual_objective_value(model, F, S, T, attr.result_index)::T end if MOI.get(model, MOI.ObjectiveSense()) != MOI.MAX_SENSE @@ -436,7 +436,7 @@ function variable_dual( ) end end - for FS in MOI.get(model, MOI.ListOfConstraints()) + for FS in MOI.get(model, MOI.ListOfConstraintTypesPresent()) dual -= variable_dual(model, attr, ci, vi, FS[1], FS[2]) end return dual diff --git a/src/Utilities/struct_of_constraints.jl b/src/Utilities/struct_of_constraints.jl index d4dade254d..a3cd328d14 100644 --- a/src/Utilities/struct_of_constraints.jl +++ b/src/Utilities/struct_of_constraints.jl @@ -82,7 +82,7 @@ end function MOI.get( model::StructOfConstraints, - loc::MOI.ListOfConstraints, + loc::MOI.ListOfConstraintTypesPresent, ) where {T} return broadcastvcat(model) do v return MOI.get(v, loc) @@ -142,7 +142,7 @@ function broadcastcall end """ broadcastvcat(f::Function, model::AbstractModel) -Calls `f(contrs)` for every vector `constrs::Vector{ConstraintIndex{F, S}, F, S}` of the model and concatenate the results with `vcat` (this is used internally for `ListOfConstraints`). +Calls `f(contrs)` for every vector `constrs::Vector{ConstraintIndex{F, S}, F, S}` of the model and concatenate the results with `vcat` (this is used internally for `ListOfConstraintTypesPresent`). # Examples diff --git a/src/Utilities/universalfallback.jl b/src/Utilities/universalfallback.jl index e23bfcf611..eb7d26b96c 100644 --- a/src/Utilities/universalfallback.jl +++ b/src/Utilities/universalfallback.jl @@ -356,7 +356,10 @@ function MOI.get( ) where {F,S} return MOI.get(constraints(uf, F, S), listattr) end -function MOI.get(uf::UniversalFallback, listattr::MOI.ListOfConstraints) +function MOI.get( + uf::UniversalFallback, + listattr::MOI.ListOfConstraintTypesPresent, +) list = MOI.get(uf.model, listattr) for (S, constraints) in uf.single_variable_constraints if !isempty(constraints) diff --git a/src/Utilities/vector_of_constraints.jl b/src/Utilities/vector_of_constraints.jl index f46353dcdb..05cf605610 100644 --- a/src/Utilities/vector_of_constraints.jl +++ b/src/Utilities/vector_of_constraints.jl @@ -116,7 +116,7 @@ end function MOI.get( v::VectorOfConstraints{F,S}, - ::MOI.ListOfConstraints, + ::MOI.ListOfConstraintTypesPresent, )::Vector{Tuple{DataType,DataType}} where {F,S} return isempty(v.constraints) ? [] : [(F, S)] end diff --git a/src/attributes.jl b/src/attributes.jl index 8dba41a0ee..127e83920d 100644 --- a/src/attributes.jl +++ b/src/attributes.jl @@ -881,13 +881,13 @@ A model attribute for the number of constraints of the type `F`-in-`S` present i struct NumberOfConstraints{F,S} <: AbstractModelAttribute end """ - ListOfConstraints() + ListOfConstraintTypesPresent() A model attribute for the list of tuples of the form `(F,S)`, where `F` is a function type and `S` is a set type indicating that the attribute `NumberOfConstraints{F,S}()` has value greater than zero. """ -struct ListOfConstraints <: AbstractModelAttribute end +struct ListOfConstraintTypesPresent <: AbstractModelAttribute end """ ObjectiveFunction{F<:AbstractScalarFunction}() @@ -1628,7 +1628,7 @@ method should be defined for attributes which are copied indirectly during * [`ObjectiveFunctionType`](@ref): this attribute is set indirectly when setting the [`ObjectiveFunction`](@ref) attribute. * [`NumberOfConstraints`](@ref), [`ListOfConstraintIndices`](@ref), - [`ListOfConstraints`](@ref), [`CanonicalConstraintFunction`](@ref), + [`ListOfConstraintTypesPresent`](@ref), [`CanonicalConstraintFunction`](@ref), [`ConstraintFunction`](@ref) and [`ConstraintSet`](@ref): these attributes are set indirectly by [`add_constraint`](@ref) and [`add_constraints`](@ref). @@ -1649,7 +1649,7 @@ function is_copyable( NumberOfConstraints, ObjectiveFunctionType, ListOfConstraintIndices, - ListOfConstraints, + ListOfConstraintTypesPresent, CanonicalConstraintFunction, ConstraintFunction, ConstraintSet, diff --git a/src/precompile.jl b/src/precompile.jl index 658a472a21..23cdbaffe5 100644 --- a/src/precompile.jl +++ b/src/precompile.jl @@ -60,7 +60,7 @@ end function precompile_model(model, constraints) Base.precompile(empty!, (model,)) Base.precompile(is_empty, (model,)) - Base.precompile(get, (model, ListOfConstraints)) + Base.precompile(get, (model, ListOfConstraintTypesPresent)) Base.precompile(optimize!, (model,)) Base.precompile(add_variable, (model,)) Base.precompile(add_variables, (model, Int)) diff --git a/test/Bridges/Constraint/slack.jl b/test/Bridges/Constraint/slack.jl index 2aa7470e2d..700cc37449 100644 --- a/test/Bridges/Constraint/slack.jl +++ b/test/Bridges/Constraint/slack.jl @@ -141,11 +141,11 @@ config = MOIT.TestConfig() @test MOI.get(bridged_mock, MOI.ConstraintPrimal(), c2[]) ≈ 1.0 @test MOI.get(bridged_mock, MOI.ConstraintDual(), c2[]) ≈ 0.0 - loc = MOI.get(bridged_mock, MOI.ListOfConstraints()) + loc = MOI.get(bridged_mock, MOI.ListOfConstraintTypesPresent()) @test length(loc) == 2 @test (MOI.ScalarAffineFunction{Float64}, MOI.LessThan{Float64}) in loc @test (MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64}) in loc - loc = MOI.get(mock, MOI.ListOfConstraints()) + loc = MOI.get(mock, MOI.ListOfConstraintTypesPresent()) @test length(loc) == 3 @test (MOI.ScalarAffineFunction{Float64}, MOI.EqualTo{Float64}) in loc @test (MOI.SingleVariable, MOI.LessThan{Float64}) in loc @@ -275,11 +275,11 @@ end @test MOI.get(bridged_mock, MOI.ConstraintPrimal(), c2[]) ≈ [-100.0] @test MOI.get(bridged_mock, MOI.ConstraintDual(), c2[]) ≈ [1.0] - loc = MOI.get(bridged_mock, MOI.ListOfConstraints()) + loc = MOI.get(bridged_mock, MOI.ListOfConstraintTypesPresent()) @test length(loc) == 2 @test (MOI.VectorAffineFunction{Float64}, MOI.Nonnegatives) in loc @test (MOI.VectorAffineFunction{Float64}, MOI.Nonpositives) in loc - loc = MOI.get(mock, MOI.ListOfConstraints()) + loc = MOI.get(mock, MOI.ListOfConstraintTypesPresent()) @test length(loc) == 3 @test (MOI.VectorAffineFunction{Float64}, MOI.Zeros) in loc @test (MOI.VectorOfVariables, MOI.Nonnegatives) in loc diff --git a/test/Bridges/Variable/free.jl b/test/Bridges/Variable/free.jl index 3bd9b2c20f..7abb61e0aa 100644 --- a/test/Bridges/Variable/free.jl +++ b/test/Bridges/Variable/free.jl @@ -100,7 +100,7 @@ end ) MOIT.linear6test(bridged_mock, config) - loc = MOI.get(bridged_mock, MOI.ListOfConstraints()) + loc = MOI.get(bridged_mock, MOI.ListOfConstraintTypesPresent()) @test length(loc) == 2 @test !((MOI.VectorOfVariables, MOI.Reals) in loc) @test (MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64}) in loc diff --git a/test/Bridges/bridge_optimizer.jl b/test/Bridges/bridge_optimizer.jl index 26b176236f..4c70f1ee21 100644 --- a/test/Bridges/bridge_optimizer.jl +++ b/test/Bridges/bridge_optimizer.jl @@ -245,7 +245,7 @@ end f1 = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(3, x)], 7) c1 = MOI.add_constraint(model, f1, MOI.Interval(-1, 1)) - @test MOI.get(model, MOI.ListOfConstraints()) == + @test MOI.get(model, MOI.ListOfConstraintTypesPresent()) == [(MOI.ScalarAffineFunction{Int}, MOI.Interval{Int})] test_num_constraints( model, @@ -270,7 +270,7 @@ end f2 = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([2, -1], [x, y]), 2) c2 = MOI.add_constraint(model, f1, MOI.GreaterThan(-2)) - @test MOI.get(model, MOI.ListOfConstraints()) == [ + @test MOI.get(model, MOI.ListOfConstraintTypesPresent()) == [ (MOI.ScalarAffineFunction{Int}, MOI.GreaterThan{Int}), (MOI.ScalarAffineFunction{Int}, MOI.Interval{Int}), ] @@ -309,7 +309,7 @@ end c = MOI.add_constraint(model, f, MOI.Interval(i, 2i)) push!(scon_indices, c) - @test Set(MOI.get(model, MOI.ListOfConstraints())) == Set([ + @test Set(MOI.get(model, MOI.ListOfConstraintTypesPresent())) == Set([ (MOI.ScalarAffineFunction{Int}, MOI.GreaterThan{Int}), (MOI.ScalarAffineFunction{Int}, MOI.Interval{Int}), (MOI.SingleVariable, MOI.Interval{Int}), @@ -354,7 +354,7 @@ end c = MOI.add_constraint(model, f, MOI.Nonnegatives(1)) push!(vcon_indices, c) - @test Set(MOI.get(model, MOI.ListOfConstraints())) == Set([ + @test Set(MOI.get(model, MOI.ListOfConstraintTypesPresent())) == Set([ (MOI.ScalarAffineFunction{Int}, MOI.GreaterThan{Int}), (MOI.ScalarAffineFunction{Int}, MOI.Interval{Int}), (MOI.SingleVariable, MOI.Interval{Int}), @@ -410,7 +410,7 @@ end @test MOI.is_valid(model, c2) MOI.delete(model, c2) - @test Set(MOI.get(model, MOI.ListOfConstraints())) == Set([ + @test Set(MOI.get(model, MOI.ListOfConstraintTypesPresent())) == Set([ (MOI.ScalarAffineFunction{Int}, MOI.Interval{Int}), (MOI.SingleVariable, MOI.Interval{Int}), (MOI.VectorOfVariables, MOI.Nonnegatives), diff --git a/test/Bridges/utilities.jl b/test/Bridges/utilities.jl index dff2d713f6..6abe198b76 100644 --- a/test/Bridges/utilities.jl +++ b/test/Bridges/utilities.jl @@ -1,8 +1,9 @@ function test_num_constraints(bridged_mock, F, S, n) @test MOI.get(bridged_mock, MOI.NumberOfConstraints{F,S}()) == n @test length(MOI.get(bridged_mock, MOI.ListOfConstraintIndices{F,S}())) == n - @test ((F, S) in MOI.get(bridged_mock, MOI.ListOfConstraints())) == - !iszero(n) + @test ( + (F, S) in MOI.get(bridged_mock, MOI.ListOfConstraintTypesPresent()) + ) == !iszero(n) end function warn_incomplete_list_num_constraints(BT, list_num_constraints) diff --git a/test/Utilities/cachingoptimizer.jl b/test/Utilities/cachingoptimizer.jl index 977486f61e..6747adcde3 100644 --- a/test/Utilities/cachingoptimizer.jl +++ b/test/Utilities/cachingoptimizer.jl @@ -632,12 +632,12 @@ function constrained_variables_test(model) (MOI.SingleVariable, MOI.ZeroOne), (MOI.VectorOfVariables, MOI.Nonnegatives), ]) - @test Set(MOI.get(model.model_cache, MOI.ListOfConstraints())) == + @test Set(MOI.get(model.model_cache, MOI.ListOfConstraintTypesPresent())) == constraint_types if MOIU.state(model) == MOIU.EMPTY_OPTIMIZER MOIU.attach_optimizer(model) end - @test Set(MOI.get(model.optimizer, MOI.ListOfConstraints())) == + @test Set(MOI.get(model.optimizer, MOI.ListOfConstraintTypesPresent())) == constraint_types end diff --git a/test/Utilities/model.jl b/test/Utilities/model.jl index 4e369a324e..ca6c62b217 100644 --- a/test/Utilities/model.jl +++ b/test/Utilities/model.jl @@ -252,7 +252,7 @@ end }(), )) == [c2] - loc = MOI.get(model, MOI.ListOfConstraints()) + loc = MOI.get(model, MOI.ListOfConstraintTypesPresent()) @test length(loc) == 2 @test ( MOI.VectorQuadraticFunction{Int}, @@ -341,7 +341,7 @@ end MOI.NumberOfConstraints{MOI.VectorOfVariables,MOI.SecondOrderCone}(), ) - loc1 = MOI.get(model, MOI.ListOfConstraints()) + loc1 = MOI.get(model, MOI.ListOfConstraintTypesPresent()) loc2 = Vector{Tuple{DataType,DataType}}() function _pushloc(v::MOI.Utilities.VectorOfConstraints{F,S}) where {F,S} if !MOI.is_empty(v) @@ -494,7 +494,7 @@ end model = MOIU.Model{Float64}() x = MOI.add_variable(model) MOI.add_constraint(model, MOI.SingleVariable(x), set) - @test MOI.get(model, MOI.ListOfConstraints()) == + @test MOI.get(model, MOI.ListOfConstraintTypesPresent()) == [(MOI.SingleVariable, typeof(set))] end end diff --git a/test/Utilities/universalfallback.jl b/test/Utilities/universalfallback.jl index c1f82a37b4..648b3cd81e 100644 --- a/test/Utilities/universalfallback.jl +++ b/test/Utilities/universalfallback.jl @@ -341,7 +341,7 @@ end cy1 = MOI.add_constraint(uf, _affine(y), sets[1]) cy2 = MOI.add_constraint(uf, _affine(y), sets[2]) # check that the constraint types are in the order they were added in - @test MOI.get(uf, MOI.ListOfConstraints()) == + @test MOI.get(uf, MOI.ListOfConstraintTypesPresent()) == [(F, typeof(sets[1])), (F, typeof(sets[2]))] # check that the constraints given the constraint type are in the order they were added in for set in sets From e566497ed553e8ee4045852e433c45685ac75c69 Mon Sep 17 00:00:00 2001 From: odow Date: Fri, 30 Apr 2021 12:25:33 +1200 Subject: [PATCH 2/2] Add deprecation --- src/attributes.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/attributes.jl b/src/attributes.jl index 127e83920d..b33261028b 100644 --- a/src/attributes.jl +++ b/src/attributes.jl @@ -888,6 +888,7 @@ and `S` is a set type indicating that the attribute `NumberOfConstraints{F,S}()` has value greater than zero. """ struct ListOfConstraintTypesPresent <: AbstractModelAttribute end +@deprecate ListOfConstraints ListOfConstraintTypesPresent """ ObjectiveFunction{F<:AbstractScalarFunction}()