diff --git a/src/Test/test_attribute.jl b/src/Test/test_attribute.jl index a8fa9faaac..a5bb796f27 100644 --- a/src/Test/test_attribute.jl +++ b/src/Test/test_attribute.jl @@ -393,3 +393,55 @@ function test_attribute_unsupported_constraint(model::MOI.ModelLike, ::Config) end version_added(::typeof(test_attribute_unsupported_constraint)) = v"1.9.0" + +""" + test_attribute_VariableBridgingCost(model::MOI.ModelLike, config::Config) + +Test that, for every set `S` that the model claims to support via +`supports_add_constrained_variable(s)`, the corresponding +[`MOI.VariableBridgingCost`](@ref) attribute returns a finite value. + +This is the variable-side analog of the `ConstraintBridgingCost` check in +`_basic_constraint_test_helper`. + +The fallback works for most model but it may need custom method for some MOI +layers (see https://github.com/jump-dev/MathOptInterface.jl/pull/3001#issuecomment-4468198935). + +This test is here to catch that. +""" +function test_attribute_VariableBridgingCost( + model::MOI.ModelLike, + ::Config{T}, +) where {T} + for S in Any[ + MOI.GreaterThan{T}, + MOI.LessThan{T}, + MOI.EqualTo{T}, + MOI.Interval{T}, + MOI.Integer, + MOI.ZeroOne, + MOI.Semicontinuous{T}, + MOI.Semiinteger{T}, + ] + if MOI.supports_add_constrained_variable(model, S) + @test MOI.get(model, MOI.VariableBridgingCost{S}()) < Inf + end + end + for S in Any[ + MOI.Reals, + MOI.Zeros, + MOI.Nonnegatives, + MOI.Nonpositives, + MOI.SecondOrderCone, + MOI.RotatedSecondOrderCone, + MOI.ExponentialCone, + MOI.PositiveSemidefiniteConeTriangle, + ] + if MOI.supports_add_constrained_variables(model, S) + @test MOI.get(model, MOI.VariableBridgingCost{S}()) < Inf + end + end + return +end + +version_added(::typeof(test_attribute_VariableBridgingCost)) = v"1.52.0" diff --git a/src/Test/test_basic_constraint.jl b/src/Test/test_basic_constraint.jl index 0d3788d009..bacc84d8e6 100644 --- a/src/Test/test_basic_constraint.jl +++ b/src/Test/test_basic_constraint.jl @@ -253,6 +253,16 @@ function _basic_constraint_test_helper( ### @requires MOI.supports_constraint(model, F, S) ### + ### Test MOI.ConstraintBridgingCost + ### + # If `supports_constraint(F, S)` returns `true`, then the model must be + # able to handle that pair (possibly via bridging), so the bridging cost + # must be finite. The fallback works for most model but it may need + # custom method for some MOI layer (see + # https://github.com/jump-dev/MathOptInterface.jl/pull/3001#issuecomment-4468198935) + # This test is here to catch that. + @test MOI.get(model, MOI.ConstraintBridgingCost{F,S}()) < Inf + ### ### Test MOI.NumberOfConstraints ### @test MOI.get(model, MOI.NumberOfConstraints{F,S}()) == 0